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