猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
8.2 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view>
  3. <view class="personal-pet-health-info">
  4. <view class="personal-pet-info-title border-bottom">
  5. 宠物健康情况
  6. </view>
  7. <u--form labelPosition="left" :model="petHealthInfo" ref="uForm">
  8. <u-form-item required label="疫苗" :prop="`petHealthInfo.vaccine`" labelWidth="80" borderBottom
  9. @click="showVaccine = true">
  10. <u--input v-model="vaccineText" disabled disabledColor="#ffffff" placeholder="请选择"
  11. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  12. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  13. </u-form-item>
  14. <u-form-item required label="驱虫" :prop="`petHealthInfo.deworm`" labelWidth="80" borderBottom
  15. @click="showExpelling = true">
  16. <u--input v-model="dewormText" disabled disabledColor="#ffffff" placeholder="请选择"
  17. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  18. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  19. </u-form-item>
  20. <u-form-item label="绝育" :prop="`petHealthInfo.neutered`" labelWidth="80" borderBottom
  21. @click="showSterilization = true" ref="item1">
  22. <u--input v-model="neuteredText" disabled disabledColor="#ffffff" placeholder="请选择"
  23. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  24. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  25. </u-form-item>
  26. <u-form-item v-if="petType === '1' || petType === '狗狗' " label="狗证" :prop="`petHealthInfo.petCard`"
  27. labelWidth="80" borderBottom @click="showDog = true" ref="item1">
  28. <u--input v-model="petCartText" disabled disabledColor="#ffffff" placeholder="请选择"
  29. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  30. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  31. </u-form-item>
  32. <view class="dog-tips" v-if="petType === 'dog' || petType === '狗狗'">
  33. <u-icon name="info-circle" color="#A94F20" size="12"></u-icon>
  34. <view style="margin-left: 3px;">
  35. 未办理养犬许可证且需要外出遛狗, 犬只存在被相关单位收缴
  36. 甚至捕杀的可能请您遵守当地养犬规范合法文明养犬具体
  37. 请您查看当地养犬条例
  38. </view>
  39. </view>
  40. <!-- 赶进度先注释 -->
  41. <!-- <u-form-item required label="健康" :prop="`petHealthInfo.healths`" labelWidth="80" @click="healthsSelect"> -->
  42. <u-form-item required label="健康" :prop="`petHealthInfo.health`" labelWidth="80">
  43. <u--input disabledColor="#ffffff" placeholder="请输入" v-model="petHealthInfo.health"
  44. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  45. <view slot="right">
  46. <u-icon v-if="showHealths" name="arrow-down" color="#AAA"></u-icon>
  47. <u-icon v-else name="arrow-right" color="#AAA"></u-icon>
  48. </view>
  49. </u-form-item>
  50. </u--form>
  51. </view>
  52. <!-- 赶进度先注释 -->
  53. <!-- <view class="health-select" v-show="showHealths">
  54. <view style="padding: 10px;height: 85%;">
  55. <u-checkbox-group v-model="petHealthInfo.healthStatus" @change="checkboxChange" placement="column"
  56. activeColor="#ffbf60">
  57. <u-checkbox :customStyle="{marginBottom: '8px'}" v-for="(item, index) in healthData" :key="index"
  58. :label="item" :name="item">
  59. </u-checkbox>
  60. </u-checkbox-group>
  61. <u--input placeholder="请输入其他健康特征"
  62. :disabled="!(petHealthInfo.healthStatus && petHealthInfo.healthStatus.includes('其他'))"
  63. border="surround" maxlength='20' :customStyle="{backgroundColor: '#fff'}"
  64. @change="updatePetHealthInfo()" v-model="petHealthInfo.remark"></u--input>
  65. </view>
  66. </view> -->
  67. <u-picker :show="showVaccine" :showToolbar='false' :columns="vaccineActions" @cancel="showVaccine = false"
  68. :immediateChange="true" @change="vaccineSelect"></u-picker>
  69. <u-picker :show="showExpelling" :showToolbar='false' :columns="expellingActions" @cancel="showExpelling = false"
  70. :immediateChange="true" @change="expellingSelect"></u-picker>
  71. <u-picker :show="showSterilization" :showToolbar='false' :columns="sterilizationActions"
  72. @cancel="showSterilization = false" :immediateChange="true" @change="sterilizationSelect"></u-picker>
  73. <u-picker :show="showDog" :showToolbar='false' :columns="dogActions" @cancel="showDog = false"
  74. :immediateChange="true" @change="dogSelect"></u-picker>
  75. </view>
  76. </template>
  77. <script setup>
  78. import {
  79. ref,
  80. onMounted,
  81. watch,
  82. computed
  83. } from 'vue';
  84. // 定义 props
  85. const props = defineProps({
  86. petType: {
  87. type: String,
  88. default: 'dog'
  89. },
  90. petHealthInfo: {
  91. type: Object,
  92. default: () => ({
  93. vaccine: '',
  94. deworm: '',
  95. neutered: '',
  96. petCard: '',
  97. health: [],
  98. remark: ''
  99. })
  100. }
  101. });
  102. // 定义 emits
  103. const emits = defineEmits(['update:petHealthInfo']);
  104. // 定义响应式数据
  105. const showVaccine = ref(false);
  106. const showExpelling = ref(false);
  107. const showSterilization = ref(false);
  108. const showDog = ref(false);
  109. const showHealths = ref(false);
  110. const vaccineActions = ref([
  111. ['每年都免疫', '有免疫史', '未免疫']
  112. ]);
  113. const expellingActions = ref([
  114. ['未驱虫', '定期驱虫', '有驱虫史']
  115. ]);
  116. const sterilizationActions = ref([
  117. ['已绝育', '未绝育']
  118. ]);
  119. const dogActions = ref([
  120. ['是', '否']
  121. ]);
  122. const healthData = ref([]);
  123. const tempHealths = ref([]);
  124. const uForm = ref(null);
  125. const item1 = ref(null);
  126. const vaccineText = computed(() => {
  127. const vaccineMap = {
  128. 0: '每年都免疫',
  129. 1: '有免疫史',
  130. 2: '未免疫'
  131. };
  132. return vaccineMap[props.petHealthInfo.vaccine] || ''
  133. });
  134. const dewormText = computed(() => {
  135. const dewormMap = {
  136. 0: '未驱虫',
  137. 1: '定期驱虫',
  138. 2: '有驱虫史'
  139. };
  140. return dewormMap[props.petHealthInfo.deworm] || ''
  141. });
  142. const neuteredText = computed(() => {
  143. const neuteredMap = {
  144. 0: '已绝育',
  145. 1: '未绝育'
  146. };
  147. return neuteredMap[props.petHealthInfo.neutered] || ''
  148. });
  149. const petCartText = computed(() => {
  150. const petCartMap = {
  151. 0: '是',
  152. 1: '否'
  153. };
  154. return petCartMap[props.petHealthInfo.petCard] || ''
  155. });
  156. // 定义方法
  157. const getHealthDataList = () => {
  158. // getDictList('pet_health_status').then(res => {
  159. // if (res.code === 200) {
  160. // healthData.value = res.data.map(e => e.dictLabel);
  161. // } else {
  162. // uni.showToast({
  163. // title: '获取健康类型失败',
  164. // icon: 'none'
  165. // });
  166. // }
  167. // });
  168. };
  169. const vaccineSelect = (e) => {
  170. props.petHealthInfo.vaccine = e.index;
  171. showVaccine.value = false;
  172. updatePetHealthInfo();
  173. };
  174. const expellingSelect = (e) => {
  175. props.petHealthInfo.deworm = e.index;
  176. showExpelling.value = false;
  177. updatePetHealthInfo();
  178. };
  179. const sterilizationSelect = (e) => {
  180. props.petHealthInfo.neutered = e.index;
  181. showSterilization.value = false;
  182. updatePetHealthInfo();
  183. };
  184. const dogSelect = (e) => {
  185. props.petHealthInfo.petCard = e.index;
  186. showDog.value = false;
  187. updatePetHealthInfo();
  188. };
  189. const healthsSelect = () => {
  190. showHealths.value = !showHealths.value;
  191. uni.pageScrollTo({
  192. scrollTop: 2000,
  193. duration: 300
  194. });
  195. };
  196. const checkboxChange = (n) => {
  197. updatePetHealthInfo();
  198. };
  199. const changeRemark = (e) => {
  200. props.petHealthInfo.remark = e;
  201. updatePetHealthInfo();
  202. };
  203. const updatePetHealthInfo = () => {
  204. // 触发 update 事件,将修改后的 petHealthInfo 对象发送给父组件
  205. emits('update:petHealthInfo', props.petHealthInfo);
  206. };
  207. // 生命周期钩子
  208. onMounted(() => {
  209. // getHealthDataList();
  210. // defaultVaccine.value = vaccineActions.value[0].indexOf(props.petHealthInfo.vaccineStatus);
  211. // defaultDeworming.value = expellingActions.value[0].indexOf(props.petHealthInfo.dewormingStatus);
  212. // defaultSterilization.value = sterilizationActions.value[0].indexOf(props.petHealthInfo.sterilization);
  213. // defaultDoglicense.value = dogActions.value[0].indexOf(props.petHealthInfo.doglicenseStatus);
  214. });
  215. </script>
  216. <style lang="scss">
  217. .personal-pet-health-info {
  218. background-color: #fff;
  219. padding: 10px 20px 0 20px;
  220. margin-top: 10px;
  221. }
  222. .health-select {
  223. background-color: #fffcf2;
  224. padding: 10px 20px;
  225. }
  226. .dog-tips {
  227. color: #A94F20;
  228. font-size: 12px;
  229. display: flex;
  230. align-items: baseline;
  231. margin-top: 5px;
  232. }
  233. </style>