2 lines
5.3 KiB
JavaScript
2 lines
5.3 KiB
JavaScript
"use strict";var e=Object.defineProperty,l=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,n=(l,o,a)=>o in l?e(l,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):l[o]=a;const u=require("../../../../common/vendor.js");if(!Array){(u.resolveComponent("wd-icon")+u.resolveComponent("wd-picker-view")+u.resolveComponent("wd-popup"))()}Math||((()=>"../wd-icon/wd-icon.js")+(()=>"../wd-picker-view/wd-picker-view.js")+(()=>"../wd-popup/wd-popup.js"))();const i=u.defineComponent((s=((e,l)=>{for(var o in l||(l={}))t.call(l,o)&&n(e,o,l[o]);if(a)for(var o of a(l))r.call(l,o)&&n(e,o,l[o]);return e})({},{name:"wd-picker",options:{virtualHost:!0,addGlobalClass:!0,styleIsolation:"shared"}}),c={props:u.pickerProps,emits:["confirm","open","cancel","update:modelValue"],setup(e,{expose:l,emit:o}){const{translate:a}=u.useTranslate("picker"),t=e,r=o,n=u.ref(null),i=u.useCell(),s=u.ref(!1),c=u.ref(!1),d=u.ref(""),p=u.ref(""),m=u.ref([]),v=u.ref([]),f=u.ref(!1),b=u.ref(!1),g=u.computed((()=>t.loading||s.value));u.watch((()=>t.displayFormat),(e=>{e&&u.isFunction(e),n.value&&0!==n.value.getSelectedIndex().length&&k(t.modelValue)}),{immediate:!0,deep:!0}),u.watch((()=>t.modelValue),(e=>{p.value=e,k(e)}),{deep:!0,immediate:!0}),u.watch((()=>t.columns),(e=>{m.value=u.deepClone(e),v.value=u.deepClone(e),k(t.modelValue)}),{deep:!0,immediate:!0}),u.watch((()=>t.columnChange),(e=>{e&&u.isFunction(e)}),{deep:!0,immediate:!0});const{parent:y}=u.useParent(u.FORM_KEY),h=u.computed((()=>y&&t.prop&&y.errorMessages&&y.errorMessages[t.prop]?y.errorMessages[t.prop]:"")),w=u.computed((()=>{let e=!1;if(y&&y.props.rules){const l=y.props.rules;for(const o in l)Object.prototype.hasOwnProperty.call(l,o)&&o===t.prop&&Array.isArray(l[o])&&(e=l[o].some((e=>e.required)))}return t.required||t.rules.some((e=>e.required))||e})),{proxy:C}=u.getCurrentInstance();function k(e){u.isArray(e)&&e.length>0||u.isDef(e)&&!u.isArray(e)&&""!==e?n.value?u.nextTick$1((()=>{j(n.value.getSelects())})):j(function(e){const l=u.formatArray(t.columns,t.valueKey,t.labelKey);if(0===t.columns.length)return;if(""===e||!u.isDef(e)||u.isArray(e)&&0===e.length)return;const o=u.getType(e);if(-1===["string","number","boolean","array"].indexOf(o))return[];0===(e=(e=u.isArray(e)?e:[e]).slice(0,l.length)).length&&(e=l.map((()=>0)));let a=[];e.forEach(((e,o)=>{let r=l[o].findIndex((l=>l[t.valueKey].toString()===e.toString()));r=-1===r?0:r,a.push(r)}));const r=a.map(((e,o)=>l[o][e]));return 1===r.length?r[0]:r}(e)):d.value=""}function _(){t.disabled||t.readonly||(r("open"),c.value=!0,p.value=t.modelValue,m.value=v.value)}function x(){c.value=!1,r("cancel")}function O(){if(g.value)return;if(f.value)return void(b.value=!0);const{beforeConfirm:e}=t;e&&u.isFunction(e)?e(p.value,(e=>{e&&V()}),C.$.exposed):V()}function V(){if(g.value||t.disabled)return void(c.value=!1);const e=n.value.getSelects(),l=n.value.getValues(),o=n.value.getColumnsData();c.value=!1,v.value=u.deepClone(o),r("update:modelValue",l),j(e),r("confirm",{value:l,selectedItems:e})}function $({value:e}){p.value=e}function j(e){if(u.isArray(e)&&!e.length||!e)return;const{valueKey:l,labelKey:o}=t;d.value=(t.displayFormat||u.defaultDisplayFormat)(e,{valueKey:l,labelKey:o})}function A(){}function S(){f.value=!0}function K(){f.value=!1,b.value&&(b.value=!1,O())}return u.onMounted((()=>{k(t.modelValue)})),u.onBeforeMount((()=>{m.value=u.deepClone(t.columns),v.value=u.deepClone(t.columns)})),l({close:function(){x()},open:function(){_()},setLoading:function(e){s.value=e}}),(e,l)=>u.e({a:e.useDefaultSlot},e.useDefaultSlot?{}:u.e({b:e.label||e.useLabelSlot},e.label||e.useLabelSlot?u.e({c:e.label},e.label?{d:u.t(e.label)}:{},{e:u.n(`wd-picker__label ${e.customLabelClass} ${w.value?"is-required":""}`),f:u.s(e.labelWidth?"min-width:"+e.labelWidth+";max-width:"+e.labelWidth+";":"")}):{},{g:u.t(d.value?d.value:e.placeholder||u.unref(a)("placeholder")),h:u.n(`wd-picker__value ${e.ellipsis&&"is-ellipsis"} ${e.customValueClass} ${d.value?"":"wd-picker__placeholder"}`),i:!e.disabled&&!e.readonly},e.disabled||e.readonly?{}:{j:u.p({"custom-class":"wd-picker__arrow",name:"arrow-right"})},{k:h.value},h.value?{l:u.t(h.value)}:{}),{m:u.o(_),n:u.t(e.cancelButtonText||u.unref(a)("cancel")),o:u.o(x),p:e.title},e.title?{q:u.t(e.title)}:{},{r:u.t(e.confirmButtonText||u.unref(a)("done")),s:u.n("wd-picker__action "+(g.value?"is-loading":"")),t:u.o(O),v:u.o(A),w:u.sr(n,"2b53a586-2,2b53a586-1",{k:"pickerViewWd"}),x:u.o($),y:u.o(S),z:u.o(K),A:u.o((e=>p.value=e)),B:u.p({"custom-class":e.customViewClass,columns:m.value,loading:g.value,"loading-color":e.loadingColor,"columns-height":e.columnsHeight,"value-key":e.valueKey,"label-key":e.labelKey,"immediate-change":e.immediateChange,"column-change":e.columnChange,modelValue:p.value}),C:u.o(x),D:u.o((e=>c.value=e)),E:u.p({position:"bottom","hide-when-close":!1,"close-on-click-modal":e.closeOnClickModal,"z-index":e.zIndex,"safe-area-inset-bottom":e.safeAreaInsetBottom,"custom-class":"wd-picker__popup",modelValue:c.value}),F:u.n(`wd-picker ${e.disabled?"is-disabled":""} ${e.size?"is-"+e.size:""} ${u.unref(i).border.value?"is-border":""} ${e.alignRight?"is-align-right":""} ${e.error?"is-error":""} ${e.customClass}`),G:u.s(e.customStyle)})}},l(s,o(c))));var s,c;const d=u._export_sfc(i,[["__scopeId","data-v-2b53a586"]]);wx.createComponent(d);
|