Files
appco_dist/.output/public/_nuxt/DahHpqW_.js
T
2026-03-07 16:09:22 +03:30

2 lines
9.7 KiB
JavaScript

import{au as X,cM as ee,r as o,l as te,aB as y,J as ae,cN as j,cC as ie,H as le,Q as b,cO as se,cP as ne}from"./sHYMdOhR.js";import{u as O}from"./CfQT9Pjy.js";import{g as H,a as re}from"./DqDlbiR0.js";import{S as oe,c as ue}from"./DESWC84c.js";import{a as de,b as V}from"./CcRNtUWx.js";import{b as ce}from"./BCNp_OwF.js";import{b as q,l as J,i as I}from"./BtazoGfv.js";import{i as fe}from"./D9spR2Y-.js";function ve(e,t,a){for(var r=-1,u=e==null?0:e.length;++r<u;)if(a(t,e[r]))return!0;return!1}var pe=200;function Z(e,t,a,r){var u=-1,s=de,d=!0,n=e.length,_=[],v=t.length;if(!n)return _;a&&(t=X(t,ee(a))),r?(s=ve,d=!1):t.length>=pe&&(s=ue,d=!1,t=new oe(t));e:for(;++u<n;){var c=e[u],l=a==null?c:a(c);if(c=r||c!==0?c:0,d&&l===l){for(var p=v;p--;)if(t[p]===l)continue e;_.push(c)}else s(t,l,r)||_.push(c)}return _}var _e=q(function(e,t){var a=J(t);return I(a)&&(a=void 0),I(e)?Z(e,V(t,1,I,!0),ce(a)):[]}),he=q(function(e,t){var a=J(t);return I(a)&&(a=void 0),I(e)?Z(e,V(t,1,I,!0),void 0,a):[]});const F=o(),Q=o(),G=o(!1),x=o(1),ge=o(!1);let w=[];const C=o(),U=o([]),S=o([]),h=o([]),A=o({url:void 0,index:0}),me=o([]),be=o([]),ye=o(),xe=o(),Y=o([]),P=o([]),Ce=o([]),we=o([]),E=ae({title_fa:"",title:"",price:0,body:"",is_show:!0,is_active:!0,box_size:0,sell_type:"numeric",original_image:void 0,product_attributes:[],upload_files:[],files:[],price_type:"manual",auto_calculate:!1,is_exist:!0,created_at:void 0,updated_at:void 0,deleted_at:null,count_order:void 0,count_fav:void 0,count_view:void 0,min_price:void 0,max_price:void 0,type:"simple",owner_id:void 0,users:void 0,saved:[],variants:[],code:void 0,pre_sale:!1,brand_id:void 0,collection_id:void 0,collections:{parent_id:void 0,id:void 0},discount:void 0,discount_type:void 0,id:void 0,count:void 0,display_price:void 0,meta:void 0,seo_title:void 0,description:void 0,weight:void 0,rial_fee:void 0,percent_fee:void 0}),Fe=y(E);function R(){Object.assign(E,Fe),S.value=[],U.value=[],P.value=[],x.value=1,A.value={url:void 0,index:0},h.value=[],C.value=void 0,F.value=void 0,ye.value=void 0,N.value=[],k().mediaFiles=[],k().originalFile=void 0,me.value=[],be.value=[],ge.value=!1,(E.count??0)<=0&&(E.count=void 0)}const K=te(()=>{let e=y(h.value);return e?.splice(0,0,A.value),e=e?.map((t,a)=>t),console.log(e),e});function Ne(e){const t=Q.value;if(!Array.isArray(h.value)||t==null||t<0||t>=h.value.length){console.warn("invalid index or list",t,h.value?.length);return}const a=h.value[t];if(a&&a?.startsWith("blob:"))try{URL.revokeObjectURL(a)}catch{}const r=j(e,Ie(N.value[t])),u=URL.createObjectURL(r);N.value[t]=r,h.value[t]=u,F.value=u}function ke(e){const t=k(),a=Q.value;if(!e?.startsWith("data:"))return;if(a===-2||F.value===A.value?.url){const v=A.value?.url,c=t.originalFile?.file instanceof File&&t.originalFile.file.name||B(v,"original.jpg"),l=j(e,c),p=URL.createObjectURL(l);A.value.url=p,t.originalFile={file:l,index:0},W(v),F.value=p;return}let r=typeof a=="number"&&a>=0&&a<h.value.length?a:-1;if(r<0&&(r=h.value.findIndex(v=>(typeof v=="string"?v:v?.url)===F.value)),r<0)return;const u=h.value[r],s=typeof u=="string"?u:u.url,d=B(s,`image-${r}.jpg`),n=j(e,d),_=URL.createObjectURL(n);if(console.log(n,e,1111111),typeof u=="string"?h.value[r]=_:h.value[r]={...u,url:_},Array.isArray(t.mediaFiles))if(typeof u=="string")t.mediaFiles[r]&&"file"in t.mediaFiles[r]?t.mediaFiles[r].file=n:t.mediaFiles[r]=n;else{const v=t.mediaFiles.findIndex(c=>c.index===u.index);v>=0?t.mediaFiles[v].file=n:(t.mediaFiles.push({file:n,index:u.index}),t.mediaFiles.sort((c,l)=>(c.index??0)-(l.index??0)))}W(s),F.value=_}function W(e){if(e&&e.startsWith("blob:"))try{URL.revokeObjectURL(e)}catch{}}function B(e,t="image.jpg"){if(!e)return t;try{const a=new URL(e).pathname.split("/").pop()||"";if(/\.[a-z0-9]+$/i.test(a))return a}catch{}return t}function Ie(e){if(e instanceof File)return M(e.name);const t="image.jpg";return e&&typeof e=="object"&&"name"in e&&typeof e.name=="string"?M(e.name):t}function M(e){return e&&/\.[a-zA-Z0-9]+$/.test(e)?e:`${e||"image"}.jpg`}function Ee(){let e=[],t=[];U.value?.forEach(a=>{a.valueId,e.push(a.valueId),t.push(a.valueName)}),console.log(e,U.value),E.variants?.push({id:void 0,attribute_values:[],attribute_values_name:[],price:0,weight:0,stock:0,auto_calculate:!1,discount_type:void 0,discount:void 0,is_default:!1,sku:""})}function ze(e,t){let a=e;x.value=1,S.value=[],U.value=[];let r=0,u=[];e?.forEach((s,d)=>{s.show_in_variable?(x.value=2,E.variants.length===0&&Ee(),S.value.push({attributeId:s.id,name:s.name,values:s.new_feature,show:s.show_in_variable,valueKey:d}),s.new_feature?.forEach((n,_)=>{U.value.push({attributeName:s.name,attributeId:s.id,valueId:n.id,valueName:n.value,valueKey:r})})):(u.push(d),P.value?.forEach(n=>{a.length>n.attribute_values.length&&n.attribute_values[d]!=null&&(n.attribute_values.length!=d?(n.attribute_values.splice(d,0,null),n.attribute_values_name.splice(d,0,null)):(n.attribute_values=[...n.attribute_values||[],null],n.attribute_values_name=[...n.attribute_values_name||[],null]))})),r++,P.value?.forEach((n,_)=>{a.length>n.attribute_values.length&&n.attribute_values[d]!=null&&(n.attribute_values=[...n.attribute_values||[],null],n.attribute_values_name=[...n.attribute_values_name||[],null])})}),Ue(P.value),u.length!=0&&P.value?.forEach(s=>{u.forEach(d=>{s.attribute_values[d]=null,s.attribute_values_name[d]=null})})}function Ue(e){e?.forEach((t,a)=>{w=y(t.attribute_values),S.value.length<=w.length&&w?.forEach((r,u)=>{U.value?.forEach((s,d)=>{w.find(n=>n==s?.valueId)&&t.attribute_values[s.valueKey]!=w.find(n=>n==s.valueId)&&(t.attribute_values[s.valueKey]=w.find(n=>n==s.valueId),t.attribute_values_name[s.valueKey]=s.valueName)})}),a==0&&(C.value=$(t.attribute_values_name)),t.is_default&&(C.value=$(t.attribute_values_name))})}function $(e){let t="";return e.forEach((a,r)=>{if(a)return t+=(r!==0?" - ":"")+a}),t}async function Te(){try{G.value=!0,we.value=await re()}catch(e){console.log(e)}finally{G.value=!1}}async function Ge(e){let t;e[e.length-1]!=null&&(t=await H(e[e.length-1]));let a;a=t?t[0]:null,a&&(Object.assign(a,{new_feature:[],show_in_product:!1,show_in_variable:!1}),Y.value.push(a))}async function Ke(e){const t=await H(e),a=Y.value.find(r=>r.id===e);a&&(a.attribute_values=[],a.attribute_values=t[0]?.attribute_values?y(t[0]?.attribute_values):[])}const We=e=>e.split("-")[0]==="edit",L=o([]),N=o([]),k=ie("product",()=>{const e=o(),t=o([]),a=o(0),r=o(!1),u=o(!1),s=le();let d=0;const n=async(c,l=-1)=>{r.value=!0,d=y(100/(t.value.length+3)),a.value=d,l!=-1?await v(c,l):await _(c)},_=async c=>{let l=y(c);console.log(l,"ddddddddddddddddddddddd");const p=await O(e.value.file,{endpoint:s.STORAGE_UPLOAD});a.value=d;try{const i=t.value.map(async(g,f)=>{const m=await O(g.file,{endpoint:s.STORAGE_UPLOAD});return a.value=d*(f+1),{url:m.data?.fullPath,type:g.file.type.includes("video")?"video":"image"}});l.original_image=p.data?.fullPath,l.files.push({url:p.data?.fullPath,type:e.value.file.type.includes("video")?"video":"image"});const z=await Promise.all(i);l.files.push(...z),l.collection_id=l.collection_id??l.collections?.parent_id,l.price=l.price?parseInt(l.price):0,l.weight=l.weight?parseFloat(l.weight):0,l.percent_fee=l.percent_fee?parseFloat(l.percent_fee):0,l.rial_fee=l.rial_fee?parseInt(l.rial_fee):0,l.count=l.count?parseInt(l.count):void 0,l.discount=l.discount?parseInt(l.discount):void 0,l.box_size=parseInt(l.box_size),l.variants?.forEach(g=>{g.discount=g.discount?parseInt(g.discount):void 0})}catch(i){throw b.error(s.useString("theProductImageDidNotLoadCorrectly")),a.value=0,console.error(i),new Error(s.useString("theProductImageDidNotLoadCorrectly"))}if(l.original_image&&!p.error)try{console.log(l,"ddddddddddddddddddddddd"),await se(l),R(),a.value=100,b.success(s.useString("addedSuccessfully"))}catch(i){throw console.error(i),b.error(i),a.value=0,new Error(i)}finally{r.value=!1}else throw b.error(s.useString("theProductImageDidNotLoadCorrectly")),r.value=!1,a.value=0,new Error(s.useString("theProductImageDidNotLoadCorrectly"));R(),t.value=[],e.value=void 0},v=async(c,l)=>{let p,i=y(c);_e(L.value,K.value,"index").forEach(f=>{L.value.splice(f.index,1,null),i.files.splice(f.index,1,null)}),L.value=L.value.filter(f=>f!=null),p=he(K.value,L.value,fe);let g;if(p.length!=0){e.value&&t.value.splice(0,0,e.value);const f=t.value.map(async(m,D)=>{const T=await O(m.file,{endpoint:s.STORAGE_UPLOAD});if(a.value=d*(D+1),T.error)throw b.error(s.useString("theProductImageDidNotLoadCorrectly")),a.value=0,new Error(s.useString("theProductImageDidNotLoadCorrectly"));return{value:{url:T.data?.fullPath,type:m.file.type.includes("video")?"video":"image"},id:p[D]?.index}});g=await Promise.all(f),i.files||(i.files=[]),g.forEach((m,D)=>{i.files[m.id]=m.value})}i.files=i.files.filter(f=>f!=null),i.original_image=i.files[0].url,i.price=i.price?parseInt(i.price):void 0,i.weight=i.weight?parseFloat(i.weight):void 0,i.percent_fee=i.weight?parseFloat(i.percent_fee):void 0,i.rial_fee=i.rial_fee?parseInt(i.rial_fee):0,i.count=i.count?parseInt(i.count):void 0,i.discount=i.discount?parseInt(i.discount):void 0,i.collection_id=i.collection_id??i.collections?.parent_id,i.collection_id=i?.collection_id??null,i.upload_files=c.upload_files,delete i.collections,i.variants?.forEach(f=>{f.discount=f.discount?parseInt(f.discount):void 0}),i.box_size=parseInt(i.box_size),i.discount==null&&(i.discount=void 0);try{a.value=99.5,await ne(i,l),R(),a.value=100,b.success(s.useString("updatedSuccessfully"))}catch(f){throw console.error(f),a.value=0,b.error(f),new Error(f)}finally{r.value=!1}t.value=[],e.value=void 0,R()};return{originalFile:e,percentUpload:a,mediaFiles:t,fileUpLoader:n,isFileChanged:u,loading:r}});export{me as A,Ee as B,be as C,C as D,$ as E,U as F,ke as G,ye as H,L as a,K as b,E as c,N as d,F as e,We as f,Q as g,Ne as h,Y as i,we as j,ge as k,G as l,h as m,Te as n,A as o,xe as p,Ke as q,R as r,Ce as s,Ge as t,k as u,_e as v,P as w,ze as x,S as y,x as z};