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.

1587 lines
64 KiB

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="service-new container">
  3. <view style="background-color: #FFF4E5; margin: 10px; padding: 10px; border-radius: 8rpx;">
  4. <view style="display: flex;">
  5. <image style="width: 40rpx; height: 40rpx;" slot='cover'
  6. src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/petServiceOrder/OrderIcon.png">
  7. </image>
  8. <text style="color: #A94F20; font-size: 28rpx; font-weight: 500;">
  9. 下单方式
  10. <text v-if="buyInfo.teacher">指定喂养员 - {{ buyInfo.teacher.userName }}</text>
  11. <text v-else>系统派单</text>
  12. </text>
  13. </view>
  14. <view style="margin-top: 10rpx;">
  15. <text v-if="buyInfo.teacher" style="color: #A94F20; font-size: 24rpx; font-weight: 400;">
  16. (若伴宠师1小时内无响应或拒绝接单则系统派单)
  17. </text>
  18. </view>
  19. </view>
  20. <view>
  21. <uni-card padding=0 :is-shadow="false">
  22. <view class="service-new-title" slot="title">
  23. <view class="service-new-title-left">
  24. <view class="service-new-flag"></view>
  25. <view>爱宠选择</view>
  26. </view>
  27. </view>
  28. <view class="split-line"></view>
  29. <view class="service-new-pet-content">
  30. <scroll-view scroll-x class="scroll-view">
  31. <view class="scroll-content">
  32. <view v-for="item in currentPets" :key="item.id" class="service-new-pet-item ellipsis"
  33. :class="{ 'pet-selected': item.id === currentPetId, 'pet-unselect': item.id !== currentPetId }"
  34. @click="selectPet(item)">
  35. {{ item.name }}
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </uni-card>
  41. </view>
  42. <view>
  43. <uni-card padding=0 :is-shadow="false">
  44. <view class="service-new-title" slot="title">
  45. <view class="service-new-title-left">
  46. <view class="service-new-flag"></view>
  47. <view>服务日期</view>
  48. </view>
  49. </view>
  50. <view class="split-line"></view>
  51. <view class="service-new-pet-content">
  52. <scroll-view scroll-y class="scroll-view-vertical">
  53. <view v-for="(month, monthIndex) in sortedGroupedDates" :key="monthIndex" class="month-group">
  54. <view class="month-title">{{ month.monthLabel }}</view>
  55. <scroll-view scroll-x class="scroll-view-horizontal">
  56. <view class="dates-wrapper">
  57. <view v-for="(day, dayIndex) in month.dates" :key="dayIndex" class="calendar-day"
  58. :class="{ 'day-selected': isDateSelected(day) }" @click="selectDate(day)">
  59. <image :src="isDateSelected(day) ?
  60. 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/updated.png' :
  61. 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/update_un.png'" class="calendar-bg" />
  62. <text class="day-text"
  63. :class="{ 'day-highlighted': isCurrentSelected(day), 'day-normal': !isCurrentSelected(day) }">
  64. {{ day.date < 10 ? '0' + day.date : day.date }}</text>
  65. </view>
  66. </view>
  67. </scroll-view>
  68. </view>
  69. </scroll-view>
  70. </view>
  71. </uni-card>
  72. </view>
  73. <view>
  74. <uni-card padding=0 :is-shadow="false">
  75. <view class="service-new-title" slot="title">
  76. <view class="service-new-title-left">
  77. <view class="service-new-flag"></view>
  78. <view>期望时间 <span class="time-slot-time-tip">*请勾选您可以接受的上门时间段</span></view>
  79. </view>
  80. </view>
  81. <view class="split-line"></view>
  82. <view class="service-new-pet-content">
  83. <view class="time-slots">
  84. <view v-for="slot in timeSlots" :key="slot.id" class="time-slot-item"
  85. @click="selectTimeSlot(slot.id)">
  86. <image :src="slot.selected ? slot.activeIcon : slot.inactiveIcon" class="time-slot-icon" />
  87. <view class="time-slot-info">
  88. <text class="time-slot-time">{{ slot.time }}</text>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </uni-card>
  94. </view>
  95. <view>
  96. <uni-card padding=0 :is-shadow="false">
  97. <view class="service-new-title" slot="title">
  98. <view class="service-new-title-left">
  99. <view class="service-new-flag"></view>
  100. <view>服务选择</view>
  101. </view>
  102. <view style="display: flex; justify-content: flex-end; align-items: center; ">
  103. <view style="margin-right: 10rpx;color: #AAAAAA;">爱宠{{ currentPetId && getCurrentPetName() }}
  104. 全日期保持一致</view>
  105. <u-switch space="2" :value="isAllSame" activeColor="#f9ae3d" size="18" @change="isAllSameChange"
  106. inactiveColor="rgb(230, 230, 230)">
  107. </u-switch>
  108. </view>
  109. </view>
  110. <view class="split-line"></view>
  111. <view class="service-new-pet-content">
  112. <view class="service-item">
  113. <view class="service-item-header">
  114. <image src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/service.png"
  115. class="service-icon"></image>
  116. <text class="service-title">基础服务</text>
  117. </view>
  118. <view class="service-list">
  119. <!-- <view style="border-radius: 8rpx" :style="{'background-color': needFeed.length > 0 ? '#FFFCF2' : '#F9F9F9', 'border': needFeed.length > 0 ? '1px solid #FFBF60' : 'none'}" >
  120. <view style="padding: 30rpx 0; margin: 0 20rpx; ">
  121. <u-checkbox-group
  122. v-model="needFeed"
  123. iconPlacement="right"
  124. placement="column">
  125. <u-checkbox activeColor="#FFBF60" label="专业喂养" shape="circle"></u-checkbox>
  126. </u-checkbox-group>
  127. </view>
  128. </view> -->
  129. <view class="service-list" style="border-radius: 8rpx;margin-top: 28rpx;">
  130. <view class="service-row" style="background-color: #FFECCD">
  131. <view class="service-row-content"
  132. :style="{ 'border-bottom': feedCount > 1 ? '1rpx solid #ECBFA8' : 'none' }">
  133. <text class="service-name" style="color: #A94F20;">一天多次</text>
  134. <view class="service-price">
  135. <u-number-box slot="right-icon" :value="feedCount" @change="feedCountChange"
  136. step="1" :min="1" :max="3">
  137. <view slot="minus" class="minus">
  138. <u-icon name="minus-circle-fill" size="20" color="#FFBF60"></u-icon>
  139. </view>
  140. <text slot="input" style="width: 40rpx;text-align: center;"
  141. class="input">{{ feedCount }}</text>
  142. <view slot="plus" class="plus">
  143. <u-icon name="plus-circle-fill" color="#FFBF60" size="20"></u-icon>
  144. </view>
  145. </u-number-box>
  146. </view>
  147. </view>
  148. </view>
  149. <view v-if="feedCount > 1" class="service-row" style="background-color: #FFECCD">
  150. <view class="service-row-content">
  151. <text class="service-name" style="color: #A94F20;">额外服务费</text>
  152. <view class="service-price" style="color:#A94F20">
  153. ¥{{ feedCount > 2 ? price_config.multiService.three.price : price_config.multiService.two.price }}
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. <view class="service-item">
  161. <view class="service-item-header">
  162. <image src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/love.png"
  163. class="service-icon"></image>
  164. <text class="service-title">定制服务</text>
  165. </view>
  166. <view class="service-list" style="border-radius: 8rpx;">
  167. <view class="service-row" v-for="(item, index) in customServices" :key="item.skuId">
  168. <view class="service-row-content"
  169. :style="{ 'border-bottom': index !== customServices.length - 1 ? '1rpx solid #EFEFEF' : 'none' }">
  170. <text class="service-name" style="">{{ item.name }}</text>
  171. <view class="service-price">
  172. <text
  173. style="font-size: 32rpx; color: #FFBF60; margin-right: 20rpx;">¥{{ item.price }}/</text>
  174. <u-number-box slot="right-icon" :value="item.quantity" :name="item.name"
  175. @change="customServiceCountChange" step="1" :min="0" :max="10">
  176. <view slot="minus" class="minus">
  177. <u-icon name="minus-circle-fill" size="20" color="#FFBF60"></u-icon>
  178. </view>
  179. <text slot="input" style="width: 40rpx;text-align: center;"
  180. class="input">{{ item.quantity }}</text>
  181. <view slot="plus" class="plus">
  182. <u-icon name="plus-circle-fill" color="#FFBF60" size="20"></u-icon>
  183. </view>
  184. </u-number-box>
  185. </view>
  186. </view>
  187. </view>
  188. </view>
  189. </view>
  190. </view>
  191. </uni-card>
  192. </view>
  193. <view v-if="!showPriceDetails" class="details-subscribe">
  194. <view style="display: flex;justify-content: space-between;">
  195. <view style="height: 80rpx;">
  196. <view>
  197. <text style="color: #333333;">订单总价 </text>
  198. <text style="color: #FF530A; font-size: 40rpx;">¥{{ Number(totalPrice).toFixed(2) }} <text
  199. style="font-size: 32rpx;"></text></text>
  200. </view>
  201. <view style="display: flex; justify-content: flex-end;" @click="togglePriceDetails">
  202. <text v-if="currentDayPrice" style="color:#FF530A; font-size: 22rpx;"> 当日价格¥{{ Number(currentDayPrice).toFixed(2)
  203. }}|</text>
  204. <text style="color:#FF530A; font-size: 22rpx;margin-left: 10rpx;">明细</text>
  205. <u-icon name="arrow-up" color="#FF530A" size="10"></u-icon>
  206. </view>
  207. </view>
  208. <view style="display: flex;">
  209. <u-button color="#FFF4E4" customStyle="width: 200rpx; color: #FFAA48; margin-right: 20rpx;"
  210. text="上一步" @click="goBack"></u-button>
  211. <u-button color="#FFBF60" customStyle="width: 200rpx; color: #FFF;" text="确认下单"
  212. @click="goNext"></u-button>
  213. </view>
  214. </view>
  215. </view>
  216. <!-- 遮罩层 -->
  217. <view v-if="showPriceDetails" class="price-details-overlay">
  218. <view class="price-details">
  219. <view class="price-details-header">
  220. <text
  221. style="text-align: center; width: 100%; font-size: 32rpx; font-weight: 500; color: #333333;">价格明细</text>
  222. <u-icon name="close" @click="togglePriceDetails"></u-icon>
  223. </view>
  224. <view style="text-align: center; width: 100%; font-size: 28rpx; color: #AAAAAA; margin: 20rpx 0;">
  225. 实际支付金额以确认下单页为准</view>
  226. <view class="split-line"></view>
  227. <scroll-view class="price-details-body" scroll-y>
  228. <view v-for="(item, index) in priceDetails" :key="index">
  229. <view class="price-details-item">
  230. <view v-if="showName(item)" style="font-size: 28rpx; color: #333333;">{{ item.name }}</view>
  231. <view class="price-details-item-price-total">
  232. <view style="display: flex;" v-for="(item2, index) in item.item" :key="index">
  233. <view style="display: flex; align-items: center;">
  234. <view v-if="item2.date && item2.quantity"
  235. class="price-details-item-price-total-item">{{ item2.date }}</view>
  236. <view v-if="item2.itemName != item.name && item2.quantity"
  237. class="price-details-item-price-total-item">{{ item2.itemName }}</view>
  238. <view v-if="item2.quantity" class="price-details-item-price-total-item">
  239. ¥{{ item2.price }} × {{ item2.quantity }} {{ item2.unit }}</view>
  240. </view>
  241. <view v-if="item2.quantity"
  242. style="color: #333333; margin-left: 20rpx; margin: auto 0; width: 100rpx; text-align: right; font-size: 28rpx;">
  243. ¥{{ item2.price * item2.quantity }}</view>
  244. </view>
  245. </view>
  246. </view>
  247. </view>
  248. </scroll-view>
  249. <view style="position: absolute; bottom: 0; left: 0; right: 0; padding: 20rpx;">
  250. <view class="split-line"></view>
  251. <view class="price-details-item" style="margin: 20rpx 0;">
  252. <view style="font-size: 32rpx; color: #333333; font-weight: 500;">合计</view>
  253. <view style="font-size: 32rpx; color: #333333; font-weight: 500;">¥{{ Number(totalPrice).toFixed(2) }}</view>
  254. </view>
  255. <view class="split-line"></view>
  256. </view>
  257. </view>
  258. <view class="details-subscribe">
  259. <view style="display: flex;justify-content: space-between;">
  260. <view style="height: 80rpx;">
  261. <view>
  262. <text style="color: #333333;">订单总价 </text>
  263. <text style="color: #FF530A; font-size: 40rpx;">¥{{ Number(totalPrice).toFixed(2) }} <text
  264. style="font-size: 32rpx;"></text></text>
  265. </view>
  266. <view style="display: flex; justify-content: flex-end;" @click="togglePriceDetails">
  267. <text v-if="currentDayPrice" style="color:#FF530A; font-size: 22rpx;"> 当日价格¥{{
  268. Number(currentDayPrice).toFixed(2) }}|</text>
  269. <text style="color:#FF530A; font-size: 22rpx;margin-left: 10rpx;">明细</text>
  270. <u-icon name="arrow-up" color="#FF530A" size="10"></u-icon>
  271. </view>
  272. </view>
  273. <view style="display: flex;">
  274. <u-button color="#FFF4E4" customStyle="width: 200rpx; color: #FFAA48; margin-right: 20rpx;"
  275. text="上一步" @click="goBack"></u-button>
  276. <u-button color="#FFBF60" customStyle="width: 200rpx; color: #FFF;" text="确认下单"
  277. @click="goNext"></u-button>
  278. </view>
  279. </view>
  280. </view>
  281. </view>
  282. </view>
  283. </template>
  284. <script>
  285. import {
  286. getProductList,
  287. getOpenId
  288. } from "@/api/system/user"
  289. import { setToken, setOpenIdKey } from '@/utils/auth'
  290. import positionMixin from '../../mixins/position';
  291. export default {
  292. mixins: [positionMixin],
  293. data() {
  294. return {
  295. basePrice: 75,
  296. baseProduct: '专业喂养',
  297. // 节假日价格配置
  298. holidayPrice: 75,
  299. normalPrice: 75,
  300. distancePrice: 1,
  301. holidayDate: [],
  302. currentPets: [],
  303. currentPetId: '',
  304. currentMonthDay: {},
  305. selectedDates: [],
  306. groupedDates: [],
  307. timeSlots: [
  308. {
  309. id: 'MORNING',
  310. name: '早上',
  311. time: '08:00-12:00',
  312. selected: false,
  313. activeIcon: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/morning.png',
  314. inactiveIcon: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/morning_un.png'
  315. },
  316. {
  317. id: 'AFTERNOON',
  318. name: '午后',
  319. time: '12:00-18:00',
  320. selected: false,
  321. activeIcon: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/noon.png',
  322. inactiveIcon: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/noon_un.png'
  323. },
  324. {
  325. id: 'EVENING',
  326. name: '晚间',
  327. time: '18:00-22:00',
  328. selected: false,
  329. activeIcon: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/night.png',
  330. inactiveIcon: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/newOrder/night_un.png'
  331. }
  332. ],
  333. feedCount: 1,
  334. // customServices原始值
  335. customServicesStr: '',
  336. customServices: [
  337. // { name: '陪玩(20分钟)', price: 20, quantity: 0 },
  338. // { name: '活动区吸毛', price: 20, quantity: 0 },
  339. // { name: '毛发梳理', price: 15, quantity: 0 },
  340. // { name: '身体清洁(如眼、耳、鼻等)', price: 5, quantity: 0 },
  341. // { name: '指甲修剪', price: 10, quantity: 0 },
  342. // { name: '会员深度清洁', price: 20, quantity: 0 },
  343. // { name: '喂药', price: 15, quantity: 0 },
  344. // { name: '上药', price: 25, quantity: 0 }
  345. ],
  346. showPriceDetails: false, // 控制价格明细的显示
  347. priceDetails: [],
  348. totalPrice: 0,
  349. isAllSame: false,
  350. newOrderData: [],
  351. // 提前熟悉费用
  352. needPreFamiliarizeCost: 0,
  353. // 基础服务总费用
  354. baseServiceTotalCost: 0,
  355. // 额外宠物总费用
  356. additionalTotalCost: 0,
  357. // 多次服务总费用
  358. multServicesTotalCost: 0,
  359. // 定制服务总费用
  360. customServicesTotalCost: 0,
  361. // 一天两次日期
  362. oneDayTwoTimesDates: [],
  363. // 一天三次日期
  364. oneDayThreeTimesDates: [],
  365. // 宠物类型次数统计
  366. petTypeCounts: [],
  367. // 定制服务单项总次数统计
  368. customServiceItemCount: [],
  369. // 当日价格
  370. currentDayPrice: 0,
  371. }
  372. },
  373. onLoad: function (option) {
  374. this.$globalData.newOrderData.distancePrice = this.calculateDistancePrice()
  375. },
  376. mounted() {
  377. console.log('this.$globalData', this.$globalData)
  378. this.currentPets = this.$globalData.newOrderData.currentPets;
  379. if (this.currentPets.length < 1) {
  380. uni.reLaunch({
  381. url: '/pages/index'
  382. });
  383. return
  384. }
  385. if (this.$globalData.mainSku && this.$globalData.mainSku[0]) {
  386. this.basePrice = this.$globalData.mainSku[0].price
  387. this.baseProduct = this.$globalData.mainSku[0].name
  388. }
  389. // 初始化价格配置
  390. this.initPriceConfig()
  391. this.getProductList()
  392. },
  393. watch: {
  394. currentPetId: {
  395. immediate: true,
  396. handler(newId) {
  397. if (newId) {
  398. this.updateGroupedDates()
  399. }
  400. }
  401. }
  402. },
  403. methods: {
  404. companionLevelPrice(){
  405. let companionLevel = this.$globalData.newOrderData.companionLevel
  406. let price = Number(companionLevel.paramValueText) * this.isAddPrice()
  407. return price * this.$store.state.memberRate
  408. },
  409. //判断当前选中的地址是否加价
  410. isAddPrice(){
  411. let currentAddress = this.$globalData.newOrderData.currentAddress || {}
  412. let defaultPrice = 1
  413. try{
  414. defaultPrice = this.price_config.cityConfig.priceRates.default
  415. }catch(e){
  416. defaultPrice = 1
  417. }
  418. if(!this.price_config.cityConfig || !currentAddress.province || !currentAddress.city){
  419. return defaultPrice
  420. }
  421. let addressList = this.price_config.cityConfig.priceRates || []
  422. for(let key in addressList){
  423. if((currentAddress.province + currentAddress.city).includes(key)){
  424. return addressList[key]
  425. }
  426. }
  427. return defaultPrice
  428. },
  429. //计算距离价格
  430. calculateDistancePrice() {
  431. if(!this.buyInfo.teacher || !this.buyInfo.teacher.appletAddresseList){
  432. return
  433. }
  434. let addressList = this.buyInfo.teacher.appletAddresseList
  435. let d = this.calculateDistanceAddressList(addressList, {
  436. latitude: this.$globalData.newOrderData.latitude,
  437. longitude: this.$globalData.newOrderData.longitude,
  438. })[0]?.distance || 0
  439. return d * this.distancePrice
  440. },
  441. initNewOrderData() {
  442. const needPreFamiliarize = this.$globalData.newOrderData.needPreFamiliarize.length > 0
  443. const pets = []
  444. // 初始化当前宠物全日期保持一致
  445. this.currentPets = this.currentPets.map(pet => {
  446. pet.isAllSame = false
  447. return pet
  448. })
  449. this.currentPets.map(pet => {
  450. // 单个宠物服务日期列表
  451. const serviceDateList = pet.selectedDate.map(item => item.date)
  452. serviceDateList.forEach(date => {
  453. pets.push({
  454. petId: pet.id,
  455. serviceDate: date,
  456. name: pet.name,
  457. gender: pet.gender,
  458. petType: pet.petType,
  459. bodyType: pet.bodyType,
  460. photo: pet.photo,
  461. feedCount: 1,
  462. selectedTimeSlots: [],
  463. customServices: [],
  464. //额外费用
  465. additionalCost: 0
  466. })
  467. })
  468. })
  469. this.newOrderData = {
  470. needPreFamiliarize: needPreFamiliarize, // 是否需要提前熟悉 40元/次 参与计算
  471. pets: pets
  472. }
  473. // 默认选择第一个宠物
  474. this.selectPet(this.currentPets[0] || {})
  475. this.calculateTotalPrice()
  476. },
  477. // 选择宠物
  478. selectPet(pet) {
  479. this.currentPetId = pet.id
  480. // 默认选择当前宠物的最小日期
  481. if (pet.selectedDate?.length > 1) {
  482. const minDate = pet.selectedDate.reduce((min, date) => {
  483. const currentDate = new Date(date.date);
  484. const minDate = new Date(min.date);
  485. return currentDate < minDate ? date : min;
  486. }, pet.selectedDate[0]);
  487. // 当前选择日期
  488. this.currentMonthDay = {
  489. petId: this.currentPetId,
  490. date: new Date(minDate.date).getDate(),
  491. fullDate: minDate.date
  492. }
  493. } else {
  494. this.currentMonthDay = {
  495. petId: this.currentPetId,
  496. date: new Date(pet.selectedDate[0].date).getDate(),
  497. fullDate: pet.selectedDate[0].date
  498. }
  499. }
  500. this.getCurrentPetIsAllSame()
  501. this.selectDate(this.currentMonthDay)
  502. },
  503. selectDate(day) {
  504. // 当前选择日期
  505. this.currentMonthDay = day
  506. const selectedDay = this.selectedDates?.find(item => item.fullDate === day.fullDate && item
  507. .currentPetId === day.petId)
  508. if (!selectedDay) {
  509. this.selectedDates.push(day)
  510. }
  511. // 还原当前选择日期是否已选择期望时间
  512. const pets = this.newOrderData?.pets
  513. const selectedPet = pets.find(pet => pet.petId === this.currentPetId && pet.serviceDate === this
  514. .currentMonthDay.fullDate);
  515. const selectedTimeSlots = selectedPet ? selectedPet.selectedTimeSlots : [];
  516. if (selectedTimeSlots.length > 0) {
  517. this.timeSlots.forEach(slot => {
  518. if (selectedTimeSlots.includes(slot.id)) {
  519. slot.selected = true
  520. } else {
  521. slot.selected = false
  522. }
  523. })
  524. } else {
  525. this.timeSlots.forEach(slot => {
  526. slot.selected = false
  527. })
  528. }
  529. // 还原当前选择日期喂食次数
  530. this.feedCount = selectedPet ? selectedPet.feedCount : 1
  531. // 还原当前选择日期是否已选择定制服务
  532. this.customServices = selectedPet.customServices.length > 0 ? selectedPet.customServices : JSON.parse(this.customServicesStr)
  533. this.getCurrentDayPrice(this.currentMonthDay.fullDate)
  534. },
  535. isDateSelected(day) {
  536. const selectedDay = this.selectedDates.find(item => item.fullDate === day.fullDate && this.currentPetId ===
  537. item.petId)
  538. if (selectedDay) {
  539. return true
  540. }
  541. return false
  542. },
  543. isCurrentSelected(day) {
  544. return this.currentMonthDay.fullDate === day.fullDate && this.currentPetId === day.petId
  545. },
  546. updateGroupedDates() {
  547. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  548. if (!currentPet) return
  549. // 按月份分组日期
  550. const grouped = currentPet.selectedDate.reduce((acc, dateObj) => {
  551. const date = new Date(dateObj.date)
  552. const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`
  553. const monthLabel = `${date.getFullYear()}${date.getMonth() + 1}`
  554. if (!acc[monthKey]) {
  555. acc[monthKey] = {
  556. monthLabel,
  557. dates: []
  558. }
  559. }
  560. acc[monthKey].dates.push({
  561. petId: currentPet.id,
  562. date: date.getDate(),
  563. fullDate: dateObj.date
  564. })
  565. return acc
  566. }, {})
  567. // 转换为数组并排序
  568. this.groupedDates = Object.values(grouped).sort((a, b) => {
  569. return a.monthLabel.localeCompare(b.monthLabel)
  570. })
  571. },
  572. selectTimeSlot(slotId) {
  573. const slot = this.timeSlots.find(slot => slot.id === slotId)
  574. if (slot) {
  575. slot.selected = !slot.selected
  576. }
  577. // 将期望时间添加到当前宠物
  578. const selectedTimeSlots = this.timeSlots.filter(slot => slot.selected)
  579. if (this.isAllSame) {
  580. // 如果保持一致,则更新该宠物所有期望时间
  581. this.newOrderData.pets.forEach(pet => {
  582. pet.selectedTimeSlots = selectedTimeSlots.map(item => item.id)
  583. })
  584. } else {
  585. const currentPetIndex = this.newOrderData.pets.findIndex(pet => pet.petId === this.currentPetId
  586. && pet.serviceDate === this.currentMonthDay.fullDate)
  587. if (currentPetIndex !== -1) {
  588. this.newOrderData.pets[currentPetIndex].selectedTimeSlots = selectedTimeSlots.map(item => item.id)
  589. }
  590. }
  591. },
  592. feedCountChange(e) {
  593. this.feedCount = e.value
  594. if (this.isAllSame) {
  595. // 如果保持一致,则更新该宠物的喂食次数
  596. this.newOrderData.pets.forEach(pet => {
  597. if (pet.petId === this.currentPetId) {
  598. pet.feedCount = this.feedCount
  599. }
  600. })
  601. } else {
  602. const pets = this.newOrderData.pets
  603. const currentPetIndex = pets.findIndex(pet => pet.petId === this.currentPetId && pet.serviceDate ===
  604. this.currentMonthDay.fullDate)
  605. if (currentPetIndex !== -1) {
  606. this.newOrderData.pets[currentPetIndex].feedCount = this.feedCount
  607. }
  608. }
  609. this.calculateTotalPrice()
  610. },
  611. customServiceCountChange(val) {
  612. console.log(val)
  613. this.customServices.forEach(item => {
  614. if (item.name === val.name) {
  615. item.quantity = val.value
  616. }
  617. })
  618. if (this.isAllSame) {
  619. // 如果保持一致,则更新当前宠物的定制服务次数
  620. this.newOrderData.pets.forEach(pet => {
  621. if (pet.petId === this.currentPetId) {
  622. pet.customServices = JSON.parse(JSON.stringify(this.customServices))
  623. }
  624. })
  625. } else {
  626. const pets = this.newOrderData.pets
  627. const currentPetIndex = pets.findIndex(pet => pet.petId === this.currentPetId && pet.serviceDate ===
  628. this.currentMonthDay.fullDate)
  629. if (currentPetIndex !== -1) {
  630. this.newOrderData.pets[currentPetIndex].customServices = JSON.parse(JSON.stringify(this
  631. .customServices))
  632. }
  633. }
  634. this.calculateTotalPrice()
  635. },
  636. togglePriceDetails() {
  637. this.showPriceDetails = !this.showPriceDetails; // 切换价格明细的显示状态
  638. if (this.showPriceDetails) {
  639. this.priceDetailDate()
  640. }
  641. },
  642. calculateTotalPrice() {
  643. // 1. 订单维度:是否需要提前熟悉
  644. if (this.$globalData.newOrderData.needPreFamiliarize && this.$globalData.newOrderData.needPreFamiliarize.length > 0) {
  645. this.needPreFamiliarizeCost = this.price_config.preFamiliarize.price
  646. } else {
  647. this.needPreFamiliarizeCost = 0
  648. }
  649. // 2. 日期维度
  650. // 2.1 基础服务费用 - 根据节假日和非节假日分别计算
  651. const uniqueDates = new Set(this.newOrderData.pets.map(item => item.serviceDate)); // 去重日期
  652. let baseServiceTotalCost = 0;
  653. uniqueDates.forEach(date => {
  654. const isHolidayDate = this.isHoliday(date);
  655. const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice);
  656. baseServiceTotalCost += dayPrice;
  657. });
  658. this.baseServiceTotalCost = baseServiceTotalCost;
  659. // 2.2 额外宠物费用
  660. // petType为dog 且bodyType包含 '大型' 则为大型犬,40元/次
  661. // petType为dog 且bodyType包含 '中型' 则为中型犬,30元/次
  662. // petType为dog 且bodyType包含 '小型' 则为小型犬,15元/次
  663. // petType为cat 则为猫,10元/次
  664. this.newOrderData.pets.forEach(pet => {
  665. pet.additionalCost = this.calculatePetCost(pet)
  666. // if (pet.petType === 'dog' && pet.bodyType.includes('大型')) {
  667. // pet.additionalCost = 40
  668. // } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) {
  669. // pet.additionalCost = 30
  670. // } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) {
  671. // pet.additionalCost = 15
  672. // } else if (pet.petType === 'cat') {
  673. // pet.additionalCost = 10
  674. // }
  675. })
  676. // const largeDogArray = this.newOrderData.pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型'));
  677. // this.additionalTotalCost = this.additionalTotalCost + (largeDogArray.length * 40)
  678. // // 非大型犬
  679. // const otherPets = this.newOrderData.pets.filter(pet => pet.petType !== 'dog' && !pet.bodyType.includes('大型'));
  680. // 宠物日期分组
  681. const dailyPets = [];
  682. // 按日期分组宠物
  683. this.newOrderData.pets.forEach(pet => {
  684. const serviceDate = pet.serviceDate;
  685. if (!dailyPets[serviceDate]) {
  686. dailyPets[serviceDate] = [];
  687. }
  688. dailyPets[serviceDate].push(pet);
  689. });
  690. const petTypeCounts = []
  691. let additionalTotalCost = 0
  692. // 计算每日额外宠物费用
  693. for (const date in dailyPets) {
  694. const pets = dailyPets[date];
  695. const largeDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型')).length;
  696. let mediumDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('中型')).length;
  697. let smallDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('小型')).length;
  698. let catCount = pets.filter(pet => pet.petType === 'cat').length;
  699. let additionalCost = 0
  700. // 总宠物费用
  701. let totalPetCost = pets.reduce((acc, pet) => {
  702. return acc + this.calculatePetCost(pet);
  703. }, 0);
  704. // 如果总宠物费用>30
  705. const freeQuota = this.price_config.freeQuota
  706. if (totalPetCost > Number(freeQuota.threshold)) {
  707. freeQuota.rules.forEach(rule => {
  708. if (rule.type === 'cat' && catCount >= rule.count) {
  709. additionalCost = totalPetCost - Number(rule.freeAmount)
  710. catCount = catCount - rule.count
  711. }else if(rule.type === 'smallDog' && smallDogCount >= rule.count){
  712. additionalCost = totalPetCost - Number(rule.freeAmount)
  713. smallDogCount = smallDogCount - rule.count
  714. }else if(rule.type === 'mediumDog' && mediumDogCount >= rule.count){
  715. additionalCost = totalPetCost - Number(rule.freeAmount)
  716. mediumDogCount = mediumDogCount - rule.count
  717. }else{
  718. additionalCost = totalPetCost - Number(rule.freeAmount)
  719. }
  720. })
  721. // if (totalPetCost > 30) {
  722. // // 如果猫数量>=3
  723. // if (catCount >= 3) {
  724. // additionalCost = totalPetCost - 30
  725. // catCount = catCount - 3
  726. // } else if (smallDogCount >= 2) {
  727. // additionalCost = totalPetCost - 30
  728. // smallDogCount = smallDogCount - 2
  729. // } else if (mediumDogCount >= 1) {
  730. // additionalCost = totalPetCost - 30
  731. // mediumDogCount = mediumDogCount - 1
  732. // } else {
  733. // additionalCost = totalPetCost - 25
  734. // catCount = catCount - 1
  735. // smallDogCount = smallDogCount - 1
  736. // }
  737. petTypeCounts.push({
  738. date,
  739. largeDogCount,
  740. mediumDogCount,
  741. smallDogCount,
  742. catCount
  743. })
  744. }
  745. // 如果有大型犬,额外费用为40元/只
  746. if (largeDogCount > 0) {
  747. additionalCost += (40 * largeDogCount)
  748. }
  749. // 如果有额外费用,添加到总额外费用
  750. if (additionalCost > 0) {
  751. additionalTotalCost += additionalCost;
  752. }
  753. }
  754. this.additionalTotalCost = additionalTotalCost
  755. this.petTypeCounts = petTypeCounts
  756. // 2.3 当日多次服务总价
  757. // 计算每日多次服务次数费用
  758. let multServicesTotalCost = 0
  759. let oneDayTwoTimesDates = []
  760. let oneDayThreeTimesDates = []
  761. for (const date in dailyPets) {
  762. const maxFeedCount = Math.max(...dailyPets[date].map(pet => pet.feedCount));
  763. if (maxFeedCount === 2) {
  764. multServicesTotalCost += this.price_config.multiService.two.price; // 1天2次
  765. oneDayTwoTimesDates.push(date)
  766. } else if (maxFeedCount === 3) {
  767. multServicesTotalCost += this.price_config.multiService.three.price; // 1天3次
  768. oneDayThreeTimesDates.push(date)
  769. }
  770. }
  771. this.oneDayTwoTimesDates = oneDayTwoTimesDates
  772. this.oneDayThreeTimesDates = oneDayThreeTimesDates
  773. this.multServicesTotalCost = multServicesTotalCost
  774. // 3. 定制服务
  775. //定制服务单项总次数统计
  776. const customServiceItemCount = JSON.parse(this.customServicesStr)
  777. let customServicesTotalCost = 0
  778. this.newOrderData.pets.forEach(pet => {
  779. const customServices = pet.customServices
  780. // 定制服务费用
  781. customServices.forEach(service => {
  782. const itemIndex = customServiceItemCount.findIndex(item => item.name === service.name)
  783. if (itemIndex !== -1) {
  784. customServiceItemCount[itemIndex].quantity += service.quantity
  785. }
  786. customServicesTotalCost += service.price * service.quantity;
  787. })
  788. });
  789. this.customServiceItemCount = customServiceItemCount
  790. this.customServicesTotalCost = customServicesTotalCost
  791. this.totalPrice = Number(this.needPreFamiliarizeCost)
  792. + Number(this.baseServiceTotalCost)
  793. + Number(this.additionalTotalCost)
  794. + Number(this.multServicesTotalCost)
  795. + Number(this.companionLevelPrice())
  796. + Number(this.customServicesTotalCost); // 更新总价
  797. this.getCurrentDayPrice(this.currentMonthDay.fullDate)
  798. },
  799. calculatePetCost(pet) {
  800. // 宠物额外费用 不计算大型犬
  801. let petExtra = this.price_config.petExtra
  802. let petCost = 0;
  803. if (pet.petType === 'cat') {
  804. petCost += Number(petExtra.cat); // 猫额外费用
  805. } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) {
  806. petCost += Number(petExtra.smallDog); // 小型犬额外费用
  807. } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) {
  808. petCost += Number(petExtra.mediumDog); // 中型犬额外费用
  809. }
  810. return petCost;
  811. },
  812. goNext() {
  813. this.calculateTotalPrice(); // 计算总价
  814. this.showPriceDetails = false;
  815. this.$globalData.newOrderData.currentPetsByDay = this.newOrderData.pets
  816. this.$globalData.newOrderData.totalPrice = this.totalPrice
  817. uni.navigateTo({
  818. url: '/pages/newOrder/confirmOrder'
  819. });
  820. },
  821. goBack() {
  822. this.showPriceDetails = false
  823. let len = getCurrentPages().length;
  824. this.loading = false
  825. if (len >= 2) {
  826. uni.navigateBack();
  827. } else {
  828. uni.redirectTo({
  829. url: '/pages/newOrder/serviceNew'
  830. });
  831. }
  832. },
  833. // 价格明细数据
  834. priceDetailDate() {
  835. const priceDetails = []
  836. if (this.newOrderData.needPreFamiliarize) {
  837. priceDetails.push({
  838. name: '提前熟悉',
  839. item: [{
  840. itemName: '提前熟悉',
  841. price: this.price_config.preFamiliarize.price,
  842. quantity: this.newOrderData.needPreFamiliarize ? 1 : 0,
  843. unit: '次'
  844. },]
  845. })
  846. }
  847. let companionLevel = this.$globalData.newOrderData.companionLevel
  848. if (companionLevel) {
  849. priceDetails.push({
  850. name: '伴宠师等级',
  851. item: [{
  852. itemName: companionLevel.paramValue,
  853. price: this.companionLevelPrice(),
  854. quantity: 1,
  855. unit: '位'
  856. },]
  857. })
  858. }
  859. // 分别统计节假日和非节假日的天数
  860. const uniqueDates = new Set(this.newOrderData.pets.map(item => item.serviceDate));
  861. let holidayCount = 0;
  862. let normalCount = 0;
  863. uniqueDates.forEach(date => {
  864. if (this.isHoliday(date)) {
  865. holidayCount++;
  866. } else {
  867. normalCount++;
  868. }
  869. });
  870. const baseServiceItems = [];
  871. if (normalCount > 0) {
  872. baseServiceItems.push({
  873. itemName: '非节假日 | ',
  874. price: parseFloat(this.normalPrice),
  875. quantity: normalCount,
  876. unit: '天'
  877. });
  878. }
  879. if (holidayCount > 0) {
  880. baseServiceItems.push({
  881. itemName: '节假日 | ',
  882. price: parseFloat(this.holidayPrice),
  883. quantity: holidayCount,
  884. unit: '天'
  885. });
  886. }
  887. if (baseServiceItems.length > 0) {
  888. priceDetails.push({
  889. name: this.baseProduct,
  890. item: baseServiceItems
  891. });
  892. }
  893. if (this.oneDayTwoTimesDates.length > 0 || this.oneDayThreeTimesDates.length > 0) {
  894. priceDetails.push({
  895. name: '上门次数',
  896. item: [{
  897. itemName: '1天2次',
  898. price: this.price_config.multiService.two.price,
  899. quantity: this.oneDayTwoTimesDates.length,
  900. unit: '天'
  901. },
  902. {
  903. itemName: '1天3次',
  904. price: this.price_config.multiService.three.price,
  905. quantity: this.oneDayThreeTimesDates.length,
  906. unit: '天'
  907. },
  908. ]
  909. })
  910. }
  911. // 过滤宠物类型数量>0的数组
  912. const additionalCostItem = []
  913. const petTypeArr = this.petTypeCounts.filter(item => item.largeDogCount > 0 || item.mediumDogCount > 0 ||
  914. item.smallDogCount > 0 || item.catCount > 0)
  915. // 假设largeDogCount=1 mediumDogCount=2 smallDogCount=3 catCount=4 则生成4条数据
  916. petTypeArr.forEach(item => {
  917. if (item.largeDogCount > 0) {
  918. additionalCostItem.push({
  919. itemName: '大型犬',
  920. price: this.calculatePetCost({
  921. petType: 'dog',
  922. bodyType: '大型',
  923. }),
  924. quantity: item.largeDogCount,
  925. unit: '只',
  926. date: item.date
  927. })
  928. }
  929. if (item.mediumDogCount > 0) {
  930. additionalCostItem.push({
  931. itemName: '中型犬',
  932. price: this.calculatePetCost({
  933. petType: 'dog',
  934. bodyType: '中型',
  935. }),
  936. quantity: item.mediumDogCount,
  937. unit: '只',
  938. date: item.date
  939. })
  940. }
  941. if (item.smallDogCount > 0) {
  942. additionalCostItem.push({
  943. itemName: '小型犬',
  944. price: this.calculatePetCost({
  945. petType: 'dog',
  946. bodyType: '小型',
  947. }),
  948. quantity: item.smallDogCount,
  949. unit: '只',
  950. date: item.date
  951. })
  952. }
  953. if (item.catCount > 0) {
  954. additionalCostItem.push({
  955. itemName: '猫猫',
  956. price: this.calculatePetCost({
  957. petType: 'cat',
  958. }),
  959. quantity: item.catCount,
  960. unit: '只',
  961. date: item.date
  962. })
  963. }
  964. })
  965. // 按日期先后顺序排序
  966. additionalCostItem.sort((a, b) => new Date(a.date) - new Date(b.date))
  967. if (additionalCostItem.length > 0) {
  968. priceDetails.push({
  969. name: '额外宠物费用',
  970. item: additionalCostItem
  971. })
  972. }
  973. const customServiceItem = this.customServiceItemCount.filter(item => item.quantity > 0).map(service => {
  974. return { itemName: service.name, price: service.price, quantity: service.quantity, unit: '次' }
  975. })
  976. if (customServiceItem.length > 0) {
  977. priceDetails.push({
  978. name: '定制服务',
  979. item: customServiceItem
  980. })
  981. }
  982. this.priceDetails = priceDetails
  983. this.calculateTotalPrice()
  984. },
  985. showName(item) {
  986. return item.item.some(item2 => item2.quantity > 0)
  987. },
  988. isAllSameChange(e) {
  989. if (e) {
  990. this.isAllSame = true
  991. this.setCurrentPetIsAllSame()
  992. // 当前宠物全日期保持一致
  993. this.newOrderData.pets.forEach(pet => {
  994. if (pet.petId === this.currentPetId) {
  995. pet.selectedTimeSlots = this.timeSlots.filter(slot => slot.selected).map(item => item.id)
  996. pet.feedCount = this.feedCount
  997. pet.customServices = this.customServices
  998. }
  999. })
  1000. this.calculateTotalPrice()
  1001. } else {
  1002. this.isAllSame = false
  1003. this.setCurrentPetIsAllSame()
  1004. }
  1005. },
  1006. // 初始化价格配置
  1007. initPriceConfig() {
  1008. let priceConfig = this.$store.state.price_config
  1009. console.log('价格配置:', priceConfig)
  1010. if(priceConfig.basePrice && priceConfig.basePrice.holiday){
  1011. this.holidayPrice = (priceConfig.basePrice.holiday * this.$store.state.memberRate).toFixed(2)
  1012. }
  1013. if(priceConfig.basePrice && priceConfig.basePrice.normal){
  1014. this.normalPrice = (priceConfig.basePrice.normal * this.$store.state.memberRate).toFixed(2)
  1015. }
  1016. if(priceConfig.holidays && priceConfig.holidays.length > 0){
  1017. this.holidayDate = priceConfig.holidays
  1018. }else{
  1019. this.holidayDate = []
  1020. }
  1021. },
  1022. // 判断是否为节假日
  1023. isHoliday(date) {
  1024. return this.holidayDate.some(holiday => holiday === date)
  1025. },
  1026. getProductList() {
  1027. getProductList({
  1028. "publishStatus": 1,
  1029. "categoryId": 78,
  1030. "needSku": true
  1031. }).then(response => {
  1032. if (response && response.content && response.content.length > 0) {
  1033. this.customServices = response.content.map(item => {
  1034. const skus = item.skus
  1035. if (skus && skus.length > 0) {
  1036. let productSku = {
  1037. "skuId": skus[0].id,
  1038. "price": (skus[0].price * this.$store.state.memberRate).toFixed(2),
  1039. "name": item.name,
  1040. "quantity": 0,
  1041. "isMainProduct": false
  1042. }
  1043. return productSku
  1044. }
  1045. })
  1046. this.customServicesStr = JSON.stringify(this.customServices)
  1047. // 初始化新订单数据
  1048. this.initNewOrderData()
  1049. } else {
  1050. uni.showToast('获取主产品失败,请联系管理员')
  1051. }
  1052. console.log(response);
  1053. })
  1054. },
  1055. login() {
  1056. uni.login({
  1057. provider: 'weixin',
  1058. success: (loginRes) => {
  1059. this.getOpenId(loginRes.code)
  1060. },
  1061. fail: function (error) {
  1062. // 授权失败处理
  1063. uni.showToast('授权失败,请授权后再试')
  1064. }
  1065. });
  1066. },
  1067. getOpenId(code) {
  1068. getOpenId(code).then(res => {
  1069. if (res.code == 200 && res.data) {
  1070. let resData = JSON.parse(res.data)
  1071. let token = resData.token;
  1072. let openId = resData.openId;
  1073. setOpenIdKey(openId)
  1074. if (token) {
  1075. setToken(token)
  1076. }
  1077. }
  1078. })
  1079. },
  1080. getCurrentDayPrice(currentDay) {
  1081. const currentDayPets = this.newOrderData.pets.filter(pet => pet.serviceDate === currentDay)
  1082. // 根据是否为节假日确定基础服务价格
  1083. const isHolidayDate = this.isHoliday(currentDay)
  1084. const baseServiceCost = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice)
  1085. const largeDogCount = currentDayPets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型')).length;
  1086. let mediumDogCount = currentDayPets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('中型')).length;
  1087. let smallDogCount = currentDayPets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('小型')).length;
  1088. let catCount = currentDayPets.filter(pet => pet.petType === 'cat').length;
  1089. const additionalCostItem = []
  1090. let additionalCost = 0
  1091. // 单天总宠物费用
  1092. let totalPetCost = currentDayPets.reduce((acc, pet) => {
  1093. return acc + this.calculatePetCost(pet);
  1094. }, 0);
  1095. // 如果总宠物费用>30
  1096. const freeQuota = this.price_config.freeQuota
  1097. if (totalPetCost > Number(freeQuota.threshold)) {
  1098. freeQuota.rules.forEach(rule => {
  1099. if (rule.type === 'cat' && catCount >= rule.count) {
  1100. additionalCost = totalPetCost - Number(rule.freeAmount)
  1101. catCount = catCount - rule.count
  1102. }else if(rule.type === 'smallDog' && smallDogCount >= rule.count){
  1103. additionalCost = totalPetCost - Number(rule.freeAmount)
  1104. smallDogCount = smallDogCount - rule.count
  1105. }else if(rule.type === 'mediumDog' && mediumDogCount >= rule.count){
  1106. additionalCost = totalPetCost - Number(rule.freeAmount)
  1107. mediumDogCount = mediumDogCount - rule.count
  1108. }else{
  1109. additionalCost = totalPetCost - Number(rule.freeAmount)
  1110. }
  1111. })
  1112. if (largeDogCount > 0) {
  1113. additionalCostItem.push({ itemName: '大型犬', price: this.calculatePetCost({
  1114. petType: 'dog',
  1115. bodyType: '大型',
  1116. }), quantity: largeDogCount, unit: '只' })
  1117. }
  1118. if (mediumDogCount > 0) {
  1119. additionalCostItem.push({ itemName: '中型犬', price: this.calculatePetCost({
  1120. petType: 'dog',
  1121. bodyType: '中型',
  1122. }), quantity: mediumDogCount, unit: '只' })
  1123. }
  1124. if (smallDogCount > 0) {
  1125. additionalCostItem.push({ itemName: '小型犬', price: this.calculatePetCost({
  1126. petType: 'dog',
  1127. bodyType: '小型',
  1128. }), quantity: smallDogCount, unit: '只' })
  1129. }
  1130. if (catCount > 0) {
  1131. additionalCostItem.push({ itemName: '猫猫', price: this.calculatePetCost({
  1132. petType: 'cat',
  1133. }), quantity: catCount, unit: '只' })
  1134. }
  1135. }
  1136. // 如果有大型犬,额外费用为40元/只
  1137. if (largeDogCount > 0) {
  1138. additionalCost += (this.calculatePetCost({
  1139. petType: 'dog',
  1140. bodyType: '大型',
  1141. }) * largeDogCount)
  1142. }
  1143. // 当日多次服务次数
  1144. let multServicesTotalCost = 0
  1145. const maxFeedCount = Math.max(...currentDayPets.map(pet => pet.feedCount));
  1146. if (maxFeedCount === 2) {
  1147. multServicesTotalCost += this.price_config.multiService.two.price; // 1天2次
  1148. } else if (maxFeedCount === 3) {
  1149. multServicesTotalCost += this.price_config.multiService.three.price; // 1天3次
  1150. }
  1151. // 所有宠物定制服务费用
  1152. const customServiceCost = currentDayPets.reduce((acc, pet) => acc + this.calculatePetCustomServiceCost(pet), 0)
  1153. const totalCost = baseServiceCost + additionalCost + multServicesTotalCost + customServiceCost
  1154. this.currentDayPrice = totalCost
  1155. },
  1156. calculatePetCustomServiceCost(pet) {
  1157. const customServiceCost = pet.customServices.reduce((acc, item) => acc + item.price * item.quantity, 0)
  1158. return customServiceCost
  1159. },
  1160. getCurrentPetName() {
  1161. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  1162. return currentPet.name
  1163. },
  1164. setCurrentPetIsAllSame() {
  1165. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  1166. currentPet.isAllSame = this.isAllSame
  1167. },
  1168. getCurrentPetIsAllSame() {
  1169. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  1170. this.isAllSame = currentPet.isAllSame
  1171. },
  1172. },
  1173. computed: {
  1174. sortedGroupedDates() {
  1175. return this.groupedDates.sort((a, b) => {
  1176. const dateA = new Date(a.monthLabel.replace('年', '-').replace('月', '-01'))
  1177. const dateB = new Date(b.monthLabel.replace('年', '-').replace('月', '-01'))
  1178. return dateA - dateB
  1179. })
  1180. }
  1181. }
  1182. }
  1183. </script>
  1184. <style scoped lang="less">
  1185. .container {
  1186. position: relative;
  1187. height: 100%;
  1188. padding-bottom: 160rpx;
  1189. .details-subscribe {
  1190. background-color: #FFFFFF;
  1191. padding: 10px;
  1192. width: 100%;
  1193. height: 160rpx;
  1194. position: fixed;
  1195. bottom: 0;
  1196. z-index: 100;
  1197. .details-btn {
  1198. width: 100%;
  1199. border-radius: 6px;
  1200. background: #FFB13F;
  1201. font-size: 16px;
  1202. color: #FFFFFF;
  1203. }
  1204. }
  1205. }
  1206. .service-new {
  1207. .service-new-flag {
  1208. width: 8rpx;
  1209. height: 32rpx;
  1210. background: #FFBF60;
  1211. border-radius: 30rpx 30rpx 30rpx 30rpx;
  1212. margin-right: 10rpx;
  1213. }
  1214. .split-line {
  1215. width: 100%;
  1216. height: 1rpx;
  1217. background: #EFEFEF;
  1218. }
  1219. .service-new-title {
  1220. display: flex;
  1221. font-weight: 500;
  1222. font-size: 28rpx;
  1223. color: #333333;
  1224. line-height: 33rpx;
  1225. margin: 42rpx 0 30rpx;
  1226. justify-content: space-between;
  1227. .service-new-title-left {
  1228. display: flex;
  1229. align-items: center;
  1230. }
  1231. }
  1232. .service-new-pet-content {
  1233. padding: 20rpx 0;
  1234. }
  1235. .service-new-pet-item {
  1236. height: 96rpx;
  1237. width: 184rpx;
  1238. border-radius: 8rpx;
  1239. padding: 0 20rpx;
  1240. margin-right: 40rpx;
  1241. display: flex;
  1242. align-items: center;
  1243. justify-content: center;
  1244. font-size: 28rpx;
  1245. flex-shrink: 0;
  1246. }
  1247. .scroll-content {
  1248. display: inline-flex;
  1249. }
  1250. .scroll-view {
  1251. width: 100%;
  1252. white-space: nowrap;
  1253. }
  1254. .pet-selected {
  1255. background: #FFBF60;
  1256. color: #FFFFFF;
  1257. }
  1258. .pet-unselect {
  1259. background: #F5F5F7;
  1260. color: #7D8196;
  1261. }
  1262. }
  1263. .calendar-wrapper {
  1264. display: flex;
  1265. gap: 20rpx;
  1266. padding: 20rpx;
  1267. }
  1268. .scroll-view {
  1269. width: 100%;
  1270. white-space: nowrap;
  1271. }
  1272. .calendar-day {
  1273. position: relative;
  1274. width: 80rpx;
  1275. height: 80rpx;
  1276. display: flex;
  1277. align-items: center;
  1278. justify-content: center;
  1279. cursor: pointer;
  1280. margin-right: 20rpx;
  1281. flex-shrink: 0;
  1282. }
  1283. .calendar-bg {
  1284. position: absolute;
  1285. width: 88rpx;
  1286. height: 78rpx;
  1287. z-index: 1;
  1288. }
  1289. .day-text {
  1290. position: relative;
  1291. z-index: 2;
  1292. top: 5rpx;
  1293. }
  1294. .day-highlighted {
  1295. font-size: 38rpx;
  1296. font-weight: bold;
  1297. color: #FFBF60;
  1298. }
  1299. .day-normal {
  1300. color: #3E3A39;
  1301. font-size: 32rpx;
  1302. }
  1303. .month-group {
  1304. margin-bottom: 30rpx;
  1305. .month-title {
  1306. font-size: 32rpx;
  1307. color: #666;
  1308. margin-bottom: 20rpx;
  1309. }
  1310. .dates-wrapper {
  1311. display: inline-flex;
  1312. }
  1313. }
  1314. .scroll-view-vertical {
  1315. height: 100%;
  1316. }
  1317. .scroll-view-horizontal {
  1318. width: 100%;
  1319. white-space: nowrap;
  1320. }
  1321. .time-slots {
  1322. display: flex;
  1323. justify-content: space-around;
  1324. }
  1325. .time-slot-item {
  1326. display: flex;
  1327. flex-direction: column;
  1328. align-items: center;
  1329. width: 200rpx;
  1330. cursor: pointer;
  1331. }
  1332. .time-slot-icon {
  1333. width: 160rpx;
  1334. height: 160rpx;
  1335. margin-bottom: 10rpx;
  1336. }
  1337. .time-slot-info {
  1338. display: flex;
  1339. flex-direction: column;
  1340. align-items: center;
  1341. }
  1342. .time-slot-name {
  1343. font-size: 28rpx;
  1344. color: #333;
  1345. margin-bottom: 8rpx;
  1346. }
  1347. .time-slot-time {
  1348. font-size: 24rpx;
  1349. color: #666;
  1350. }
  1351. .time-slot-time-tip {
  1352. background-color: #FFECCD;
  1353. color: #A94F20;
  1354. margin-left: 10rpx;
  1355. padding: 5rpx 10rpx;
  1356. font-size: 20rpx;
  1357. }
  1358. .service-item {
  1359. margin-bottom: 20rpx;
  1360. /* 每个服务项之间的间距 */
  1361. }
  1362. .service-item-header {
  1363. display: flex;
  1364. align-items: center;
  1365. margin-bottom: 10rpx;
  1366. /* 标题与服务列表之间的间距 */
  1367. }
  1368. .service-icon {
  1369. width: 40rpx;
  1370. /* 图标大小 */
  1371. height: 40rpx;
  1372. /* 图标大小 */
  1373. margin-right: 10rpx;
  1374. /* 图标与标题之间的间距 */
  1375. }
  1376. .service-title {
  1377. font-size: 28rpx;
  1378. /* 服务标题字体大小 */
  1379. font-weight: bold;
  1380. /* 服务标题加粗 */
  1381. }
  1382. .service-row {
  1383. display: flex;
  1384. align-items: center;
  1385. /* 垂直居中对齐 */
  1386. flex-wrap: wrap;
  1387. background-color: #F9F9F9;
  1388. }
  1389. .service-row-content {
  1390. display: flex;
  1391. justify-content: space-between;
  1392. /* 每行的上下内边距 */
  1393. width: 100%;
  1394. padding: 32rpx 0rpx;
  1395. margin: 0 20rpx;
  1396. }
  1397. .service-name {
  1398. width: 50%;
  1399. white-space: nowrap;
  1400. overflow: hidden;
  1401. text-overflow: ellipsis;
  1402. font-size: 28rpx;
  1403. color: #333;
  1404. /* 服务名称颜色 */
  1405. }
  1406. .service-price {
  1407. display: flex;
  1408. align-items: center;
  1409. /* 垂直居中对齐 */
  1410. }
  1411. .service-count {
  1412. display: flex;
  1413. align-items: center;
  1414. /* 垂直居中对齐 */
  1415. margin-left: 10rpx;
  1416. /* 价格数量之间的间距 */
  1417. }
  1418. .price-details {
  1419. position: fixed;
  1420. /* 固定位置 */
  1421. bottom: 160rpx;
  1422. /* 根据需要调整位置 */
  1423. left: 0;
  1424. right: 0;
  1425. background: #FFF;
  1426. /* 背景颜色 */
  1427. padding: 10px 10px 0 10px;
  1428. /* 内边距 */
  1429. border-radius: 8rpx 8rpx 0 0;
  1430. /* 圆角 */
  1431. z-index: 1000;
  1432. /* 确保在其他元素之上 */
  1433. min-height: 600rpx;
  1434. /* 固定高度 */
  1435. overflow: hidden;
  1436. /* 隐藏超出部分 */
  1437. }
  1438. .price-details-header {
  1439. display: flex;
  1440. justify-content: space-between;
  1441. align-items: center;
  1442. }
  1443. .price-details-body {
  1444. margin-top: 10px;
  1445. max-height: 300rpx;
  1446. /* 留出头部空间 */
  1447. overflow-y: auto;
  1448. /* 允许上下滚动 */
  1449. }
  1450. .price-details-overlay {
  1451. position: fixed;
  1452. /* 固定位置 */
  1453. top: 0;
  1454. left: 0;
  1455. right: 0;
  1456. bottom: 0;
  1457. background: rgba(0, 0, 0, 0.5);
  1458. /* 半透明背景 */
  1459. z-index: 999;
  1460. /* 确保在其他元素之上 */
  1461. display: flex;
  1462. justify-content: center;
  1463. align-items: center;
  1464. }
  1465. .price-details-item {
  1466. display: flex;
  1467. justify-content: space-between;
  1468. margin-bottom: 20rpx;
  1469. .price-details-item-price-total {
  1470. display: flex;
  1471. width: 70%;
  1472. justify-content: flex-end;
  1473. flex-wrap: wrap;
  1474. }
  1475. .price-details-item-price-total-item {
  1476. color: #999999;
  1477. text-align: right;
  1478. font-size: 28rpx;
  1479. margin-right: 20rpx;
  1480. }
  1481. }
  1482. </style>