import{t as e}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{n as t}from"./vuex.esm-CDgO7zd-.js";import{i as n,n as r,r as i,t as a}from"./keyword-CcwMZVN0.js";import{n as o}from"./vue-composition-api-C3MbKFsM.js";var s=e({name:`ShopeeKeywordList`,mixins:[o({data(){return{loadingData:!1,listCollection:[],popupCreate:!1,formCreate:{id:``,name:``,description:``}}},methods:{...t([`ShopeeKeywordExport`]),onOpen(e){return this.openExternalUrl(this.createPopupUrl(`/shopee/keyword/${e._id}`),!0)},onRemove(e){let t=e._id;this.$Modal.confirm({content:this.$t(`REMOVE_CONFIRM`),title:e.name,onOk:async()=>{this.$Message.success(this.$t(`REMOVE_SUCCESS`)),this.listCollection=this.listCollection.filter(e=>e._id!==t),i(t)}})},async onExport(e,t){this.listCollection[t].loading=!0,await this.ShopeeKeywordExport({id:e._id,name:e.name}),this.listCollection[t].loading=!1},onCreate(){this.formCreate.id=``,this.formCreate.name=``,this.formCreate.description=``,this.popupCreate=!0},onEdit(e){this.formCreate.id=e._id,this.formCreate.name=e.name,this.formCreate.description=e.description,this.popupCreate=!0},handlerPopup(){if(this.formCreate.id)return this.updateCollection();this.createCollection()},async getList(){this.loadingData=!0,this.listCollection=(await r()).data.map(e=>({...e,loading:!1})),this.loadingData=!1},async updateCollection(){let{success:e}=await n(this.formCreate.id,{name:this.formCreate.name,description:this.formCreate.description});if(!e)return this.$Message.error(this.$t(`UPDATE_ERROR`));let t=this.listCollection.find(e=>e._id===this.formCreate.id);t.name=this.formCreate.name,t.description=this.formCreate.description,this.$Message.success(this.$t(`UPDATE_SUCCESS`))},async createCollection(){let{data:e,success:t}=await a({name:this.formCreate.name,description:this.formCreate.description});if(!t)return this.$Message.error(this.$t(`CREATE_ERROR`));e.loading=!1,this.listCollection.push(e),this.$Message.success(this.$t(`CREATE_SUCCESS`))}},created(){this.getList()},computed:{listCollectionShow(){return this.listCollection.map(e=>({...e,title:this.$t(`KEYWORD_COLLECTION_GET_TITLE`,{name:e.name,count:e.count,time:this.$d(new Date(e.timeCreate),`long`)})}))}}})]},function(){var e=this,t=e._self._c;return t(`div`,[t(`div`,{staticClass:`mb-10 text-right`},[t(`Button`,{attrs:{type:`primary`},on:{click:e.onCreate}},[e._v(` `+e._s(e.$t(`KEYWORD_COLLECTION_CREATE_BTN`))+` `)])],1),t(`div`,[e.listCollection.length?e._e():t(`div`,[t(`Alert`,{attrs:{type:`warning`,"show-icon":``}},[e._v(` `+e._s(e.$t(`KEYWORD_LIST_EMPTY`))+` `)])],1),t(`List`,e._l(e.listCollectionShow,function(n,r){return t(`ListItem`,{key:n._id,scopedSlots:e._u([{key:`action`,fn:function(){return[t(`li`,[t(`Button`,{staticClass:`text-success`,attrs:{type:`text`,size:`small`,loading:n.loading},on:{click:function(t){return e.onExport(n,r)}}},[e._v(` `+e._s(e.$t(`EXPORT_BTN`))+` `)])],1),t(`li`,[t(`Button`,{staticClass:`text-secondary`,attrs:{type:`text`,size:`small`,loading:n.loading},on:{click:function(t){return e.onEdit(n)}}},[e._v(` `+e._s(e.$t(`EDIT_BTN`))+` `)])],1),t(`li`,[t(`Button`,{staticClass:`text-primary`,attrs:{type:`text`,size:`small`,loading:n.loading},on:{click:function(t){return e.onOpen(n)}}},[e._v(` `+e._s(e.$t(`OPEN_BTN`))+` `)])],1),t(`li`,{staticStyle:{width:`50px`}},[t(`Button`,{staticClass:`text-danger`,attrs:{type:`text`,size:`small`,loading:n.loading},on:{click:function(t){return e.onRemove(n)}}},[e._v(` `+e._s(e.$t(`DELETE_BTN`))+` `)])],1)]},proxy:!0}],null,!0)},[t(`ListItemMeta`,{attrs:{title:n.title,description:n.description}})],1)}),1)],1),t(`div`,[t(`Modal`,{attrs:{title:e.$t(`KEYWORD_COLLECTION_NEW`)},on:{"on-ok":e.handlerPopup},model:{value:e.popupCreate,callback:function(t){e.popupCreate=t},expression:`popupCreate`}},[t(`Form`,[t(`FormItem`,{attrs:{label:e.$t(`KEYWORD_COLLECTION_INPUT_NAME`)}},[t(`Input`,{attrs:{type:`text`},model:{value:e.formCreate.name,callback:function(t){e.$set(e.formCreate,`name`,t)},expression:`formCreate.name`}})],1),t(`FormItem`,{attrs:{label:e.$t(`KEYWORD_COLLECTION_INPUT_DESCRIPTION`)}},[t(`Input`,{attrs:{type:`text`},model:{value:e.formCreate.description,callback:function(t){e.$set(e.formCreate,`description`,t)},expression:`formCreate.description`}})],1)],1)],1)],1)])},[],!1,null,null,null,null).exports,c=e({name:`ShopeeKeywordIndex`,components:{"keyword-list":s}},function(){var e=this._self._c;return e(`div`,[e(`Row`,[e(`Col`,{attrs:{span:10,offset:7}},[e(`keyword-list`)],1)],1)],1)},[],!1,null,null,null,null).exports;export{c as default};