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

232 lines
9.2 KiB

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. <u-picker :show="showVaccine" :showToolbar='false' :columns="vaccineActions" @cancel="showVaccine = false" :immediateChange="true"
  68. :defaultIndex="defaultVaccine"
  69. @change="vaccineSelect"></u-picker>
  70. <u-picker :show="showExpelling" :showToolbar='false' :columns="expellingActions" @cancel="showExpelling = false" :immediateChange="true"
  71. :defaultIndex="defaultDeworming"
  72. @change="expellingSelect"></u-picker>
  73. <u-picker :show="showSterilization" :showToolbar='false' :columns="sterilizationActions" @cancel="showSterilization = false" :immediateChange="true"
  74. :defaultIndex="defaultSterilization"
  75. @change="sterilizationSelect"></u-picker>
  76. <u-picker :show="showDog" :showToolbar='false' :columns="dogActions" @cancel="showDog = false" :immediateChange="true"
  77. :defaultIndex="defaultDoglicense"
  78. @change="dogSelect"></u-picker>
  79. </view>
  80. </template>
  81. <script setup>
  82. import { ref, onMounted, watch } from 'vue';
  83. // 定义 props
  84. const props = defineProps({
  85. petType: {
  86. type: String,
  87. default: 'dog'
  88. },
  89. petHealthInfo: {
  90. type: Object,
  91. default: () => ({
  92. vaccineStatus: '',
  93. dewormingStatus: '',
  94. sterilization: '',
  95. doglicenseStatus: '',
  96. healthStatus: [],
  97. remark: ''
  98. })
  99. },
  100. defaultVaccine: {
  101. type: Number,
  102. default: 0
  103. },
  104. defaultDeworming: {
  105. type: Number,
  106. default: 0
  107. },
  108. defaultSterilization: {
  109. type: Number,
  110. default: 0
  111. },
  112. defaultDoglicense: {
  113. type: Number,
  114. default: 0
  115. }
  116. });
  117. // 定义 emits
  118. const emits = defineEmits(['update:petHealthInfo']);
  119. // 定义响应式数据
  120. const showVaccine = ref(false);
  121. const showExpelling = ref(false);
  122. const showSterilization = ref(false);
  123. const showDog = ref(false);
  124. const showHealths = ref(false);
  125. const vaccineActions = ref([[ '每年都免疫','有免疫史','未免疫']]);
  126. const expellingActions = ref([['未驱虫', '定期驱虫', '有驱虫史']]);
  127. const sterilizationActions = ref([['已绝育','未绝育']]);
  128. const dogActions = ref([[ '是','否']]);
  129. const healthData = ref([]);
  130. const tempHealths = ref([]);
  131. const uForm = ref(null);
  132. const item1 = ref(null);
  133. // 定义方法
  134. const getHealthDataList = () => {
  135. // getDictList('pet_health_status').then(res => {
  136. // if (res.code === 200) {
  137. // healthData.value = res.data.map(e => e.dictLabel);
  138. // } else {
  139. // uni.showToast({
  140. // title: '获取健康类型失败',
  141. // icon: 'none'
  142. // });
  143. // }
  144. // });
  145. };
  146. const vaccineSelect = (e) => {
  147. props.petHealthInfo.vaccineStatus = e.value[0];
  148. showVaccine.value = false;
  149. updatePetHealthInfo();
  150. };
  151. const expellingSelect = (e) => {
  152. props.petHealthInfo.dewormingStatus = e.value[0];
  153. showExpelling.value = false;
  154. updatePetHealthInfo();
  155. };
  156. const sterilizationSelect = (e) => {
  157. props.petHealthInfo.sterilization = e.value[0];
  158. showSterilization.value = false;
  159. updatePetHealthInfo();
  160. };
  161. const dogSelect = (e) => {
  162. props.petHealthInfo.doglicenseStatus = e.value[0];
  163. showDog.value = false;
  164. updatePetHealthInfo();
  165. };
  166. const healthsSelect = () => {
  167. showHealths.value = !showHealths.value;
  168. uni.pageScrollTo({
  169. scrollTop: 2000,
  170. duration: 300
  171. });
  172. };
  173. const checkboxChange = (n) => {
  174. console.log('change', n);
  175. updatePetHealthInfo();
  176. };
  177. const changeRemark = (e) => {
  178. props.petHealthInfo.remark = e;
  179. updatePetHealthInfo();
  180. };
  181. const updatePetHealthInfo = () => {
  182. // 触发 update 事件,将修改后的 petHealthInfo 对象发送给父组件
  183. emits('update:petHealthInfo', props.petHealthInfo);
  184. };
  185. // 生命周期钩子
  186. onMounted(() => {
  187. // getHealthDataList();
  188. // defaultVaccine.value = vaccineActions.value[0].indexOf(props.petHealthInfo.vaccineStatus);
  189. // defaultDeworming.value = expellingActions.value[0].indexOf(props.petHealthInfo.dewormingStatus);
  190. // defaultSterilization.value = sterilizationActions.value[0].indexOf(props.petHealthInfo.sterilization);
  191. // defaultDoglicense.value = dogActions.value[0].indexOf(props.petHealthInfo.doglicenseStatus);
  192. });
  193. </script>
  194. <style lang="scss">
  195. .personal-pet-health-info{
  196. background-color: #fff;
  197. padding: 10px 20px 0 20px;
  198. margin-top: 10px;
  199. }
  200. .health-select{
  201. background-color: #fffcf2;
  202. padding: 10px 20px;
  203. }
  204. .dog-tips{
  205. color: #A94F20;
  206. font-size: 12px;
  207. display: flex;
  208. align-items: baseline;
  209. margin-top: 5px;
  210. .icon {
  211. width: 12px;
  212. height: 12px;
  213. margin-right: 3px;
  214. }
  215. }
  216. </style>