forked from nsjcy/frontEnd/nsjcy

LAPTOP-RI7D261L\Mr Ke
2020-02-13 a2789abb73725738127b03d95c95081b66954916
1
"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/classNames")),_arrayTreeFilter=_interopRequireDefault(require("../helpers/arrayTreeFilter")),_props=require("../multi-picker-view/props");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}function ownKeys(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(r,!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}(0,_baseComponent.default)({properties:_objectSpread({},_props.props,{cols:{type:Number,value:3}}),data:{inputValue:[],showOptions:[],fieldNames:_props.defaultFieldNames},observers:_defineProperty({inputValue:function(e){var r=this.getFieldName("value"),n=this.getFieldName("label"),t=this.getShowOptions(e).reduce(function(e,t){return[].concat(_toConsumableArray(e),[t.map(function(e){var t;return _defineProperty(t={},r,e[r]),_defineProperty(t,n,e[n]),_defineProperty(t,"disabled",!!e.disabled),t})])},[]);this.setData({showOptions:t})}},"value, options, cols",function(e,t,r){this.setValue(e,t,r)}),methods:{updated:function(e){this.data.inputValue!==e&&this.setData({inputValue:e})},setValue:function(e,t,r){var n=0<arguments.length&&void 0!==e?e:this.data.inputValue,i=1<arguments.length&&void 0!==t?t:this.data.options,a=2<arguments.length&&void 0!==r?r:this.data.cols,o=this.getRealValue(i,n,a);this.updated(o)},onValueChange:function(e){var t=e.detail,r=t.value,n=t.index,i=this.getNextValue(r,n),a=this.getRealValue(this.data.options,i),o=this.getValue(a);this.updated(a),this.triggerEvent("valueChange",_objectSpread({},o,{index:n}))},getValue:function(e){var t=0<arguments.length&&void 0!==e?e:this.data.inputValue,r=this.getRealValue(this.data.options,t),n=this.getShowOptions(r);return this.picker=this.picker||this.selectComponent("#wux-picker"),this.picker.getValue(r,n)},getNextValue:function(r,n){for(var e=this.data.options,i=this.getFieldName("value"),t=this.getFieldName("children"),a=(0,_arrayTreeFilter.default)(e,function(e,t){return t<=n&&e[i]===r[t]},{childrenKeyName:t})[n],o=n+1;o<this.data.cols;)a&&a[t]&&a[t].length&&(a=a[t][0],r[o]=a[i]),o++;return r.length=o,r},getRealValue:function(o,u,e){var l=this,s=2<arguments.length&&void 0!==e?e:this.data.cols;if(!u||!u.length||-1<u.indexOf(void 0)||u.length!==s){var t=function(){for(var t=l.getFieldName("value"),e=l.getFieldName("children"),r=[],n=_toConsumableArray(o),i=0;i<s;){if(n&&n.length){r[i]=u[i]||n[0][t];var a=0;r[i]&&-1===(a=n.map(function(e){return e[t]}).indexOf(r[i]))&&(a=0,r[i]=n[0][t]),n=n[a][e]}i++}return{v:r}}();if("object"===_typeof(t))return t.v}return u},getActiveOptions:function(r){var e=this.data.options,n=this.getFieldName("value"),t=this.getFieldName("children");return(0,_arrayTreeFilter.default)(e,function(e,t){return e[n]===r[t]},{childrenKeyName:t})},getShowOptions:function(e){var t=this.data,r=t.options,n=t.cols,i=this.getFieldName("children"),a=this.getActiveOptions(e).map(function(e){return e[i]}).filter(function(e){return!!e});return[r].concat(_toConsumableArray(a)).filter(function(e,t){return t<n})},getFieldName:function(e){return this.data.fieldNames[e]}},attached:function(){var e=this.data,t=e.value,r=e.options,n=e.cols,i=Object.assign({},_props.defaultFieldNames,this.data.defaultFieldNames);this.setData({fieldNames:i}),this.setValue(t,r,n)}});