|
@@ -68,7 +68,7 @@
|
|
|
<view class="form-group">
|
|
<view class="form-group">
|
|
|
<view class="form-row">
|
|
<view class="form-row">
|
|
|
<text class="form-label">药品名称</text>
|
|
<text class="form-label">药品名称</text>
|
|
|
- <view class="medicine-selector" @click="showMedicinePicker = true">
|
|
|
|
|
|
|
+ <view class="medicine-selector" @click="openMedicinePicker">
|
|
|
<text class="selector-text" :class="{ placeholder: !selectedMedicine }">{{ selectedMedicine ? selectedMedicine.name : '请选择药品' }}</text>
|
|
<text class="selector-text" :class="{ placeholder: !selectedMedicine }">{{ selectedMedicine ? selectedMedicine.name : '请选择药品' }}</text>
|
|
|
<uni-icons type="arrowdown" size="16" color="#999" />
|
|
<uni-icons type="arrowdown" size="16" color="#999" />
|
|
|
</view>
|
|
</view>
|
|
@@ -147,7 +147,7 @@
|
|
|
@click="selectMedicine(medicine)"
|
|
@click="selectMedicine(medicine)"
|
|
|
>
|
|
>
|
|
|
<text class="medicine-name">{{ medicine.name }}</text>
|
|
<text class="medicine-name">{{ medicine.name }}</text>
|
|
|
- <text class="medicine-pinyin">{{ medicine.pinyin }}</text>
|
|
|
|
|
|
|
+ <text class="medicine-pinyin">{{ medicine.pinyinFirstLetters }}</text>
|
|
|
</view>
|
|
</view>
|
|
|
</scroll-view>
|
|
</scroll-view>
|
|
|
</view>
|
|
</view>
|
|
@@ -192,6 +192,9 @@
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { ref, computed, onMounted, watch } from 'vue'
|
|
import { ref, computed, onMounted, watch } from 'vue'
|
|
|
import CustomNav from '@/components/custom-nav.vue'
|
|
import CustomNav from '@/components/custom-nav.vue'
|
|
|
|
|
+import { getMedicineList } from '@/api/medicine'
|
|
|
|
|
+
|
|
|
|
|
+console.log('Medication component loaded')
|
|
|
|
|
|
|
|
interface Medication {
|
|
interface Medication {
|
|
|
id: string
|
|
id: string
|
|
@@ -205,7 +208,7 @@ interface Medication {
|
|
|
interface Medicine {
|
|
interface Medicine {
|
|
|
id: string
|
|
id: string
|
|
|
name: string
|
|
name: string
|
|
|
- pinyin: string
|
|
|
|
|
|
|
+ pinyinFirstLetters: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const medications = ref<Medication[]>([
|
|
const medications = ref<Medication[]>([
|
|
@@ -254,18 +257,7 @@ const minutesRange = ['00', '30']
|
|
|
|
|
|
|
|
// 药品搜索
|
|
// 药品搜索
|
|
|
const medicineSearch = ref('')
|
|
const medicineSearch = ref('')
|
|
|
-const allMedicines = ref<Medicine[]>([
|
|
|
|
|
- { id: '1', name: '阿司匹林', pinyin: 'aspirin' },
|
|
|
|
|
- { id: '2', name: '硝苯地平', pinyin: 'xiaobendiping' },
|
|
|
|
|
- { id: '3', name: '盐酸二甲双胍片', pinyin: 'yansuanerjiashuanggua' },
|
|
|
|
|
- { id: '4', name: '格列美脲', pinyin: 'gelimeiwo' },
|
|
|
|
|
- { id: '5', name: '瑞格列奈', pinyin: 'ruigelienai' },
|
|
|
|
|
- { id: '6', name: '胰岛素', pinyin: 'yidaosu' },
|
|
|
|
|
- { id: '7', name: '美托洛尔', pinyin: 'meituoluoer' },
|
|
|
|
|
- { id: '8', name: '氨氯地平', pinyin: 'anlviping' },
|
|
|
|
|
- { id: '9', name: '辛伐他汀', pinyin: 'xinfatating' },
|
|
|
|
|
- { id: '10', name: '阿托伐他汀', pinyin: 'atuofatating' }
|
|
|
|
|
-])
|
|
|
|
|
|
|
+const allMedicines = ref<Medicine[]>([])
|
|
|
|
|
|
|
|
// 过滤后的药品列表
|
|
// 过滤后的药品列表
|
|
|
const filteredMedicines = computed(() => {
|
|
const filteredMedicines = computed(() => {
|
|
@@ -275,8 +267,8 @@ const filteredMedicines = computed(() => {
|
|
|
const search = medicineSearch.value.toLowerCase()
|
|
const search = medicineSearch.value.toLowerCase()
|
|
|
return allMedicines.value.filter(medicine =>
|
|
return allMedicines.value.filter(medicine =>
|
|
|
medicine.name.includes(search) ||
|
|
medicine.name.includes(search) ||
|
|
|
- medicine.pinyin.toLowerCase().includes(search) ||
|
|
|
|
|
- medicine.pinyin.toLowerCase().startsWith(search)
|
|
|
|
|
|
|
+ medicine.pinyinFirstLetters.toLowerCase().includes(search) ||
|
|
|
|
|
+ medicine.pinyinFirstLetters.toLowerCase().startsWith(search)
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -291,6 +283,7 @@ const filteredMedicines = computed(() => {
|
|
|
|
|
|
|
|
// 打开添加模态框
|
|
// 打开添加模态框
|
|
|
const openAdd = () => {
|
|
const openAdd = () => {
|
|
|
|
|
+ console.log('openAdd called')
|
|
|
showAdd.value = true
|
|
showAdd.value = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -345,7 +338,11 @@ const closeAdd = () => {
|
|
|
|
|
|
|
|
// 打开药品选择器
|
|
// 打开药品选择器
|
|
|
const openMedicinePicker = () => {
|
|
const openMedicinePicker = () => {
|
|
|
|
|
+ console.log('openMedicinePicker called')
|
|
|
showMedicinePicker.value = true
|
|
showMedicinePicker.value = true
|
|
|
|
|
+ medicineSearch.value = ''
|
|
|
|
|
+ // 加载药品列表
|
|
|
|
|
+ loadMedicineList()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 关闭药品选择器
|
|
// 关闭药品选择器
|
|
@@ -356,7 +353,52 @@ const closeMedicinePicker = () => {
|
|
|
|
|
|
|
|
// 药品搜索
|
|
// 药品搜索
|
|
|
const onMedicineSearch = () => {
|
|
const onMedicineSearch = () => {
|
|
|
- // 搜索逻辑在 computed 中处理
|
|
|
|
|
|
|
+ console.log('onMedicineSearch called, search value:', medicineSearch.value)
|
|
|
|
|
+ // 搜索时重新加载药品列表
|
|
|
|
|
+ loadMedicineList()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 加载药品列表
|
|
|
|
|
+const loadMedicineList = async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 构建参数对象
|
|
|
|
|
+ const params: any = {
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 100 // 获取足够多的药品数据
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 只有当搜索词非空时才添加keyword参数
|
|
|
|
|
+ const trimmedKeyword = medicineSearch.value.trim()
|
|
|
|
|
+ if (trimmedKeyword) {
|
|
|
|
|
+ params.keyword = trimmedKeyword
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('loadMedicineList called with params:', params)
|
|
|
|
|
+
|
|
|
|
|
+ const result: any = await getMedicineList(params)
|
|
|
|
|
+ console.log('API response:', result)
|
|
|
|
|
+
|
|
|
|
|
+ if (result?.data?.code === 200) {
|
|
|
|
|
+ // 转换字段名以适配组件
|
|
|
|
|
+ allMedicines.value = result.data.data.records.map((item: any) => ({
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ name: item.name,
|
|
|
|
|
+ pinyinFirstLetters: item.pinyinFirstLetters
|
|
|
|
|
+ }))
|
|
|
|
|
+ console.log('Medicine list loaded, count:', result.data.data.records.length)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '获取药品列表失败',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Load medicine list error:', error)
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '获取药品列表失败',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 选择药品
|
|
// 选择药品
|
|
@@ -428,7 +470,7 @@ const editMedication = (id: string) => {
|
|
|
selectedMedicine.value = {
|
|
selectedMedicine.value = {
|
|
|
id: '',
|
|
id: '',
|
|
|
name: medication.name,
|
|
name: medication.name,
|
|
|
- pinyin: ''
|
|
|
|
|
|
|
+ pinyinFirstLetters: ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
addDosage.value = medication.dosage
|
|
addDosage.value = medication.dosage
|