UNPKG

tt-mp

Version:

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

1 lines 2.92 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 ownKeys(t,e){var i,a=Object.keys(t);return Object.getOwnPropertySymbols&&(i=Object.getOwnPropertySymbols(t),e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,i)),a}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(i),!0).forEach(function(e){_defineProperty(t,e,i[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):ownKeys(Object(i)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,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,r=2<arguments.length&&void 0!==i?i:this.data.multiple;return(0,_utils.getRealValue)(a,n,r)},updated:function(e,t){var i;this.hasFieldDecorator&&!t||(i=this.getRealValue(this.data.options,e),this.data.inputValue!==i&&this.setData({inputValue:i}))},setVisibleState:function(i,e){var a,n=this,r=1<arguments.length&&void 0!==e?e:function(){};this.data.popupVisible!==i&&(a={mounted:!0,inputValue:this.getRealValue(this.data.options,this.data.value),popupVisible:i},this.setData(i?a:{popupVisible:i},function(){var t,e;i&&(t=a.inputValue,e=n.getFieldElem(),n.hasFieldDecorator&&e&&(t=e.data.value,e.changeValue(t)),n.getBoundingClientRect(function(e){n.scrollIntoView(t,e)})),r()}))},onValueChange:function(e){var t,i,a,n;this.data.mounted&&((t=this.data).options,i=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(_objectSpread({},e.detail),{},{value:n})))))},scrollIntoView:function(e,t){var i=this.data,a=i.options,n=i.multiple,r=(0,_utils.getSelectIndex)(a,e,n),o=a.length,l=Array.isArray(r)?r[r.length-1]:r;-1!==l&&void 0!==l||(l=0);var u=1<=o?parseFloat(t/o*l):0;this.data.scrollTop!==u&&this.setData({scrollTop:u})},getBoundingClientRect:function(e){return this.selectComponent("#wux-select").getBoundingClientRect(e)}}});