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.

537 lines
19 KiB

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