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.

263 lines
8.6 KiB

1 month 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. <view style="background-color: #fffcf2;padding: 10px 20px;" v-show="showDisposition">
  42. <view style="height: 85%;">
  43. <u-checkbox-group
  44. v-model="petBaseInfo.personality"
  45. @change="checkboxChange"
  46. iconPlacement="left"
  47. placement="row"
  48. style="flex-wrap: wrap;"
  49. activeColor="#ffbf60">
  50. <u-checkbox :customStyle="{margin: '8px'}" v-for="(item, index) in dispositionActions"
  51. :key="item" :label="item" :name="item">
  52. </u-checkbox>
  53. </u-checkbox-group>
  54. </view>
  55. </view>
  56. <u-picker :show="showSex" :showToolbar='false' :columns="sexActions" @cancel="showSex = false" :immediateChange="true"
  57. @confirm="sexSelect"></u-picker>
  58. <u-picker :show="showWeight" :showToolbar='false' :columns="weightActions" @cancel="showWeight = false" :immediateChange="true"
  59. @confirm="weightSelect"></u-picker>
  60. <u-overlay :show="showBreed">
  61. <view class="breed-select" style="height: 60%;">
  62. <u-search shape="round" :show-action="false" v-model="searchValue" @change="searchBreed"></u-search>
  63. <view style="padding: 10px;height: 80%;overflow: auto;">
  64. <u-radio-group v-model="tempBreed" placement="column">
  65. <u-radio v-for="(item,index) in searchBreedData" :customStyle="{marginBottom: '8px'}"
  66. activeColor="#ffbf60" :label="item" :name="item" :key="item"></u-radio>
  67. </u-radio-group>
  68. </view>
  69. <view class="personal-pet-breed-btns">
  70. <view class="personal-pet-breed-btn">
  71. <u-button color="#FFF4E4" @click="breedSelectClose">
  72. <view style="color: #FFAA48;">
  73. 取消
  74. </view>
  75. </u-button>
  76. </view>
  77. <view class="personal-pet-breed-btn" @click="breedSelectConfirm">
  78. <u-button color="#FFBF60">
  79. <view style="color: #fff;">
  80. 确定
  81. </view>
  82. </u-button>
  83. </view>
  84. </view>
  85. </view>
  86. </u-overlay>
  87. <u-datetime-picker :maxDate='getMaxDate()' :minDate="getMinDate()" :show="showBirthday" v-model="tempBirthday" mode="year-month" @confirm="yearMonthConfirm"
  88. @cancel="yearMonthClose"></u-datetime-picker>
  89. </view>
  90. </template>
  91. <script>
  92. import { getDictList } from "@/api/system/user"
  93. export default {
  94. data() {
  95. return {
  96. showSex: false,
  97. showBreed: false,
  98. showWeight: false,
  99. showBirthday: false,
  100. showDisposition: false,
  101. sexActions: [['男生','女生']],
  102. weightActions: [['小型(<10 KG)','中型(10~20KG)', '大型(20KG以上)']],
  103. dispositionActions: [],
  104. breedData: [],
  105. searchBreedData:[],
  106. tempBreed: '',
  107. searchValue: '',
  108. tempBirthday: '',
  109. tempDisposition: ''
  110. }
  111. },
  112. props:{
  113. petType: {
  114. type: String,
  115. default: 'dog'
  116. },
  117. petBaseInfo:{
  118. type: Object,
  119. default: ()=> ({
  120. name: '',
  121. gender: '',
  122. breed: '',
  123. bodyType: '',
  124. birthDate: '',
  125. personality: ''
  126. })
  127. }
  128. },
  129. mounted() {
  130. this.getPersonalityDataList()
  131. this.getPetBreed()
  132. },
  133. methods: {
  134. nameChange(){
  135. this.updatePetBaseInfo()
  136. },
  137. sexSelect(e) {
  138. this.petBaseInfo.gender = e.value[0];
  139. this.showSex = false;
  140. this.updatePetBaseInfo()
  141. },
  142. weightSelect(e) {
  143. this.petBaseInfo.bodyType = e.value[0];
  144. this.showWeight=false;
  145. this.updatePetBaseInfo()
  146. },
  147. breedSelectOpen() {
  148. this.searchBreedData=this.breedData;
  149. this.searchValue='';
  150. this.tempBreed = this.petBaseInfo.breed;
  151. this.showBreed = true;
  152. },
  153. searchBreed(){
  154. if(this.searchValue&&this.searchValue!=''){
  155. this.searchBreedData=this.breedData.filter(e=>e.includes(this.searchValue));
  156. }else{
  157. this.searchBreedData=this.breedData
  158. }
  159. },
  160. breedSelectClose() {
  161. this.tempBreed = '';
  162. this.showBreed = false;
  163. },
  164. breedSelectConfirm() {
  165. this.petBaseInfo.breed = this.tempBreed;
  166. this.showBreed = false;
  167. this.updatePetBaseInfo()
  168. },
  169. yearMonthOpen() {
  170. if (this.petBaseInfo.birthDate) {
  171. this.tempBirthday = Number(new Date(this.petBaseInfo.birthDate))
  172. } else {
  173. this.tempBirthday = Number(new Date())
  174. }
  175. this.showBirthday = true;
  176. },
  177. yearMonthClose() {
  178. this.showBirthday = false;
  179. },
  180. yearMonthConfirm(e) {
  181. const timeFormat = uni.$u.timeFormat;
  182. this.petBaseInfo.birthDate = timeFormat(e.value, 'yyyy-mm');
  183. this.showBirthday = false;
  184. this.updatePetBaseInfo()
  185. },
  186. dispositionSelectOpen() {
  187. this.tempDisposition = this.petBaseInfo.personality;
  188. this.showDisposition = true;
  189. },
  190. dispositionSelectClose() {
  191. this.tempDisposition = '';
  192. this.showDisposition = false;
  193. },
  194. dispositionSelectConfirm() {
  195. this.petBaseInfo.personality = this.tempDisposition;
  196. this.showDisposition = false;
  197. this.updatePetBaseInfo()
  198. },
  199. checkboxChange(n) {
  200. console.log('change', n);
  201. this.updatePetBaseInfo();
  202. },
  203. updatePetBaseInfo() {
  204. // 触发 update 事件,将修改后的 petBaseInfo 对象发送给父组件
  205. this.$emit('update:petBaseInfo', this.petBaseInfo);
  206. },
  207. getPersonalityDataList(){
  208. getDictList('pet_personality').then(res=>{
  209. if (res.code == 200) {
  210. this.dispositionActions = Array.from(new Set(res.data.map(e=>e.dictLabel)))
  211. } else {
  212. this.$modal.showToast('获取性格失败')
  213. }
  214. })
  215. },
  216. getPetBreed(){
  217. let petBreedType = this.petType=='cat'?'pet_brand_cat':'pet_brand_dog'
  218. getDictList(petBreedType).then(res=>{
  219. if (res.code == 200) {
  220. this.breedData =Array.from(new Set(res.data.map(e=>e.dictLabel)))
  221. } else {
  222. this.$modal.showToast('获取种类失败')
  223. }
  224. })
  225. },
  226. getMaxDate(){
  227. return Date.now()
  228. },
  229. getMinDate(){
  230. let dt = new Date();
  231. dt.setFullYear(dt.getFullYear() - 30)
  232. return Date.parse(dt)
  233. }
  234. }
  235. }
  236. </script>
  237. <style >
  238. .personal-pet-basic-info{
  239. background-color: #fff;
  240. margin-top: 10px;
  241. padding: 10px 20px;
  242. }
  243. .personal-pet-breed-btns{
  244. display: flex;
  245. justify-content: space-around;
  246. align-items: center;
  247. flex-wrap: nowrap;
  248. flex-direction: row;
  249. }
  250. .personal-pet-breed-btn{
  251. width: 40%;
  252. }
  253. </style>