epmet 工作端 小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1 lines
7.0 KiB

"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames2=_interopRequireDefault(require("../helpers/classNames")),_styleToCssString=_interopRequireDefault(require("../helpers/styleToCssString")),_arrayTreeFilter=_interopRequireDefault(require("../helpers/arrayTreeFilter"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,i)}return a}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(a,!0).forEach(function(e){_defineProperty(t,e,a[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):ownKeys(a).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))})}return t}function _objectWithoutProperties(e,t){if(null==e)return{};var a,i,r=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(i=0;i<n.length;i++)a=n[i],0<=t.indexOf(a)||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var a,i,r={},n=Object.keys(e);for(i=0;i<n.length;i++)a=n[i],0<=t.indexOf(a)||(r[a]=e[a]);return r}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,a=new Array(e.length);t<e.length;t++)a[t]=e[t];return a}}function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}var WUX_CASCADER_VIEW="wux-cascader-view",defaultFieldNames={label:"label",value:"value",children:"children",disabled:"disabled"};(0,_baseComponent.default)({externalClasses:["wux-scroll-view-class"],properties:{prefixCls:{type:String,value:"wux-cascader-view"},defaultValue:{type:Array,value:[]},value:{type:Array,value:[]},controlled:{type:Boolean,value:!1},options:{type:Array,value:[]},full:{type:Boolean,value:!1},placeholder:{type:String,value:"请选择"},height:{type:[String,Number],value:"auto"},defaultFieldNames:{type:Object,value:defaultFieldNames},skipAnimation:{type:Boolean,value:!1}},data:{activeOptions:[],activeIndex:0,bodyStyle:"",activeValue:[],showOptions:[],fieldNames:void 0,scrollViewStyle:""},computed:{classes:["prefixCls, full",function(e,t){return{wrap:(0,_classNames2.default)(e),hd:"".concat(e,"__hd"),bd:"".concat(e,"__bd"),innerScroll:(0,_classNames2.default)("".concat(e,"__inner-scroll"),_defineProperty({},"".concat(e,"__inner-scroll--full"),t)),scrollView:"".concat(e,"__scroll-view"),ft:"".concat(e,"__ft")}}]},observers:{value:function(e){this.data.controlled&&(this.setData({activeValue:e}),this.getCurrentOptions(e))},options:function(){this.getCurrentOptions(this.data.activeValue)},height:function(e){this.updateStyle(e)}},methods:{getActiveOptions:function(a){var e=this.data.options,i=this.getFieldName("value"),t=this.getFieldName("children");return(0,_arrayTreeFilter.default)(e,function(e,t){return e[i]===a[t]},{childrenKeyName:t})},getShowOptions:function(e){var t=this.data.options,a=this.getFieldName("children"),i=this.getActiveOptions(e).map(function(e){return e[a]}).filter(function(e){return!!e});return[t].concat(_toConsumableArray(i))},getMenus:function(e,t){var a=0<arguments.length&&void 0!==e?e:[],i=1<arguments.length?t:void 0,r=this.data.placeholder,n=this.getActiveOptions(a);if(i){var o,l=this.getFieldName("value"),s=this.getFieldName("label");n.push((_defineProperty(o={},l,WUX_CASCADER_VIEW),_defineProperty(o,s,r),o))}return n},getNextActiveValue:function(e,t){var a=this.data.activeValue;return(a=a.slice(0,t+1))[t]=e,a},updated:function(e,t,a,i){var r=this.getFieldName("value"),n=this.getFieldName("children"),o=e&&e[n]&&0<e[n].length,l=this.getNextActiveValue(e[r],t),s=this.getMenus(l,o),u=s.length-1,c=this.getShowOptions(l),d={activeValue:l,activeOptions:s,activeIndex:u,showOptions:c};(o||l.length===c.length&&(t=Math.max(0,t-1)))&&(d.bodyStyle=this.getTransform(t+1),d.showOptions=c),a&&this.setCascaderView(d),"function"==typeof i&&i.call(this,e,l)},getCurrentOptions:function(e){var t=0<arguments.length&&void 0!==e?e:this.data.activeValue,a=Math.max(0,t.length-1),i=this.getActiveOptions(t),r=i[a];if(r)this.updated(r,a,!0);else{var n,o=this.getFieldName("value"),l=this.getFieldName("label");i.push((_defineProperty(n={},o,WUX_CASCADER_VIEW),_defineProperty(n,l,this.data.placeholder),n));var s={showOptions:this.getShowOptions(t),activeOptions:i,activeIndex:i.length-1,bodyStyle:""};this.setCascaderView(s)}},setCascaderView:function(e){var t=this,a=e.activeOptions,i=_objectWithoutProperties(e,["activeOptions"]);this.setData({activeOptions:a},function(){t.data.activeIndex!==i.activeIndex&&t.triggerEvent("tabsChange",{index:i.activeIndex}),t.setData(i)})},getTransform:function(e,t){var a=1<arguments.length&&void 0!==t?t:!this.data.skipAnimation,i=this.data.full?2:1,r=this.data.full?e:e-1;return(0,_styleToCssString.default)({transition:a?"transform .3s":"none",transform:"translate(".concat(-50*i*Math.max(0,r),"%)")})},onTabsChange:function(e){var t=parseInt(e.detail.key),a=this.getTransform(t);this.data.bodyStyle===a&&this.data.activeIndex===t||(this.setData({bodyStyle:a,activeIndex:t}),this.triggerEvent("tabsChange",{index:t}))},onItemSelect:function(e){var t=e.currentTarget.dataset.optionIndex,a=e.detail.index,i=this.data.showOptions[t][a];this.updated(i,t,!this.data.controlled,this.onChange)},onChange:function(e,t){var a=0<arguments.length&&void 0!==e?e:{},i=1<arguments.length&&void 0!==t?t:[],r=this.getValue(i);if(a&&!1===a.isLeaf&&!a.children)return this.triggerEvent("change",_objectSpread({},r)),void this.triggerEvent("load",{value:r.value,options:r.options});this.triggerEvent("change",_objectSpread({},r))},getValue:function(e){var t=0<arguments.length&&void 0!==e?e:this.data.activeValue,a=Math.max(0,t.length-1),i=this.getActiveOptions(t),r=i[a],n=this.getFieldName("value"),o=this.getFieldName("children"),l=r&&r[o]&&0<r[o].length,s=i.filter(function(e){return e[n]!==WUX_CASCADER_VIEW}),u=s.map(function(e){return e[n]});return r&&!1===r.isLeaf&&!r.children?{value:u,options:s,done:!1}:{value:u,options:s,done:!l}},getFieldName:function(e){var t=this.data,a=t.defaultFieldNames,i=t.fieldNames;return void 0!==i?i[e]:a[e]},updateStyle:function(e){var t=(0,_styleToCssString.default)({height:e,minHeight:e});this.data.scrollViewStyle!==t&&this.setData({scrollViewStyle:t})}},attached:function(){var e=this.data,t=e.defaultValue,a=e.value,i=e.controlled,r=e.height,n=i?a:t,o=Object.assign({},defaultFieldNames,this.data.defaultFieldNames);this.setData({activeValue:n,fieldNames:o}),this.getCurrentOptions(n),this.updateStyle(r)}});