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

258 lines
9.6 KiB

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