From 7d6267e7e331d648cc3a1363cdca3b6860927dbb Mon Sep 17 00:00:00 2001 From: zoujiandong <10130823232@qq.com> Date: Tue, 8 Sep 2026 13:41:56 +0800 Subject: [PATCH] 2 --- src/components/sysmedinceDetailModal.vue | 75 ++++++++++++++++---- src/views/medince/platform-medince/index.vue | 4 +- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/components/sysmedinceDetailModal.vue b/src/components/sysmedinceDetailModal.vue index 2cd0cb7..8832bf1 100644 --- a/src/components/sysmedinceDetailModal.vue +++ b/src/components/sysmedinceDetailModal.vue @@ -25,14 +25,14 @@ {{ item.pharmacy_name }} ({{ item.pharmacy_code }}) @@ -264,11 +264,53 @@ const medinceList = ref([]); const pharmacyList = ref([]); const loading = ref(false); +// 自动匹配并设置所属药房 +const matchAndSetPharmacy = (target = {}) => { + if (!target) return; + const pid = target.pharmacy_id ?? target.pharmacy?.pharmacy_id; + const pcode = target.pharmacy_code ?? target.pharmacy?.pharmacy_code; + const pname = target.pharmacy_name ?? target.pharmacy?.pharmacy_name; + + let matched = null; + if (pid !== undefined && pid !== null && pid !== '') { + matched = pharmacyList.value.find((p) => String(p.pharmacy_id) === String(pid)); + } + if (!matched && pcode) { + const codeStr = String(pcode).trim().toLowerCase(); + matched = pharmacyList.value.find( + (p) => p.pharmacy_code && String(p.pharmacy_code).trim().toLowerCase() === codeStr + ); + } + + if (matched) { + modalForm.value.pharmacy_id = String(matched.pharmacy_id); + modalForm.value.pharmacy_name = matched.pharmacy_name; + modalForm.value.pharmacy_code = matched.pharmacy_code; + } else if (pid !== undefined && pid !== null && pid !== '') { + modalForm.value.pharmacy_id = String(pid); + modalForm.value.pharmacy_name = pname || ''; + modalForm.value.pharmacy_code = pcode || ''; + if (!pharmacyList.value.some((p) => String(p.pharmacy_id) === String(pid))) { + pharmacyList.value.push({ + pharmacy_id: String(pid), + pharmacy_name: modalForm.value.pharmacy_name || '所属药房', + pharmacy_code: modalForm.value.pharmacy_code || '', + }); + } + } else if (pcode) { + modalForm.value.pharmacy_code = pcode; + if (pname) modalForm.value.pharmacy_name = pname; + } +}; + const fetchPharmacyList = async () => { try { const res = await getPharmacyList(); if (res.code === 200) { pharmacyList.value = res.data || []; + if (modalForm.value && (modalForm.value.pharmacy_id || modalForm.value.pharmacy_code)) { + matchAndSetPharmacy(modalForm.value); + } } } catch (e) { console.error('获取药房列表异常:', e); @@ -286,7 +328,7 @@ watch(() => props.modalVisible, (val) => { }); const rules = { - pharmacy_id: [{ required: true, message: '请选择所属药房' }], + pharmacy_id: [{ required: true, message: '请先选择药品以匹配所属药房' }], product_platform_id: [{ required: true, message: '请输入药品名称' }], product_price: [{ required: true, message: '请输入药品价格' }], product_platform_code: [{ required: true, message: '请输入处方平台编码' }], @@ -309,7 +351,7 @@ const handleClose = () => { }; const handAdd = async () => { if (!modalForm.value.pharmacy_id) { - Message.warning('请选择所属药房'); + Message.warning('所属药房不能为空,请先选择药品以匹配药房'); return; } delete modalForm.value.avatar; @@ -344,15 +386,12 @@ const handleEditStatus=async(status)=>{ } //详情 const handleDetail = async (product_platform_id) => { - const currentPharmacyId = modalForm.value.pharmacy_id; const { code, data, message } = await getMedinceDetail(product_platform_id); if (code == 200) { Object.assign(modalForm.value, data); modalForm.value.stock = data.stock; - if (currentPharmacyId) { - modalForm.value.pharmacy_id = currentPharmacyId; - } + matchAndSetPharmacy(data); } }; const handList= async(value)=>{ @@ -367,12 +406,24 @@ const handList= async(value)=>{ } } const changeMedince = (value) => { + if (!value) { + modalForm.value.product_platform_id = ''; + modalForm.value.pharmacy_id = ''; + modalForm.value.pharmacy_name = ''; + modalForm.value.pharmacy_code = ''; + modalForm.value.product_spec = ''; + modalForm.value.product_pharmacy_code = ''; + modalForm.value.manufacturer = ''; + return; + } let arr = medinceList.value.filter((item) => item.product_platform_id == value); + if (!arr.length) return; modalForm.value.product_platform_id = arr[0].product_platform_id; console.log(arr[0]); - modalForm.value.product_spec=arr[0].product_spec; - modalForm.value.product_pharmacy_code=arr[0].product_pharmacy_code; - modalForm.value.manufacturer=arr[0].manufacturer; + modalForm.value.product_spec = arr[0].product_spec; + modalForm.value.product_pharmacy_code = arr[0].product_pharmacy_code; + modalForm.value.manufacturer = arr[0].manufacturer; + matchAndSetPharmacy(arr[0]); handleDetail(arr[0].product_platform_id); } diff --git a/src/views/medince/platform-medince/index.vue b/src/views/medince/platform-medince/index.vue index eaeb410..b1f388d 100644 --- a/src/views/medince/platform-medince/index.vue +++ b/src/views/medince/platform-medince/index.vue @@ -147,8 +147,8 @@ { title: '单价(元)', dataIndex: 'product_price', slotName: 'product_price',width: 150 }, { title: '批准文号', dataIndex: 'license_number',width:200 }, { title: '生产厂家', dataIndex: 'manufacturer',width:200 }, - { title: '药店编码', dataIndex: 'product_pharmacy_code',width:100 }, - { title: '第三方药房编码', dataIndex: 'pharmacy_code', width: 160, ellipsis: true }, + { title: '第三方药房药品编码', dataIndex: 'product_pharmacy_code',width:160,ellipsis: true }, + { title: '药店编码', dataIndex: 'pharmacy_code', width: 100, ellipsis: true }, // { title: '启用状态', dataIndex: 'status', slotName: 'status' }, { title: '操作', slotName: 'action', fixed: "right", width: 180 }, ];