2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
import{J as yt,x as z,d as ht,u as bt,v as xt,a as N,w as i,i as j,l as $,r as u,o as d,c as s,h as S,f as x,K as kt,b as k,e as B,F as C,n as P,L as wt,t as w,E as It,N as Ct,A as qt,y as F,p as J,z as E,k as Ut,_ as Nt}from"./index-BA_yBNil.js";import{X as St}from"./model-DVG0-wm0.js";import{b as Ot}from"./productListModel-pSztNZC_.js";import{u as Pt}from"./auth-Dax0yuDC.js";import"./filters-BmJ4MQFf.js";import"./index-B0WdP3B3.js";import"./SettingOutlined-CumAardg.js";const G="admin_cart_items",zt=yt("cart",{state:()=>({items:[]}),actions:{addToCart(l){const v=this.items.findIndex(g=>g.pid==l.pid&&g.vid==l.vid),f=l.product.variants_all.filter(g=>g.id===l.vid)[0];f&&!(!f.is_pre_order&&f.qty===0)&&(v==-1?this.items.push(l):(this.items[v].product=l.product,this.items[v].qty=l.qty))},setItems(l){this.items=l,localStorage.setItem(G,JSON.stringify(l))},add(l){this.addToCart(l),this.setItems(this.items)},remove(l){const v=this.items.findIndex(f=>f.pid==l.pid&&f.vid==l.vid);v>-1&&this.items.splice(v,1),this.setItems(this.items)},updateItemQuantity(l){this.items[l.index].qty=l.quantity,this.setItems(this.items)},clear(){this.items=[],this.setItems(this.items)},async init(){try{const l=JSON.parse(localStorage.getItem(G)??"[]")||[],v=l.map(g=>g.product.id);if(v.length===0){this.setItems([]);return}const{data:f}=await z.post("product/variant",{products_id:v});if(f){const g=[];for(const y of l){const h=f.find(L=>L.id==y.product.id);h&&(!h.variants_all[0].is_pre_order&&h.variants_all[0].qty===0||g.push({vid:y.vid,pid:h.id,product:h,qty:y.qty,promotion_id:h.promotion&&h.promotion.id?h.promotion.id:null}))}this.setItems(g)}}catch(l){console.log("error in cart",l)}}}}),Vt=["src"],$t={key:1,class:"flex items-center"},Bt=["src"],Et={key:4,class:"flex"},Lt={style:{width:"max-content"}},Rt={class:"grid-5"},Tt={class:"totals"},H="/img/no-items.png",Qt=ht({__name:"create",setup(l){const v=Ut(),f=bt(),g=Pt(),y=zt(),h=e=>!!f.hasPermission(e),L=Ot(),Y=$(null),O=$(!1),M=$([]),A=$({}),Z={1:"ثبت سفارش",2:"تایید مدیر سیستم",3:"در حال تامین",4:"در حال آماده سازی",5:"ارسال",6:"تحویل مشتری"},n=F({customer_id:void 0,sts:void 0,type:void 0,note:"",shipping_address:{reciver_fname:"",reciver_lname:"",province:"",city:"",zipcode:"",reciver_phone:"",reciver_fixed_phone:"",address:""}}),c=F({}),tt=J(()=>{var e;return(e=g.user)==null?void 0:e.id}),b=J(()=>y.items),et=[{title:"حذف",dataIndex:"delete",width:60,align:"center"},{title:"کد محصول",dataIndex:"pid",align:"center",width:90},{title:"محصول",dataIndex:"product"},{title:"اجرت",dataIndex:"wage",align:"center"},{title:"تعداد",dataIndex:"qty",align:"center",width:140},{title:"وزن",dataIndex:"weight",align:"center",width:90},{title:"مجموع",dataIndex:"total",align:"center"}],m=F({});function I(e){return e.product.variants_all.find(t=>t.id===e.vid)??{}}function at(e){var t,o,p;return((t=e==null?void 0:e.thumb)==null?void 0:t.full)??((p=(o=e==null?void 0:e.ProductImage)==null?void 0:o[0])==null?void 0:p.image)??H}const st=J(()=>{let e=0;for(const t of b.value)e+=Number(I(t).grams??0);return e});function it(e){return Number(I(e).grams??0)*e.qty}function nt(e){const t=b.value[e];if(!t)return 1/0;const o=Number(I(t).qty??0);return o>0?o:1/0}function ot(e,t){y.updateItemQuantity({index:e,quantity:Number(t)})}function lt(e,t){rt(e,String(t.key))}function rt(e,t){y.add({vid:t,pid:e.id,product:e,qty:1,promotion_id:e.promotion&&e.promotion.id?e.promotion.id:null}),E.info("اضافه شد")}function dt(e){const t=I(e);m.id=t.id,m.grams=Number(t.grams??0)}async function ut(){var e,t;if(!(!m.id||!m.grams))try{O.value=!0;const o=b.value.find(p=>p.vid===m.id);await z.post("add/variant",{product_id:o==null?void 0:o.pid,title:`${m.grams} گرم`,grams:m.grams}),await y.init(),m.id=void 0,m.grams=void 0}catch(o){E.error(((t=(e=o==null?void 0:o.response)==null?void 0:e.data)==null?void 0:t.message)??"خطا در ثبت وزن")}finally{O.value=!1}}function pt(e,t){var o,p;return String(((p=(o=t==null?void 0:t.children)==null?void 0:o[0])==null?void 0:p.children)??"").toLowerCase().includes(e.toLowerCase())}function mt(){return Object.keys(c).forEach(e=>delete c[e]),n.customer_id||(c.customer_id="مقدار را وارد نمایید"),n.sts===void 0&&(c.sts="مقدار را وارد نمایید"),n.type===void 0&&(c.type="مقدار را وارد نمایید"),Object.keys(c).length===0}async function D(){var e,t;if(mt())try{O.value=!0;const o=b.value.map(p=>{const R=I(p);return{vid:p.vid,qty:p.qty,percent:R.percentage_pay,promotion_id:p.promotion_id}});await z.post("order",{...n,reagent_id:tt.value,app:"app",order_items:o}),E.info("عملیات با موفقیت انجام شد"),y.clear(),v.push("/order/list")}catch(o){console.log(o),E.error(((t=(e=o==null?void 0:o.response)==null?void 0:e.data)==null?void 0:t.message)??"خطا در ثبت اطلاعات.")}finally{O.value=!1}}return xt(async()=>{try{const[e,t]=await Promise.all([z.get("order/type"),z.post("single-customer",{page:1,limit:500})]);A.value=e.data,M.value=t.data.rows??[]}catch(e){console.log(e)}await y.init()}),(e,t)=>{const o=u("a-button"),p=u("a-menu-item"),R=u("a-menu"),ct=u("a-dropdown"),K=u("a-input-number"),_t=u("a-table"),T=u("a-select-option"),Q=u("a-select"),_=u("a-form-item"),q=u("a-input"),W=u("a-textarea"),vt=u("a-tag"),ft=u("a-form"),X=u("a-card"),gt=u("a-spin");return h("order.create")?(d(),N(gt,{key:0,spinning:O.value},{default:i(()=>[s(X,{title:"لیست محصولات"},{default:i(()=>[s(St,{ref_key:"tblProducts",ref:Y,model:S(L)},{image:i(({record:a})=>[P("img",{width:"90px",height:"90px",style:{"object-fit":"scale-down"},src:a.thumb&&a.thumb.full?a.thumb.full:H},null,8,Vt)]),op:i(({record:a})=>[s(ct,null,{overlay:i(()=>[s(R,{onClick:r=>lt(a,r)},{default:i(()=>[(d(!0),k(C,null,B(a.variants_all,r=>(d(),N(p,{key:r.id},{default:i(()=>[x(" افزودن تنوع "+w(r.title),1)]),_:2},1024))),128))]),_:2},1032,["onClick"])]),default:i(()=>[s(o,{style:{"margin-left":"8px"}},{default:i(()=>[t[13]||(t[13]=x(" افزودن ",-1)),s(S(kt))]),_:1})]),_:2},1024)]),_:1},8,["model"]),b.value.length>0?(d(),N(X,{key:0,title:"ثبت سفارش",class:"mt-5"},{default:i(()=>[s(_t,{columns:et,"data-source":b.value,bordered:"",pagination:!1,"row-key":"vid"},{bodyCell:i(({column:a,record:r,index:V})=>[a.dataIndex==="delete"?(d(),N(S(wt),{key:0,class:"cursor-pointer",onClick:U=>S(y).remove(r)},null,8,["onClick"])):a.dataIndex==="product"?(d(),k("div",$t,[P("img",{src:at(r.product),width:"50px"},null,8,Bt),x(" "+w(r.product.title),1)])):a.dataIndex==="wage"?(d(),k(C,{key:2},[x(w(I(r).percentage_pay)+"٪ ",1)],64)):a.dataIndex==="qty"?(d(),N(K,{key:3,value:b.value[V].qty,"onUpdate:value":U=>b.value[V].qty=U,min:1,max:nt(V),onChange:U=>ot(V,U)},null,8,["value","onUpdate:value","max","onChange"])):a.dataIndex==="weight"?(d(),k("div",Et,[!m.grams||m.id!==I(r).id?(d(),k(C,{key:0},[P("span",Lt,w(I(r).title),1),s(S(It),{class:"cursor-pointer ml-2 text-primary",onClick:U=>dt(r)},null,8,["onClick"])],64)):(d(),k(C,{key:1},[s(K,{value:m.grams,"onUpdate:value":t[0]||(t[0]=U=>m.grams=U)},null,8,["value"]),s(S(Ct),{class:"cursor-pointer ml-2 text-success",onClick:ut})],64))])):a.dataIndex==="total"?(d(),k(C,{key:5},[x(w(it(r))+" گرم ",1)],64)):j("",!0)]),_:1},8,["data-source"]),s(ft,{layout:"vertical",class:"mt-4",onSubmit:qt(D,["prevent"])},{default:i(()=>[P("div",Rt,[s(_,{label:"مشتری","validate-status":c.customer_id?"error":"",help:c.customer_id},{default:i(()=>[s(Q,{value:n.customer_id,"onUpdate:value":t[1]||(t[1]=a=>n.customer_id=a),"show-search":"","option-filter-prop":"children","filter-option":pt},{default:i(()=>[(d(!0),k(C,null,B(M.value,a=>(d(),N(T,{key:a.id,value:a.id},{default:i(()=>[x(w(`${a.id}-${a.fname} ${a.lname}`),1)]),_:2},1032,["value"]))),128))]),_:1},8,["value"])]),_:1},8,["validate-status","help"]),s(_,{label:"وضعیت تحویل","validate-status":c.sts?"error":"",help:c.sts},{default:i(()=>[s(Q,{value:n.sts,"onUpdate:value":t[2]||(t[2]=a=>n.sts=a)},{default:i(()=>[(d(),k(C,null,B(Z,(a,r)=>s(T,{key:r,value:Number(r)},{default:i(()=>[x(w(a),1)]),_:2},1032,["value"])),64))]),_:1},8,["value"])]),_:1},8,["validate-status","help"]),s(_,{label:"نوع فروش","validate-status":c.type?"error":"",help:c.type},{default:i(()=>[s(Q,{value:n.type,"onUpdate:value":t[3]||(t[3]=a=>n.type=a)},{default:i(()=>[(d(!0),k(C,null,B(A.value,(a,r)=>(d(),N(T,{key:r,value:Number(r)},{default:i(()=>[x(w(a),1)]),_:2},1032,["value"]))),128))]),_:1},8,["value"])]),_:1},8,["validate-status","help"]),s(_,{label:"نام دریافت کننده"},{default:i(()=>[s(q,{value:n.shipping_address.reciver_fname,"onUpdate:value":t[4]||(t[4]=a=>n.shipping_address.reciver_fname=a)},null,8,["value"])]),_:1}),s(_,{label:"نام خانوادگی دریافت کننده"},{default:i(()=>[s(q,{value:n.shipping_address.reciver_lname,"onUpdate:value":t[5]||(t[5]=a=>n.shipping_address.reciver_lname=a)},null,8,["value"])]),_:1}),s(_,{label:"استان"},{default:i(()=>[s(q,{value:n.shipping_address.province,"onUpdate:value":t[6]||(t[6]=a=>n.shipping_address.province=a)},null,8,["value"])]),_:1}),s(_,{label:"شهر"},{default:i(()=>[s(q,{value:n.shipping_address.city,"onUpdate:value":t[7]||(t[7]=a=>n.shipping_address.city=a)},null,8,["value"])]),_:1}),s(_,{label:"کد پستی"},{default:i(()=>[s(q,{value:n.shipping_address.zipcode,"onUpdate:value":t[8]||(t[8]=a=>n.shipping_address.zipcode=a)},null,8,["value"])]),_:1}),s(_,{label:"تلفن همراه"},{default:i(()=>[s(q,{value:n.shipping_address.reciver_phone,"onUpdate:value":t[9]||(t[9]=a=>n.shipping_address.reciver_phone=a)},null,8,["value"])]),_:1}),s(_,{label:"تلفن ثابت"},{default:i(()=>[s(q,{value:n.shipping_address.reciver_fixed_phone,"onUpdate:value":t[10]||(t[10]=a=>n.shipping_address.reciver_fixed_phone=a)},null,8,["value"])]),_:1})]),s(_,{label:"توضیحات"},{default:i(()=>[s(W,{value:n.note,"onUpdate:value":t[11]||(t[11]=a=>n.note=a),"auto-size":{minRows:3,maxRows:5}},null,8,["value"])]),_:1}),s(_,{label:"آدرس"},{default:i(()=>[s(W,{value:n.shipping_address.address,"onUpdate:value":t[12]||(t[12]=a=>n.shipping_address.address=a),"auto-size":{minRows:3,maxRows:5}},null,8,["value"])]),_:1}),P("div",Tt,[s(vt,{color:"blue"},{default:i(()=>[x("مجموع وزن: "+w(st.value)+" گرم",1)]),_:1})]),s(o,{type:"primary",class:"mt-4",disabled:!b.value||b.value.length<1,onClick:D},{default:i(()=>[...t[14]||(t[14]=[x(" ثبت تغییرات ",-1)])]),_:1},8,["disabled"])]),_:1})]),_:1})):j("",!0)]),_:1})]),_:1},8,["spinning"])):j("",!0)}}}),Wt=Nt(Qt,[["__scopeId","data-v-cfb22e94"]]);export{Wt as default};
|