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.

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