import{p as M,G as P,E as $}from"./el-button-b67915d8.js";import{a as A,b as D,E as O}from"./el-breadcrumb-item-762e8056.js";import{E as G,a as K}from"./el-form-item-07a15cb5.js";import{E as Q}from"./el-progress-4ca8ef53.js";import"./el-icon-08628b36.js";import{a as X,u as Z,b as H,E as J}from"./product-f5a3d530.js";import{E as W}from"./el-input-5189b047.js";import"./el-scrollbar-5edfcb3f.js";import"./el-tag-d3d38fd0.js";import{a1 as Y,Z as ee,q as n,z as ae,v as te,L as oe,o as v,f as k,M as u,Q as a,w as l,N as d,c as le,a as C,O as re}from"./index-b2bcea28.js";import{C as se}from"./ckeditor-140c1ad2.js";import{g as ne}from"./category-c7be7113.js";import{u as ie}from"./request-88e5850c.js";import{E as p}from"./el-message-447d52b9.js";import{_ as ue}from"./_plugin-vue_export-helper-c27b6911.js";import"./castArray-8eb82dce.js";import"./index-07bb2cc4.js";import"./_baseClone-49d9099a.js";import"./cloneDeep-996df659.js";import"./strings-31e22773.js";import"./aria-60e0cdc6.js";import"./index-8ca69aa2.js";const de={class:"main"},pe={class:"breadcrumb-section"},me=["src"],ce={class:""},fe={class:"demo-drawer__footer",style:{"text-align":"right","margin-top":"20px"}},_e={__name:"form",setup(ge){const f=Y(),_=ee(),V=se,w=n({simpleUpload:{uploadUrl:"https://prodio.zltest.com.tw/adminapi/article/uploadImage",headers:{"X-CSRF-TOKEN":"CSFR-Token",Authorization:`${sessionStorage.getItem("token")}`}},image:{resize:!0,toolbar:["imageTextAlternative","|","imageStyle:alignLeft","imageStyle:alignRight","|","imageStyle:alignBlockLeft","imageStyle:block","imageStyle:alignBlockRight"],styles:["full","alignLeft","alignRight"]}}),S={emitPath:!1},y=n("insert"),b=n([]),m=n(!1),E=n(null),t=n({id:0,cat_id:0,name:"",imageurl:"",description:"",content:""});ae(async()=>{let o=await ne();if(o.code===200&&(b.value=o.data.map(e=>({value:e.id,label:e.name,children:e.children.map(r=>({value:r.id,label:r.name}))}))),f.query.id){let e=await X(f.query.id);e.code===200?(t.value=e.data,y.value="update"):(p({message:"取得資料失敗.",type:"error"}),_.push("/product/list"))}});const U=te({name:[{required:!0,message:"產品名稱必填",trigger:"blur"}],cat_id:[{required:!0,message:"產品類別必填",trigger:"change"}]}),x=()=>{_.push("/product/list")},B=o=>{o&&o.validate(async e=>{if(e){let r,i;y.value==="update"?(t.value.id=f.query.id,r=await Z(t.value),i="修改成功."):(r=await H(t.value),i="新增成功."),r.code===200&&(p({message:i,type:"success"}),_.push("/product/list"))}else return p({message:"操作失敗.",type:"error"}),!1})},I=o=>o.type!=="image/jpeg"&&o.type!=="image/png"&&o.type!=="image/jpg"?(p.error("圖片格式只能是jpeg/png/jpg!"),!1):!0,R=async o=>{const e=new FormData;e.append("file",o.file),e.append("fileType","IMAGE"),m.value=!0;let r=await ie("/product/uploadImage",e);r.code===200?t.value.imageurl=r.data:p.error("上傳失敗"),m.value=!1},q=(o,e)=>{};return(o,e)=>{const r=A,i=D,g=P,h=W,c=G,F=J,T=$,L=Q,N=oe("ckeditor"),j=K,z=O;return v(),k("div",de,[u("div",pe,[u("div",null,[a(i,{separator:"/"},{default:l(()=>[a(r,null,{default:l(()=>[d(" 產品管理 ")]),_:1}),a(r,null,{default:l(()=>[d(" 產品表單 ")]),_:1})]),_:1})]),u("div",null,[a(g,{type:"primary",onClick:e[0]||(e[0]=s=>o.$router.back())},{default:l(()=>[d("回產品列表")]),_:1})])]),a(z,null,{default:l(()=>[a(j,{ref_key:"formRef",ref:E,model:t.value,"status-icon":"",rules:U,"label-width":"120px"},{default:l(()=>[a(c,{label:"產品名稱",prop:"name"},{default:l(()=>[a(h,{modelValue:t.value.name,"onUpdate:modelValue":e[1]||(e[1]=s=>t.value.name=s)},null,8,["modelValue"])]),_:1}),a(c,{label:"產品類別",prop:"cat_id"},{default:l(()=>[a(F,{modelValue:t.value.cat_id,"onUpdate:modelValue":e[2]||(e[2]=s=>t.value.cat_id=s),options:b.value,props:S,onChange:o.handleChange},null,8,["modelValue","options","onChange"])]),_:1}),a(c,{label:"產品圖片",prop:"imageurl"},{default:l(()=>[a(L,{class:"avatar-uploader",action:"#",accept:"image/*","http-request":R,"show-file-list":!1,"auto-upload":!0,"on-success":q,"before-upload":s=>I(s)},{default:l(()=>[t.value.imageurl?(v(),k("img",{key:0,src:t.value.imageurl,class:"avatar",id:"imageurl"},null,8,me)):(v(),le(T,{key:1,class:"avatar-uploader-icon"},{default:l(()=>[a(C(M))]),_:1}))]),_:1},8,["before-upload"])]),_:1}),a(c,{label:"產品簡述",prop:"description"},{default:l(()=>[a(h,{type:"textarea",modelValue:t.value.description,"onUpdate:modelValue":e[3]||(e[3]=s=>t.value.description=s),row:4},null,8,["modelValue"])]),_:1}),u("div",ce,[a(N,{editor:C(V),modelValue:t.value.content,"onUpdate:modelValue":e[4]||(e[4]=s=>t.value.content=s),config:w.value},null,8,["editor","modelValue","config"])])]),_:1},8,["model","rules"]),u("div",fe,[a(g,{onClick:x},{default:l(()=>[d("取消")]),_:1}),a(g,{type:"primary",loading:m.value,onClick:e[5]||(e[5]=s=>B(E.value))},{default:l(()=>[d(re(m.value?"提交中 ...":"確認"),1)]),_:1},8,["loading"])])]),_:1})])}}},Me=ue(_e,[["__scopeId","data-v-27e453a3"]]);export{Me as default};
