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.

482 lines
17 KiB

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week 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.gender == '男生' ? '.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.photo ? item.photo : defaultPhoto" size="60" shape="circle"></u-avatar>
  10. </view>
  11. <view class="personal-pet-info-1" style="width: calc(100% - 120px);">
  12. <view class="personal-pet-info-2">
  13. <view class="personal-pet-name ellipsis">
  14. {{ item.name }}
  15. </view>
  16. <view class="personal-pet-sex">
  17. <img :src="item.gender == '男生' ? '../../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.breed || '未知' }}
  24. </view>
  25. <view class="personal-pet-info-age" style="max-width: 90px;">
  26. {{ item.birthDate || '未知' }}
  27. </view>
  28. <view class="ellipsis" style="max-width: 25%;">
  29. {{ item.bodyType || '未知' }}
  30. </view>
  31. </view>
  32. </view>
  33. <view style="margin-left: auto; width: 20px;">
  34. <u-checkbox-group v-model="item.checked">
  35. <u-checkbox shape="circle" activeColor="#ffbf60"></u-checkbox>
  36. </u-checkbox-group>
  37. </view>
  38. </view>
  39. <view class="personal-pet-info-disposition ellipsis">
  40. 性格 {{ item.personality }}
  41. </view>
  42. <view class="personal-pet-info-btns">
  43. <view style="display: flex; align-items: center;">
  44. <u-button v-if="item.selectedDate.length == 0" color="#FFBF60" size="mini"
  45. iconPlacement="right" shape="circle" plain @click="selectDate(item)">
  46. <view style="font-size: 14px;">请选择服务日期</view>
  47. <u-icon name="arrow-right" color="#FFBF60" size="14"
  48. style="margin-right: 5px;"></u-icon>
  49. </u-button>
  50. <u-button v-else color="#FFBF60" type="primary" size="mini" iconPlacement="right"
  51. shape="circle" @click="selectDate(item)">
  52. <view style="font-size: 14px;">{{ showSelectedDate(item.selectedDate) }}</view>
  53. <u-icon name="arrow-right" color="#ffffff" size="14"
  54. style="margin-right: 5px;"></u-icon>
  55. </u-button>
  56. </view>
  57. <view style="display: flex; align-items: center; justify-content: flex-end;">
  58. <view class="personal-pet-info-btn" @click="editPet(item)">
  59. <u-icon name="edit-pen" color="#7d8196" size="16" style="margin-right: 5px;"></u-icon>
  60. <view style="margin-left: 5px;">
  61. 编辑
  62. </view>
  63. </view>
  64. <view class="personal-pet-info-btn" @click="deletePet(item)">
  65. <u-icon name="trash" color="#7d8196" size="16"></u-icon>
  66. <view style="margin-left: 5px;">
  67. 删除
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view v-else class="personal-pet-none">
  76. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  77. style="width: 149px;height: 124px;" mode="widthFix" />
  78. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  79. </view>
  80. <view class="personal-pet-add">
  81. <view style="width: 45%;">
  82. <u-button class="personal-pet-add-btn" color="#FFF4E4" @click="addPet">
  83. <view style="font-size: 32rpx;font-weight: 500;color: #FFAA48;">
  84. 新增宠物
  85. </view>
  86. </u-button>
  87. </view>
  88. <view style="width: 45%;">
  89. <u-button class="personal-pet-add-btn" color="#FFBF60" @click="confirm">
  90. <view style="font-size: 32rpx;font-weight: 500;color: #fff;">
  91. 确定
  92. </view>
  93. </u-button>
  94. </view>
  95. </view>
  96. <view class="">
  97. <u-picker :showToolbar='false' :show="show" :columns="petTypes" @change="petTypeChange" @cancel="cancel"
  98. @confirm="confirmPetType"></u-picker>
  99. </view>
  100. <u-modal :show="showDel" @confirm="confirmDel" @cancel="cancelDel" ref="uModal" showCancelButton
  101. :asyncClose="true" :content='delContent'>
  102. </u-modal>
  103. <view v-if="showCalendar" class="calendar-popup">
  104. <view class="calendar-mask"></view>
  105. <view class="calendar-content">
  106. <uni-calendar class="uni-calendar--hook" :selected="selectedDate" :startDate="startDate"
  107. :endDate="endDate" @change="change" :showMonth="false" />
  108. <u-button color="#FFBF60" type="primary" @click="confirmCanlendar">确定</u-button>
  109. </view>
  110. </view>
  111. </view>
  112. </template>
  113. <script>
  114. import { getDictList } from "@/api/system/user.js"
  115. import { getPetList, delPet } from "@/api/system/pet"
  116. export default {
  117. data() {
  118. return {
  119. defaultPhoto: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png',
  120. petList: [],
  121. show: false,
  122. showDel: false,
  123. petTypes: [],
  124. delContent: '',
  125. deleteId: '',
  126. petType: '',
  127. startDate: '',
  128. endDate: '',
  129. showCalendar: false,
  130. selectedDate: [],
  131. currentPets: []
  132. }
  133. },
  134. onShow() {
  135. this.getPetList();
  136. },
  137. onPullDownRefresh() {
  138. this.getPetList();
  139. },
  140. mounted() {
  141. this.getPetTypeList();
  142. this.getPetList();
  143. this.getCalendarDate();
  144. },
  145. methods: {
  146. getPetList() {
  147. this.petList = []
  148. getPetList().then(res => {
  149. let currentPets = this.$globalData.newOrderData.currentPets
  150. if (res && res.content) {
  151. this.petList = res.content.map(e => {
  152. const currentPet = currentPets.find(item => item.id === e.id)
  153. if (currentPet) {
  154. e.selectedDate = currentPet.selectedDate
  155. e.checked = currentPet.checked
  156. } else {
  157. e.selectedDate = []
  158. e.checked = false
  159. }
  160. return e
  161. })
  162. this.showDel = false;
  163. }
  164. })
  165. },
  166. getPetTypeList() {
  167. getDictList('pet_type').then(res => {
  168. if (res.code == 200) {
  169. let petType = res.data.map(e => e.dictLabel)
  170. this.petTypes = [petType]
  171. console.log(this.petTypes)
  172. } else {
  173. this.$modal.showToast('获取pet type失败')
  174. }
  175. })
  176. },
  177. addPet() {
  178. this.show = true;
  179. },
  180. cancel() {
  181. this.show = false
  182. },
  183. petTypeChange(e) {
  184. console.log(e)
  185. this.petType = e.value[0]
  186. },
  187. confirmPetType(e) {
  188. console.log(e)
  189. this.show = false
  190. // 获取宠物类型,优先使用已选择的petType,否则使用e.value[0]
  191. const type = this.petType || e.value[0]
  192. // 根据宠物类型映射到英文类型
  193. const petTypeMap = {
  194. '猫猫': 'cat',
  195. '狗狗': 'dog'
  196. }
  197. const petType = petTypeMap[type]
  198. if (petType) {
  199. uni.navigateTo({
  200. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=add&isNewOrder=true`
  201. });
  202. }
  203. },
  204. editPet(item) {
  205. const petTypeMap = {
  206. '猫猫': 'cat',
  207. 'cat': 'cat',
  208. '狗狗': 'dog',
  209. 'dog': 'dog'
  210. }
  211. const petType = petTypeMap[item.petType]
  212. if (petType) {
  213. uni.navigateTo({
  214. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=edit&petId=${item.id}&isNewOrder=true`
  215. });
  216. }
  217. },
  218. deletePet(item) {
  219. this.delContent = "确定要删除" + item.name + '?';
  220. this.showDel = true;
  221. this.deleteId = item.id;
  222. },
  223. confirmDel() {
  224. delPet(this.deleteId).then(res => {
  225. console.log(res);
  226. this.$modal.showToast('删除成功');
  227. this.getPetList()
  228. })
  229. },
  230. cancelDel() {
  231. this.showDel = false;
  232. this.deleteId = '';
  233. },
  234. getCalendarDate() {
  235. let tomorrow = new Date()
  236. tomorrow.setDate(tomorrow.getDate());
  237. this.startDate = this.formatDate(tomorrow);
  238. // 获取三个月后的日期
  239. let threeMonthsLater = new Date();
  240. threeMonthsLater.setMonth(threeMonthsLater.getMonth() + 3);
  241. this.endDate = this.formatDate(threeMonthsLater);
  242. },
  243. formatDate(date) {
  244. let year = date.getFullYear();
  245. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  246. let day = date.getDate().toString().padStart(2, '0');
  247. return year + '-' + month + '-' + day;
  248. },
  249. selectDate(item) {
  250. this.currentId = item.id
  251. this.selectedDate = item.selectedDate
  252. this.showCalendar = true;
  253. },
  254. confirmCanlendar() {
  255. this.petList.find(e => e.id == this.currentId).selectedDate = this.selectedDate.sort((a, b) => new Date(a.date) - new Date(b.date))
  256. this.selectedDate = []
  257. this.showCalendar = false;
  258. },
  259. change(e) {
  260. const selectedValue = this.selectedDate.find(item => item.date === e.fulldate)
  261. if (selectedValue) {
  262. // 存在则移除
  263. this.selectedDate = this.selectedDate.filter(item => item.date !== e.fulldate);
  264. } else {
  265. this.selectedDate.push({
  266. date: e.fulldate,
  267. info: '预定'
  268. })
  269. }
  270. },
  271. confirm() {
  272. const selectedPets = this.petList.filter(e => e.checked)
  273. const unselectedDatePets = selectedPets.filter(pet => !pet.selectedDate || pet.selectedDate.length === 0)
  274. if (unselectedDatePets.length > 0) {
  275. const petNames = unselectedDatePets.map(pet => pet.name).join('、')
  276. this.$modal.showToast(`请为${petNames}选择服务时间`)
  277. return
  278. }
  279. this.$globalData.newOrderData.currentPets = selectedPets
  280. uni.redirectTo({
  281. url: '/pages/newOrder/serviceNew'
  282. })
  283. },
  284. showSelectedDate(selectedDate) {
  285. // 显示格式:首日...最后一日 共几天
  286. // 日期格式只需要月份和日期 例如:01/01...01/07
  287. const firstDate = selectedDate[0].date.substring(5).replace('-', '/')
  288. const lastDate = selectedDate[selectedDate.length - 1].date.substring(5).replace('-', '/')
  289. const days = selectedDate.length
  290. return `${firstDate}${days > 2 ? '...' : ''}${days == 2 ? ',' : ''}${days > 1 ? lastDate : ''}${days}`
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. .personal-pet {
  297. position: relative;
  298. height: 100%;
  299. padding-bottom: 90px;
  300. .personal-pet-add {
  301. background-color: #FFFFFF;
  302. padding: 10px 20px 40px;
  303. width: 100%;
  304. height: 90px;
  305. position: fixed;
  306. bottom: 0;
  307. z-index: 100;
  308. display: flex;
  309. justify-content: space-between;
  310. .personal-pet-add-btn {
  311. width: 100%;
  312. border-radius: 6px;
  313. font-size: 16px;
  314. }
  315. }
  316. .personal-pet-list {
  317. .personal-pet-list-add {
  318. width: 100%;
  319. height: 44px;
  320. background-color: #FFFFFF;
  321. display: flex;
  322. justify-content: space-between;
  323. align-items: center;
  324. padding: 0 15px;
  325. .personal-pet-list-add-btn {
  326. font-size: 14px;
  327. color: #AAA;
  328. display: flex;
  329. align-items: center;
  330. }
  331. }
  332. .personal-pet-list-item_backgroud_m {
  333. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  334. }
  335. .personal-pet-list-item_backgroud_f {
  336. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  337. }
  338. .personal-pet-list-item {
  339. margin: 10px 10px 0 10px;
  340. border-radius: 5px;
  341. padding: 20px 10px 10px;
  342. .personal-pet-info {
  343. display: flex;
  344. align-items: center;
  345. justify-content: flex-start;
  346. .personal-pet-info-1 {
  347. margin-left: 10px;
  348. .personal-pet-info-2 {
  349. display: flex;
  350. flex-wrap: wrap;
  351. .personal-pet-name {
  352. color: #333;
  353. font-size: 16px;
  354. margin-right: 10px;
  355. }
  356. }
  357. .personal-pet-info-3 {
  358. display: flex;
  359. align-items: baseline;
  360. font-size: 14px;
  361. margin-top: 5px;
  362. color: #7D8196;
  363. .personal-pet-info-age {
  364. padding: 0 10px;
  365. margin: 0 10px;
  366. border-left: solid 2px #7D8196;
  367. border-right: solid 2px #7D8196;
  368. }
  369. }
  370. }
  371. }
  372. .personal-pet-info-disposition {
  373. padding: 10px;
  374. color: #7D8196;
  375. font-size: 14px;
  376. background: #f9f9f9;
  377. border-radius: 5px;
  378. margin-top: 10px;
  379. }
  380. .personal-pet-info-btns {
  381. display: flex;
  382. justify-content: space-between;
  383. margin-top: 10px;
  384. .personal-pet-info-btn {
  385. display: flex;
  386. font-size: 14px;
  387. color: #7D8196;
  388. margin-left: 20px;
  389. }
  390. }
  391. }
  392. }
  393. .personal-pet-none {
  394. display: flex;
  395. justify-content: center;
  396. align-items: center;
  397. flex-wrap: wrap;
  398. margin-top: 40%;
  399. .personal-pet-none-text {
  400. color: #666;
  401. text-align: center;
  402. font-size: 14px;
  403. width: 100%;
  404. margin-top: 10px;
  405. }
  406. }
  407. .calendar-popup {
  408. position: fixed;
  409. bottom: 0;
  410. left: 0;
  411. right: 0;
  412. z-index: 999;
  413. .calendar-content {
  414. background: #fff;
  415. border-radius: 16px 16px 0 0;
  416. padding: 0 20px 20px;
  417. }
  418. }
  419. .calendar-mask {
  420. position: fixed;
  421. top: 0;
  422. left: 0;
  423. right: 0;
  424. bottom: 0;
  425. background: rgba(0, 0, 0, 0.5);
  426. /* 半透明黑色 */
  427. z-index: 998;
  428. /* 确保在内容下方 */
  429. pointer-events: none;
  430. /* 使遮罩层不阻止点击事件 */
  431. }
  432. .calendar-content {
  433. position: relative;
  434. /* 确保内容在遮罩层之上 */
  435. z-index: 999;
  436. /* 确保内容在遮罩层之上 */
  437. }
  438. }
  439. </style>