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

364 lines
8.3 KiB

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