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

352 lines
8.0 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="personal-pet">
  3. <view v-if="petList.length > 0" class="personal-pet-list">
  4. <view v-for="(item, index) in petList" :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 || 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/sex/boy.svg' : '../../../static/images/sex/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 style="max-width: 35%;">
  23. {{ item.type || '未知' }}
  24. </view>
  25. <view class="personal-pet-info-age" style="max-width: 90px;">
  26. {{ item.age || '未知' }}
  27. </view>
  28. <view 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="personal-pet-info-btns">
  38. <view class="personal-pet-info-btn" @click="editPet(item)">
  39. <u-icon name="edit-pen" color="#7d8196" size="16" style="margin-right: 5px;"></u-icon>
  40. <view style="margin-left: 5px;">
  41. 编辑
  42. </view>
  43. </view>
  44. <view class="personal-pet-info-btn" @click="deletePet(item)">
  45. <u-icon name="trash" color="#7d8196" size="16"></u-icon>
  46. <view style="margin-left: 5px;">
  47. 删除
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view v-else class="personal-pet-none">
  55. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  56. style="width: 149px;height: 124px;" mode="widthFix" />
  57. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  58. </view>
  59. <view class="personal-pet-add">
  60. <button class="personal-pet-add-btn" @click="addPet">
  61. <view style="font-size: 16px;font-weight: 500;">
  62. 添加宠物
  63. </view>
  64. </button>
  65. </view>
  66. <view>
  67. <u-picker :show="show" :columns="petTypes" @confirm="petTypeChange" @cancel="cancel"
  68. :immediateChange="true"></u-picker>
  69. </view>
  70. <u-modal :show="showDel" @confirm="confirmDel" @cancel="cancelDel" ref="uModal" showCancelButton
  71. :asyncClose="true" :content="delContent"></u-modal>
  72. </view>
  73. </template>
  74. <script setup>
  75. import {
  76. ref,
  77. onMounted
  78. } from 'vue';
  79. // import {
  80. // getDictList
  81. // } from "@/api/system/user.js"
  82. import {
  83. getpetList,
  84. delByPetId
  85. } from "@/api/pet/index.js";
  86. import {
  87. useRouter
  88. } from 'vue-router';
  89. import {
  90. onShow,
  91. onPullDownRefresh
  92. } from '@dcloudio/uni-app'
  93. const router = useRouter();
  94. const defaultPhoto = ref('https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png');
  95. const petList = ref([]);
  96. const show = ref(false);
  97. const showDel = ref(false);
  98. const petTypes = ref([
  99. [
  100. '猫咪', '狗狗'
  101. ]
  102. ]);
  103. const delContent = ref('');
  104. const deleteId = ref('');
  105. const petType = ref('');
  106. const getPetList = async () => {
  107. petList.value = [];
  108. try {
  109. const res = await getpetList();
  110. if (res && res.data) {
  111. petList.value = res.data;
  112. showDel.value = false;
  113. }
  114. } catch (error) {
  115. console.error('获取宠物列表失败', error);
  116. }
  117. };
  118. // const getPetTypeList = async () => {
  119. // try {
  120. // const res = await getDictList('pet_type');
  121. // if (res.code === 200) {
  122. // const petType = res.data.map(e => e.dictLabel);
  123. // petTypes.value = [petType];
  124. // } else {
  125. // console.error('获取pet type失败');
  126. // }
  127. // } catch (error) {
  128. // console.error('获取pet type列表失败', error);
  129. // }
  130. // };
  131. const addPet = () => {
  132. show.value = true;
  133. };
  134. const cancel = () => {
  135. show.value = false;
  136. };
  137. const petTypeChange = (e) => {
  138. petType.value = e.value[0];
  139. show.value = false;
  140. if (petType.value === '猫咪') {
  141. uni.navigateTo({
  142. url: "/otherPages/userManage/pet/petInfo?petType=0&optionType=add"
  143. })
  144. }
  145. if (petType.value === '狗狗') {
  146. uni.navigateTo({
  147. url: "/otherPages/userManage/pet/petInfo?petType=1&optionType=add"
  148. })
  149. }
  150. };
  151. const editPet = (item) => {
  152. if (item.petType === '猫咪' || item.petType === 0) {
  153. uni.navigateTo({
  154. url: `/otherPages/userManage/pet/petInfo?petType=0&optionType=edit&petId=${item.id}`
  155. })
  156. }
  157. if (item.petType === '狗狗' || item.petType === 1) {
  158. uni.navigateTo({
  159. url: `/otherPages/userManage/pet/petInfo?petType=1&optionType=edit&petId=${item.id}`
  160. })
  161. }
  162. };
  163. const deletePet = (item) => {
  164. delContent.value = "确定要删除" + item.nickName + '?';
  165. showDel.value = true;
  166. deleteId.value = item.id;
  167. };
  168. const confirmDel = async () => {
  169. try {
  170. await delByPetId({
  171. id: deleteId.value
  172. });
  173. getPetList();
  174. } catch (error) {
  175. console.error('删除宠物失败', error);
  176. }
  177. };
  178. const cancelDel = () => {
  179. showDel.value = false;
  180. deleteId.value = '';
  181. };
  182. onMounted(() => {
  183. // getPetTypeList();
  184. getPetList();
  185. });
  186. onShow(() => {
  187. getPetList();
  188. });
  189. onPullDownRefresh(() => {
  190. getPetList();
  191. });
  192. </script>
  193. <style lang="scss" scoped>
  194. .personal-pet {
  195. position: relative;
  196. height: 100%;
  197. padding-bottom: 90px;
  198. .personal-pet-add {
  199. box-sizing: border-box;
  200. background-color: #FFFFFF;
  201. padding: 20rpx 20rpx 40rpx 20rpx;
  202. width: 100%;
  203. height: 160rpx;
  204. position: fixed;
  205. bottom: 0;
  206. z-index: 100;
  207. display: flex;
  208. .personal-pet-add-btn {
  209. width: 100%;
  210. height: 90rpx;
  211. border-radius: 6px;
  212. background: #FFB13F;
  213. font-size: 16px;
  214. color: #FFFFFF;
  215. }
  216. }
  217. .personal-pet-list {
  218. .personal-pet-list-add {
  219. width: 100%;
  220. height: 44px;
  221. background-color: #FFFFFF;
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. padding: 0 15px;
  226. .personal-pet-list-add-btn {
  227. font-size: 14px;
  228. color: #AAA;
  229. display: flex;
  230. align-items: center;
  231. }
  232. }
  233. .personal-pet-list-item_backgroud_m {
  234. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  235. }
  236. .personal-pet-list-item_backgroud_f {
  237. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  238. }
  239. .personal-pet-list-item {
  240. margin: 10px 10px 0 10px;
  241. border-radius: 5px;
  242. padding: 20px 10px 10px;
  243. .personal-pet-info {
  244. display: flex;
  245. align-items: center;
  246. justify-content: flex-start;
  247. .personal-pet-info-1 {
  248. margin-left: 10px;
  249. width: calc(100% - 60px);
  250. .personal-pet-info-2 {
  251. display: flex;
  252. flex-wrap: wrap;
  253. .personal-pet-name {
  254. color: #333;
  255. font-size: 16px;
  256. margin-right: 10px;
  257. }
  258. }
  259. .personal-pet-info-3 {
  260. display: flex;
  261. align-items: baseline;
  262. font-size: 14px;
  263. margin-top: 5px;
  264. color: #7D8196;
  265. .personal-pet-info-age {
  266. padding: 0 10px;
  267. margin: 0 10px;
  268. border-left: solid 2px #7D8196;
  269. border-right: solid 2px #7D8196;
  270. }
  271. }
  272. }
  273. }
  274. .personal-pet-info-disposition {
  275. padding: 10px;
  276. color: #7D8196;
  277. font-size: 14px;
  278. background: #f9f9f9;
  279. border-radius: 5px;
  280. margin-top: 10px;
  281. }
  282. .personal-pet-info-btns {
  283. display: flex;
  284. justify-content: flex-end;
  285. margin-top: 10px;
  286. .personal-pet-info-btn {
  287. display: flex;
  288. font-size: 14px;
  289. color: #7D8196;
  290. margin-left: 20px;
  291. }
  292. }
  293. }
  294. }
  295. .personal-pet-none {
  296. display: flex;
  297. justify-content: center;
  298. align-items: center;
  299. flex-wrap: wrap;
  300. margin-top: 40%;
  301. .personal-pet-none-text {
  302. color: #666;
  303. text-align: center;
  304. font-size: 14px;
  305. width: 100%;
  306. margin-top: 10px;
  307. }
  308. }
  309. }
  310. </style>