2 lines
3.8 KiB
JavaScript
2 lines
3.8 KiB
JavaScript
import{bc as U,bd as z,be as A,av as R,az as j,bf as D,bg as L,bh as w,aA as k,bi as x,b0 as H,r as m,H as W,bj as _,bk as F,S as p,bl as q,bm as B,bn as G}from"./BYv1load.js";import{r as C,f as v,a as P}from"./OQQ34J4k.js";function M(r,t,i){for(var n=-1,g=r==null?0:r.length;++n<g;)if(i(t,r[n]))return!0;return!1}var O=200;function N(r,t,i,n){var g=-1,u=z,d=!0,y=r.length,h=[],b=t.length;if(!y)return h;i&&(t=R(t,j(i))),n?(u=M,d=!1):t.length>=O&&(u=A,d=!1,t=new U(t));e:for(;++g<y;){var s=r[g],a=i==null?s:i(s);if(s=n||s!==0?s:0,d&&a===a){for(var o=b;o--;)if(t[o]===a)continue e;h.push(s)}else u(t,a,n)||h.push(s)}return h}var Y=D(function(r,t){var i=L(t);return w(i)&&(i=void 0),w(r)?N(r,x(t,1,w,!0),k(i)):[]}),Z=D(function(r,t){var i=L(t);return w(i)&&(i=void 0),w(r)?N(r,x(t,1,w,!0),void 0,i):[]});const Q=H("product",()=>{const r=m(),t=m([]),i=m(0),n=m(!1),g=m(!1),u=W();let d=0;const y=async(s,a=-1)=>{n.value=!0,d=_(100/(t.value.length+3)),i.value=d,a!=-1?await b(s,a):await h(s)},h=async s=>{let a=_(s);const o=await F(r.value.file);i.value=d;try{const e=t.value.map(async(c,l)=>{const f=await F(c.file);return i.value=d*(l+1),{url:f.data?.fullPath,type:c.file.type.includes("video")?"video":"image"}});a.original_image=o.data?.fullPath,a.files.push({url:o.data?.fullPath,type:r.value.file.type.includes("video")?"video":"image"});const S=await Promise.all(e);a.files.push(...S),a.price=a.price?parseInt(a.price):0,a.weight=a.weight?parseFloat(a.weight):0,a.percent_fee=a.percent_fee?parseFloat(a.percent_fee):0,a.rial_fee=a.rial_fee?parseInt(a.rial_fee):0,a.count=a.count?parseInt(a.count):void 0,a.discount=a.discount?parseInt(a.discount):void 0,a.box_size=parseInt(a.box_size),a.variants?.forEach(c=>{c.discount=c.discount?parseInt(c.discount):void 0})}catch(e){throw p.error(u.useString("theProductImageDidNotLoadCorrectly")),i.value=0,console.log(e),new Error(u.useString("theProductImageDidNotLoadCorrectly"))}if(console.log(a,o.error),a.original_image&&!o.error)try{await q(a),i.value=100,p.success(u.useString("addedSuccessfully"))}catch(e){throw console.log(e),p.error(e),i.value=0,new Error(e)}finally{n.value=!1}else throw p.error(u.useString("theProductImageDidNotLoadCorrectly")),n.value=!1,i.value=0,new Error(u.useString("theProductImageDidNotLoadCorrectly"));C(),t.value=[],r.value=void 0},b=async(s,a)=>{let o,e=_(s);Y(v.value,P.value,"index").forEach(l=>{v.value.splice(l.index,1,null),e.files.splice(l.index,1,null)}),v.value=v.value.filter(l=>l!=null),o=Z(P.value,v.value,B),console.log(e,o,v.value,P.value);let c;if(o.length!=0){r.value&&t.value.splice(0,0,r.value);const l=t.value.map(async(f,I)=>{const E=await F(f.file);if(i.value=d*(I+1),E.error)throw p.error(u.useString("theProductImageDidNotLoadCorrectly")),i.value=0,new Error(u.useString("theProductImageDidNotLoadCorrectly"));return{value:{url:E.data?.fullPath,type:f.file.type.includes("video")?"video":"image"},id:o[I]?.index}});c=await Promise.all(l),e.files||(e.files=[]),c.forEach((f,I)=>{e.files[f.id]=f.value})}e.files=e.files.filter(l=>l!=null),e.original_image=e.files[0].url,e.price=e.price?parseInt(e.price):void 0,e.weight=e.weight?parseFloat(e.weight):void 0,e.percent_fee=e.weight?parseFloat(e.percent_fee):void 0,e.rial_fee=e.rial_fee?parseInt(e.rial_fee):0,e.count=e.count?parseInt(e.count):void 0,e.discount=e.discount?parseInt(e.discount):void 0,e.variants?.forEach(l=>{l.discount=l.discount?parseInt(l.discount):void 0}),e.box_size=parseInt(e.box_size),e.discount==null&&(e.discount=void 0),console.log(e,c,t,o);try{i.value=99.5,await G(e,a),i.value=100,p.success(u.useString("updatedSuccessfully"))}catch(l){throw console.log(l),i.value=0,p.error(l),new Error(l)}finally{n.value=!1}t.value=[],r.value=void 0,C()};return{originalFile:r,percentUpload:i,mediaFiles:t,fileUpLoader:y,isFileChanged:g,loading:n}});export{Y as d,Q as u};
|