import{t as e}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{a as t}from"./logger-BTOOQRog.js";import"./render-ju_tzmp-.js";import{t as n}from"./moment-BMP7hRUy.js";import{i as r,n as i,t as a}from"./spy-ClD6aGlQ.js";import{c as o,o as s}from"./utils-TqnRpWKT.js";import{c}from"./api-hgs6YYEz.js";import{t as l}from"./get-ZYlZLxc3.js";import"./product-DSemKnKs.js";import{i as u}from"./Table-Be4a8zWQ.js";var d=e({name:`ShopeeSpyDashboard`,data(){return{listProductSpy:[]}},methods:{async fetchList(){this.listProductSpy=(await a.findMany({type:`product`})).map(e=>({...e,loading:!1}))},getSpyId(e){return this.listProductSpy.find(t=>t._id===e)},async onFetchProduct(e){let n=this.getSpyId(e._id);n.loading=!0;try{if(e.type===`product`){let t=await l(e.productId,e.shopId);t||=(await c(e.productUrl,2e3).catch(()=>{}),await l(e.productId,e.shopId)),t&&r(e,t)}}catch(e){t.error({msg:`SHOPEE_SPY_FETCH_ERROR`,error:e})}n.loading=!1},onRemoveProduct(e){this.$Modal.confirm({content:e.name,title:this.$t(`REMOVE_CONFIRM`),onOk:async()=>{this.$Message.success(this.$t(`REMOVE_SUCCESS`)),a.removeId(e._id),e.type===`product`&&(this.listProductSpy=this.listProductSpy.filter(t=>t._id!==e._id))}})}},created(){this.fetchList(),a.syncRemote(),i.syncRemote()},computed:{tableProductSpy(){return{columns:u.columns,data:this.listProductSpy.map(e=>({...e,productUrl:s(e.productId,e.shopId),shopUrl:o(e.shopId),showTime:n(new Date(e.time)),sale:e.sale,sold:e.sold,price:e.price,promotion:e.promotion}))}}}},function(){var e=this,t=e._self._c;return t(`div`,[t(`Table`,{ref:`TableProductList`,attrs:{columns:e.tableProductSpy.columns,data:e.tableProductSpy.data,"highlight-row":``,size:`small`,height:`800`,border:``},scopedSlots:e._u([{key:`name`,fn:function({row:n}){return[t(`a`,{attrs:{href:n.productUrl,target:`_blank`}},[e._v(e._s(e._f(`maxString`)(n.name,80)))])]}},{key:`shopName`,fn:function({row:n}){return[t(`a`,{attrs:{href:n.shopUrl,target:`_blank`}},[e._v(e._s(n.shopName))])]}},{key:`image`,fn:function({row:e}){return[t(`img`,{staticStyle:{width:`50px`},attrs:{src:e.image}})]}},{key:`action`,fn:function({row:n}){return[t(`Button`,{staticClass:`mr-5`,attrs:{type:`primary`,ghost:``,size:`small`,loading:n.loading},on:{click:function(t){return e.onFetchProduct(n)}}},[e._v(` `+e._s(e.$t(`FETCH_BTN`))+` `)]),t(`Button`,{attrs:{type:`error`,ghost:``,size:`small`,loading:n.loading},on:{click:function(t){return e.onRemoveProduct(n)}}},[e._v(` `+e._s(e.$t(`REMOVE_BTN`))+` `)])]}}])})],1)},[],!1,null,null,null,null).exports;export{d as default};