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

225 lines
9.1 KiB

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