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

231 lines
5.3 KiB

  1. <template>
  2. <view class="personal-pet">
  3. <view v-if="petLists.length > 0" class="personal-pet-list">
  4. <view v-for="(item, index) in petLists" :key="index">
  5. <view
  6. :class="['personal-pet-list-item', item.sex === 0 ? '.personal-pet-list-item_backgroud_m' : '.personal-pet-list-item_backgroud_f']">
  7. <view class="personal-pet-info">
  8. <view>
  9. <u-avatar :src="item.headImage? item.headImage : defaultPhoto" size="60" shape="circle"></u-avatar>
  10. </view>
  11. <view class="personal-pet-info-1">
  12. <view class="personal-pet-info-2">
  13. <view class="personal-pet-name">
  14. {{ item.nickName }}
  15. </view>
  16. <view class="personal-pet-sex">
  17. <img :src="item.sex === 0 ? '../../static/images/details/boy.svg' : '../../static/images/details/girl.svg'"
  18. alt="sex" style="width: 16px;height: 16px;" />
  19. </view>
  20. </view>
  21. <view class="personal-pet-info-3" style="width: 100%;">
  22. <view class="ellipsis" style="max-width: 25%;">
  23. {{ item.type || '未知' }}
  24. </view>
  25. <view class="personal-pet-info-age" style="max-width: 90px;">
  26. {{ item.type || '未知' }}
  27. </view>
  28. <view class="ellipsis" style="max-width: 25%;">
  29. {{ item.weight + 'kg' }}
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="personal-pet-info-disposition ellipsis">
  35. 性格 {{ item.personality }}
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view v-else class="personal-pet-none">
  41. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  42. style="width: 149px;height: 124px;" mode="widthFix" />
  43. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import {
  49. ref,
  50. onMounted
  51. } from 'vue';
  52. import {
  53. petList
  54. } from "@/api/pet/index.js";
  55. import {
  56. onShow,
  57. onPullDownRefresh
  58. } from "@dcloudio/uni-app"
  59. // 定义响应式数据
  60. const defaultPhoto = ref('https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png');
  61. const petLists = ref([]);
  62. const deleteId = ref('');
  63. const petType = ref('');
  64. // 获取宠物列表
  65. const getPetListData = async () => {
  66. petLists.value = [];
  67. try {
  68. const res = await petList();
  69. if (res && res.data) {
  70. petLists.value = res.data;
  71. }
  72. } catch (error) {
  73. console.error('获取宠物列表失败', error);
  74. }
  75. };
  76. // 添加宠物
  77. const addPet = () => {
  78. show.value = true;
  79. };
  80. // 编辑宠物
  81. const editPet = (item) => {
  82. if (item.petType === '猫猫' || item.petType === 'cat') {
  83. uni.navigateTo({
  84. url: `/pages/personalCenter/petInfo?petType=cat&optionType=edit&petId=${item.id}`
  85. });
  86. }
  87. if (item.petType === '狗狗' || item.petType === 'dog') {
  88. uni.navigateTo({
  89. url: `/pages/personalCenter/petInfo?petType=dog&optionType=edit&petId=${item.id}`
  90. });
  91. }
  92. };
  93. // 删除宠物
  94. const deletePet = (item) => {
  95. showDel.value = true;
  96. deleteId.value = item.id;
  97. };
  98. // 生命周期钩子
  99. onMounted(() => {
  100. getPetListData();
  101. });
  102. onShow(() => {
  103. getPetListData();
  104. });
  105. onPullDownRefresh(() => {
  106. getPetListData();
  107. });
  108. </script>
  109. <style lang="scss">
  110. .personal-pet {
  111. position: relative;
  112. height: 100%;
  113. padding-bottom: 90px;
  114. .personal-pet-list {
  115. .personal-pet-list-add {
  116. width: 100%;
  117. height: 44px;
  118. background-color: #FFFFFF;
  119. display: flex;
  120. justify-content: space-between;
  121. align-items: center;
  122. padding: 0 15px;
  123. .personal-pet-list-add-btn {
  124. font-size: 14px;
  125. color: #AAA;
  126. display: flex;
  127. align-items: center;
  128. }
  129. }
  130. .personal-pet-list-item_backgroud_m {
  131. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  132. }
  133. .personal-pet-list-item_backgroud_f {
  134. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  135. }
  136. .personal-pet-list-item {
  137. margin: 10px 10px 0 10px;
  138. border-radius: 5px;
  139. padding: 20px 10px 10px;
  140. .personal-pet-info {
  141. display: flex;
  142. align-items: center;
  143. justify-content: flex-start;
  144. .personal-pet-info-1 {
  145. margin-left: 10px;
  146. .personal-pet-info-2 {
  147. display: flex;
  148. flex-wrap: wrap;
  149. .personal-pet-name {
  150. color: #333;
  151. font-size: 16px;
  152. margin-right: 10px;
  153. }
  154. }
  155. .personal-pet-info-3 {
  156. display: flex;
  157. align-items: baseline;
  158. font-size: 14px;
  159. margin-top: 5px;
  160. color: #7D8196;
  161. .personal-pet-info-age {
  162. padding: 0 10px;
  163. margin: 0 10px;
  164. border-left: solid 2px #7D8196;
  165. border-right: solid 2px #7D8196;
  166. }
  167. }
  168. }
  169. }
  170. .personal-pet-info-disposition {
  171. padding: 10px;
  172. color: #7D8196;
  173. font-size: 14px;
  174. background: #f9f9f9;
  175. border-radius: 5px;
  176. margin-top: 10px;
  177. }
  178. .personal-pet-info-btns {
  179. display: flex;
  180. justify-content: flex-end;
  181. margin-top: 10px;
  182. .personal-pet-info-btn {
  183. display: flex;
  184. font-size: 14px;
  185. color: #7D8196;
  186. margin-left: 20px;
  187. }
  188. }
  189. }
  190. }
  191. .personal-pet-none {
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. flex-wrap: wrap;
  196. margin-top: 40%;
  197. .personal-pet-none-text {
  198. color: #666;
  199. text-align: center;
  200. font-size: 14px;
  201. width: 100%;
  202. margin-top: 10px;
  203. }
  204. }
  205. }
  206. </style>