157 行
5.1 KiB
JavaScript
可执行文件
157 行
5.1 KiB
JavaScript
可执行文件
/**
|
|
* 选择商品标签
|
|
*/
|
|
Vue.component('select-goods-label', {
|
|
template: `<el-select v-model="label_id_arr"
|
|
:placeholder="placeholder"
|
|
:disabled="isDisabled"
|
|
size="small"
|
|
:class="customerClass"
|
|
:multiple-limit="10"
|
|
value-key="id" @change="changeLabel"
|
|
multiple clearable filterable>
|
|
<el-option-group v-for="group in dataList"
|
|
:key="group.id"
|
|
:label="group.name">
|
|
<el-option v-for="item in group.list"
|
|
:key="item.id"
|
|
:disabled="item.industry_id>0&&(limitIndustryId>0&&limitIndustryId!=item.industry_id||selIndustryId>0&&selIndustryId!=item.industry_id)"
|
|
:label="item.name"
|
|
:value="item">
|
|
</el-option>
|
|
</el-option-group>
|
|
</el-select>`,
|
|
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();
|
|
}
|
|
},
|
|
}
|
|
}); |