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.

182 lines
4.1 KiB

1 month ago
  1. <template>
  2. <view class="personal-pet">
  3. <view v-if="petList.length>0" class="personal-service-list">
  4. <view v-for="(item,index) in petList" :key="index">
  5. <view class="personal-service-list-item" @click="goServiceInfo(item)">
  6. <view style="display: flex;align-items: center;">
  7. <u-avatar :src="item.photo?item.photo:defaultPhoto" size="46" shape="circle"></u-avatar>
  8. <view class="personal-service-tips ellipsis">
  9. {{serviceTips(item)}}
  10. </view>
  11. </view>
  12. <view>
  13. <u-icon slot="right" name="arrow-right" color="#AAA"></u-icon>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <view v-else class="personal-pet-none">
  19. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  20. style="width: 149px;height: 124px;" mode="widthFix"/>
  21. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  22. </view>
  23. <view class="personal-pet-add" v-if="petList.length==0">
  24. <button class="personal-pet-add-btn" @click="addPet">添加宠物</button>
  25. </view>
  26. <view class="">
  27. <u-picker
  28. :showToolbar='false'
  29. :show="show"
  30. :columns="petTypes"
  31. @change="petTypeChange"
  32. @cancel="cancel"
  33. @confirm="confirm"
  34. ></u-picker>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { getPetList } from "@/api/system/pet"
  40. import { getDictList } from "@/api/system/user.js"
  41. export default{
  42. data(){
  43. return{
  44. petList:[],
  45. show:false,
  46. petTypes:[],
  47. petType:''
  48. }
  49. },
  50. onShow() {
  51. this.getPetList();
  52. },
  53. mounted() {
  54. this.getPetList();
  55. },
  56. methods:{
  57. getPetList(){
  58. getPetList({owner:this.openIdStr}).then(res=>{
  59. if(res&&res.content){
  60. this.petList=res.content
  61. if(this.petList.length==0){
  62. this.getPetTypeList()
  63. }
  64. }
  65. })
  66. },
  67. getPetTypeList(){
  68. getDictList('pet_type').then(res=>{
  69. if (res.code == 200) {
  70. let petType = res.data.map(e=>e.dictLabel)
  71. this.petTypes=[petType]
  72. console.log(this.petTypes)
  73. } else {
  74. this.$modal.showToast('获取pet type失败')
  75. }
  76. })
  77. },
  78. addPet(){
  79. this.show = true;
  80. },
  81. cancel() {
  82. this.show = false
  83. },
  84. petTypeChange(e){
  85. console.log(e)
  86. this.petType=e.value[0]
  87. },
  88. confirm(e) {
  89. this.show = false
  90. if(this.petType==='猫猫'){
  91. uni.navigateTo({
  92. url: `/pages/personalCenter/petInfo?petType=cat&optionType=add`
  93. });
  94. }
  95. if(this.petType==='狗狗'){
  96. uni.navigateTo({
  97. url: `/pages/personalCenter/petInfo?petType=dog&optionType=add`
  98. });
  99. }
  100. if(!this.petType){
  101. if(e.value[0]==='猫猫'){
  102. uni.navigateTo({
  103. url: `/pages/personalCenter/petInfo?petType=cat&optionType=add`
  104. });
  105. }
  106. if(e.value[0]==='狗狗'){
  107. uni.navigateTo({
  108. url: `/pages/personalCenter/petInfo?petType=dog&optionType=add`
  109. });
  110. }
  111. }
  112. },
  113. serviceTips(item){
  114. return `完善${item.petType=='dog'?"狗狗":"猫猫"}"${item.name}"的服务信息`
  115. },
  116. goServiceInfo(item){
  117. uni.navigateTo({
  118. url: `/pages/personalCenter/serviceInfo?petType=${item.petType}&petId=${item.id}`
  119. });
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss">
  125. .personal-pet{
  126. position: relative;
  127. height: 100%;
  128. padding-bottom: 58px;
  129. .personal-pet-add{
  130. background-color: #FFFFFF;
  131. padding: 10px 20px 40px;
  132. width: 100%;
  133. height: 90px;
  134. position: fixed;
  135. bottom: 0;
  136. z-index: 100;
  137. display: flex;
  138. .personal-pet-add-btn{
  139. width: 100%;
  140. border-radius: 6px;
  141. background: #FFB13F;
  142. font-size: 16px;
  143. color: #FFFFFF;
  144. }
  145. }
  146. .personal-service-list{
  147. .personal-service-list-item{
  148. background-color: #fff;
  149. margin: 10px 10px 0 10px;
  150. border-radius: 5px;
  151. padding: 10px;
  152. display: flex;
  153. align-items: center;
  154. justify-content: space-between;
  155. .personal-service-tips{
  156. margin-left: 10px;
  157. color:#333;
  158. font-size: 14px;
  159. }
  160. }
  161. }
  162. .personal-pet-none{
  163. display:flex;
  164. justify-content: center;
  165. align-items: center;
  166. flex-wrap: wrap;
  167. margin-top: 40%;
  168. .personal-pet-none-text{
  169. color: #666;
  170. text-align: center;
  171. font-size: 14px;
  172. width: 100%;
  173. margin-top: 10px;
  174. }
  175. }
  176. }
  177. </style>