UNPKG

wux-weapp

Version:

一套组件化、可复用、易扩展的微信小程序 UI 组件库

1 lines 2.73 kB
"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_popupMixin=_interopRequireDefault(require("../helpers/popupMixin")),_utils=require("./utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _objectSpread(t){for(var e=1;e<arguments.length;e++)if(e%2){var i=null!=arguments[e]?arguments[e]:{},a=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),a.forEach(function(e){_defineProperty(t,e,i[e])})}else Object.defineProperties(t,Object.getOwnPropertyDescriptors(arguments[e]));return t}function _defineProperty(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}(0,_baseComponent.default)({behaviors:[(0,_popupMixin.default)("#wux-select")],properties:{prefixCls:{type:String,value:"wux-select"},value:{type:[String,Array],value:""},options:{type:Array,value:[]},multiple:{type:Boolean,value:!1},max:{type:Number,value:-1}},data:{scrollTop:0},observers:_defineProperty({},"options, multiple",function(e,t){this.setData({inputValue:this.getRealValue(e,this.data.inputValue,t)})}),methods:{getRealValue:function(e,t,i){var a=0<arguments.length&&void 0!==e?e:this.data.options,n=1<arguments.length&&void 0!==t?t:this.data.inputValue,l=2<arguments.length&&void 0!==i?i:this.data.multiple;return(0,_utils.getRealValue)(a,n,l)},updated:function(e,t){if(!this.hasFieldDecorator||t){var i=this.getRealValue(this.data.options,e);this.data.inputValue!==i&&this.setData({inputValue:i})}},setVisibleState:function(i,e){var a=this,n=1<arguments.length&&void 0!==e?e:function(){};if(this.data.popupVisible!==i){var l={mounted:!0,inputValue:this.getRealValue(this.data.options,this.data.value),popupVisible:i};this.setData(i?l:{popupVisible:i},function(){if(i){var t=l.inputValue,e=a.getFieldElem();a.hasFieldDecorator&&e&&(t=e.data.value,e.changeValue(t)),a.getBoundingClientRect(function(e){a.scrollIntoView(t,e)})}n()})}},onValueChange:function(e){if(this.data.mounted){var t=this.data,i=(t.options,t.max),a=t.multiple,n=e.detail.selectedValue;a&&1<=i&&i<n.length||(this.setScrollValue(n),this.updated(n,!0),this.triggerEvent("valueChange",this.formatPickerValue(_objectSpread({},e.detail,{value:n}))))}},scrollIntoView:function(e,t){var i=this.data,a=i.options,n=i.multiple,l=(0,_utils.getSelectIndex)(a,e,n),o=a.length,r=Array.isArray(l)?l[l.length-1]:l;-1!==r&&void 0!==r||(r=0);var u=1<=o?parseFloat(t/o*r):0;this.data.scrollTop!==u&&this.setData({scrollTop:u})},getBoundingClientRect:function(e){return this.selectComponent("#wux-select").getBoundingClientRect(e)}}});