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.

166 lines
5.6 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <template>
  2. <view class="">
  3. <view class="personal-pet-basic-info">
  4. <view class="personal-pet-info-title border-bottom">
  5. 宠物基本信息
  6. </view>
  7. <u--form labelPosition="left" :model="model" ref="uForm">
  8. <u-form-item required label="昵称" prop="petBaseInfo.name" labelWidth="80" borderBottom>
  9. <u--input v-model="petBaseInfo.name" placeholder="请输入宠物昵称" @change="nameChange"
  10. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  11. </u-form-item>
  12. <u-form-item label="性别" prop="petBaseInfo.gender" labelWidth="80" borderBottom @click="showSex = true">
  13. <u--input v-model="petBaseInfo.gender" disabled disabledColor="#ffffff" placeholder="请选择"
  14. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  15. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  16. </u-form-item>
  17. <u-form-item required label="品种" prop="petBaseInfo.breed" labelWidth="80" borderBottom @click="breedSelectOpen">
  18. <u--input v-model="petBaseInfo.breed" disabled disabledColor="#ffffff" placeholder="请选择"
  19. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  20. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  21. </u-form-item>
  22. <u-form-item required label="体重" prop="petBaseInfo.bodyType" labelWidth="80" borderBottom @click="showWeight = true"
  23. ref="item1">
  24. <u--input v-model="petBaseInfo.bodyType" disabled disabledColor="#ffffff" placeholder="请选择"
  25. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  26. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  27. </u-form-item>
  28. <u-form-item label="出生年月" prop="petBaseInfo.birthDate" labelWidth="80" borderBottom @click="yearMonthOpen">
  29. <u--input v-model="petBaseInfo.birthDate" disabled disabledColor="#ffffff" placeholder="请选择"
  30. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  31. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  32. </u-form-item>
  33. <u-form-item required label="性格" prop="petBaseInfo.personality" labelWidth="80" borderBottom
  34. @click="dispositionSelectOpen">
  35. <u--input v-model="petBaseInfo.personality" disabled disabledColor="#ffffff" placeholder="请选择"
  36. placeholderStyle="text-align:right;color:#AAA" border="none" inputAlign="right"></u--input>
  37. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  38. </u-form-item>
  39. </u--form>
  40. </view>
  41. <u-picker :show="showSex" :showToolbar='false' :columns="sexActions" @cancel="showSex = false" :immediateChange="true"
  42. @confirm="sexSelect"></u-picker>
  43. <u-picker :show="showWeight" :showToolbar='false' :columns="weightActions" @cancel="showWeight = false" :immediateChange="true"
  44. @confirm="weightSelect"></u-picker>
  45. <u-datetime-picker :maxDate='getMaxDate()' :minDate="getMinDate()" :show="showBirthday" v-model="tempBirthday" mode="year-month" @confirm="yearMonthConfirm"
  46. @cancel="yearMonthClose"></u-datetime-picker>
  47. </view>
  48. </template>
  49. <script>
  50. import { getDictList } from "@/api/system/user"
  51. export default {
  52. data() {
  53. return {
  54. showSex: false,
  55. showWeight: false,
  56. showBirthday: false,
  57. sexActions: [['男生','女生']],
  58. weightActions: [['小型(<10 KG)','中型(10~20KG)', '大型(20KG以上)']],
  59. tempBirthday: ''
  60. }
  61. },
  62. watch: {
  63. 'petBaseInfo.breed': {
  64. handler(newVal) {
  65. console.log('品种数据更新:', newVal);
  66. this.updatePetBaseInfo();
  67. },
  68. immediate: true
  69. }
  70. },
  71. props:{
  72. petType: {
  73. type: String,
  74. default: 'dog'
  75. },
  76. petBaseInfo:{
  77. type: Object,
  78. default: ()=> ({
  79. name: '',
  80. gender: '',
  81. breed: '',
  82. bodyType: '',
  83. birthDate: '',
  84. personality: ''
  85. })
  86. }
  87. },
  88. methods: {
  89. nameChange(){
  90. this.updatePetBaseInfo()
  91. },
  92. sexSelect(e) {
  93. this.petBaseInfo.gender = e.value[0];
  94. this.showSex = false;
  95. this.updatePetBaseInfo()
  96. },
  97. weightSelect(e) {
  98. this.petBaseInfo.bodyType = e.value[0];
  99. this.showWeight=false;
  100. this.updatePetBaseInfo()
  101. },
  102. breedSelectOpen() {
  103. // 跳转到品种选择页面
  104. uni.navigateTo({
  105. url: `/pages/personalCenter/breedSelect?petType=${this.petType}&selectedBreed=${encodeURIComponent(this.petBaseInfo.breed || '')}`
  106. });
  107. },
  108. yearMonthOpen() {
  109. if (this.petBaseInfo.birthDate) {
  110. this.tempBirthday = Number(new Date(this.petBaseInfo.birthDate))
  111. } else {
  112. this.tempBirthday = Number(new Date())
  113. }
  114. this.showBirthday = true;
  115. },
  116. yearMonthClose() {
  117. this.showBirthday = false;
  118. },
  119. yearMonthConfirm(e) {
  120. const timeFormat = uni.$u.timeFormat;
  121. this.petBaseInfo.birthDate = timeFormat(e.value, 'yyyy-mm');
  122. this.showBirthday = false;
  123. this.updatePetBaseInfo()
  124. },
  125. dispositionSelectOpen() {
  126. // 跳转到性格选择页面
  127. uni.navigateTo({
  128. url: `/pages/personalCenter/personalitySelect?personality=${encodeURIComponent(this.petBaseInfo.personality || '')}`
  129. });
  130. },
  131. updatePetBaseInfo() {
  132. // 触发 update 事件,将修改后的 petBaseInfo 对象发送给父组件
  133. this.$emit('update:petBaseInfo', this.petBaseInfo);
  134. },
  135. getMaxDate(){
  136. return Date.now()
  137. },
  138. getMinDate(){
  139. let dt = new Date();
  140. dt.setFullYear(dt.getFullYear() - 30)
  141. return Date.parse(dt)
  142. }
  143. }
  144. }
  145. </script>
  146. <style >
  147. .personal-pet-basic-info{
  148. background-color: #fff;
  149. margin-top: 10px;
  150. padding: 10px 20px;
  151. }
  152. </style>