/** * 药品批量操作管理类 */ class GoodsBatchManager { constructor(vueInstance) { this.vue = vueInstance; } /** * 显示批量操作对话框 */ showBatchOperate() { if (!this.vue.checkedList.length) { return this.vue.$message.info('请先选择需要修改的药品'); } this.vue.changeForm.key = 'status'; this.vue.submitLoading = false; this.vue.showBatchOperate = true; } /** * 选择批量修改的字段 */ selectedChangeKey(val) { this.resetFormValue(val); this.vue.changeForm.delivery_template_id = ''; if (['goods_info', 'goods_plu'].includes(val)) { this.openBatchEditDialog(val); } } /** * 重置表单值 */ resetFormValue(val) { switch (val) { case 'status': this.vue.changeForm.value = 1; break; case 'retail_state': case 'online_state': case 'vip_retail_state': case 'vip_online_state': case 'guide_royalty_state': case 'refund_state': case 'exchange_state': this.vue.changeForm.value = 0; break; case 'delivery_type': this.vue.changeForm.value = []; if (!this.vue.deliveryTemplateList.length) { this.getDeliveryTemplateList(); } break; case 'goods_class_id': case 'fictitious_num': this.vue.changeForm.value = ''; break; } } /** * 打开批量编辑对话框 */ openBatchEditDialog(val) { const ids = this.vue.checkedList.map(item => item.id).join(','); const urlMap = { 'goods_info': { title: '批量修改药品', url: `updateGoods?id=${ids}` }, 'goods_plu': { title: '批量修改药品PLU', url: `updateGoodsPLU?id=${ids}` }, }; GoodsUtils.openDialog({ title: urlMap[val].title, content: `/index.php/Retail/Goods/${urlMap[val].url}`, end: () => { this.vue.getData(); } }); this.vue.showBatchOperate = false; } /** * 批量操作药品 */ async batchOperateGoods(close) { const validation = GoodsUtils.validateBatchOperation(this.vue.changeForm, this.vue.checkedList); if (!validation.valid) { return this.vue.$message.warning(validation.message); } const goodsIds = this.vue.checkedList.map(item => item.id).join(','); this.vue.submitLoading = true; if (this.vue.changeForm.key === 'goods_class_id') { await this.verifyGoodsChangeClass(goodsIds, close); } else { await this.submitChangeGoods(goodsIds, close); } } /** * 验证药品分类变更 */ async verifyGoodsChangeClass(goodsIds, close) { try { const res = await GoodsUtils.apiRequest('Retail/LabelInventory/verifyGoodsChangeClass', { class_id: this.vue.changeForm.value, operate_type: 2, goods_ids: goodsIds, }); if (res.status == 1) { await this.submitChangeGoods(goodsIds, close); } else { this.vue.submitLoading = false; this.handleVerificationError(res); } } catch (error) { this.vue.submitLoading = false; this.vue.$message.error('验证失败'); } } /** * 处理验证错误 */ handleVerificationError(res) { if (res.data && res.data.length > 0) { let str = `
${res.message}
`; res.data.forEach((item, index) => { str += `${index + 1}. ${item.goods_name}
`; }); str += `