1. 特色方功能迭代
This commit is contained in:
@@ -550,6 +550,28 @@ export default {
|
||||
this.$emit('select', payload);
|
||||
},
|
||||
|
||||
/**
|
||||
* 自动添加药品:快捷克数/输入克数时若尚未加入处方则自动添加
|
||||
* @param {Object} drug 搜索列表中的药品
|
||||
* @param {{ showToast?: boolean }} options showToast 仅首次添加时提示
|
||||
*/
|
||||
tryAutoAddDrug(drug, options = {}) {
|
||||
if (!drug || !drug._quantity || drug._quantity <= 0) {
|
||||
return;
|
||||
}
|
||||
const existIndex = this.findSelectedIndex(drug);
|
||||
const isNew = existIndex === -1;
|
||||
if (existIndex !== -1) {
|
||||
this.$set(this.selectedDrugs[existIndex], 'number', drug._quantity);
|
||||
} else {
|
||||
this.selectedDrugs.push(this.buildSelectedItem(drug));
|
||||
}
|
||||
this.emitSelect();
|
||||
if (isNew && options.showToast) {
|
||||
this.$toast(`已将${this.getDrugName(drug)}添加到处方`);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 添加药品到处方
|
||||
* @param {Event} event - 点击事件对象
|
||||
@@ -571,15 +593,7 @@ export default {
|
||||
this.$set(drug, '_quantity', 1);
|
||||
}
|
||||
|
||||
// 已经在 selectedDrugs 中则只更新数量
|
||||
const existIndex = this.findSelectedIndex(drug);
|
||||
if (existIndex !== -1) {
|
||||
this.$set(this.selectedDrugs[existIndex], 'number', drug._quantity);
|
||||
} else {
|
||||
this.selectedDrugs.push(this.buildSelectedItem(drug));
|
||||
}
|
||||
this.emitSelect();
|
||||
this.$toast(`已将${this.getDrugName(drug)}添加到处方`);
|
||||
this.tryAutoAddDrug(drug, { showToast: true });
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -651,7 +665,7 @@ export default {
|
||||
this.$set(drug, '_quantity', 0);
|
||||
}
|
||||
this.$set(drug, '_quantity', (drug._quantity || 0) + 1);
|
||||
this.syncQuantityToSelected(drug);
|
||||
this.tryAutoAddDrug(drug, { showToast: !this.isInSelected(drug) });
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -724,7 +738,11 @@ export default {
|
||||
|
||||
if (!isNaN(numValue) && numValue >= 0) {
|
||||
this.$set(drug, '_quantity', numValue);
|
||||
this.syncQuantityToSelected(drug);
|
||||
if (numValue > 0) {
|
||||
this.tryAutoAddDrug(drug, { showToast: !this.isInSelected(drug) });
|
||||
} else {
|
||||
this.syncQuantityToSelected(drug);
|
||||
}
|
||||
} else if (value === '') {
|
||||
this.$set(drug, '_quantity', 0);
|
||||
this.syncQuantityToSelected(drug);
|
||||
@@ -763,9 +781,9 @@ export default {
|
||||
if (typeof drug._quantity === 'undefined') {
|
||||
this.$set(drug, '_quantity', 0);
|
||||
}
|
||||
// 设置数量
|
||||
// 设置数量并自动添加到处方
|
||||
this.$set(drug, '_quantity', quantity);
|
||||
this.syncQuantityToSelected(drug);
|
||||
this.tryAutoAddDrug(drug, { showToast: !this.isInSelected(drug) });
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user