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

362 lines
8.2 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks 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. computed
  79. } from 'vue';
  80. // import {
  81. // getDictList
  82. // } from "@/api/system/user.js"
  83. import {
  84. getpetList,
  85. delByPetId
  86. } from "@/api/pet/index.js";
  87. import {
  88. useRouter
  89. } from 'vue-router';
  90. import {
  91. onShow,
  92. onPullDownRefresh
  93. } from '@dcloudio/uni-app'
  94. import {
  95. useStore
  96. } from "vuex"
  97. const store = useStore();
  98. const userInfo = computed(() => {
  99. return store.getters.userInfo
  100. })
  101. const router = useRouter();
  102. const defaultPhoto = ref('https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png');
  103. const petList = ref([]);
  104. const show = ref(false);
  105. const showDel = ref(false);
  106. const petTypes = ref([
  107. [
  108. '猫咪', '狗狗'
  109. ]
  110. ]);
  111. const delContent = ref('');
  112. const deleteId = ref('');
  113. const petType = ref('');
  114. const getPetList = async () => {
  115. petList.value = [];
  116. try {
  117. const res = await getpetList({
  118. userId: userInfo.value.userId
  119. });
  120. if (res && res.data) {
  121. petList.value = res.data;
  122. showDel.value = false;
  123. }
  124. } catch (error) {
  125. console.error('获取宠物列表失败', error);
  126. }
  127. };
  128. // const getPetTypeList = async () => {
  129. // try {
  130. // const res = await getDictList('pet_type');
  131. // if (res.code === 200) {
  132. // const petType = res.data.map(e => e.dictLabel);
  133. // petTypes.value = [petType];
  134. // } else {
  135. // console.error('获取pet type失败');
  136. // }
  137. // } catch (error) {
  138. // console.error('获取pet type列表失败', error);
  139. // }
  140. // };
  141. const addPet = () => {
  142. show.value = true;
  143. };
  144. const cancel = () => {
  145. show.value = false;
  146. };
  147. const petTypeChange = (e) => {
  148. petType.value = e.value[0];
  149. show.value = false;
  150. if (petType.value === '猫咪') {
  151. uni.navigateTo({
  152. url: "/otherPages/userManage/pet/petInfo?petType=0&optionType=add&userId="+userInfo.value.userId
  153. })
  154. }
  155. if (petType.value === '狗狗') {
  156. uni.navigateTo({
  157. url: "/otherPages/userManage/pet/petInfo?petType=1&optionType=add&userId="+userInfo.value.userId
  158. })
  159. }
  160. };
  161. const editPet = (item) => {
  162. if (item.petType === '猫咪' || item.petType === 0) {
  163. uni.navigateTo({
  164. url: `/otherPages/userManage/pet/petInfo?petType=0&optionType=edit&petId=${item.id}`
  165. })
  166. }
  167. if (item.petType === '狗狗' || item.petType === 1) {
  168. uni.navigateTo({
  169. url: `/otherPages/userManage/pet/petInfo?petType=1&optionType=edit&petId=${item.id}`
  170. })
  171. }
  172. };
  173. const deletePet = (item) => {
  174. delContent.value = "确定要删除" + item.nickName + '?';
  175. showDel.value = true;
  176. deleteId.value = item.id;
  177. };
  178. const confirmDel = async () => {
  179. try {
  180. await delByPetId({
  181. id: deleteId.value
  182. });
  183. getPetList();
  184. } catch (error) {
  185. console.error('删除宠物失败', error);
  186. }
  187. };
  188. const cancelDel = () => {
  189. showDel.value = false;
  190. deleteId.value = '';
  191. };
  192. // onMounted(() => {
  193. // // getPetTypeList();
  194. // getPetList();
  195. // });
  196. onShow(() => {
  197. getPetList();
  198. });
  199. onPullDownRefresh(() => {
  200. getPetList();
  201. });
  202. </script>
  203. <style lang="scss" scoped>
  204. .personal-pet {
  205. position: relative;
  206. height: 100%;
  207. padding-bottom: 90px;
  208. .personal-pet-add {
  209. box-sizing: border-box;
  210. background-color: #FFFFFF;
  211. padding: 20rpx 20rpx 40rpx 20rpx;
  212. width: 100%;
  213. height: 160rpx;
  214. position: fixed;
  215. bottom: 0;
  216. z-index: 100;
  217. display: flex;
  218. .personal-pet-add-btn {
  219. width: 100%;
  220. height: 90rpx;
  221. border-radius: 6px;
  222. background: #FFB13F;
  223. font-size: 16px;
  224. color: #FFFFFF;
  225. }
  226. }
  227. .personal-pet-list {
  228. .personal-pet-list-add {
  229. width: 100%;
  230. height: 44px;
  231. background-color: #FFFFFF;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. padding: 0 15px;
  236. .personal-pet-list-add-btn {
  237. font-size: 14px;
  238. color: #AAA;
  239. display: flex;
  240. align-items: center;
  241. }
  242. }
  243. .personal-pet-list-item_backgroud_m {
  244. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  245. }
  246. .personal-pet-list-item_backgroud_f {
  247. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  248. }
  249. .personal-pet-list-item {
  250. margin: 10px 10px 0 10px;
  251. border-radius: 5px;
  252. padding: 20px 10px 10px;
  253. .personal-pet-info {
  254. display: flex;
  255. align-items: center;
  256. justify-content: flex-start;
  257. .personal-pet-info-1 {
  258. margin-left: 10px;
  259. width: calc(100% - 60px);
  260. .personal-pet-info-2 {
  261. display: flex;
  262. flex-wrap: wrap;
  263. .personal-pet-name {
  264. color: #333;
  265. font-size: 16px;
  266. margin-right: 10px;
  267. }
  268. }
  269. .personal-pet-info-3 {
  270. display: flex;
  271. align-items: baseline;
  272. font-size: 14px;
  273. margin-top: 5px;
  274. color: #7D8196;
  275. .personal-pet-info-age {
  276. padding: 0 10px;
  277. margin: 0 10px;
  278. border-left: solid 2px #7D8196;
  279. border-right: solid 2px #7D8196;
  280. }
  281. }
  282. }
  283. }
  284. .personal-pet-info-disposition {
  285. padding: 10px;
  286. color: #7D8196;
  287. font-size: 14px;
  288. background: #f9f9f9;
  289. border-radius: 5px;
  290. margin-top: 10px;
  291. }
  292. .personal-pet-info-btns {
  293. display: flex;
  294. justify-content: flex-end;
  295. margin-top: 10px;
  296. .personal-pet-info-btn {
  297. display: flex;
  298. font-size: 14px;
  299. color: #7D8196;
  300. margin-left: 20px;
  301. }
  302. }
  303. }
  304. }
  305. .personal-pet-none {
  306. display: flex;
  307. justify-content: center;
  308. align-items: center;
  309. flex-wrap: wrap;
  310. margin-top: 40%;
  311. .personal-pet-none-text {
  312. color: #666;
  313. text-align: center;
  314. font-size: 14px;
  315. width: 100%;
  316. margin-top: 10px;
  317. }
  318. }
  319. }
  320. </style>