2 lines
9.0 KiB
JavaScript
2 lines
9.0 KiB
JavaScript
import{_ as Z,r as d,a as ee,$ as te,b as p,a0 as le,o as _,c as f,d as g,e as l,w as s,g as ae,a1 as oe,y as ne,h as c,F as O,ad as R,B as x,C as se,E as m}from"./index.173459ae.js";import{b as ue,e as re,g as T,h as ie}from"./splitAccount.9dd0ca83.js";import"./request.431ecd42.js";import"./axios.e318b91e.js";const de={class:"split-account-config"},pe={class:"page-header",style:{display:"flex","justify-content":"space-between","align-items":"center","margin-bottom":"16px"}},ce={style:{display:"flex",gap:"12px","margin-bottom":"12px"}},_e={key:0,style:{"font-size":"13px","line-height":"1.8"}},me={key:1,style:{color:"#999"}},fe={style:{display:"flex","justify-content":"flex-end","margin-top":"16px"}},ge={class:"rule-items-section",style:{background:"#fafafa",padding:"12px 16px","border-radius":"6px","margin-bottom":"18px"}},ve={style:{"font-weight":"600","margin-bottom":"8px","font-size":"14px"}},ye={style:{display:"flex",gap:"16px"}},be={__name:"SplitAccountConfig",setup(he){const V=d([]),C=d(!1),k=d(1),L=d(20),S=d(0),w=d(""),v=d(!1),U=d(""),z=d(!1),I=d(null),A=d(!1),N=d(null),B=()=>[{product_type:"\u4ED3\u5E93\u65B9",ratio:"",add_amount:""},{product_type:"\u5206\u6DA6\u65B9",ratio:"",add_amount:""}],o=ee({rule_name:"",rule_items:B(),description:"",status:1}),$={rule_name:[{required:!0,message:"\u8BF7\u8F93\u5165\u914D\u7F6E\u540D\u79F0",trigger:"blur"},{max:50,message:"\u4E0D\u80FD\u8D85\u8FC750\u4E2A\u5B57\u7B26",trigger:"blur"}]},y=async()=>{C.value=!0;try{const e=(await ue({keyword:w.value||void 0,page:k.value,page_size:L.value})).data;if(e&&e.list){const t=e.list.map(u=>{let r=u.rule_value;if(typeof r=="string")try{r=JSON.parse(r)}catch{r=[]}return{...u,rule_value:r,_status:u.status}});V.value=t,S.value=e.total||t.length}else if(Array.isArray(e)){const t=e.map(u=>{let r=u.rule_value;if(typeof r=="string")try{r=JSON.parse(r)}catch{r=[]}return{...u,rule_value:r,_status:u.status}});V.value=t,S.value=t.length}else V.value=[],S.value=0}catch(n){console.error("\u83B7\u53D6\u5206\u8D26\u914D\u7F6E\u5217\u8868\u5931\u8D25",n)}finally{C.value=!1}},E=()=>{k.value=1,y()},j=()=>{A.value=!1,N.value=null,U.value="\u65B0\u589E\u914D\u7F6E",o.rule_name="",o.rule_items=B(),o.description="",o.status=1,v.value=!0},q=n=>{A.value=!0,N.value=n.id,U.value="\u7F16\u8F91\u914D\u7F6E",o.rule_name=n.rule_name||"";const e=n.rule_value;e&&e.length>=2?o.rule_items=e.map(t=>({product_type:t.product_type,ratio:t.ratio!==void 0&&t.ratio!==null?String(Number(t.ratio)*100):"",add_amount:t.add_amount!==void 0&&t.add_amount!==null?String(t.add_amount):""})):o.rule_items=B(),o.description=n.description||"",o.status=n.status,v.value=!0},M=n=>{se.confirm("\u786E\u5B9A\u5220\u9664\u914D\u7F6E\u300C"+n.rule_name+"\u300D\u5417\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D\u3002","\u786E\u8BA4\u5220\u9664",{confirmButtonText:"\u786E\u5B9A\u5220\u9664",cancelButtonText:"\u53D6\u6D88",type:"warning"}).then(async()=>{try{await re(n.id),m.success("\u5220\u9664\u6210\u529F"),y()}catch{m.error("\u5220\u9664\u5931\u8D25")}}).catch(()=>{})},F=async(n,e)=>{try{await T({id:n.id,rule_name:n.rule_name,rule_value:typeof n.rule_value=="object"?JSON.stringify(n.rule_value):n.rule_value,status:e,description:n.description||""}),n.status=e,m.success(e===1?"\u5DF2\u542F\u7528":"\u5DF2\u7981\u7528")}catch{n._status=n.status,m.error("\u64CD\u4F5C\u5931\u8D25")}},K=async()=>{if(!!await I.value.validate().catch(()=>!1)){for(let e=0;e<o.rule_items.length;e++){const t=o.rule_items[e];if(!t.ratio&&t.ratio!==0){m.warning("\u8BF7\u586B\u5199 "+t.product_type+" \u7684\u5206\u8D26\u767E\u5206\u6BD4");return}if(t.add_amount===""&&t.add_amount!==0){m.warning("\u8BF7\u586B\u5199 "+t.product_type+" \u7684\u589E\u52A0\u91D1\u989D");return}}z.value=!0;try{const e=JSON.stringify(o.rule_items.map(u=>({product_type:u.product_type,ratio:(typeof u.ratio=="string",String(Number(u.ratio)/100)),add_amount:typeof u.add_amount=="string"?u.add_amount:String(u.add_amount)}))),t={rule_name:o.rule_name,rule_value:e,status:o.status,description:o.description};A.value?(t.id=N.value,await T(t),m.success("\u4FEE\u6539\u6210\u529F")):(await ie(t),m.success("\u65B0\u589E\u6210\u529F")),v.value=!1,y()}catch(e){console.error("\u63D0\u4EA4\u5931\u8D25",e)}finally{z.value=!1}}};return te(()=>{y()}),(n,e)=>{const t=p("el-button"),u=p("el-input"),r=p("el-table-column"),D=p("el-tag"),P=p("el-switch"),G=p("el-table"),H=p("el-pagination"),b=p("el-form-item"),J=p("el-radio"),Q=p("el-radio-group"),W=p("el-form"),X=p("el-dialog"),Y=le("loading");return _(),f("div",de,[g("div",pe,[e[8]||(e[8]=g("h3",{style:{margin:"0"}},"\u5206\u8D26\u914D\u7F6E",-1)),l(t,{type:"primary",onClick:j},{default:s(()=>[...e[7]||(e[7]=[c("\u65B0\u589E\u914D\u7F6E",-1)])]),_:1})]),g("div",ce,[l(u,{modelValue:w.value,"onUpdate:modelValue":e[0]||(e[0]=a=>w.value=a),placeholder:"\u914D\u7F6E\u540D\u79F0\u641C\u7D22",clearable:"",style:{width:"240px"},onKeyup:ae(E,["enter"]),onClear:E},null,8,["modelValue"]),l(t,{type:"primary",onClick:E},{default:s(()=>[...e[9]||(e[9]=[c("\u67E5\u8BE2",-1)])]),_:1})]),oe((_(),ne(G,{data:V.value,stripe:"",border:"",style:{width:"100%"}},{default:s(()=>[l(r,{prop:"id",label:"ID",width:"60",align:"center"}),l(r,{prop:"rule_name",label:"\u914D\u7F6E\u540D\u79F0","min-width":"140"}),l(r,{label:"\u5206\u8D26\u89C4\u5219","min-width":"260"},{default:s(({row:a})=>[a.rule_value?(_(),f("div",_e,[(_(!0),f(O,null,R(a.rule_value,(i,h)=>(_(),f("div",{key:h},x(i.product_type)+"\uFF1A"+x(i.ratio*100)+"% + "+x(i.add_amount)+"\u5143 ",1))),128))])):(_(),f("span",me,"-"))]),_:1}),l(r,{prop:"status",label:"\u72B6\u6001",width:"80",align:"center"},{default:s(({row:a})=>[l(D,{type:a.status===1?"success":"info",size:"small"},{default:s(()=>[c(x(a.status===1?"\u542F\u7528":"\u7981\u7528"),1)]),_:2},1032,["type"])]),_:1}),l(r,{prop:"description",label:"\u63CF\u8FF0","min-width":"160","show-overflow-tooltip":""}),l(r,{prop:"created_by",label:"\u521B\u5EFA\u4EBA",width:"100",align:"center"}),l(r,{label:"\u64CD\u4F5C",width:"180",fixed:"right",align:"center"},{default:s(({row:a})=>[l(t,{type:"primary",link:"",size:"small",onClick:i=>q(a)},{default:s(()=>[...e[10]||(e[10]=[c("\u7F16\u8F91",-1)])]),_:1},8,["onClick"]),l(t,{type:"danger",link:"",size:"small",onClick:i=>M(a)},{default:s(()=>[...e[11]||(e[11]=[c("\u5220\u9664",-1)])]),_:1},8,["onClick"]),l(P,{modelValue:a._status,"onUpdate:modelValue":i=>a._status=i,"active-value":1,"inactive-value":0,size:"small",onChange:i=>F(a,i),style:{"margin-left":"8px"}},null,8,["modelValue","onUpdate:modelValue","onChange"])]),_:1})]),_:1},8,["data"])),[[Y,C.value]]),g("div",fe,[l(H,{"current-page":k.value,"onUpdate:currentPage":e[1]||(e[1]=a=>k.value=a),"page-size":L.value,total:S.value,layout:"prev, pager, next, total",onCurrentChange:y},null,8,["current-page","page-size","total"])]),l(X,{modelValue:v.value,"onUpdate:modelValue":e[6]||(e[6]=a=>v.value=a),title:U.value,width:"560px","close-on-click-modal":!1},{footer:s(()=>[l(t,{onClick:e[5]||(e[5]=a=>v.value=!1)},{default:s(()=>[...e[14]||(e[14]=[c("\u53D6\u6D88",-1)])]),_:1}),l(t,{type:"primary",onClick:K,loading:z.value},{default:s(()=>[...e[15]||(e[15]=[c("\u786E\u5B9A",-1)])]),_:1},8,["loading"])]),default:s(()=>[l(W,{ref_key:"formRef",ref:I,model:o,rules:$,"label-width":"100px"},{default:s(()=>[l(b,{label:"\u914D\u7F6E\u540D\u79F0",prop:"rule_name"},{default:s(()=>[l(u,{modelValue:o.rule_name,"onUpdate:modelValue":e[2]||(e[2]=a=>o.rule_name=a),placeholder:"\u8BF7\u8F93\u5165\u914D\u7F6E\u540D\u79F0",maxlength:"50"},null,8,["modelValue"])]),_:1}),g("div",ge,[(_(!0),f(O,null,R(o.rule_items,(a,i)=>(_(),f("div",{class:"rule-item",key:i,style:{"margin-bottom":"12px"}},[g("div",ve,x(a.product_type),1),g("div",ye,[l(b,{label:"\u5206\u8D26\u767E\u5206\u6BD4",prop:"rule_items."+i+".ratio",rules:[{required:!0,message:"\u8BF7\u8F93\u5165\u767E\u5206\u6BD4",trigger:"blur"}],"label-width":"90px"},{default:s(()=>[l(u,{modelValue:a.ratio,"onUpdate:modelValue":h=>a.ratio=h,placeholder:"\u5982 30",style:{width:"140px"}},null,8,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"]),l(b,{label:"\u589E\u52A0\u91D1\u989D",prop:"rule_items."+i+".add_amount",rules:[{required:!0,message:"\u8BF7\u8F93\u5165\u91D1\u989D",trigger:"blur"}],"label-width":"90px"},{default:s(()=>[l(u,{modelValue:a.add_amount,"onUpdate:modelValue":h=>a.add_amount=h,placeholder:"\u5982 1",style:{width:"140px"}},null,8,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"])])]))),128))]),l(b,{label:"\u914D\u7F6E\u63CF\u8FF0",prop:"description"},{default:s(()=>[l(u,{modelValue:o.description,"onUpdate:modelValue":e[3]||(e[3]=a=>o.description=a),type:"textarea",rows:3,placeholder:"\u8BF7\u8F93\u5165\u914D\u7F6E\u63CF\u8FF0",maxlength:"200"},null,8,["modelValue"])]),_:1}),l(b,{label:"\u72B6\u6001",prop:"status"},{default:s(()=>[l(Q,{modelValue:o.status,"onUpdate:modelValue":e[4]||(e[4]=a=>o.status=a)},{default:s(()=>[l(J,{value:1},{default:s(()=>[...e[12]||(e[12]=[c("\u542F\u7528",-1)])]),_:1}),l(J,{value:0},{default:s(()=>[...e[13]||(e[13]=[c("\u7981\u7528",-1)])]),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])])}}};var Ce=Z(be,[["__scopeId","data-v-97f154e0"]]);export{Ce as default};
|