index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="pet-add-page">
  3. <nav-bar title="新增宠物档案"></nav-bar>
  4. <!-- 基础信息 -->
  5. <view class="section-title">基础信息</view>
  6. <view class="form-card">
  7. <view class="form-item">
  8. <text class="form-label require">宠物名称</text>
  9. <input class="form-input" v-model="form.name" placeholder="请输入宠物名称" />
  10. </view>
  11. <view class="form-item">
  12. <text class="form-label require">所属主人</text>
  13. <picker :range="customerOptions" range-key="name" @change="onCustomerChange">
  14. <view class="picker-value" :class="{'placeholder': !form.userId}">{{ getCustomerLabel }}</view>
  15. </picker>
  16. </view>
  17. <view class="form-item">
  18. <text class="form-label require">品种</text>
  19. <view class="form-combox-wrapper">
  20. <uni-combox :candidates="breedCandidates" v-model="form.breed" placeholder="可选择也可自填品种" emptyTips="未找到对应品种,可直接输入"></uni-combox>
  21. </view>
  22. </view>
  23. <view class="form-item">
  24. <text class="form-label">性别</text>
  25. <picker :range="genderOptions" range-key="label" @change="onGenderChange">
  26. <view class="picker-value">{{ getGenderLabel }}</view>
  27. </picker>
  28. </view>
  29. <view class="form-item">
  30. <text class="form-label require">体型</text>
  31. <picker :range="sizeOptions" range-key="label" @change="onSizeChange">
  32. <view class="picker-value" :class="{'placeholder': !form.size}">{{ getSizeLabel }}</view>
  33. </picker>
  34. </view>
  35. <view class="form-item">
  36. <text class="form-label require">年龄(岁)</text>
  37. <input class="form-input" v-model="form.age" type="number" placeholder="请输入年龄" />
  38. </view>
  39. <view class="form-item">
  40. <text class="form-label require">体重(kg)</text>
  41. <input class="form-input" v-model="form.weight" type="digit" placeholder="请输入体重" />
  42. </view>
  43. </view>
  44. <!-- 性格特征 -->
  45. <view class="section-title">性格特征</view>
  46. <view class="form-card">
  47. <view class="form-item">
  48. <text class="form-label">性格关键词</text>
  49. <input class="form-input" v-model="form.personality" placeholder="例如活泼、粘人" />
  50. </view>
  51. <view class="form-item vertical">
  52. <text class="form-label">萌宠性格描述</text>
  53. <textarea class="form-textarea" v-model="form.cutePersonality" placeholder="详细描述宠物的性格"></textarea>
  54. </view>
  55. </view>
  56. <!-- 家庭信息 -->
  57. <view class="section-title">家庭信息</view>
  58. <view class="form-card">
  59. <view class="form-item">
  60. <text class="form-label require">房屋类型</text>
  61. <picker :range="houseTypeOptions" range-key="label" @change="onHouseTypeChange">
  62. <view class="picker-value" :class="{'placeholder': !form.houseType}">{{ getHouseTypeLabel }}</view>
  63. </picker>
  64. </view>
  65. <view class="form-item">
  66. <text class="form-label require">入门方式</text>
  67. <picker :range="entryMethodOptions" range-key="label" @change="onEntryMethodChange">
  68. <view class="picker-value" :class="{'placeholder': !form.entryMethod}">{{ getEntryMethodLabel }}</view>
  69. </picker>
  70. </view>
  71. <view class="form-item" v-if="form.entryMethod === 'password'">
  72. <text class="form-label require">门锁密码</text>
  73. <input class="form-input" v-model="form.entryPassword" placeholder="请输入门锁密码" />
  74. </view>
  75. <view class="form-item" v-if="form.entryMethod === 'key'">
  76. <text class="form-label require">钥匙存放处</text>
  77. <input class="form-input" v-model="form.keyLocation" placeholder="请输入取钥匙位置" />
  78. </view>
  79. </view>
  80. <!-- 健康状况 -->
  81. <view class="section-title">健康状况</view>
  82. <view class="form-card">
  83. <view class="form-item">
  84. <text class="form-label require">健康状态</text>
  85. <picker :range="healthStatusOptions" @change="onHealthChange">
  86. <view class="picker-value">{{ form.healthStatus || '请选择' }}</view>
  87. </picker>
  88. </view>
  89. <view class="form-item">
  90. <text class="form-label require">疫苗接种</text>
  91. <picker :range="vaccineOptions" @change="onVaccineChange">
  92. <view class="picker-value">{{ form.vaccineStatus || '请选择' }}</view>
  93. </picker>
  94. </view>
  95. <view class="form-item">
  96. <text class="form-label require">攻击倾向</text>
  97. <picker :range="aggressionOptions" range-key="label" @change="onAggressionChange">
  98. <view class="picker-value">{{ getAggressionLabel }}</view>
  99. </picker>
  100. </view>
  101. <view class="form-item vertical">
  102. <text class="form-label require">既往病史</text>
  103. <textarea class="form-textarea" v-model="form.medicalHistory" placeholder="如有病史请务必记录"></textarea>
  104. </view>
  105. <view class="form-item vertical">
  106. <text class="form-label require">过敏史</text>
  107. <textarea class="form-textarea" v-model="form.allergies" placeholder="如有过敏源请务必记录"></textarea>
  108. </view>
  109. <view class="form-item vertical">
  110. <text class="form-label">补充备注</text>
  111. <textarea class="form-textarea" v-model="form.remark" placeholder="请输入其他备注信息"></textarea>
  112. </view>
  113. </view>
  114. <!-- 底部固定操作栏 -->
  115. <view class="footer-bar">
  116. <button class="save-btn" @click="onSave">保存档案</button>
  117. </view>
  118. </view>
  119. </template>
  120. <script setup>
  121. import { ref, reactive, computed } from 'vue'
  122. import { onLoad } from '@dcloudio/uni-app'
  123. import { addPet } from '@/api/archieves/pet'
  124. import { listAllCustomer } from '@/api/archieves/customer'
  125. import { getDicts } from '@/api/system/dict/data'
  126. import navBar from '@/components/nav-bar/index.vue'
  127. import customerEnums from '@/json/customer.json'
  128. const genderOptions = [{ label: '未知', value: 0 }, { label: '公', value: 1 }, { label: '母', value: 2 }]
  129. const sizeOptions = [{ label: '小型(0-10kg)', value: 'small' }, { label: '中型(10-25kg)', value: 'medium' }, { label: '大型(25kg+)', value: 'large' }]
  130. const { houseTypeOptions, entryMethodOptions } = customerEnums
  131. const healthStatusOptions = ['健康', '亚健康', '疾病']
  132. const vaccineOptions = ['无', '已打1次', '已打2次', '已打3次']
  133. const aggressionOptions = [{ label: '否', value: 0 }, { label: '是', value: 1 }]
  134. const customerOptions = ref([])
  135. const breedCandidates = ref([])
  136. onLoad(async () => {
  137. try {
  138. const res = await listAllCustomer({ status: 0 })
  139. customerOptions.value = Array.isArray(res) ? res : (res?.data || [])
  140. } catch(e) {
  141. console.error('获取主人列表失败', e)
  142. }
  143. try {
  144. const dictRes = await getDicts('sys_pet_breed')
  145. const list = Array.isArray(dictRes) ? dictRes : (dictRes?.data || [])
  146. // 提取中文名给 combox,RuoYi 系统对应的字段可能是 dictLabel/dictValue
  147. breedCandidates.value = list.map(item => item.dictLabel || item.dictValue || item.label || item.value)
  148. } catch(e) {
  149. console.error('获取宠物品种字典失败', e)
  150. }
  151. })
  152. const form = reactive({
  153. name: '', userId: '', breed: '', gender: 0, age: '', weight: '', size: '',
  154. houseType: '', entryMethod: '', entryPassword: '', keyLocation: '',
  155. personality: '', cutePersonality: '', healthStatus: '健康', aggression: 0,
  156. vaccineStatus: '无', medicalHistory: '', allergies: '', remark: ''
  157. })
  158. const getCustomerLabel = computed(() => {
  159. const c = customerOptions.value.find(i => i.id === form.userId)
  160. return c ? `${c.name} - ${c.phone}` : '请选择主人'
  161. })
  162. const getGenderLabel = computed(() => genderOptions.find(i => i.value === form.gender)?.label || '请选择')
  163. const getSizeLabel = computed(() => sizeOptions.find(i => i.value === form.size)?.label || '请选择')
  164. const getHouseTypeLabel = computed(() => houseTypeOptions.find(i => i.value === form.houseType)?.label || '请选择')
  165. const getEntryMethodLabel = computed(() => entryMethodOptions.find(i => i.value === form.entryMethod)?.label || '请选择')
  166. const getAggressionLabel = computed(() => aggressionOptions.find(i => i.value === form.aggression)?.label || '请选择')
  167. const onCustomerChange = (e) => { form.userId = customerOptions.value[e.detail.value]?.id }
  168. const onGenderChange = (e) => { form.gender = genderOptions[e.detail.value].value }
  169. const onSizeChange = (e) => { form.size = sizeOptions[e.detail.value].value }
  170. const onHouseTypeChange = (e) => { form.houseType = houseTypeOptions[e.detail.value].value }
  171. const onEntryMethodChange = (e) => { form.entryMethod = entryMethodOptions[e.detail.value].value }
  172. const onHealthChange = (e) => { form.healthStatus = healthStatusOptions[e.detail.value] }
  173. const onVaccineChange = (e) => { form.vaccineStatus = vaccineOptions[e.detail.value] }
  174. const onAggressionChange = (e) => { form.aggression = aggressionOptions[e.detail.value].value }
  175. const onSave = async () => {
  176. if (!form.name) return uni.showToast({ title: '请输入宠物名称', icon: 'none' })
  177. if (!form.userId) return uni.showToast({ title: '请选择所属主人', icon: 'none' })
  178. if (!form.breed) return uni.showToast({ title: '请输入品种', icon: 'none' })
  179. if (!form.size) return uni.showToast({ title: '请选择体型', icon: 'none' })
  180. if (!form.weight) return uni.showToast({ title: '请输入体重', icon: 'none' })
  181. if (!form.age) return uni.showToast({ title: '请输入年龄', icon: 'none' })
  182. if (!form.houseType) return uni.showToast({ title: '请选择家庭房屋类型', icon: 'none' })
  183. if (!form.entryMethod) return uni.showToast({ title: '请选择入门方式', icon: 'none' })
  184. if (form.entryMethod === 'password' && !form.entryPassword) return uni.showToast({ title: '请输入门锁密码', icon: 'none' })
  185. if (form.entryMethod === 'key' && !form.keyLocation) return uni.showToast({ title: '请输入钥匙存放位置', icon: 'none' })
  186. if (!form.healthStatus) return uni.showToast({ title: '请选择健康状态', icon: 'none' })
  187. if (!form.vaccineStatus) return uni.showToast({ title: '请选择疫苗情况', icon: 'none' })
  188. if (!form.medicalHistory) return uni.showToast({ title: '请输入既往病史', icon: 'none' })
  189. if (!form.allergies) return uni.showToast({ title: '请输入过敏史', icon: 'none' })
  190. try {
  191. uni.showLoading({ title: '保存中' })
  192. await addPet(form)
  193. uni.hideLoading()
  194. uni.showToast({ title: '新增成功', icon: 'success' })
  195. setTimeout(() => uni.navigateBack(), 1000)
  196. } catch (error) {
  197. uni.hideLoading()
  198. uni.showToast({ title: '保存失败', icon: 'none' })
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .pet-add-page { min-height: 100vh; background: #f7f8fa; padding-bottom: calc(140rpx + env(safe-area-inset-bottom)); }
  204. .section-title { font-size: 28rpx; font-weight: bold; color: #666; padding: 24rpx 32rpx 12rpx; }
  205. .form-card { background: #fff; border-radius: 24rpx; padding: 8rpx 32rpx; margin: 0 24rpx; }
  206. .form-item { display: flex; align-items: center; padding: 28rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  207. .form-item:last-child { border-bottom: none; }
  208. .form-item.vertical { flex-direction: column; align-items: flex-start; border-bottom: none; }
  209. .form-item.vertical .form-textarea { width: 100%; height: 160rpx; margin-top: 16rpx; background: #f9f9f9; padding: 16rpx; box-sizing: border-box; border-radius: 12rpx; }
  210. .form-label { width: 220rpx; font-size: 28rpx; color: #333; flex-shrink: 0; }
  211. .form-label.require::before { content: '*'; color: #f56c6c; margin-right: 4rpx; }
  212. .form-input { flex: 1; font-size: 28rpx; color: #333; text-align: right; }
  213. .form-combox-wrapper { flex: 1; min-width: 0; }
  214. .picker-value { flex: 1; font-size: 28rpx; color: #333; text-align: right; min-height: 40rpx; }
  215. .picker-value.placeholder { color: #ccc; }
  216. .footer-bar { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; padding: 20rpx 32rpx calc(20rpx + env(safe-area-inset-bottom)); box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05); z-index: 100; }
  217. .save-btn { width: 100%; height: 88rpx; background: linear-gradient(90deg, #ffd53f, #ff9500); color: #333; border: none; border-radius: 44rpx; font-size: 32rpx; font-weight: bold; line-height: 88rpx; }
  218. :deep(.uni-combox) { border: none !important; }
  219. :deep(.uni-combox__input-box) { display: flex; justify-content: flex-end; padding-right: 0; }
  220. :deep(.uni-combox__input) { text-align: right; font-size: 28rpx; padding-right: 0;}
  221. :deep(.uni-combox__input-plholder) { color: #ccc; text-align: right; font-size: 28rpx; padding-right: 0;}
  222. </style>