Vue.component('manage-goods-label', {
template: `
`,
props: {
'operateType': {
type: Number,
required: true,
},//1商户 2门店
'storeId': {
type: String,
default: '',
},
},
data() {
return {
bandGoodsLabelId: '',//绑定商品的标签ID
showBindGoodsDialog: false,//是否显示绑定商品弹框
showBindGoodsDetailsDialog: false,//是否显示已绑定商品弹框
dataList: [], // 标签数据列表
storeIndustryId: localStorage.industry_id,//门店的行业ID
searchForm: {
name: '',
industry_id: this.operateType == 2 ? (localStorage.industry_id > 0 ? localStorage.industry_id : '') : '',
page: 1, // 分页
limit: 10, // 每页显示条数
},//搜索表单
count: 0, // 总条数
showAddLabel: false, //是否显示添加
operate: {}, //权限
ruleForm: {
id: 0,
name: '',
industry_id: this.operateType == 2 ? (localStorage.industry_id > 0 ? localStorage.industry_id : '') : '',
},//新增、编辑表单
rules: {
industry_id: [{message: '请选择所属行业', required: false, trigger: 'change'}],
name: [{message: '请输入标签名称', required: true, trigger: 'change'}],
},
requestUrl: {
addLabel: '/index.php/Retail/LabelInventory/' + (this.operateType == 1 ? 'addMerchantLabelData' : 'addStoreLabelData'),
delLabel: '/index.php/Retail/LabelInventory/' + (this.operateType == 1 ? 'delMerchantLabelData' : 'delStoreLabelData'),
bandGoods: '/index.php/Retail/LabelInventory/' + (this.operateType == 1 ? 'addMerchantLinkGoods' : 'addStoreLinkGoods'),
delLinkGoods: '/index.php/Retail/LabelInventory/' + (this.operateType == 1 ? 'delMerchantLinkGoods' : 'delStoreLinkGoods'),
},
};
},
methods: {
//展示绑定商品
addGoodsLink(id) {
this.bandGoodsLabelId = id;
this.showBindGoodsDialog = true;
},
//关闭绑定商品弹框
closeBindGoods() {
this.bandGoodsLabelId = '';
this.showBindGoodsDialog = false;
this.getLabelList();
},
//查看已绑定的商品详情
goodsLinkDetail(id) {
this.bandGoodsLabelId = id;
this.showBindGoodsDetailsDialog = true;
},
//关闭绑定商品弹框
closeSeeGoods() {
this.bandGoodsLabelId = '';
this.showBindGoodsDetailsDialog = false;
this.getLabelList();
},
//编辑标签
editLabel(item) {
console.log(item);
this.ruleForm = {...item};
this.showAddLabel = true;
},
closeEditLabel() {
this.$refs.ruleForm.resetFields();
this.ruleForm.id = '';
this.showAddLabel = false;
},
/* 获取数据 */
getLabelList() {
this.dataList = [];
this.loading = true;
this.sendRequest('Retail/LabelInventory/getLabelInventoryList', {
data: {
...this.searchForm,
store_industry_id: this.storeIndustryId,
operate_type: this.operateType,
},
success: (res) => {
this.loading = false;
if (res.status == 1) {
this.count = res.data.count;
this.dataList = res.data.list;
}
},
error: () => {
this.loading = false;
}
})
},
/* 切换每页数量 */
sizeChange(val) {
this.searchForm.limit = val;
this.searchForm.page = 1;
this.getLabelList();
},
/* 切换页数 */
currentChange(val) {
this.searchForm.page = val;
this.getLabelList();
},
//保存标签
saveLabel() {
this.$refs.ruleForm.validate((valid) => {
if (!valid) {
return false;
}
this.$confirm("确认要保存该标签吗?", "温馨提示", {
confirmButtonText: '保存',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
this.$loading({
lock: true,
text: '保存中,请等待',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.7)'
});
this.sendRequest(this.requestUrl.addLabel, {
data: {
...this.ruleForm,
operate_type: this.operateType,
},
success: (res) => {
this.$loading().close();
if (res.status == 1) {
this.closeEditLabel();
this.$message.success(res.message);
this.getLabelList();
} else {
this.$message.error(res.message)
}
},
})
}).catch(() => {
})
});
},
//删除标签
delLabel(id) {
this.$confirm("确认要删除该标签吗?", "温馨提示", {
confirmButtonText: '删除',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
this.$loading({
lock: true,
text: '删除中,请等待',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.7)'
});
this.sendRequest(this.requestUrl.delLabel, {
data: {
id: id,
operate_type: this.operateType,
},
success: (res) => {
this.$loading().close();
if (res.status == 1) {
this.$message.success(res.message);
this.getLabelList();
} else {
this.$message.error(res.message)
}
},
})
}).catch(() => {
})
},
},
created() {
this.getLabelList();
this.checkOperateAuth(this.requestUrl, (data) => {
this.operate = data;
})
},
});