1. 优化了一些交互,中药药品编辑交互

2. dev和生产环境统一鉴别
This commit is contained in:
李琦
2026-05-15 16:59:16 +08:00
parent 69195e639b
commit d4a66b7d90
5 changed files with 222 additions and 29 deletions

View File

@@ -27,6 +27,31 @@
/>
</view>
<!-- 已选药材横向滑动 -->
<view v-if="selectedDrugs.length > 0" class="selected-strip-wrap m-b-24">
<scroll-view class="selected-strip-scroll" scroll-x enable-flex>
<view class="selected-strip-inner flex-row">
<view
v-for="(sel, six) in selectedDrugs"
:key="'sch-' + six"
class="selected-chip flex-row flex-ali-center"
>
<view
class="selected-chip-main flex-row flex-ali-center"
:data-six="six"
@click="handleSelectedChipSearch"
>
<text class="selected-chip-name">{{ sel.drug_name || sel.name || '—' }}</text>
<text class="selected-chip-dose">{{ String(sel.number || 0) }}{{ sel.unit && sel.unit.name ? sel.unit.name : 'g' }}</text>
</view>
<view class="selected-chip-close" :data-six="six" @click.stop="handleSelectedChipRemove">
<u-icon name="close" size="22" color="#8A92A3"></u-icon>
</view>
</view>
</view>
</scroll-view>
</view>
<!-- 药品列表可滚动支持触底加载 -->
<scroll-view
class="drug-list-scroll"
@@ -148,7 +173,7 @@
<script>
// 保留所有原有逻辑代码与注释
import { getProductListDoctorReception } from '@/api/reception.js';
import { getProductListDoctorReception, getChineseMedicineQuickGramsApi } from '@/api/reception.js';
export default {
name: 'ChineseMedicineModal',
@@ -166,6 +191,11 @@ export default {
currentDrugs: {
type: Array,
default: () => []
},
/** 打开时预填搜索关键词(如标签长按「编辑」) */
initialSearchKey: {
type: String,
default: ''
}
},
data() {
@@ -179,8 +209,8 @@ export default {
page: 1,
pageSize: 20,
hasMore: false,
// 常用克数(后端返回,暂时硬编码
commonQuantities: [5, 8, 10]
// 常用克数(后端全局配置,每次打开抽屉拉取
commonQuantities: []
};
},
watch: {
@@ -188,7 +218,17 @@ export default {
this.show = newVal;
if (newVal) {
this.selectedDrugs = JSON.parse(JSON.stringify(this.currentDrugs));
this.resetList();
this.fetchQuickGrams();
const kw = (this.initialSearchKey || '').trim();
if (kw) {
clearTimeout(this.searchTimer);
this.searchKey = kw;
this.page = 1;
this.hasMore = true;
this.loadDrugList(kw);
} else {
this.resetList();
}
}
},
show(newVal) {
@@ -198,6 +238,56 @@ export default {
}
},
methods: {
/**
* 拉取全局中药快捷克数(每次打开抽屉一次)
*/
async fetchQuickGrams() {
try {
const res = await getChineseMedicineQuickGramsApi();
if (res && (res.code === 0 || res.errcode === 0)) {
const data = res.data || res.result || {};
const list = Array.isArray(data.grams) ? data.grams : (Array.isArray(data) ? data : []);
this.commonQuantities = list
.map((v) => parseFloat(v))
.filter((n) => !Number.isNaN(n) && n > 0);
} else {
this.commonQuantities = [];
}
} catch (e) {
console.error('获取中药快捷克数失败:', e);
this.commonQuantities = [];
}
},
/**
* 点击已选 chip用药名搜索列表小程序端勿在 @click 传对象,用 data-six + dataset
*/
handleSelectedChipSearch(e) {
const six = Number(e && e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.six : NaN);
if (Number.isNaN(six)) return;
const sel = this.selectedDrugs[six];
if (!sel) return;
const name = String(sel.drug_name || sel.name || '').trim();
if (!name) return;
clearTimeout(this.searchTimer);
this.searchKey = name;
this.page = 1;
this.hasMore = true;
this.loadDrugList(name);
},
/**
* 从已选条移除一味(不同步二次确认)
*/
handleSelectedChipRemove(e) {
const six = Number(e && e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.six : NaN);
if (Number.isNaN(six) || six < 0 || six >= this.selectedDrugs.length) return;
this.selectedDrugs.splice(six, 1);
this.emitSelect();
const name = (this.searchKey || '').trim();
if (name) {
this.page = 1;
this.loadDrugList(name);
}
},
resetList() {
this.searchKey = '';
this.drugList = [];
@@ -325,33 +415,17 @@ export default {
},
/**
* 获取单位名称
* @param {Object} drug - 药品数据
* @returns {string} 单位名称
* 获取单位名称(中药抽屉内统一按克展示)
*/
getUnitName(drug) {
if (drug.drug && drug.drug.unit && drug.drug.unit.name) {
return drug.drug.unit.name;
}
if (drug.unit && drug.unit.name) {
return drug.unit.name;
}
getUnitName() {
return 'g';
},
/**
* 获取规格
* @param {Object} drug - 药品数据
* @returns {string} 规格
* 获取规格(中药抽屉内统一按克展示)
*/
getSpecification(drug) {
if (drug.drug && drug.drug.specification) {
return drug.drug.specification;
}
if (drug.specification) {
return drug.specification;
}
return '--';
getSpecification() {
return 'g';
},
/**
@@ -698,6 +772,7 @@ export default {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
overflow: hidden;
}
@@ -713,6 +788,62 @@ export default {
display: flex;
flex-direction: column;
overflow: hidden;
min-height: 0;
}
.selected-strip-wrap {
width: 100%;
flex-shrink: 0;
}
.selected-strip-scroll {
width: 100%;
white-space: nowrap;
}
.selected-strip-inner {
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
padding-bottom: 4rpx;
}
.selected-chip {
flex-shrink: 0;
margin-right: 16rpx;
background: #fff;
border-radius: 32rpx;
padding: 8rpx 8rpx 8rpx 20rpx;
border: 1rpx solid #E2E8F0;
box-shadow: 0 2rpx 8rpx rgba(42, 46, 53, 0.06);
}
.selected-chip-main {
max-width: 280rpx;
}
.selected-chip-name {
font-size: 26rpx;
font-weight: bold;
color: #2A2E35;
max-width: 180rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.selected-chip-dose {
font-size: 24rpx;
color: #00A88A;
margin-left: 8rpx;
white-space: nowrap;
}
.selected-chip-close {
padding: 8rpx 12rpx 8rpx 8rpx;
display: flex;
align-items: center;
justify-content: center;
}
.drug-list-scroll {

View File

@@ -229,8 +229,9 @@
<view
class="tcm-tag"
v-for="(it, tcmIndex) in currentDrugs"
:key="it.id || it.index_id || tcmIndex"
@longpress.stop="onTcmTagLongPress(it, tcmIndex)">
:key="tcmTagKey(it, tcmIndex)"
:data-idx="tcmIndex"
@longpress.stop="onTcmTagLongPress">
<text class="tcm-name">{{it.drug_name || it.name}}</text>
<text class="tcm-weight">{{String(it.number)}}{{it.unit ? it.unit.name : 'g'}}</text>
</view>
@@ -569,6 +570,7 @@ export default {
showWesternMedicineModal: false,
westernModalInitialKeyword: '',
showChineseMedicineModal: false,
chineseModalInitialKeyword: '',
showSimpleProductModal: false,
showWesternUsageModal: false,
showSaveCommonPrescriptionModal: false,
@@ -720,6 +722,9 @@ export default {
showWesternMedicineModal(val) {
if (!val) this.westernModalInitialKeyword = '';
},
showChineseMedicineModal(val) {
if (!val) this.chineseModalInitialKeyword = '';
},
// #ifdef MP-WEIXIN
hasPrescriptionOverlay(val) {
this.pageBackGuardShow = !!val;
@@ -1207,7 +1212,37 @@ export default {
this.saveToLocalStorage();
this.$toast(`已添加 ${newDrug.drug_name}`);
},
handleOpenChineseMedicineModal() { this.showChineseMedicineModal = true; },
handleOpenChineseMedicineModal() {
this.chineseModalInitialKeyword = '';
this.showChineseMedicineModal = true;
},
/** 微信小程序 :key 中勿写 it.id || it.index_id 等表达式,会编译异常 */
tcmTagKey(it, tcmIndex) {
if (it && it.id != null && it.id !== '') return `tcm-${it.id}`;
if (it && it.index_id != null && it.index_id !== '') return `tcm-i-${it.index_id}`;
return `tcm-idx-${tcmIndex}`;
},
/**
* 中药标签长按菜单(小程序 showActionSheet 回调里勿依赖闭包 item用 dataset.idx + currentDrugs
*/
onTcmTagLongPress(e) {
const raw = e && e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.idx : undefined;
const idx = raw === undefined || raw === '' ? NaN : Number(raw);
if (Number.isNaN(idx) || idx < 0 || idx >= this.currentDrugs.length) return;
uni.showActionSheet({
itemList: ['编辑', '删除'],
success: (res) => {
const row = this.currentDrugs[idx];
if (!row) return;
if (res.tapIndex === 0) {
this.chineseModalInitialKeyword = String(row.drug_name || row.name || '').trim();
this.showChineseMedicineModal = true;
} else if (res.tapIndex === 1) {
this.handleRemoveDrug(idx);
}
}
});
},
handleSelectChineseDrug(drugs) {
this.currentDrugs = drugs || [];
this.saveToLocalStorage();