2 lines
8.2 KiB
JavaScript
2 lines
8.2 KiB
JavaScript
import{_ as K}from"./BasicModal.vue_vue_type_style_index_0_lang-c60160bb.js";import{_ as Q,u as Y}from"./useBaseTable-c7721a03.js";import{_ as Z}from"./button.vue_vue_type_style_index_0_lang-4dc9d3e9.js";import{I as P}from"./Icon-83dbbbe4.js";import{t as ee}from"./useDataTime-7a9ebe02.js";import{g as T}from"./convert-c2e7255b.js";import{_ as E}from"./TextPreview.vue_vue_type_script_setup_true_lang-d2a051b6.js";import{_ as D}from"./CustomTag.vue_vue_type_script_setup_true_lang-19fd431b.js";import{b as a,d as te,g as m,r as ae,l as oe,x as ne,n as se,o as j,c as F,a as g,w as r,e as le,j as c,G as ie,k as re,D as p,H as O}from"./index-9a17e55b.js";import{g as N}from"./index-d0cad351.js";import{a as ue,u as ce,c as de,d as pe}from"./brand-827c9b37.js";import{M as me,_ as fe}from"./index-d5d26f82.js";import{I as _e,_ as ge}from"./index-369204e0.js";import{_ as ve,F as he}from"./index-dad403b6.js";import{U as xe}from"./index-b78b7a1c.js";import{T as q}from"./shallowequal-5f876352.js";import"./index-26298d7e.js";import"./vnode-0a46e202.js";import"./Col-dc7ee55f.js";import"./_plugin-vue_export-helper-09135f79.js";import"./index-4182a454.js";import"./toArray-c5dd79c4.js";import"./FormItemContext-101590b9.js";import"./pickAttrs-0804445f.js";import"./useState-6ac08ff3.js";import"./index-e6e78cc4.js";import"./isPlainObject-7dd54c5e.js";import"./useRefs-707c512d.js";const be=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:t=>t.index+1},{title:"تصویر ",dataIndex:"image",key:"image",customRender:t=>{const C=T(t.record.image);return a("img",{src:C,width:60},null)}},{title:"عنوان",dataIndex:"title",key:"title"},{title:"توضیحات",dataIndex:"description",key:"description",width:500,customRender:t=>a(E,{text:t.record.description},null)},{title:"وضعیت ",dataIndex:"active",key:"active",type:"Boolean",width:100,customRender:t=>a("div",{class:"flex justify-center"},[a(D,{class:"px-3 font-bold py-1",textColor:t!=null&&t.record.active?"#65a30d":"#dc2626",bgColor:t!=null&&t.record.active?"#ecfccb":"#fee2e2"},{default:()=>[t!=null&&t.record.active?"فعال":"غیر فعال"]})])},{title:"وضعیت دسترسی ",dataIndex:"active",key:"active",type:"Boolean",width:150,customRender:t=>a("div",{class:"flex justify-center"},[a(D,{class:"px-3 font-bold py-1",textColor:t!=null&&t.record.public?"#0d6fa3":"#333333",bgColor:t!=null&&t.record.public?"#cbe9fc":"#eaeaea"},{default:()=>[t!=null&&t.record.public?"عمومی":"خصوصی"]})])},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:t=>ee(t.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],ye={class:"flex justify-between items-center mb-4"},ke=g("h2",null,"برند ها",-1),we={class:"gap-2 flex justify-center"},Ie=g("span",null,"حذف",-1),Be=g("span",null,"ویرایش",-1),Ce={class:"grid grid-cols-3 gap-4"},Ue={key:0},$e=g("div",{style:{"margin-top":"8px"}},"آپلود",-1),ot=te({__name:"index",setup(t){`${N()||localStorage.getItem("tamin_token")||""}`;const[C,M]=Y(),V=m({columns:be,api:ue,defaultPageLimit:20}),h=m(!1),k=m(!1),w=m(null),W=m([]),x=m(0),I=m(0),l=ae({title:"",active:!0,image:void 0,owner_id:void 0,id:void 0,description:void 0,public:void 0});let z=oe.cloneDeep(l);m();const v=m([]);function H(){W.value=[],k.value=!1,w.value=null,h.value=!0}function R(){Object.assign(l,z),v.value=[],h.value=!1}function S(s){return s.type.startsWith("image/")?s.size/1024/1024<5?!0:(p.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(p.error("فقط فایلهای تصویری مجاز است"),!1)}async function A(s){const{file:e,onSuccess:d,onError:u,onProgress:b}=s,f=new FormData;f.append("file",e);const B=`${O}/upload/machartaa-img`;I.value=0,x.value++,await new Promise((U,y)=>{const i=new XMLHttpRequest;i.open("POST",B);const $=N()||localStorage.getItem("tamin_token")||"";i.setRequestHeader("Authorization",`Bearer ${$}`),i.upload.onprogress=o=>{if(o.lengthComputable){const n=Math.round(o.loaded/o.total*100);I.value=n,b==null||b({percent:n})}},i.onload=()=>{if(I.value=100,i.status>=200&&i.status<300)try{const o=JSON.parse(i.responseText||"{}"),n=o.full_src||o.url||o.src||o.path||o.data&&(o.data.full_src||o.data.url||o.data.src||o.data.path)||"";let _=n;n!=null&&n.startsWith("http")&&(_=n.replace(/^https?:\/\/[^\/]+/,""));const L=_.startsWith("http")?_:`${O}${_}`;l.image=_,v.value=L?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:L,response:{path:_}}]:[],d==null||d(o,i),p.success("کاور با موفقیت آپلود شد!"),U()}catch(o){u==null||u(o,i),y(o)}else{const o=new Error("خطا در آپلود تصویر");u==null||u(o,i),y(o)}},i.onerror=()=>{const o=new Error("خطا در آپلود کاور");u==null||u(o,i),y(o)},i.onloadend=()=>{x.value=Math.max(0,x.value-1),I.value=0},i.send(f)})}async function J(){var s;if(!((s=l.title)!=null&&s.trim())){p.error("لطفاً عنوان برند را وارد کنید");return}if(x.value>0){p.warning("لطفاً تا پایان آپلود صبر کنید");return}try{k.value&&w.value?(await ce(w.value,l),p.success("برند با موفقیت ویرایش شد")):(await de(l),p.success("برند با موفقیت افزوده شد")),R(),await M()}catch(e){console.error("Error saving Product:",e),p.error("خطا در ذخیره برند: "+(e.message||"خطای ناشناخته"))}}function G(s){k.value=!0,w.value=s.id,console.log(s);let e=s.image||null;e&&e.startsWith("http")&&(e=e.replace(/^https?:\/\/[^\/]+/,""));for(const d in l)s.hasOwnProperty(d)&&(l[d]=s[d]);v.value=e?[{uid:"-1",name:"image.jpg",status:"done",url:T(e),response:{path:T(e)}}]:[],h.value=!0}function X(s){me.confirm({title:"حذف برند",content:`آیا مطمئن هستید که میخواهید برند "${s.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await pe(s.id),p.success("برند با موفقیت حذف شد"),await M()}catch(e){console.error("Error deleting Product:",e),p.error("خطا در حذف برند: "+(e.message||"خطای ناشناخته"))}}})}return ne(async()=>{}),(s,e)=>{const d=Z,u=Q,b=_e,f=ve,B=fe,U=ge,y=se("plus-outlined"),i=xe,$=he,o=K;return j(),F("div",null,[g("div",ye,[ke,a(d,{type:"primary",onClick:H},{default:r(()=>[le("افزودن برند")]),_:1})]),a(u,ie(V.value,{ref:"table",onRegister:c(C)}),{text:r(({record:n})=>[a(E,{text:n.description},null,8,["text"])]),action:r(({record:n})=>[g("div",we,[a(c(q),{class:"cursor-pointer"},{title:r(()=>[Ie]),default:r(()=>[a(P,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:_=>X(n)},null,8,["onClick"])]),_:2},1024),a(c(q),{class:"cursor-pointer"},{title:r(()=>[Be]),default:r(()=>[a(P,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:_=>G(n)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),a(o,{visible:h.value,"onUpdate:visible":e[5]||(e[5]=n=>h.value=n),title:k.value?"ویرایش برند":"افزودن برند",onOk:J,onClose:R,width:"80%",confirmLoading:x.value>0},{default:r(()=>[a($,{layout:"vertical",class:"grid grid-cols-2 gap-2"},{default:r(()=>[a(f,{label:"عنوان برند",required:""},{default:r(()=>[a(b,{value:c(l).title,"onUpdate:value":e[0]||(e[0]=n=>c(l).title=n),placeholder:"عنوان فارسی محصول"},null,8,["value"])]),_:1}),g("div",Ce,[a(f,{label:"فعال"},{default:r(()=>[a(B,{checked:c(l).active,"onUpdate:checked":e[1]||(e[1]=n=>c(l).active=n)},null,8,["checked"])]),_:1}),a(f,{label:"دسترسی عمومی"},{default:r(()=>[a(B,{checked:c(l).public,"onUpdate:checked":e[2]||(e[2]=n=>c(l).public=n)},null,8,["checked"])]),_:1})]),a(f,{label:"توضیحات برند"},{default:r(()=>[a(U,{value:c(l).description,"onUpdate:value":e[3]||(e[3]=n=>c(l).description=n),rows:"4",placeholder:"توضیحات محصول"},null,8,["value"])]),_:1}),a(f,{label:"تصویر اصلی"},{default:r(()=>[a(i,{"file-list":v.value,"onUpdate:fileList":e[4]||(e[4]=n=>v.value=n),"before-upload":S,"custom-request":A,accept:"image/*","list-type":"picture-card","max-count":1},{default:r(()=>[v.value.length<1?(j(),F("div",Ue,[a(y),$e])):re("",!0)]),_:1},8,["file-list"])]),_:1})]),_:1})]),_:1},8,["visible","title","confirmLoading"])])}}});export{ot as default};
|