/** * 选择商品标签 */ Vue.component('select-goods-label', { template: ` `, props: { 'goodsId': { type: Number, default: '', },//选择商品ID 'customerClass': { type: String, default: '', }, 'placeholder': { type: String, default: '选择商品标签', }, 'industryId': { type: String, default: '', }, 'isDisabled': { type: Boolean, default: false, },//是否禁止修改 'type': { type: Number, default: 1, },//提交的来源类型 1商户 2门店 'selIndustryId': { type: String, default: '', },//已选中标签的行业ID 'limitIndustryId': { type: String, default: '', },//限制的行业ID }, data() { return { label_id_arr: [],//已选中的标签列表 dataList: [],// 数据 }; }, methods: { changeLabel(val) { if (val && val.length) { let flag = false; for (let i = 0; i < val.length; i++) { if (val[i].industry_id > 0) { this.$emit('update:selIndustryId', val[i].industry_id); flag = true; break; } } if(!flag){ this.$emit('update:selIndustryId', ''); } } else { this.$emit('update:selIndustryId', ''); } }, //获取标签列表 getLabelList() { this.sendRequest('Retail/LabelInventory/getLabelList', { data: { industry_id: this.industryId }, success: (res) => { if (res.status == 1) { this.dataList = res.data.list; } else { this.$message.error(res.message); } }, }) }, //获取商品的标签 getGoodsLabel() { this.sendRequest('Retail/LabelInventory/getGoodsLabel', { data: { goods_id: this.goodsId, user_type: this.type, }, success: (res) => { if (res.status == 1) { this.label_id_arr = res.data.list; this.changeLabel(this.label_id_arr); } else { this.$message.error(res.message); } }, }) }, //提交标签设置 submitLabel(goods_id, callback) { if (goods_id) { let label_ids = []; this.label_id_arr.forEach((item)=>{ label_ids.push(item.id); }); this.sendRequest('Retail/LabelInventory/addGoodsLabelLink', { data: { label_ids: JSON.stringify(label_ids), goods_id: goods_id, user_type: this.type }, success: (res) => { if (res.status != 1) { this.$message.error(res.message); } else { typeof callback == "function" && callback(); } }, }) } else { typeof callback == "function" && callback(); } }, //清除标签选择 clearLabel() { this.label_id_arr = []; } }, created() { if (this.goodsId > 0) { this.getGoodsLabel(); } this.getLabelList(); }, watch: { goodsId(n) { if (n > 0) { this.getGoodsLabel(); } }, } });