猫妈狗爸伴宠师小程序前端代码
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.

241 lines
8.0 KiB

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