451 行
16 KiB
JavaScript
可执行文件
451 行
16 KiB
JavaScript
可执行文件
/**
|
|
* 药品管理主应用
|
|
*/
|
|
class GoodsApp {
|
|
constructor() {
|
|
this.vueInstance = null;
|
|
this.stateManager = null;
|
|
this.batchManager = null;
|
|
this.init();
|
|
}
|
|
|
|
init() {
|
|
this.vueInstance = new Vue({
|
|
el: '#goodsListApp',
|
|
data: this.getInitialData(),
|
|
methods: this.getMethods(),
|
|
created: this.onCreated.bind(this)
|
|
});
|
|
|
|
this.stateManager = new GoodsStateManager(this.vueInstance);
|
|
this.batchManager = new GoodsBatchManager(this.vueInstance);
|
|
|
|
// 绑定状态管理方法
|
|
this.bindStateManagerMethods();
|
|
this.bindBatchManagerMethods();
|
|
}
|
|
|
|
getInitialData() {
|
|
return {
|
|
platform_type: 1,
|
|
submitLoading: false,
|
|
searchForm: {
|
|
keyword_type: 2,
|
|
keyword: '',
|
|
condition_name: '',
|
|
order_type: '',
|
|
pricing_method: '',
|
|
advance_sale_status: '',
|
|
status: '',
|
|
attribute_state: '',
|
|
person1: '',
|
|
person2: '',
|
|
person3: '',
|
|
},
|
|
merchant_id: localStorage.merchant_id,
|
|
store_id: localStorage.store_id,
|
|
showMoreSearch: false,
|
|
operate: {},
|
|
showBatchOperate: false,
|
|
changeForm: {
|
|
key: 'status',
|
|
value: null,
|
|
delivery_template_id: '',
|
|
},
|
|
goodsList: [],
|
|
currentLen: 0,
|
|
currentPage: 1,
|
|
currentLimit: 10,
|
|
checkedList: [],
|
|
table_loading: false,
|
|
loading: false,
|
|
loadingText: '数据获取中',
|
|
showBigImg: false,
|
|
bigImg: '',
|
|
deliveryTemplateList: [],
|
|
resetPluDialogVisible: false,
|
|
resetPluMethod: 3,
|
|
resetPluLoading: ''
|
|
};
|
|
}
|
|
|
|
getMethods() {
|
|
return {
|
|
// 基础方法
|
|
changeKeywordType: (val) => {
|
|
this.vueInstance.searchForm.keyword_type = val;
|
|
},
|
|
|
|
seeBig: (img) => {
|
|
if (img) {
|
|
this.vueInstance.showBigImg = true;
|
|
this.vueInstance.bigImg = img;
|
|
}
|
|
},
|
|
|
|
// 数据操作
|
|
getData: this.getData.bind(this),
|
|
searchGoods: this.searchGoods.bind(this),
|
|
|
|
// 药品操作
|
|
setGoods: this.setGoods.bind(this),
|
|
delGoods: this.delGoods.bind(this),
|
|
|
|
// 分页操作
|
|
handleSizeChange: this.handleSizeChange.bind(this),
|
|
handleCurrentChange: this.handleCurrentChange.bind(this),
|
|
handleSelectionChange: this.handleSelectionChange.bind(this),
|
|
|
|
// 导出操作
|
|
exportTable: this.exportTable.bind(this),
|
|
SkuGoodsTable: this.SkuGoodsTable.bind(this),
|
|
|
|
// 其他操作
|
|
downloadLabel: this.downloadLabel.bind(this),
|
|
syncGoods: this.syncGoods.bind(this),
|
|
twoSyncGoods: this.twoSyncGoods.bind(this),
|
|
changeGoods: this.changeGoods.bind(this),
|
|
goodsSimple: this.goodsSimple.bind(this),
|
|
getPlatformType: this.getPlatformType.bind(this),
|
|
getOperate: this.getOperate.bind(this),
|
|
|
|
// PLU码重置
|
|
resetPluConfirm: this.resetPluConfirm.bind(this),
|
|
resetPlu: this.resetPlu.bind(this),
|
|
|
|
// 批量操作相关
|
|
closeBatchEdit: () => {
|
|
this.vueInstance.showBatchOperate = false;
|
|
this.getData();
|
|
}
|
|
};
|
|
}
|
|
|
|
bindStateManagerMethods() {
|
|
this.vueInstance.changeStatus = this.stateManager.changeStatus.bind(this.stateManager);
|
|
this.vueInstance.changeOnline = this.stateManager.changeOnline.bind(this.stateManager);
|
|
this.vueInstance.doChangeRetailState = this.stateManager.changeRetailState.bind(this.stateManager);
|
|
this.vueInstance.changeOnlineDis = this.stateManager.changeOnlineDis.bind(this.stateManager);
|
|
this.vueInstance.changeRetailDis = this.stateManager.changeRetailDis.bind(this.stateManager);
|
|
this.vueInstance.changeUsual = this.stateManager.changeUsual.bind(this.stateManager);
|
|
}
|
|
|
|
bindBatchManagerMethods() {
|
|
this.vueInstance.toShowChangeGoods = this.batchManager.showBatchOperate.bind(this.batchManager);
|
|
this.vueInstance.selectedChangeKey = this.batchManager.selectedChangeKey.bind(this.batchManager);
|
|
this.vueInstance.batchOperateGoods = this.batchManager.batchOperateGoods.bind(this.batchManager);
|
|
}
|
|
|
|
async onCreated() {
|
|
await this.getPlatformType();
|
|
await this.getData();
|
|
await this.getOperate();
|
|
}
|
|
|
|
// 获取平台类型
|
|
async getPlatformType() {
|
|
try {
|
|
const res = await GoodsUtils.apiRequest('/index.php/Retail/Goods/getPlatformType');
|
|
this.vueInstance.platform_type = res.platform_type;
|
|
} catch (error) {
|
|
this.vueInstance.$message.error('获取平台类型失败');
|
|
}
|
|
}
|
|
|
|
// 获取数据
|
|
async getData() {
|
|
this.vueInstance.table_loading = true;
|
|
try {
|
|
const params = GoodsUtils.formatSearchParams(
|
|
this.vueInstance.searchForm,
|
|
{
|
|
currentPage: this.vueInstance.currentPage,
|
|
currentLimit: this.vueInstance.currentLimit
|
|
}
|
|
);
|
|
|
|
const res = await GoodsUtils.apiRequest("/index.php/Retail/Goods/goodsList", params);
|
|
if (res.code == 0) {
|
|
this.vueInstance.goodsList = res.data || [];
|
|
this.vueInstance.currentLen = parseInt(res.count) || 0;
|
|
} else {
|
|
this.vueInstance.$confirm(res.msg, '提示', {
|
|
confirmButtonText: '确定',
|
|
type: 'warning'
|
|
}).catch(() => {});
|
|
}
|
|
} catch (error) {
|
|
this.vueInstance.$message.error('获取药品列表失败');
|
|
} finally {
|
|
this.vueInstance.table_loading = false;
|
|
}
|
|
}
|
|
|
|
// 搜索药品
|
|
searchGoods() {
|
|
this.vueInstance.currentPage = 1;
|
|
this.getData();
|
|
}
|
|
|
|
// 编辑、新增药品
|
|
setGoods(id) {
|
|
MenuApp.pathData.push({
|
|
name: (id ? '编辑' : '新增') + '药品',
|
|
path: '/index.php/Retail/Goods/goodsSet' + (id ? ('?id=' + id) : ''),
|
|
onClose: () => {
|
|
this.getData();
|
|
}
|
|
});
|
|
}
|
|
|
|
// 删除药品
|
|
async delGoods(id) {
|
|
try {
|
|
await this.vueInstance.$confirm('您确认要删除该药品吗?', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
});
|
|
|
|
const res = await GoodsUtils.apiRequest("/index.php/Retail/Goods/singleDelete", { id });
|
|
if (res.status == 1) {
|
|
this.getData();
|
|
this.vueInstance.$message.success(res.msg);
|
|
} else {
|
|
this.vueInstance.$message.error(res.msg);
|
|
}
|
|
} catch (error) {
|
|
if (error !== 'cancel') {
|
|
this.vueInstance.$message.error('删除操作失败');
|
|
}
|
|
}
|
|
}
|
|
|
|
// 分页相关方法
|
|
handleSizeChange(val) {
|
|
this.vueInstance.currentLimit = val;
|
|
this.vueInstance.currentPage = 1;
|
|
this.getData();
|
|
}
|
|
|
|
handleCurrentChange(val) {
|
|
this.vueInstance.currentPage = val;
|
|
this.getData();
|
|
}
|
|
|
|
handleSelectionChange(data) {
|
|
this.vueInstance.checkedList = data;
|
|
}
|
|
|
|
// 导出相关方法
|
|
async exportTable(page = 1, online_state = '', attribute_state = '', type = 1, directory_name = '') {
|
|
this.vueInstance.loading = true;
|
|
this.vueInstance.loadingText = '文件生成中,请耐心等待';
|
|
|
|
if (type == 1) {
|
|
try {
|
|
const params = {
|
|
page,
|
|
...this.vueInstance.searchForm,
|
|
online_state,
|
|
attribute_state,
|
|
type,
|
|
directory_name
|
|
};
|
|
|
|
const res = await GoodsUtils.apiRequest("/index.php/Retail/Exporttable/goods", params);
|
|
if (res.status == 1) {
|
|
if (res.type == 1) {
|
|
this.exportTable(++page, online_state, attribute_state, res.type, res.directory_name);
|
|
} else {
|
|
this.vueInstance.loading = false;
|
|
window.location.href = `/index.php/Retail/Exporttable/goods?directory_name=${res.directory_name}&online_state=${online_state}&attribute_state=${attribute_state}`;
|
|
}
|
|
} else {
|
|
this.vueInstance.loading = false;
|
|
this.vueInstance.$confirm(res.msg, '提示', {
|
|
confirmButtonText: '确定',
|
|
type: 'warning'
|
|
}).catch(() => {});
|
|
}
|
|
} catch (error) {
|
|
this.vueInstance.loading = false;
|
|
this.vueInstance.$message.error('导出失败');
|
|
}
|
|
} else {
|
|
this.vueInstance.loading = false;
|
|
window.location.href = `/index.php/Retail/Exporttable/goods?directory_name=${directory_name}&online_state=${online_state}&attribute_state=${attribute_state}`;
|
|
}
|
|
}
|
|
|
|
async SkuGoodsTable(page = 1, limit = 200, type = 1, directory_name = '', attribute_state = 2) {
|
|
this.vueInstance.loading = true;
|
|
this.vueInstance.loadingText = '文件生成中,请耐心等待';
|
|
|
|
if (type == 1) {
|
|
try {
|
|
const params = {
|
|
page,
|
|
limit,
|
|
type,
|
|
directory_name,
|
|
attribute_state,
|
|
searchForm: this.vueInstance.searchForm
|
|
};
|
|
|
|
const res = await GoodsUtils.apiRequest("{:U('exportGoods')}", params);
|
|
this.vueInstance.loading = false;
|
|
if (res.status == 1) {
|
|
this.SkuGoodsTable(++page, limit, res.data.type, res.data.directory_name, attribute_state);
|
|
} else {
|
|
this.vueInstance.$confirm(res.msg, '提示', {
|
|
confirmButtonText: '确定',
|
|
type: 'warning'
|
|
}).catch(() => {});
|
|
}
|
|
} catch (error) {
|
|
this.vueInstance.loading = false;
|
|
this.vueInstance.$message.error('导出失败');
|
|
}
|
|
} else {
|
|
this.vueInstance.loading = false;
|
|
window.open(`{:U('exportFile')}?file_path=${directory_name}&attribute_state=${attribute_state}`);
|
|
}
|
|
}
|
|
|
|
// 其他操作方法
|
|
downloadLabel() {
|
|
GoodsUtils.openDialog({
|
|
title: "打印药品标签",
|
|
content: "/index.php/Retail/Goods/downloadLabel"
|
|
});
|
|
}
|
|
|
|
syncGoods() {
|
|
GoodsUtils.openDialog({
|
|
title: "同步商户药品",
|
|
content: "/index.php/Retail/Goods/sync_goods",
|
|
end: () => {
|
|
this.getData();
|
|
}
|
|
});
|
|
}
|
|
|
|
twoSyncGoods() {
|
|
GoodsUtils.openDialog({
|
|
title: "更新药品",
|
|
content: "/index.php/Retail/Goods/two_sync_goods",
|
|
end: () => {
|
|
this.getData();
|
|
}
|
|
});
|
|
}
|
|
|
|
changeGoods() {
|
|
GoodsUtils.openDialog({
|
|
title: "批量删除药品",
|
|
content: "/index.php/Retail/Goods/delete_goods",
|
|
end: () => {
|
|
if (localStorage.isChangeClass == 1) {
|
|
localStorage.isChangeClass = null;
|
|
this.getData();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
goodsSimple() {
|
|
GoodsUtils.openDialog({
|
|
title: '简拼设置',
|
|
content: "/index.php/Retail/Goods/simple"
|
|
});
|
|
}
|
|
|
|
// 获取操作权限
|
|
async getOperate() {
|
|
const auth_list = {
|
|
goodsSet: '/index.php/Retail/Goods/goodsSet',
|
|
downloadLabel: '/index.php/Retail/Goods/downloadLabel',
|
|
sync_goods: '/index.php/Retail/Goods/sync_goods',
|
|
two_sync_goods: '/index.php/Retail/Goods/two_sync_goods',
|
|
goods: '/index.php/Retail/Exporttable/goods',
|
|
goodstwo: '/index.php/Retail/Exporttable/goodstwo',
|
|
updateGoods: '/index.php/Retail/Goods/updateGoods',
|
|
move_class: '/index.php/Retail/Goods/move_class',
|
|
delete_goods: '/index.php/Retail/Goods/delete_goods',
|
|
addQuantity: '/index.php/Retail/Goods/addQuantity',
|
|
singleDelete: '/index.php/Retail/Goods/singleDelete',
|
|
changestatus: '/index.php/Retail/Goods/changestatus',
|
|
changeissellonline: '/index.php/Retail/Goods/changeissellonline',
|
|
changeRetailState: '/index.php/Retail/Goods/changeRetailState',
|
|
changevip_online_state: '/index.php/Retail/Goods/changevip_online_state',
|
|
changevip_retail_state: '/index.php/Retail/Goods/changevip_retail_state',
|
|
changeusualDemo: '/index.php/Retail/Goods/changeusualDemo',
|
|
simple: '/index.php/Retail/Goods/simple',
|
|
batchOperateGoods: '/index.php/Retail/Goods/batchOperateGoods',
|
|
};
|
|
|
|
try {
|
|
const res = await GoodsUtils.apiRequest('/index.php/Retail/Component/checkOperateAuth', {
|
|
auth_list: JSON.stringify(auth_list),
|
|
});
|
|
if (res.status == 1) {
|
|
this.vueInstance.operate = res.data;
|
|
}
|
|
} catch (error) {
|
|
this.vueInstance.$message.error('获取操作权限失败');
|
|
}
|
|
}
|
|
|
|
// PLU码重置相关
|
|
async resetPluConfirm() {
|
|
this.vueInstance.resetPluDialogVisible = false;
|
|
try {
|
|
await this.vueInstance.$confirm(
|
|
`<p>您确定要重置Plu码吗?</p><p style="font-size: 12px;">重置后,系统将重新生成药品的Plu码。</p>`,
|
|
'提示',
|
|
{
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
dangerouslyUseHTMLString: true,
|
|
type: 'warning'
|
|
}
|
|
);
|
|
this.vueInstance.resetPluLoading = this.vueInstance.$loading();
|
|
this.resetPlu();
|
|
} catch (error) {
|
|
// 用户取消操作
|
|
}
|
|
}
|
|
|
|
async resetPlu(goodId = 0, pluCode = 0) {
|
|
try {
|
|
const res = await GoodsUtils.apiRequest('Retail/Goods/resetStorePlu', {
|
|
pricing_method: this.vueInstance.resetPluMethod,
|
|
plu_code: pluCode,
|
|
goodId: goodId
|
|
});
|
|
|
|
if (res.status == 1) {
|
|
const data = res.data;
|
|
if (!data) {
|
|
this.vueInstance.resetPluLoading.close();
|
|
this.vueInstance.$message.success('Plu码重置完成');
|
|
} else {
|
|
this.resetPlu(data.goodId, data.pluCode);
|
|
}
|
|
} else {
|
|
this.vueInstance.resetPluLoading.close();
|
|
this.vueInstance.$message.error(res.message);
|
|
}
|
|
} catch (error) {
|
|
this.vueInstance.resetPluLoading.close();
|
|
this.vueInstance.$message.error('重置失败');
|
|
}
|
|
}
|
|
}
|
|
|
|
// 初始化应用
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
window.goodsApp = new GoodsApp();
|
|
}); |