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

265 lines
9.8 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.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. computed,
  97. onMounted,
  98. } from 'vue';
  99. import { useStore } from 'vuex'
  100. const store = useStore()
  101. const configList = computed(() => {
  102. return store.getters.configList
  103. })
  104. // 定义 props
  105. const props = defineProps({
  106. petType: {
  107. type: String,
  108. default: 'dog'
  109. },
  110. petHealthInfo: {
  111. type: Object,
  112. default: () => ({
  113. vaccine: '',
  114. deworm: '',
  115. neutered: '',
  116. doglicenseStatus: '',
  117. health: [],
  118. remark: ''
  119. })
  120. },
  121. defaultVaccine: {
  122. type: Number,
  123. default: 0
  124. },
  125. defaultDeworming: {
  126. type: Number,
  127. default: 0
  128. },
  129. defaultSterilization: {
  130. type: Number,
  131. default: 0
  132. },
  133. defaultDoglicense: {
  134. type: Number,
  135. default: 0
  136. }
  137. });
  138. // 定义 emits
  139. const emits = defineEmits(['update:petHealthInfo']);
  140. // 定义响应式数据
  141. const showVaccine = ref(false);
  142. const showExpelling = ref(false);
  143. const showSterilization = ref(false);
  144. const showDog = ref(false);
  145. const showHealths = ref(false);
  146. const vaccineActions = ref([
  147. ['每年都免疫', '有免疫史', '未免疫']
  148. ]);
  149. const expellingActions = ref([
  150. ['未驱虫', '定期驱虫', '有驱虫史']
  151. ]);
  152. const sterilizationActions = ref([
  153. ['已绝育', '未绝育']
  154. ]);
  155. const dogActions = ref([
  156. ['是', '否']
  157. ]);
  158. const healthData = ref([]);
  159. const tempHealths = ref([]);
  160. const uForm = ref(null);
  161. const item1 = ref(null);
  162. // 定义方法
  163. const getHealthDataList = () => {
  164. // getDictList('pet_health_status').then(res => {
  165. // if (res.code === 200) {
  166. // healthData.value = res.data.map(e => e.dictLabel);
  167. // } else {
  168. // uni.showToast({
  169. // title: '获取健康类型失败',
  170. // icon: 'none'
  171. // });
  172. // }
  173. // });
  174. };
  175. const vaccineSelect = (e) => {
  176. props.petHealthInfo.vaccine = e.index;
  177. showVaccine.value = false;
  178. updatePetHealthInfo();
  179. };
  180. const expellingSelect = (e) => {
  181. props.petHealthInfo.deworm = e.index;
  182. showExpelling.value = false;
  183. updatePetHealthInfo();
  184. };
  185. const sterilizationSelect = (e) => {
  186. props.petHealthInfo.neutered = e.index;
  187. showSterilization.value = false;
  188. updatePetHealthInfo();
  189. };
  190. const dogSelect = (e) => {
  191. props.petHealthInfo.doglicenseStatus = e.value[0];
  192. showDog.value = false;
  193. updatePetHealthInfo();
  194. };
  195. const healthsSelect = () => {
  196. showHealths.value = !showHealths.value;
  197. uni.pageScrollTo({
  198. scrollTop: 2000,
  199. duration: 300
  200. });
  201. };
  202. const checkboxChange = (n) => {
  203. console.log('change', n);
  204. updatePetHealthInfo();
  205. };
  206. const changeRemark = (e) => {
  207. props.petHealthInfo.remark = e;
  208. updatePetHealthInfo();
  209. };
  210. const updatePetHealthInfo = () => {
  211. // 触发 update 事件,将修改后的 petHealthInfo 对象发送给父组件
  212. emits('update:petHealthInfo', props.petHealthInfo);
  213. };
  214. // 生命周期钩子
  215. onMounted(() => {
  216. // getHealthDataList();
  217. // defaultVaccine.value = vaccineActions.value[0].indexOf(props.petHealthInfo.vaccineStatus);
  218. // defaultDeworming.value = expellingActions.value[0].indexOf(props.petHealthInfo.dewormingStatus);
  219. // defaultSterilization.value = sterilizationActions.value[0].indexOf(props.petHealthInfo.sterilization);
  220. // defaultDoglicense.value = dogActions.value[0].indexOf(props.petHealthInfo.doglicenseStatus);
  221. });
  222. </script>
  223. <style lang="scss">
  224. .personal-pet-health-info{
  225. background-color: #fff;
  226. padding: 10px 20px 0 20px;
  227. margin-top: 10px;
  228. }
  229. .health-select{
  230. background-color: #fffcf2;
  231. padding: 10px 20px;
  232. }
  233. .dog-tips{
  234. color: #A94F20;
  235. font-size: 12px;
  236. display: flex;
  237. align-items: baseline;
  238. margin-top: 5px;
  239. .icon {
  240. width: 12px;
  241. height: 12px;
  242. margin-right: 3px;
  243. }
  244. }
  245. </style>