2024-04-23 16:19:49 +08:00
|
|
|
import{_ as H,r as p,u as Q,b as d,c as m,d as L,w as a,h as S,t as W,e as j,f as l,l as K,D as M,g as k,E as g,j as te,q as le,k as ae,F as oe,i as ne,s as z}from"./index-3-t8Fk7s.js";import{p as re,c as ue,b as de,d as ie,e as se,s as ce,u as pe,f as _e}from"./shop-C3GBYBKO.js";const me={key:0},fe={key:1},ve={class:"dra-body"},ge=["src"],ye={__name:"add",emits:["reload"],setup(X,{expose:T,emit:A}){const i=p(!1),q={store_name:"",image:[],slider_image:[],attrValue:[{bar_code:"",price:"",stock:"",cost:"",ot_price:"",wholesale_price:"0",extension_one:"",extension_two:""}],content:{image:[]},unit_name:"",delivery_way:["1"]},n=p(q),U=Q(),D=A,_=p(!1),R=p(""),P=t=>{R.value=t.url,_.value=!0},N=p("add"),I=(t,e)=>{n.value=q,N.value=t,t=="add"?i.value=!0:t=="edit"&&(i.value=!0,v(e.product_id))},v=t=>{re(U.userInfo.service.mer_id,t).then(e=>{var f;e.data.image=[{url:e.data.image,uid:e.data.image}],(f=e.data.content)!=null&&f.image?e.data.content.image=e.data.content.image.map(s=>({url:s,uid:e.data.image})):e.data.content={image:[]},e.data.slider_image=e.data.slider_image.map(s=>({url:s,uid:e.data.image})),n.value=e.data,console.log(n.value)})},B=p([]);(()=>{ue(U.userInfo.service.mer_id).then(t=>{B.value=t.data})})();const E=p(null),O=()=>{var e,f,s,y,h,C;let t=JSON.parse(JSON.stringify(n.value));if(console.log(t.cate_id),t.cate_id&&typeof t.cate_id=="object"&&t.cate_id.length>0?t.cate_id=t.cate_id[t.cate_id.length-1]||"":t.cate_id=t.cate_id||"",t.image=="")return g.error("请上传商品封面图");if(t.slider_image.length==0)return g.error("请上传商品轮播图");if(t.content.image=t.content.image.map(r=>{var c,w,V,b;return(w=(c=r==null?void 0:r.response)==null?void 0:c.data)!=null&&w.path?(b=(V=r==null?void 0:r.response)==null?void 0:V.data)==null?void 0:b.path:r.url}),t.image=(s=(f=(e=t.image[0])==null?void 0:e.response)==null?void 0:f.data)!=null&&s.path?(C=(h=(y=t.image[0])==null?void 0:y.response)==null?void 0:h.data)==null?void 0:C.path:t.image[0].url,t.slider_image=t.slider_image.map(r=>{var c,w,V,b;return(w=(c=r==null?void 0:r.response)==null?void 0:c.data)!=null&&w.path?(b=(V=r==null?void 0:r.response)==null?void 0:V.data)==null?void 0:b.path:r.url}),t.store_name=="")return g.error("请输入商品名称");if(t.cate_id=="")return g.error("请选择平台分类");if(t.attrValue[0].bar_code=="")return g.error("请输入商品条码");if(t.attrValue[0].stock<=0)return g.error("请输入商品库存");if(t.attrValue[0].price<=0)return g.error("请输入商品价格");N.value=="add"?de(U.userInfo.service.mer_id,t).then(r=>{g.success(r.message),D("reload",!0),$()}):ie(U.userInfo.service.mer_id,t.product_id,t).then(r=>{g.success(r.message),D("reload",!0),$()})},J=()=>{$()},$=()=>{i.value=!1},F=()=>{};return T({drawer:i,show:I}),(t,e)=>{const f=d("el-input"),s=d("el-form-item"),y=d("el-cascader"),h=d("Plus"),C=d("el-icon"),r=d("el-upload"),c=d("el-form"),w=d("el-dialog"),V=d("el-button"),b=d("el-drawer");return m(),L(b,{size:"60rem",modelValue:i.value,"onUpdate:modelValue":e[10]||(e[10]=u=>i.value=u),direction:"rtl",onOpen:F,"before-close":$},{header:a(()=>[N.value=="add"?(m(),S("h4",me,"添加商品")):(m(),S("h4",fe,"编辑商品 ["+W(n.value.product_id)+"]",1))]),default:a(()=>[j("div",ve,[l(c,{ref_key:"formRef",ref:E,model:n.value,"label-width":"150px"},{default:a(()=>[l(s,{label:"商品条码",required:""},{default:a(()=>[l(f,{modelValue:n.value.attrValue[0].bar_code,"onUpdate:modelValue":e[0]||(e[0]=u=>n.value.attrValue[0].bar_code=u),type:"number",placeholder:"请输入商品条码"},null,8,["modelValue"])]),_:1}),l(s,{label:"商品名称",required:""},{default:a(()=>[l(f,{modelValue:n.value.store_name,"onUpdate:modelValue":e[1]||(e[1]=u=>n.value.store_name=u),placeholder:"请输入商品名称"},null,8,["modelValue"])]),_:1}),l(s,{label:"平台分类",required:""},{default:a(()=>[l(y,{modelValue:n.value.cate_id,"onUpdate:modelValue":e[2]||(e[2]=u=>n.value.cate_id=u),class:"pageWidth",options:B.value,filterable:"",clearable:""},null,8,["modelValue","options"])]),_:1}),l(s,{label:"商品封面图",required:""},{default
|