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

232 lines
5.3 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  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 class="view-pets">
  38. <view @click="toDetail" class="btn">
  39. 查看详细信息
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view v-else class="personal-pet-none">
  46. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  47. style="width: 149px;height: 124px;" mode="widthFix" />
  48. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  49. </view>
  50. </view>
  51. </template>
  52. <script setup>
  53. import {
  54. ref,
  55. onMounted
  56. } from 'vue';
  57. import {
  58. petList
  59. } from "@/api/pet/index.js";
  60. import {
  61. onShow,
  62. onPullDownRefresh
  63. } from "@dcloudio/uni-app"
  64. // 定义响应式数据
  65. const defaultPhoto = ref('https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png');
  66. const petLists = ref([]);
  67. // 获取宠物列表
  68. const getPetListData = async () => {
  69. petLists.value = [];
  70. try {
  71. const res = await petList();
  72. if (res && res.data) {
  73. petLists.value = res.data;
  74. }
  75. } catch (error) {
  76. console.error('获取宠物列表失败', error);
  77. }
  78. };
  79. // 生命周期钩子
  80. onMounted(() => {
  81. getPetListData();
  82. });
  83. onShow(() => {
  84. getPetListData();
  85. });
  86. onPullDownRefresh(() => {
  87. getPetListData();
  88. });
  89. const toDetail = () => {
  90. uni.navigateTo({
  91. url: "/otherPages/orderTakingManage/pet/detail"
  92. })
  93. }
  94. </script>
  95. <style lang="scss">
  96. .personal-pet {
  97. position: relative;
  98. height: 100%;
  99. padding-bottom: 90px;
  100. .personal-pet-list {
  101. .personal-pet-list-add {
  102. width: 100%;
  103. height: 44px;
  104. background-color: #FFFFFF;
  105. display: flex;
  106. justify-content: space-between;
  107. align-items: center;
  108. padding: 0 15px;
  109. .personal-pet-list-add-btn {
  110. font-size: 14px;
  111. color: #AAA;
  112. display: flex;
  113. align-items: center;
  114. }
  115. }
  116. .personal-pet-list-item_backgroud_m {
  117. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  118. }
  119. .personal-pet-list-item_backgroud_f {
  120. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  121. }
  122. .personal-pet-list-item {
  123. margin: 10px 10px 0 10px;
  124. border-radius: 5px;
  125. padding: 20px 10px 10px;
  126. .personal-pet-info {
  127. display: flex;
  128. align-items: center;
  129. justify-content: flex-start;
  130. .personal-pet-info-1 {
  131. margin-left: 10px;
  132. .personal-pet-info-2 {
  133. display: flex;
  134. flex-wrap: wrap;
  135. .personal-pet-name {
  136. color: #333;
  137. font-size: 16px;
  138. margin-right: 10px;
  139. }
  140. }
  141. .personal-pet-info-3 {
  142. display: flex;
  143. align-items: baseline;
  144. font-size: 14px;
  145. margin-top: 5px;
  146. color: #7D8196;
  147. .personal-pet-info-age {
  148. padding: 0 10px;
  149. margin: 0 10px;
  150. border-left: solid 2px #7D8196;
  151. border-right: solid 2px #7D8196;
  152. }
  153. }
  154. }
  155. }
  156. .personal-pet-info-disposition {
  157. padding: 10px;
  158. color: #7D8196;
  159. font-size: 14px;
  160. background: #f9f9f9;
  161. border-radius: 5px;
  162. margin: 10px 0rpx;
  163. }
  164. .view-pets {
  165. display: flex;
  166. justify-content: flex-end;
  167. .btn {
  168. display: flex;
  169. justify-content: center;
  170. align-items: center;
  171. width: 220rpx;
  172. height: 50rpx;
  173. border-radius: 25rpx;
  174. border: 2rpx solid #FFBF60;
  175. color: #FFBF60;
  176. font-size: 24rpx;
  177. }
  178. }
  179. .personal-pet-info-btns {
  180. display: flex;
  181. justify-content: flex-end;
  182. margin-top: 10px;
  183. .personal-pet-info-btn {
  184. display: flex;
  185. font-size: 14px;
  186. color: #7D8196;
  187. margin-left: 20px;
  188. }
  189. }
  190. }
  191. }
  192. .personal-pet-none {
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. flex-wrap: wrap;
  197. margin-top: 40%;
  198. .personal-pet-none-text {
  199. color: #666;
  200. text-align: center;
  201. font-size: 14px;
  202. width: 100%;
  203. margin-top: 10px;
  204. }
  205. }
  206. }
  207. </style>