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.

513 lines
18 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
  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"
  107. :disabledDay="outDateList"
  108. :selected="selectedDate" :startDate="startDate"
  109. :endDate="endDate" @change="change" :showMonth="false" />
  110. <u-button color="#FFBF60" type="primary" @click="confirmCanlendar">确定</u-button>
  111. </view>
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. import { getDictList } from "@/api/system/user.js"
  117. import { getPetList, delPet } from "@/api/system/pet"
  118. import positionMixin from '../../mixins/position';
  119. import {
  120. getTeacherAddressList,
  121. } from "@/api/order/order"
  122. export default {
  123. mixins: [positionMixin],
  124. data() {
  125. return {
  126. defaultPhoto: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png',
  127. petList: [],
  128. show: false,
  129. showDel: false,
  130. petTypes: [],
  131. delContent: '',
  132. deleteId: '',
  133. petType: '',
  134. startDate: '',
  135. endDate: '',
  136. showCalendar: false,
  137. selectedDate: [],
  138. currentPets: [],
  139. //当前技师不接单日期
  140. outDateList : ['2025-6-20'],
  141. }
  142. },
  143. onShow() {
  144. this.getPetList();
  145. this.getOutDateList()
  146. },
  147. onPullDownRefresh() {
  148. this.getPetList();
  149. },
  150. mounted() {
  151. this.getPetTypeList();
  152. this.getPetList();
  153. this.getCalendarDate();
  154. },
  155. methods: {
  156. getPetList() {
  157. this.petList = []
  158. getPetList().then(res => {
  159. let currentPets = this.$globalData.newOrderData.currentPets
  160. if (res && res.content) {
  161. this.petList = res.content.map(e => {
  162. const currentPet = currentPets.find(item => item.id === e.id)
  163. if (currentPet) {
  164. e.selectedDate = currentPet.selectedDate
  165. e.checked = currentPet.checked
  166. } else {
  167. e.selectedDate = []
  168. e.checked = false
  169. }
  170. return e
  171. })
  172. this.showDel = false;
  173. }
  174. })
  175. },
  176. //获取当前技师不接单日期
  177. getOutDateList(){
  178. if(!this.buyInfo.teacher || !this.buyInfo.teacher.userId){
  179. return
  180. }
  181. console.log('this.buyInfo', this.buyInfo);
  182. getTeacherAddressList({
  183. userId : this.buyInfo.teacher.userId
  184. }).then(response => {
  185. if (response.code == 200) {
  186. let addressList = this.calculateDistanceAddressList(response.data)
  187. if(addressList && addressList[0] && addressList[0].appletOutDate){
  188. this.outDateList = addressList[0].appletOutDate.map(n => n.date)
  189. }
  190. console.log(addressList, this.outDateList);
  191. }
  192. })
  193. },
  194. getPetTypeList() {
  195. getDictList('pet_type').then(res => {
  196. if (res.code == 200) {
  197. let petType = res.data.map(e => e.dictLabel)
  198. this.petTypes = [petType]
  199. console.log(this.petTypes)
  200. } else {
  201. this.$modal.showToast('获取pet type失败')
  202. }
  203. })
  204. },
  205. addPet() {
  206. this.show = true;
  207. },
  208. cancel() {
  209. this.show = false
  210. },
  211. petTypeChange(e) {
  212. console.log(e)
  213. this.petType = e.value[0]
  214. },
  215. confirmPetType(e) {
  216. console.log(e)
  217. this.show = false
  218. // 获取宠物类型,优先使用已选择的petType,否则使用e.value[0]
  219. const type = this.petType || e.value[0]
  220. // 根据宠物类型映射到英文类型
  221. const petTypeMap = {
  222. '猫猫': 'cat',
  223. '狗狗': 'dog'
  224. }
  225. const petType = petTypeMap[type]
  226. if (petType) {
  227. uni.navigateTo({
  228. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=add&isNewOrder=true`
  229. });
  230. }
  231. },
  232. editPet(item) {
  233. const petTypeMap = {
  234. '猫猫': 'cat',
  235. 'cat': 'cat',
  236. '狗狗': 'dog',
  237. 'dog': 'dog'
  238. }
  239. const petType = petTypeMap[item.petType]
  240. if (petType) {
  241. uni.navigateTo({
  242. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=edit&petId=${item.id}&isNewOrder=true`
  243. });
  244. }
  245. },
  246. deletePet(item) {
  247. this.delContent = "确定要删除" + item.name + '?';
  248. this.showDel = true;
  249. this.deleteId = item.id;
  250. },
  251. confirmDel() {
  252. delPet(this.deleteId).then(res => {
  253. console.log(res);
  254. this.$modal.showToast('删除成功');
  255. this.getPetList()
  256. })
  257. },
  258. cancelDel() {
  259. this.showDel = false;
  260. this.deleteId = '';
  261. },
  262. getCalendarDate() {
  263. let tomorrow = new Date()
  264. tomorrow.setDate(tomorrow.getDate() + 2);
  265. this.startDate = this.formatDate(tomorrow);
  266. // 获取三个月后的日期
  267. let threeMonthsLater = new Date();
  268. threeMonthsLater.setMonth(threeMonthsLater.getMonth() + 3);
  269. this.endDate = this.formatDate(threeMonthsLater);
  270. },
  271. formatDate(date) {
  272. let year = date.getFullYear();
  273. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  274. let day = date.getDate().toString().padStart(2, '0');
  275. return year + '-' + month + '-' + day;
  276. },
  277. selectDate(item) {
  278. this.currentId = item.id
  279. this.selectedDate = item.selectedDate
  280. this.showCalendar = true;
  281. },
  282. confirmCanlendar() {
  283. this.petList.find(e => e.id == this.currentId).selectedDate = this.selectedDate.sort((a, b) => new Date(a.date) - new Date(b.date))
  284. this.selectedDate = []
  285. this.showCalendar = false;
  286. },
  287. change(e) {
  288. const selectedValue = this.selectedDate.find(item => item.date === e.fulldate)
  289. if (selectedValue) {
  290. // 存在则移除
  291. this.selectedDate = this.selectedDate.filter(item => item.date !== e.fulldate);
  292. } else {
  293. this.selectedDate.push({
  294. date: e.fulldate,
  295. info: '预定'
  296. })
  297. }
  298. },
  299. confirm() {
  300. const selectedPets = this.petList.filter(e => e.checked)
  301. const unselectedDatePets = selectedPets.filter(pet => !pet.selectedDate || pet.selectedDate.length === 0)
  302. if (unselectedDatePets.length > 0) {
  303. const petNames = unselectedDatePets.map(pet => pet.name).join('、')
  304. this.$modal.showToast(`请为${petNames}选择服务时间`)
  305. return
  306. }
  307. this.$globalData.newOrderData.currentPets = selectedPets
  308. uni.redirectTo({
  309. url: '/pages/newOrder/serviceNew'
  310. })
  311. },
  312. showSelectedDate(selectedDate) {
  313. // 显示格式:首日...最后一日 共几天
  314. // 日期格式只需要月份和日期 例如:01/01...01/07
  315. const firstDate = selectedDate[0].date.substring(5).replace('-', '/')
  316. const lastDate = selectedDate[selectedDate.length - 1].date.substring(5).replace('-', '/')
  317. const days = selectedDate.length
  318. return `${firstDate}${days > 2 ? '...' : ''}${days == 2 ? ',' : ''}${days > 1 ? lastDate : ''}${days}`
  319. }
  320. }
  321. }
  322. </script>
  323. <style lang="scss" scoped>
  324. .personal-pet {
  325. position: relative;
  326. height: 100%;
  327. padding-bottom: 90px;
  328. .personal-pet-add {
  329. background-color: #FFFFFF;
  330. padding: 10px 20px 40px;
  331. width: 100%;
  332. height: 90px;
  333. position: fixed;
  334. bottom: 0;
  335. z-index: 100;
  336. display: flex;
  337. justify-content: space-between;
  338. .personal-pet-add-btn {
  339. width: 100%;
  340. border-radius: 6px;
  341. font-size: 16px;
  342. }
  343. }
  344. .personal-pet-list {
  345. .personal-pet-list-add {
  346. width: 100%;
  347. height: 44px;
  348. background-color: #FFFFFF;
  349. display: flex;
  350. justify-content: space-between;
  351. align-items: center;
  352. padding: 0 15px;
  353. .personal-pet-list-add-btn {
  354. font-size: 14px;
  355. color: #AAA;
  356. display: flex;
  357. align-items: center;
  358. }
  359. }
  360. .personal-pet-list-item_backgroud_m {
  361. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  362. }
  363. .personal-pet-list-item_backgroud_f {
  364. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  365. }
  366. .personal-pet-list-item {
  367. margin: 10px 10px 0 10px;
  368. border-radius: 5px;
  369. padding: 20px 10px 10px;
  370. .personal-pet-info {
  371. display: flex;
  372. align-items: center;
  373. justify-content: flex-start;
  374. .personal-pet-info-1 {
  375. margin-left: 10px;
  376. .personal-pet-info-2 {
  377. display: flex;
  378. flex-wrap: wrap;
  379. .personal-pet-name {
  380. color: #333;
  381. font-size: 16px;
  382. margin-right: 10px;
  383. }
  384. }
  385. .personal-pet-info-3 {
  386. display: flex;
  387. align-items: baseline;
  388. font-size: 14px;
  389. margin-top: 5px;
  390. color: #7D8196;
  391. .personal-pet-info-age {
  392. padding: 0 10px;
  393. margin: 0 10px;
  394. border-left: solid 2px #7D8196;
  395. border-right: solid 2px #7D8196;
  396. }
  397. }
  398. }
  399. }
  400. .personal-pet-info-disposition {
  401. padding: 10px;
  402. color: #7D8196;
  403. font-size: 14px;
  404. background: #f9f9f9;
  405. border-radius: 5px;
  406. margin-top: 10px;
  407. }
  408. .personal-pet-info-btns {
  409. display: flex;
  410. justify-content: space-between;
  411. margin-top: 10px;
  412. .personal-pet-info-btn {
  413. display: flex;
  414. font-size: 14px;
  415. color: #7D8196;
  416. margin-left: 20px;
  417. }
  418. }
  419. }
  420. }
  421. .personal-pet-none {
  422. display: flex;
  423. justify-content: center;
  424. align-items: center;
  425. flex-wrap: wrap;
  426. margin-top: 40%;
  427. .personal-pet-none-text {
  428. color: #666;
  429. text-align: center;
  430. font-size: 14px;
  431. width: 100%;
  432. margin-top: 10px;
  433. }
  434. }
  435. .calendar-popup {
  436. position: fixed;
  437. bottom: 0;
  438. left: 0;
  439. right: 0;
  440. z-index: 999;
  441. .calendar-content {
  442. background: #fff;
  443. border-radius: 16px 16px 0 0;
  444. padding: 0 20px 20px;
  445. }
  446. }
  447. .calendar-mask {
  448. position: fixed;
  449. top: 0;
  450. left: 0;
  451. right: 0;
  452. bottom: 0;
  453. background: rgba(0, 0, 0, 0.5);
  454. /* 半透明黑色 */
  455. z-index: 998;
  456. /* 确保在内容下方 */
  457. pointer-events: none;
  458. /* 使遮罩层不阻止点击事件 */
  459. }
  460. .calendar-content {
  461. position: relative;
  462. /* 确保内容在遮罩层之上 */
  463. z-index: 999;
  464. /* 确保内容在遮罩层之上 */
  465. }
  466. }
  467. </style>