Vue.component('manage-goods-unit', {
template: `
`,
props: {
'operateType': {
type: Number,
required: true,
},//1商户 2门店
},
data() {
return {
dataList: [], // 数据
searchForm: {
name: '',
page: 1, // 分页
limit: 10, // 每页显示条数
},//搜索表单
count: 0, // 总条数
showAddUnitLibrary: false, //是否显示添加
operate: {}, //权限
ruleForm: {
id: 0,
name: '',
},//新增、编辑表单
rules: {
name: [{message: '请输入单位名称', required: true, trigger: 'change'}],
},
requestUrl: {
addUnit: '/index.php/Retail/UnitLibrary/' + (this.operateType == 1 ? 'addMerchantUnit' : 'addStoreUnit'),
deleteUnit: '/index.php/Retail/UnitLibrary/' + (this.operateType == 1 ? 'deleteMerchantUnit' : 'deleteStoreUnit'),
},
};
},
methods: {
closeEditUnitLibrary() {
this.$refs.ruleForm.resetFields();
this.ruleForm.id = '';
this.showAddUnitLibrary = false;
},
/* 获取数据 */
getUnitLibraryList() {
this.dataList = [];
this.loading = true;
this.sendRequest('Retail/UnitLibrary/getUnitList',{
data: {
...this.searchForm,
type: this.operateType,
},
success: (res) => {
this.loading = false;
if (res.status == 1) {
this.count = res.data.count;
this.dataList = res.data.list;
}else{
this.$message.error(res.message);
}
},
})
},
//查询
searchData() {
this.searchForm.page = 1;
this.getUnitLibraryList();
},
/* 切换每页数量 */
sizeChange(val) {
this.searchForm.limit = val;
this.searchForm.page = 1;
this.getUnitLibraryList();
},
/* 切换页数 */
currentChange(val) {
this.searchForm.page = val;
this.getUnitLibraryList();
},
//保存单位
saveUnitLibrary() {
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.addUnit, {
data: {
...this.ruleForm
},
success: (res) => {
this.$loading().close();
if (res.status == 1) {
this.closeEditUnitLibrary();
this.$message.success(res.message);
this.getUnitLibraryList();
} else {
this.$message.error(res.message)
}
},
})
}).catch(() => {
})
})
},
//删除单位
delUnitLibrary(item) {
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.deleteUnit, {
data: {
id: item.id,
name: item.name,
},
success: (res) => {
this.$loading().close();
if (res.status == 1) {
this.$message.success(res.message);
this.getUnitLibraryList();
} else {
this.$message.error(res.message)
}
},
})
}).catch(() => {
})
},
},
created() {
this.getUnitLibraryList();
this.checkOperateAuth(this.requestUrl, (data) => {
this.operate = data;
})
},
});