import{h as I,a as L,b as P}from"./exchangeStock.a63486af.js";import{r as x}from"./responseHandle.fe68d5aa.js";import{u as W}from"./useNav.5e73c372.js";import"./remote-select.36ee67a3.js";import{a as Y,r as i,W as Z,b as m,a7 as z,c as C,e as G,Z as J,j as k,h as o,f as l,u as B,x as D,l as K,am as Q,F as X,an as N}from"./index.4d061c66.js";import{_ as ee}from"./ComCard.vue_vue_type_script_setup_true_lang.ad550102.js";import{p as ae}from"./pageListModal.b8e2dd01.js";import{_ as ue}from"./ladder-table.vue_vue_type_script_setup_true_lang.61d5aa65.js";const ce=Y({__name:"add-dialog",emits:["reload"],setup(le,{expose:V,emit:A}){const{logout:E}=W(),c=i(!1),f=i("create"),b=i(null),h=i(null),n=i(!1),v=i(""),O=i(0),y=i(""),w={group_id:"",list:[]},a=i({...w}),j=Z({group_id:[{required:!0,trigger:"change",message:"\u8BF7\u9009\u62E9\u516C\u53F8\u5361\u7C7B\u578B\uFF01"}],list:[{required:!0,type:"array",trigger:"change",message:"\u9009\u62E9\u5546\u54C1\uFF01"}]}),R=async()=>{const{code:s,data:e,message:t}=await I({id:y.value});x({code:s,message:t,logout:E,handler:()=>{Object.keys(a.value).forEach(u=>{u==="flag"?a.value[u]="1":a.value[u]=e[u]?e[u]+"":""}),O.value=Number(e.inventory)}})};function U(){if(!a.value.group_id){N.warning("\u8BF7\u9009\u62E9\u516C\u53F8\u5361\u7C7B\u578B\uFF01");return}h.value.show(a.value.group_id,"1")}function $(s){s.forEach(e=>{const{good_id:t}=e;if(a.value.list.findIndex(d=>d.good_id+""==t+"")==-1){let d=Object.assign(e,{inventory:100});a.value.list.push(d)}})}async function M(s,e,t){switch(y.value=e,n.value=!0,Object.keys(a.value).forEach(u=>{a.value[u]=w[u]}),f.value=t,f.value){case"create":v.value="\u65B0\u5EFA\u5151\u6362\u5546\u54C1\u5E93\u5B58";break;case"edit":v.value="\u7F16\u8F91\u5151\u6362\u5546\u54C1\u5E93\u5B58";break;case"view":v.value="\u5151\u6362\u5546\u54C1\u5E93\u5B58\u8BE6\u60C5";break;default:v.value="\u65B0\u5EFA\u5151\u6362\u5546\u54C1\u5E93\u5B58"}c.value=!0,f.value!=="create"&&await R(),n.value=!1}function S(){return{data:{...a.value},api:L}}function T(){return{data:{...a.value},api:P}}function q(){b.value.validate(async s=>{if(s){if(n.value)return;n.value=!0;const e=f.value==="create"?T:S,{api:t,data:u}=e(),{group_id:d,list:F}=u,p={group_id:d,list:[]};let _=!0;if(F.forEach(g=>{(Number.isNaN(g.inventory)||Number(g.inventory)===0)&&(_=!1),p.list.push({good_id:g.good_id,inventory:g.inventory})}),!_){N.warning("\u90E8\u5206\u5546\u54C1\u6DFB\u52A0\u5E93\u5B58\u6570\u4E3A0\uFF01"),n.value=!1;return}const{message:r,code:H}=await t(p);n.value=!1,x({code:H,message:r,logout:E,handler:()=>{c.value=!1,A("reload")}})}})}return V({show:M}),(s,e)=>{const t=m("el-form-item"),u=m("el-col"),d=m("el-button"),F=m("el-row"),p=m("el-dialog"),_=z("loading");return C(),G(X,null,[J((C(),k(p,{modelValue:c.value,"onUpdate:modelValue":e[5]||(e[5]=r=>c.value=r),"close-on-press-escape":!1,center:"","append-to-body":"","destroy-on-close":"",width:"1040px",title:v.value},{default:o(()=>[l(B(Q),{ref_key:"formRef",ref:b,model:a.value,rules:j,"label-width":"100px",style:{"margin-top":"-10px"},class:"demo-ruleForm","status-icon":""},{default:o(()=>[l(F,null,{default:o(()=>[l(u,{span:24},{default:o(()=>[l(t,{label:"\u516C\u53F8\u5361\u7C7B\u578B",prop:"group_id"},{default:o(()=>[l(B(ee),{modelValue:a.value.group_id,"onUpdate:modelValue":e[0]||(e[0]=r=>a.value.group_id=r),disabled:f.value==="view",placeholder:"\u516C\u53F8\u5361\u7C7B\u578B",onChange:e[1]||(e[1]=r=>a.value.list=[])},null,8,["modelValue","disabled"])]),_:1})]),_:1}),l(u,{span:24},{default:o(()=>[l(t,{label:"\u5546\u54C1\u4FE1\u606F",prop:"list"},{default:o(()=>[l(ue,{readonly:!1,ladder:a.value.list,onChoose:e[2]||(e[2]=()=>U()),onDelete:e[3]||(e[3]=r=>a.value.list.splice(r,1))},null,8,["ladder"])]),_:1})]),_:1}),l(u,{span:24,class:"flex justify-end"},{default:o(()=>[f.value!=="view"?(C(),k(d,{key:0,loading:n.value,disabled:n.value,type:"primary",onClick:q},{default:o(()=>[D("\u4FDD\u5B58")]),_:1},8,["loading","disabled"])):K("",!0),l(d,{onClick:e[4]||(e[4]=r=>c.value=!1)},{default:o(()=>[D("\u53D6\u6D88")]),_:1})]),_:1})]),_:1})]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])),[[_,n.value]]),l(B(ae),{ref_key:"modelOrderRef",ref:h,onSaveBtnClick:$},null,512)],64)}}});export{ce as _};
