Files
amb_wechatapp/public/assets/vue/category-select.9fc52e6b.js
T

2 lines
2.2 KiB
JavaScript

import{_ as p}from"./index.76a66f15.js";import{a$ as s,C as m,D as _,aJ as l,b2 as i,bG as f,bo as g}from"./arco.f3c60d68.js";const y={name:"CategorySelect",props:{value:{type:[Number,String,Array],default:void 0},modelValue:{type:[Number,String,Array],default:void 0},multiple:{type:Boolean,default:!1},allowClear:{type:Boolean,default:!0},placeholder:{type:String,default:"\u8BF7\u9009\u62E9\u5546\u54C1\u5206\u7C7B"}},data(){return{treeData:[],selectedValue:this.formatValue(this.modelValue!==void 0?this.modelValue:this.value)}},watch:{value:{handler(e){this.modelValue===void 0&&(this.selectedValue=this.formatValue(e))},immediate:!0},modelValue:{handler(e){this.selectedValue=this.formatValue(e)},immediate:!0}},methods:{handleChange(e){this.$emit("input",e),this.$emit("change",e),this.$emit("update:modelValue",e)},formatValue(e){return e==null?this.multiple?[]:void 0:e},getCategoryTree(){this.$request.post("admin/app/physical/category/tree",{}).then(e=>{const t=e.data||[];this.treeData=this.processTreeData(t)}).catch(()=>{this.treeData=[]})},processTreeData(e){return e.map(t=>{const a={id:t.id,name:t.name,level:t.level||0};return t.children&&t.children.length>0&&(a.children=this.processTreeData(t.children)),a})},goCategory(){const e=this.$router.resolve({name:"physical.category"});window.open(e.href,"_blank")},refresh(){this.getCategoryTree()}},mounted(){this.getCategoryTree()}},C={class:"category-select"};function V(e,t,a,b,r,n){const d=f,c=s("icon-plus"),o=g,u=s("icon-refresh");return m(),_("div",C,[l(d,{modelValue:r.selectedValue,"onUpdate:modelValue":t[0]||(t[0]=h=>r.selectedValue=h),data:r.treeData,multiple:a.multiple,"allow-clear":a.allowClear,placeholder:a.placeholder,"field-names":{key:"id",title:"name",children:"children"},"tree-props":{defaultExpandAll:!0},style:{width:"300px"},onChange:n.handleChange},null,8,["modelValue","data","multiple","allow-clear","placeholder","onChange"]),l(o,{type:"text",onClick:n.goCategory,style:{"margin-left":"8px"}},{icon:i(()=>[l(c)]),_:1},8,["onClick"]),l(o,{type:"text",onClick:n.refresh,style:{"margin-left":"4px"}},{icon:i(()=>[l(u)]),_:1},8,["onClick"])])}const k=p(y,[["render",V],["__scopeId","data-v-70b9b019"]]);export{k as C};