| | |
| | | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
| | | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
| | | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
| | | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
| | | return c > 3 && r && Object.defineProperty(target, key, r), r; |
| | | }; |
| | | import { SuperComponent, wxComponent } from '../common/src/index'; |
| | | import config from '../common/config'; |
| | | import props from './props'; |
| | | const { prefix } = config; |
| | | const name = `${prefix}-picker`; |
| | | let Picker = class Picker extends SuperComponent { |
| | | constructor() { |
| | | super(...arguments); |
| | | this.properties = props; |
| | | this.externalClasses = [`${prefix}-class`, `${prefix}-class-confirm`, `${prefix}-class-cancel`, `${prefix}-class-title`]; |
| | | this.options = { |
| | | multipleSlots: true, |
| | | }; |
| | | this.relations = { |
| | | '../picker-item/picker-item': { |
| | | type: 'child', |
| | | linked() { |
| | | this.updateChildren(); |
| | | }, |
| | | }, |
| | | }; |
| | | this.observers = { |
| | | value() { |
| | | this.updateChildren(); |
| | | }, |
| | | keys(obj) { |
| | | this.setData({ |
| | | labelAlias: obj.label || 'label', |
| | | valueAlias: obj.value || 'value', |
| | | }); |
| | | }, |
| | | }; |
| | | this.data = { |
| | | prefix, |
| | | classPrefix: name, |
| | | labelAlias: 'label', |
| | | valueAlias: 'value', |
| | | defaultPopUpProps: {}, |
| | | defaultPopUpzIndex: 11500, |
| | | }; |
| | | this.methods = { |
| | | updateChildren() { |
| | | const { value } = this.properties; |
| | | this.$children.forEach((child, index) => { |
| | | var _a; |
| | | child.setData({ |
| | | value: (_a = value === null || value === void 0 ? void 0 : value[index]) !== null && _a !== void 0 ? _a : '', |
| | | }); |
| | | child.update(); |
| | | }); |
| | | }, |
| | | getSelectedValue() { |
| | | const value = this.$children.map((item) => item._selectedValue); |
| | | const label = this.$children.map((item) => item._selectedLabel); |
| | | return [value, label]; |
| | | }, |
| | | getColumnIndexes() { |
| | | const columns = this.$children.map((pickerColumn, columnIndex) => { |
| | | return { |
| | | column: columnIndex, |
| | | index: pickerColumn._selectedIndex, |
| | | }; |
| | | }); |
| | | return columns; |
| | | }, |
| | | onConfirm() { |
| | | const [value, label] = this.getSelectedValue(); |
| | | const columns = this.getColumnIndexes(); |
| | | this.close('confirm-btn'); |
| | | this.triggerEvent('change', { value, label, columns }); |
| | | this.triggerEvent('confirm', { value, label, columns }); |
| | | }, |
| | | triggerColumnChange({ column, index }) { |
| | | const [value, label] = this.getSelectedValue(); |
| | | this.triggerEvent('pick', { value, label, column, index }); |
| | | }, |
| | | onCancel() { |
| | | this.close('cancel-btn'); |
| | | this.triggerEvent('cancel'); |
| | | }, |
| | | onPopupChange(e) { |
| | | const { visible } = e.detail; |
| | | this.close('overlay'); |
| | | this.triggerEvent('visible-change', { visible }); |
| | | }, |
| | | close(trigger) { |
| | | if (this.data.autoClose) { |
| | | this.setData({ visible: false }); |
| | | } |
| | | this.triggerEvent('close', { trigger }); |
| | | }, |
| | | }; |
| | | } |
| | | ready() { |
| | | this.$children.map((column, index) => (column.columnIndex = index)); |
| | | } |
| | | }; |
| | | Picker = __decorate([ |
| | | wxComponent() |
| | | ], Picker); |
| | | export default Picker; |
| | | import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";import useCustomNavbar from"../mixins/using-custom-navbar";const{prefix:prefix}=config,name=`${prefix}-picker`;let Picker=class extends SuperComponent{constructor(){super(...arguments),this.behaviors=[useCustomNavbar],this.properties=props,this.externalClasses=[`${prefix}-class`,`${prefix}-class-confirm`,`${prefix}-class-cancel`,`${prefix}-class-title`],this.options={multipleSlots:!0},this.relations={"../picker-item/picker-item":{type:"child",linked(){this.updateChildren()}}},this.observers={"value, visible"(e,t){t&&(this.updateChildren(),this.updateIndicatorPosition())},"itemHeight, visibleItemCount"(){this.updateIndicatorPosition()}},this.data={prefix:prefix,classPrefix:name,defaultPopUpProps:{},defaultPopUpzIndex:11500,indicatorTop:72},this.methods={updateChildren(){const{value:e,defaultValue:t,itemHeight:i,visibleItemCount:s}=this.properties;this.$children.forEach((o,n)=>{var r,l;o.setData({value:null!==(l=null!==(r=null==e?void 0:e[n])&&void 0!==r?r:null==t?void 0:t[n])&&void 0!==l?l:"",columnIndex:n,itemHeight:i,visibleItemCount:s}),o.update()})},getSelectedValue(){return[this.$children.map(e=>e._selectedValue),this.$children.map(e=>e._selectedLabel)]},getColumnIndexes(){return this.$children.map((e,t)=>({column:t,index:e._selectedIndex}))},onConfirm(){const e=[],t=[],i=[];this.$children.forEach((s,o)=>{const n=s.getCurrentSelected();e.push(n.value),t.push(n.label),i.push({column:o,index:n.index})}),this.close("confirm-btn"),this.triggerEvent("confirm",{value:e,label:t,columns:i}),JSON.stringify(this.data.value)!==JSON.stringify(e)&&this.triggerEvent("change",{value:e,label:t,columns:i})},triggerColumnChange({column:e,index:t}){const[i,s]=this.getSelectedValue();this.triggerEvent("pick",{value:i,label:s,column:e,index:t})},onCancel(){this.close("cancel-btn"),this.triggerEvent("cancel")},onPopupChange(e){const{visible:t}=e.detail;this.close("overlay"),this.triggerEvent("visible-change",{visible:t})},close(e){this.data.autoClose&&this.setData({visible:!1}),this.triggerEvent("close",{trigger:e})},updateIndicatorPosition(){const{itemHeight:e,visibleItemCount:t}=this.properties,i=(t-1)/2*e;this.setData({indicatorTop:i})}}}ready(){this.$children.map((e,t)=>e.columnIndex=t),this.updateIndicatorPosition()}};Picker=__decorate([wxComponent()],Picker);export default Picker; |