const coinActive = { template: /* html*/ `
{{lang.coin_text71}}{{coin_name}}
{{coin_name}}{{lang.coin_text72}}
`, data() { return { commonData: {}, coin_name: "", coinClientInfo: {}, coinActiveList: [], loading: false, home_show_coin_activity: 0, activeTab: "current", product_id: 0, host_id: 0, active_show: false, init: true, }; }, filters: { formateTime(time) { if (time && time !== 0) { return formateDate(time * 1000, "YYYY-MM-DD HH:mm"); } else { return lang.voucher_effective; } }, }, created() { if (!havePlugin("Coin")) { return; } // 加载css if ( !document.querySelector( 'link[href="' + url + 'components/coinActive/coinActive.css"]' ) ) { const link = document.createElement("link"); link.rel = "stylesheet"; link.href = `${url}components/coinActive/coinActive.css`; document.head.appendChild(link); } this.commonData = JSON.parse(localStorage.getItem("common_set_before")) || {}; this.getCoinInfo(); }, methods: { visbleShow() { this.coinActiveList.forEach((item) => { item.show_desc = false; }); this.getCoinActiveList(); }, handleTabClick() { this.getCoinActiveList(); }, // 计算场景送的活动范围 calculateSceneRange(item) { const allActions = []; item.forEach(rule => { rule.notice_actions_arr.forEach(action => { if (action.name === 'host_renew') { allActions.push(`${rule.trigger_products[0] ? rule.trigger_products[0].name : lang.coin_text108}${action.name_lang}:${lang.coin_text105}${rule.amount}${this.coin_name}`); } else if (action.name === 'order_pay') { allActions.push(`${rule.trigger_products[0] ? rule.trigger_products[0].name : lang.coin_text108}${action.name_lang}:${lang.coin_text105}${rule.amount}${this.coin_name}`); } else { if (!allActions.includes(action)) { allActions.push(`${action.name_lang}:${lang.coin_text105}${rule.amount}${this.coin_name}`); } } }); }); return allActions; }, setProductId() { const nowUrl = location.href.split("/").pop(); const pageRouter = nowUrl.indexOf("?") !== -1 ? nowUrl.split("?")[0] : nowUrl; if (pageRouter == "goods.htm") { this.product_id = getUrlParams().id; } else if (pageRouter == "productdetail.htm") { this.host_id = getUrlParams().id; } }, async getCoinInfo() { try { const res = await apiCoinClientCoupon(); this.coin_name = res.data.data.name; this.coinClientInfo = res.data.data; this.home_show_coin_activity = res.data.data.home_show_coin_activity; if (this.home_show_coin_activity == 1) { this.setProductId(); await this.getCoinActiveList(true); } } catch (error) { console.log(error); } }, async getCoinActiveList(isInit = false) { this.loading = true; const params = {}; const isProduct = this.activeTab === "current" && this.product_id; const isHost = this.activeTab === "current" && this.host_id; params.product_id = isProduct ? this.product_id : undefined; params.host_id = isHost ? this.host_id : undefined; const isGoodPage = isProduct || isHost; await apiCoinActiveList(params) .then((res) => { this.coinActiveList = res.data.data.list.map((item) => { item.show_desc = false; return item; }); if (isGoodPage && isInit === true) { this.active_show = this.coinActiveList.length > 0; } }) .finally(() => { this.loading = false; }); }, }, };