import{s as B}from"./order-BSmesayL.js";import{d as O,r as p,a as Y,G as N,g as s,z as F,k as V,w as t,e as n,c as I,F as J,y as M,t as C,E as v,_ as R}from"./index-CUnFTKV2.js";const U=O({__name:"ShipDialog",props:{modelValue:{type:Boolean},sendId:{}},emits:["update:modelValue","close","success"],setup(h,{emit:y}){const i=h,m=y,u=p(i.modelValue),c=p(),d=p(!1),o=Y({courierName:"",courierNumber:"",courierCode:""}),f=[{code:"SF",name:"顺丰速运"},{code:"YTO",name:"圆通速递"},{code:"ZTO",name:"中通快递"},{code:"STO",name:"申通快递"},{code:"YD",name:"韵达快递"},{code:"HTKY",name:"百世快递"},{code:"JD",name:"京东物流"},{code:"EMS",name:"EMS"},{code:"YZPY",name:"邮政包裹"},{code:"DBL",name:"德邦快递"},{code:"JTSD",name:"极兔速递"},{code:"ZJS",name:"宅急送"}],w={courierName:[{required:!0,message:"请选择或输入物流公司",trigger:["change","blur"]},{validator:(r,e,l)=>{!e||typeof e=="string"&&e.trim()===""?l(new Error("物流公司不能为空或纯空白字符")):l()},trigger:["change","blur"]}],courierNumber:[{required:!0,message:"请输入快递单号",trigger:["change","blur"]},{validator:(r,e,l)=>{!e||typeof e=="string"&&e.trim()===""?l(new Error("快递单号不能为空或纯空白字符")):l()},trigger:["change","blur"]}]};N(()=>i.modelValue,r=>{var e;u.value=r,r&&(o.courierName="",o.courierNumber="",o.courierCode="",(e=c.value)==null||e.resetFields())}),N(u,r=>{m("update:modelValue",r)});const S=r=>{const e=f.find(l=>l.name===r);o.courierCode=(e==null?void 0:e.code)||""},k=async()=>{var r;if(i.sendId){try{await((r=c.value)==null?void 0:r.validate())}catch{return}d.value=!0;try{await B(i.sendId,{courierName:o.courierName.trim(),courierNumber:o.courierNumber.trim(),courierCode:o.courierCode||void 0}),v.success("发货成功"),u.value=!1,m("success")}catch(e){console.error("发货失败:",e),v.error(e.message||"发货失败")}finally{d.value=!1}}},_=()=>{u.value=!1,m("close")};return(r,e)=>{const l=s("el-option"),x=s("el-select"),g=s("el-form-item"),D=s("el-input"),E=s("el-form"),b=s("el-button"),T=s("el-dialog");return V(),F(T,{modelValue:u.value,"onUpdate:modelValue":e[2]||(e[2]=a=>u.value=a),title:"发货",width:"500px","close-on-click-modal":!1,onClose:_},{footer:t(()=>[n(b,{onClick:_},{default:t(()=>[...e[3]||(e[3]=[C("取消",-1)])]),_:1}),n(b,{type:"primary",loading:d.value,onClick:k},{default:t(()=>[...e[4]||(e[4]=[C(" 确认发货 ",-1)])]),_:1},8,["loading"])]),default:t(()=>[n(E,{ref_key:"formRef",ref:c,model:o,rules:w,"label-width":"100px",class:"ship-form"},{default:t(()=>[n(g,{label:"物流公司",prop:"courierName"},{default:t(()=>[n(x,{modelValue:o.courierName,"onUpdate:modelValue":e[0]||(e[0]=a=>o.courierName=a),placeholder:"请选择物流公司",filterable:"","allow-create":"",style:{width:"100%"},onChange:S},{default:t(()=>[(V(),I(J,null,M(f,a=>n(l,{key:a.code,label:a.name,value:a.name},null,8,["label","value"])),64))]),_:1},8,["modelValue"])]),_:1}),n(g,{label:"快递单号",prop:"courierNumber"},{default:t(()=>[n(D,{modelValue:o.courierNumber,"onUpdate:modelValue":e[1]||(e[1]=a=>o.courierNumber=a),placeholder:"请输入快递单号",clearable:""},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue"])}}}),L=R(U,[["__scopeId","data-v-cf6388a6"]]);export{L as default};
