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.

1746 lines
72 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 ? (isHoliday(currentMonthDay.fullDate) ? holidayPrice : normalPrice) * price_config.multiService.three.price : (isHoliday(currentMonthDay.fullDate) ? holidayPrice : normalPrice) * price_config.multiService.two.price).toFixed(2) }}
  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. freePetConfig : {
  372. cat: { freeCount: 1 },
  373. smallDog: { freeCount: 0 },
  374. mediumDog: { freeCount: 0 },
  375. largeDog: { freeCount: 0 }
  376. },
  377. }
  378. },
  379. onLoad: function (option) {
  380. this.$globalData.newOrderData.distancePrice = this.calculateDistancePrice()
  381. },
  382. mounted() {
  383. console.log('this.$globalData', this.$globalData)
  384. this.currentPets = this.$globalData.newOrderData.currentPets;
  385. if (this.currentPets.length < 1) {
  386. uni.reLaunch({
  387. url: '/pages/index'
  388. });
  389. return
  390. }
  391. if (this.$globalData.mainSku && this.$globalData.mainSku[0]) {
  392. this.basePrice = this.$globalData.mainSku[0].price
  393. this.baseProduct = this.$globalData.mainSku[0].name
  394. }
  395. // 初始化价格配置
  396. this.initPriceConfig()
  397. this.getProductList()
  398. },
  399. watch: {
  400. currentPetId: {
  401. immediate: true,
  402. handler(newId) {
  403. if (newId) {
  404. this.updateGroupedDates()
  405. }
  406. }
  407. }
  408. },
  409. methods: {
  410. companionLevelPrice(){
  411. let companionLevel = this.$globalData.newOrderData.companionLevel
  412. let price = Number(companionLevel.paramValueText) * this.isAddPrice()
  413. return price * this.$store.state.memberRate
  414. },
  415. //判断当前选中的地址是否加价
  416. isAddPrice(){
  417. let currentAddress = this.$globalData.newOrderData.currentAddress || {}
  418. let defaultPrice = 1
  419. try{
  420. defaultPrice = this.price_config.cityConfig.priceRates.default
  421. }catch(e){
  422. defaultPrice = 1
  423. }
  424. if(!this.price_config.cityConfig || !currentAddress.province || !currentAddress.city){
  425. return defaultPrice
  426. }
  427. let addressList = this.price_config.cityConfig.priceRates || []
  428. for(let key in addressList){
  429. if((currentAddress.province + currentAddress.city).includes(key)){
  430. return addressList[key]
  431. }
  432. }
  433. return defaultPrice
  434. },
  435. //计算距离价格
  436. calculateDistancePrice() {
  437. if(!this.buyInfo.teacher || !this.buyInfo.teacher.appletAddresseList){
  438. return
  439. }
  440. let addressList = this.buyInfo.teacher.appletAddresseList
  441. let d = this.calculateDistanceAddressList(addressList, {
  442. latitude: this.$globalData.newOrderData.latitude,
  443. longitude: this.$globalData.newOrderData.longitude,
  444. })[0]?.distance || 0
  445. return d * this.distancePrice
  446. },
  447. getCustomServicesByOrder(pet, date){
  448. // 获取所有当前可用的定制服务
  449. const currentCustomServices = JSON.parse(this.customServicesStr || '[]')
  450. const customServices = []
  451. // 遍历所有当前定制服务
  452. currentCustomServices.forEach(service => {
  453. let quantity = 0 // 默认数量为0
  454. // 如果存在原订单数据,查找对应的数量
  455. if(this.$globalData.newOrderData.originalOrderData) {
  456. const originalOrderData = this.$globalData.newOrderData.originalOrderData
  457. if(originalOrderData.orderItemList && originalOrderData.orderItemList.length > 0) {
  458. // 查找原订单中对应的定制服务项目
  459. const originalItem = originalOrderData.orderItemList.find(item => {
  460. // 定制服务的categoryId为78,且不是主产品,且skuId匹配
  461. if(item.productCategoryId === 78 && item.isMainProduct !== 1 && item.skuId === service.skuId) {
  462. // 查找对应的服务记录,匹配宠物和日期
  463. const matchingService = originalOrderData.orderServiceList.find(serviceRecord => {
  464. return serviceRecord.id === item.orderServiceId &&
  465. serviceRecord.petId === pet.id &&
  466. serviceRecord.serviceDate === date
  467. })
  468. return !!matchingService
  469. }
  470. return false
  471. })
  472. if(originalItem) {
  473. quantity = originalItem.quantity
  474. }
  475. }
  476. }
  477. // 添加定制服务到结果中
  478. customServices.push({
  479. skuId: service.skuId,
  480. name: service.name,
  481. price: service.price,
  482. quantity: quantity,
  483. isMainProduct: false
  484. })
  485. })
  486. return customServices
  487. },
  488. initNewOrderData() {
  489. const needPreFamiliarize = this.$globalData.newOrderData.needPreFamiliarize.length > 0
  490. const pets = []
  491. // 初始化当前宠物全日期保持一致
  492. this.currentPets = this.currentPets.map(pet => {
  493. pet.isAllSame = false
  494. return pet
  495. })
  496. this.currentPets.map(pet => {
  497. // 单个宠物服务日期列表
  498. const serviceDateList = pet.selectedDate.map(item => item.date)
  499. serviceDateList.forEach(date => {
  500. // 获取原订单中该宠物在该日期的定制服务
  501. const originalCustomServices = this.getCustomServicesByOrder(pet, date)
  502. pets.push({
  503. petId: pet.id,
  504. serviceDate: date,
  505. name: pet.name,
  506. gender: pet.gender,
  507. petType: pet.petType,
  508. bodyType: pet.bodyType,
  509. photo: pet.photo,
  510. feedCount: 1,
  511. selectedTimeSlots: [],
  512. customServices: originalCustomServices,
  513. //额外费用
  514. additionalCost: 0
  515. })
  516. })
  517. })
  518. this.newOrderData = {
  519. needPreFamiliarize: needPreFamiliarize, // 是否需要提前熟悉 40元/次 参与计算
  520. pets: pets
  521. }
  522. // 默认选择第一个宠物
  523. this.selectPet(this.currentPets[0] || {})
  524. this.calculateTotalPrice()
  525. },
  526. // 选择宠物
  527. selectPet(pet) {
  528. this.currentPetId = pet.id
  529. // 默认选择当前宠物的最小日期
  530. if (pet.selectedDate?.length > 1) {
  531. const minDate = pet.selectedDate.reduce((min, date) => {
  532. const currentDate = new Date(date.date);
  533. const minDate = new Date(min.date);
  534. return currentDate < minDate ? date : min;
  535. }, pet.selectedDate[0]);
  536. // 当前选择日期
  537. this.currentMonthDay = {
  538. petId: this.currentPetId,
  539. date: new Date(minDate.date).getDate(),
  540. fullDate: minDate.date
  541. }
  542. } else {
  543. this.currentMonthDay = {
  544. petId: this.currentPetId,
  545. date: new Date(pet.selectedDate[0].date).getDate(),
  546. fullDate: pet.selectedDate[0].date
  547. }
  548. }
  549. this.getCurrentPetIsAllSame()
  550. this.selectDate(this.currentMonthDay)
  551. },
  552. selectDate(day) {
  553. // 当前选择日期
  554. this.currentMonthDay = day
  555. const selectedDay = this.selectedDates?.find(item => item.fullDate === day.fullDate && item
  556. .currentPetId === day.petId)
  557. if (!selectedDay) {
  558. this.selectedDates.push(day)
  559. }
  560. // 还原当前选择日期是否已选择期望时间
  561. const pets = this.newOrderData?.pets
  562. const selectedPet = pets.find(pet => pet.petId === this.currentPetId && pet.serviceDate === this
  563. .currentMonthDay.fullDate);
  564. const selectedTimeSlots = selectedPet ? selectedPet.selectedTimeSlots : [];
  565. if (selectedTimeSlots.length > 0) {
  566. this.timeSlots.forEach(slot => {
  567. if (selectedTimeSlots.includes(slot.id)) {
  568. slot.selected = true
  569. } else {
  570. slot.selected = false
  571. }
  572. })
  573. } else {
  574. this.timeSlots.forEach(slot => {
  575. slot.selected = false
  576. })
  577. }
  578. // 还原当前选择日期喂食次数
  579. this.feedCount = selectedPet ? selectedPet.feedCount : 1
  580. // 还原当前选择日期是否已选择定制服务
  581. this.customServices = selectedPet.customServices.length > 0 ? selectedPet.customServices : JSON.parse(this.customServicesStr)
  582. /*
  583. if (selectedPet && selectedPet.customServices.length > 0) {
  584. // 如果当前宠物已有定制服务(可能来自原订单),直接使用
  585. this.customServices = selectedPet.customServices
  586. } else {
  587. // 否则使用默认的定制服务列表
  588. this.customServices = JSON.parse(this.customServicesStr)
  589. // 如果存在原订单数据,尝试获取该宠物在该日期的定制服务
  590. if (this.$globalData.newOrderData.originalOrderData) {
  591. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  592. if (currentPet) {
  593. const originalCustomServices = this.getCustomServicesByOrder(currentPet, this.currentMonthDay.fullDate)
  594. if (originalCustomServices.length > 0) {
  595. this.customServices = originalCustomServices
  596. }
  597. }
  598. }
  599. }
  600. */
  601. this.getCurrentDayPrice(this.currentMonthDay.fullDate)
  602. },
  603. isDateSelected(day) {
  604. const selectedDay = this.selectedDates.find(item => item.fullDate === day.fullDate && this.currentPetId ===
  605. item.petId)
  606. if (selectedDay) {
  607. return true
  608. }
  609. return false
  610. },
  611. isCurrentSelected(day) {
  612. return this.currentMonthDay.fullDate === day.fullDate && this.currentPetId === day.petId
  613. },
  614. updateGroupedDates() {
  615. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  616. if (!currentPet) return
  617. // 按月份分组日期
  618. const grouped = currentPet.selectedDate.reduce((acc, dateObj) => {
  619. const date = new Date(dateObj.date)
  620. const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`
  621. const monthLabel = `${date.getFullYear()}${date.getMonth() + 1}`
  622. if (!acc[monthKey]) {
  623. acc[monthKey] = {
  624. monthLabel,
  625. dates: []
  626. }
  627. }
  628. acc[monthKey].dates.push({
  629. petId: currentPet.id,
  630. date: date.getDate(),
  631. fullDate: dateObj.date
  632. })
  633. return acc
  634. }, {})
  635. // 转换为数组并排序
  636. this.groupedDates = Object.values(grouped).sort((a, b) => {
  637. return a.monthLabel.localeCompare(b.monthLabel)
  638. })
  639. },
  640. selectTimeSlot(slotId) {
  641. const slot = this.timeSlots.find(slot => slot.id === slotId)
  642. if (slot) {
  643. slot.selected = !slot.selected
  644. }
  645. // 将期望时间添加到当前宠物
  646. const selectedTimeSlots = this.timeSlots.filter(slot => slot.selected)
  647. if (this.isAllSame) {
  648. // 如果保持一致,则更新该宠物所有期望时间
  649. this.newOrderData.pets.forEach(pet => {
  650. pet.selectedTimeSlots = selectedTimeSlots.map(item => item.id)
  651. })
  652. } else {
  653. const currentPetIndex = this.newOrderData.pets.findIndex(pet => pet.petId === this.currentPetId
  654. && pet.serviceDate === this.currentMonthDay.fullDate)
  655. if (currentPetIndex !== -1) {
  656. this.newOrderData.pets[currentPetIndex].selectedTimeSlots = selectedTimeSlots.map(item => item.id)
  657. }
  658. }
  659. },
  660. feedCountChange(e) {
  661. this.feedCount = e.value
  662. if (this.isAllSame) {
  663. // 如果保持一致,则更新该宠物的喂食次数
  664. this.newOrderData.pets.forEach(pet => {
  665. if (pet.petId === this.currentPetId) {
  666. pet.feedCount = this.feedCount
  667. }
  668. })
  669. } else {
  670. const pets = this.newOrderData.pets
  671. const currentPetIndex = pets.findIndex(pet => pet.petId === this.currentPetId && pet.serviceDate ===
  672. this.currentMonthDay.fullDate)
  673. if (currentPetIndex !== -1) {
  674. this.newOrderData.pets[currentPetIndex].feedCount = this.feedCount
  675. }
  676. }
  677. this.calculateTotalPrice()
  678. },
  679. customServiceCountChange(val) {
  680. console.log(val)
  681. this.customServices.forEach(item => {
  682. if (item.name === val.name) {
  683. item.quantity = val.value
  684. }
  685. })
  686. if (this.isAllSame) {
  687. // 如果保持一致,则更新当前宠物的定制服务次数
  688. this.newOrderData.pets.forEach(pet => {
  689. if (pet.petId === this.currentPetId) {
  690. pet.customServices = JSON.parse(JSON.stringify(this.customServices))
  691. }
  692. })
  693. } else {
  694. const pets = this.newOrderData.pets
  695. const currentPetIndex = pets.findIndex(pet => pet.petId === this.currentPetId && pet.serviceDate ===
  696. this.currentMonthDay.fullDate)
  697. if (currentPetIndex !== -1) {
  698. this.newOrderData.pets[currentPetIndex].customServices = JSON.parse(JSON.stringify(this
  699. .customServices))
  700. }
  701. }
  702. this.calculateTotalPrice()
  703. },
  704. togglePriceDetails() {
  705. this.showPriceDetails = !this.showPriceDetails; // 切换价格明细的显示状态
  706. if (this.showPriceDetails) {
  707. this.priceDetailDate()
  708. }
  709. },
  710. calculateTotalPrice() {
  711. // 1. 订单维度:是否需要提前熟悉
  712. if (this.$globalData.newOrderData.needPreFamiliarize && this.$globalData.newOrderData.needPreFamiliarize.length > 0) {
  713. this.needPreFamiliarizeCost = this.price_config.preFamiliarize.price
  714. } else {
  715. this.needPreFamiliarizeCost = 0
  716. }
  717. // 2. 日期维度
  718. // 2.1 基础服务费用 - 根据节假日和非节假日分别计算
  719. const uniqueDates = new Set(this.newOrderData.pets.map(item => item.serviceDate)); // 去重日期
  720. let baseServiceTotalCost = 0;
  721. uniqueDates.forEach(date => {
  722. const isHolidayDate = this.isHoliday(date);
  723. const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice);
  724. baseServiceTotalCost += dayPrice;
  725. });
  726. this.baseServiceTotalCost = baseServiceTotalCost;
  727. // 2.2 额外宠物费用
  728. // petType为dog 且bodyType包含 '大型' 则为大型犬,40元/次
  729. // petType为dog 且bodyType包含 '中型' 则为中型犬,30元/次
  730. // petType为dog 且bodyType包含 '小型' 则为小型犬,15元/次
  731. // petType为cat 则为猫,10元/次
  732. this.newOrderData.pets.forEach(pet => {
  733. pet.additionalCost = this.calculatePetCost(pet)
  734. // if (pet.petType === 'dog' && pet.bodyType.includes('大型')) {
  735. // pet.additionalCost = 40
  736. // } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) {
  737. // pet.additionalCost = 30
  738. // } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) {
  739. // pet.additionalCost = 15
  740. // } else if (pet.petType === 'cat') {
  741. // pet.additionalCost = 10
  742. // }
  743. })
  744. // const largeDogArray = this.newOrderData.pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型'));
  745. // this.additionalTotalCost = this.additionalTotalCost + (largeDogArray.length * 40)
  746. // // 非大型犬
  747. // const otherPets = this.newOrderData.pets.filter(pet => pet.petType !== 'dog' && !pet.bodyType.includes('大型'));
  748. // 宠物日期分组
  749. const dailyPets = [];
  750. // 按日期分组宠物
  751. this.newOrderData.pets.forEach(pet => {
  752. const serviceDate = pet.serviceDate;
  753. if (!dailyPets[serviceDate]) {
  754. dailyPets[serviceDate] = [];
  755. }
  756. dailyPets[serviceDate].push(pet);
  757. });
  758. const petTypeCounts = []
  759. let additionalTotalCost = 0
  760. // 计算每日额外宠物费用
  761. for (const date in dailyPets) {
  762. const pets = dailyPets[date];
  763. const largeDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型')).length;
  764. let mediumDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('中型')).length;
  765. let smallDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('小型')).length;
  766. let catCount = pets.filter(pet => pet.petType === 'cat').length;
  767. let additionalCost = 0
  768. // 总宠物费用
  769. let totalPetCost = pets.reduce((acc, pet) => {
  770. return acc + this.calculatePetCost(pet);
  771. }, 0);
  772. // 如果总宠物费用>30
  773. // const freeQuota = this.price_config.freeQuota
  774. // if (totalPetCost > Number(freeQuota.threshold)) {
  775. // freeQuota.rules.forEach(rule => {
  776. // if (rule.type === 'cat' && catCount >= rule.count) {
  777. // additionalCost = totalPetCost - Number(rule.freeAmount)
  778. // catCount = catCount - rule.count
  779. // }else if(rule.type === 'smallDog' && smallDogCount >= rule.count){
  780. // additionalCost = totalPetCost - Number(rule.freeAmount)
  781. // smallDogCount = smallDogCount - rule.count
  782. // }else if(rule.type === 'mediumDog' && mediumDogCount >= rule.count){
  783. // additionalCost = totalPetCost - Number(rule.freeAmount)
  784. // mediumDogCount = mediumDogCount - rule.count
  785. // }else{
  786. // additionalCost = totalPetCost - Number(rule.freeAmount)
  787. // }
  788. // })
  789. // // if (totalPetCost > 30) {
  790. // // // 如果猫数量>=3
  791. // // if (catCount >= 3) {
  792. // // additionalCost = totalPetCost - 30
  793. // // catCount = catCount - 3
  794. // // } else if (smallDogCount >= 2) {
  795. // // additionalCost = totalPetCost - 30
  796. // // smallDogCount = smallDogCount - 2
  797. // // } else if (mediumDogCount >= 1) {
  798. // // additionalCost = totalPetCost - 30
  799. // // mediumDogCount = mediumDogCount - 1
  800. // // } else {
  801. // // additionalCost = totalPetCost - 25
  802. // // catCount = catCount - 1
  803. // // smallDogCount = smallDogCount - 1
  804. // // }
  805. // }
  806. petTypeCounts.push({
  807. date,
  808. largeDogCount,
  809. mediumDogCount,
  810. smallDogCount,
  811. catCount
  812. })
  813. // 根据 freePetConfig 配置计算免费宠物数量
  814. const freePetConfig = this.price_config.freePetConfig || this.freePetConfig
  815. // 如果有大型犬,超过免费数量的收费
  816. if (largeDogCount > freePetConfig.largeDog.freeCount) {
  817. const chargeableCount = largeDogCount - freePetConfig.largeDog.freeCount
  818. additionalCost += (this.calculatePetCost({
  819. petType: 'dog',
  820. bodyType: '大型',
  821. }) * chargeableCount)
  822. }
  823. // 如果有中型犬,超过免费数量的收费
  824. if (mediumDogCount > freePetConfig.mediumDog.freeCount) {
  825. const chargeableCount = mediumDogCount - freePetConfig.mediumDog.freeCount
  826. additionalCost += (this.calculatePetCost({
  827. petType: 'dog',
  828. bodyType: '中型',
  829. }) * chargeableCount)
  830. }
  831. // 如果有小型犬,超过免费数量的收费
  832. if (smallDogCount > freePetConfig.smallDog.freeCount) {
  833. const chargeableCount = smallDogCount - freePetConfig.smallDog.freeCount
  834. additionalCost += (this.calculatePetCost({
  835. petType: 'dog',
  836. bodyType: '小型',
  837. }) * chargeableCount)
  838. }
  839. // 如果有猫,超过免费数量的收费
  840. if (catCount > freePetConfig.cat.freeCount) {
  841. const chargeableCount = catCount - freePetConfig.cat.freeCount
  842. additionalCost += (this.calculatePetCost({
  843. petType: 'cat',
  844. bodyType: '小型',
  845. }) * chargeableCount)
  846. }
  847. // 如果有额外费用,添加到总额外费用
  848. if (additionalCost > 0) {
  849. additionalTotalCost += additionalCost;
  850. }
  851. }
  852. this.additionalTotalCost = additionalTotalCost
  853. this.petTypeCounts = petTypeCounts
  854. // 2.3 当日多次服务总价
  855. // 计算每日多次服务次数费用 - 基础价格乘以倍数
  856. let multServicesTotalCost = 0
  857. let oneDayTwoTimesDates = []
  858. let oneDayThreeTimesDates = []
  859. for (const date in dailyPets) {
  860. const maxFeedCount = Math.max(...dailyPets[date].map(pet => pet.feedCount));
  861. const isHolidayDate = this.isHoliday(date);
  862. const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice);
  863. if (maxFeedCount === 2) {
  864. multServicesTotalCost += dayPrice * this.price_config.multiService.two.price; // 基础价格 × 2次倍数
  865. oneDayTwoTimesDates.push(date)
  866. } else if (maxFeedCount === 3) {
  867. multServicesTotalCost += dayPrice * this.price_config.multiService.three.price; // 基础价格 × 3次倍数
  868. oneDayThreeTimesDates.push(date)
  869. }
  870. }
  871. this.oneDayTwoTimesDates = oneDayTwoTimesDates
  872. this.oneDayThreeTimesDates = oneDayThreeTimesDates
  873. this.multServicesTotalCost = multServicesTotalCost
  874. // 3. 定制服务
  875. //定制服务单项总次数统计
  876. const customServiceItemCount = JSON.parse(this.customServicesStr)
  877. let customServicesTotalCost = 0
  878. this.newOrderData.pets.forEach(pet => {
  879. const customServices = pet.customServices
  880. // 定制服务费用
  881. customServices.forEach(service => {
  882. const itemIndex = customServiceItemCount.findIndex(item => item.name === service.name)
  883. if (itemIndex !== -1) {
  884. customServiceItemCount[itemIndex].quantity += service.quantity
  885. }
  886. customServicesTotalCost += service.price * service.quantity;
  887. })
  888. });
  889. this.customServiceItemCount = customServiceItemCount
  890. this.customServicesTotalCost = customServicesTotalCost
  891. // 再来一单费用
  892. const moreOrderPrice = this.$globalData.newOrderData.moreOrderPrice || 0;
  893. this.totalPrice = Number(this.needPreFamiliarizeCost)
  894. + Number(this.baseServiceTotalCost)
  895. + Number(this.additionalTotalCost)
  896. + Number(this.multServicesTotalCost)
  897. + Number(this.customServicesTotalCost)
  898. + Number(moreOrderPrice); // 更新总价
  899. this.getCurrentDayPrice(this.currentMonthDay.fullDate)
  900. },
  901. calculatePetCost(pet) {
  902. // 宠物额外费用 不计算大型犬
  903. let petExtra = this.price_config.petExtra
  904. let petCost = 0;
  905. if (pet.petType === 'cat') {
  906. petCost += Number(petExtra.cat.price); // 猫额外费用
  907. } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) {
  908. petCost += Number(petExtra.smallDog.price); // 小型犬额外费用
  909. } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) {
  910. petCost += Number(petExtra.mediumDog.price); // 中型犬额外费用
  911. }
  912. return petCost;
  913. },
  914. goNext() {
  915. console.log('this.$globalData.newOrderData', this.$globalData.newOrderData)
  916. this.calculateTotalPrice(); // 计算总价
  917. this.showPriceDetails = false;
  918. this.$globalData.newOrderData.currentPetsByDay = this.newOrderData.pets
  919. this.$globalData.newOrderData.totalPrice = this.totalPrice
  920. uni.navigateTo({
  921. url: '/pages/newOrder/confirmOrder'
  922. });
  923. },
  924. goBack() {
  925. this.showPriceDetails = false
  926. let len = getCurrentPages().length;
  927. this.loading = false
  928. if (len >= 2) {
  929. uni.navigateBack();
  930. } else {
  931. uni.redirectTo({
  932. url: '/pages/newOrder/serviceNew'
  933. });
  934. }
  935. },
  936. // 价格明细数据
  937. priceDetailDate() {
  938. const priceDetails = []
  939. if (this.newOrderData.needPreFamiliarize) {
  940. priceDetails.push({
  941. name: '提前熟悉',
  942. item: [{
  943. itemName: '提前熟悉',
  944. price: this.price_config.preFamiliarize.price,
  945. quantity: this.newOrderData.needPreFamiliarize ? 1 : 0,
  946. unit: '次'
  947. },]
  948. })
  949. }
  950. // 伴宠师等级价格已合并到基础服务价格中,不再单独显示
  951. // 分别统计节假日和非节假日的天数
  952. const uniqueDates = new Set(this.newOrderData.pets.map(item => item.serviceDate));
  953. let holidayCount = 0;
  954. let normalCount = 0;
  955. uniqueDates.forEach(date => {
  956. if (this.isHoliday(date)) {
  957. holidayCount++;
  958. } else {
  959. normalCount++;
  960. }
  961. });
  962. const baseServiceItems = [];
  963. if (normalCount > 0) {
  964. baseServiceItems.push({
  965. itemName: '非节假日 | ',
  966. price: parseFloat(this.normalPrice),
  967. quantity: normalCount,
  968. unit: '天'
  969. });
  970. }
  971. if (holidayCount > 0) {
  972. baseServiceItems.push({
  973. itemName: '节假日 | ',
  974. price: parseFloat(this.holidayPrice),
  975. quantity: holidayCount,
  976. unit: '天'
  977. });
  978. }
  979. if (baseServiceItems.length > 0) {
  980. priceDetails.push({
  981. name: this.baseProduct,
  982. item: baseServiceItems
  983. });
  984. }
  985. if (this.oneDayTwoTimesDates.length > 0 || this.oneDayThreeTimesDates.length > 0) {
  986. const multiServiceItems = []
  987. // 计算1天2次的价格明细
  988. this.oneDayTwoTimesDates.forEach(date => {
  989. const isHolidayDate = this.isHoliday(date)
  990. const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice)
  991. multiServiceItems.push({
  992. itemName: `1天2次 (${isHolidayDate ? '节假日' : '非节假日'})`,
  993. price: dayPrice * this.price_config.multiService.two.price,
  994. quantity: 1,
  995. unit: '天',
  996. date: date
  997. })
  998. })
  999. // 计算1天3次的价格明细
  1000. this.oneDayThreeTimesDates.forEach(date => {
  1001. const isHolidayDate = this.isHoliday(date)
  1002. const dayPrice = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice)
  1003. multiServiceItems.push({
  1004. itemName: `1天3次 (${isHolidayDate ? '节假日' : '非节假日'})`,
  1005. price: dayPrice * this.price_config.multiService.three.price,
  1006. quantity: 1,
  1007. unit: '天',
  1008. date: date
  1009. })
  1010. })
  1011. // 按日期排序
  1012. multiServiceItems.sort((a, b) => new Date(a.date) - new Date(b.date))
  1013. priceDetails.push({
  1014. name: '上门次数',
  1015. item: multiServiceItems
  1016. })
  1017. }
  1018. // 过滤宠物类型数量>0的数组
  1019. const additionalCostItem = []
  1020. const petTypeArr = this.petTypeCounts.filter(item => item.largeDogCount > 0 || item.mediumDogCount > 0 ||
  1021. item.smallDogCount > 0 || item.catCount > 0)
  1022. // 假设largeDogCount=1 mediumDogCount=2 smallDogCount=3 catCount=4 则生成4条数据
  1023. petTypeArr.forEach(item => {
  1024. // 获取免费宠物配置
  1025. const freePetConfig = this.price_config.freePetConfig || this.freePetConfig
  1026. // 只显示收费的宠物数量(扣除免费数量)
  1027. const chargeableLargeDogCount = Math.max(0, item.largeDogCount - freePetConfig.largeDog.freeCount)
  1028. const chargeableMediumDogCount = Math.max(0, item.mediumDogCount - freePetConfig.mediumDog.freeCount)
  1029. const chargeableSmallDogCount = Math.max(0, item.smallDogCount - freePetConfig.smallDog.freeCount)
  1030. const chargeableCatCount = Math.max(0, item.catCount - freePetConfig.cat.freeCount)
  1031. if (chargeableLargeDogCount > 0) {
  1032. additionalCostItem.push({
  1033. itemName: '大型犬',
  1034. price: this.calculatePetCost({
  1035. petType: 'dog',
  1036. bodyType: '大型',
  1037. }),
  1038. quantity: chargeableLargeDogCount,
  1039. unit: '只',
  1040. date: item.date
  1041. })
  1042. }
  1043. if (chargeableMediumDogCount > 0) {
  1044. additionalCostItem.push({
  1045. itemName: '中型犬',
  1046. price: this.calculatePetCost({
  1047. petType: 'dog',
  1048. bodyType: '中型',
  1049. }),
  1050. quantity: chargeableMediumDogCount,
  1051. unit: '只',
  1052. date: item.date
  1053. })
  1054. }
  1055. if (chargeableSmallDogCount > 0) {
  1056. additionalCostItem.push({
  1057. itemName: '小型犬',
  1058. price: this.calculatePetCost({
  1059. petType: 'dog',
  1060. bodyType: '小型',
  1061. }),
  1062. quantity: chargeableSmallDogCount,
  1063. unit: '只',
  1064. date: item.date
  1065. })
  1066. }
  1067. if (chargeableCatCount > 0) {
  1068. additionalCostItem.push({
  1069. itemName: '猫猫',
  1070. price: this.calculatePetCost({
  1071. petType: 'cat',
  1072. }),
  1073. quantity: chargeableCatCount,
  1074. unit: '只',
  1075. date: item.date
  1076. })
  1077. }
  1078. })
  1079. // 按日期先后顺序排序
  1080. additionalCostItem.sort((a, b) => new Date(a.date) - new Date(b.date))
  1081. if (additionalCostItem.length > 0) {
  1082. priceDetails.push({
  1083. name: '额外宠物费用',
  1084. item: additionalCostItem
  1085. })
  1086. }
  1087. const customServiceItem = this.customServiceItemCount.filter(item => item.quantity > 0).map(service => {
  1088. return { itemName: service.name, price: service.price, quantity: service.quantity, unit: '次' }
  1089. })
  1090. if (customServiceItem.length > 0) {
  1091. priceDetails.push({
  1092. name: '定制服务',
  1093. item: customServiceItem
  1094. })
  1095. }
  1096. // 再来一单费用
  1097. const moreOrderPrice = this.$globalData.newOrderData.moreOrderPrice || 0;
  1098. if (moreOrderPrice > 0) {
  1099. priceDetails.push({
  1100. name: '再来一单',
  1101. item: [{
  1102. itemName: '再来一单费用',
  1103. price: moreOrderPrice,
  1104. quantity: 1,
  1105. unit: '次'
  1106. }]
  1107. })
  1108. }
  1109. this.priceDetails = priceDetails
  1110. this.calculateTotalPrice()
  1111. },
  1112. showName(item) {
  1113. return item.item.some(item2 => item2.quantity > 0)
  1114. },
  1115. isAllSameChange(e) {
  1116. if (e) {
  1117. this.isAllSame = true
  1118. this.setCurrentPetIsAllSame()
  1119. // 当前宠物全日期保持一致
  1120. this.newOrderData.pets.forEach(pet => {
  1121. if (pet.petId === this.currentPetId) {
  1122. pet.selectedTimeSlots = this.timeSlots.filter(slot => slot.selected).map(item => item.id)
  1123. pet.feedCount = this.feedCount
  1124. pet.customServices = this.customServices
  1125. }
  1126. })
  1127. this.calculateTotalPrice()
  1128. } else {
  1129. this.isAllSame = false
  1130. this.setCurrentPetIsAllSame()
  1131. }
  1132. },
  1133. // 初始化价格配置
  1134. initPriceConfig() {
  1135. let priceConfig = this.$store.state.price_config
  1136. console.log('价格配置:', priceConfig)
  1137. // 获取伴宠师等级价格和城市倍率
  1138. let companionPrice = this.$globalData.newOrderData.companionLevelPrice || 0
  1139. let cityPriceRate = this.$globalData.newOrderData.cityPriceRate || 1
  1140. if(priceConfig.basePrice && priceConfig.basePrice.holiday){
  1141. this.holidayPrice = ((priceConfig.basePrice.holiday * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2)
  1142. }
  1143. if(priceConfig.basePrice && priceConfig.basePrice.normal){
  1144. this.normalPrice = ((priceConfig.basePrice.normal * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2)
  1145. }
  1146. if(priceConfig.holidays && priceConfig.holidays.length > 0){
  1147. this.holidayDate = priceConfig.holidays
  1148. }else{
  1149. this.holidayDate = []
  1150. }
  1151. },
  1152. // 判断是否为节假日
  1153. isHoliday(date) {
  1154. return this.holidayDate.some(holiday => holiday === date)
  1155. },
  1156. getProductList() {
  1157. getProductList({
  1158. "publishStatus": 1,
  1159. "categoryId": 78,
  1160. "needSku": true
  1161. }).then(response => {
  1162. if (response && response.content && response.content.length > 0) {
  1163. this.customServices = response.content.map(item => {
  1164. const skus = item.skus
  1165. if (skus && skus.length > 0) {
  1166. let productSku = {
  1167. "skuId": skus[0].id,
  1168. "price": (skus[0].price * this.$store.state.memberRate).toFixed(2),
  1169. "name": item.name,
  1170. "quantity": 0,
  1171. "isMainProduct": false
  1172. }
  1173. return productSku
  1174. }
  1175. })
  1176. this.customServicesStr = JSON.stringify(this.customServices)
  1177. // 初始化新订单数据
  1178. this.initNewOrderData()
  1179. } else {
  1180. uni.showToast('获取主产品失败,请联系管理员')
  1181. }
  1182. console.log(response);
  1183. })
  1184. },
  1185. login() {
  1186. uni.login({
  1187. provider: 'weixin',
  1188. success: (loginRes) => {
  1189. this.getOpenId(loginRes.code)
  1190. },
  1191. fail: function (error) {
  1192. // 授权失败处理
  1193. uni.showToast('授权失败,请授权后再试')
  1194. }
  1195. });
  1196. },
  1197. getOpenId(code) {
  1198. getOpenId(code).then(res => {
  1199. if (res.code == 200 && res.data) {
  1200. let resData = JSON.parse(res.data)
  1201. let token = resData.token;
  1202. let openId = resData.openId;
  1203. setOpenIdKey(openId)
  1204. if (token) {
  1205. setToken(token)
  1206. }
  1207. }
  1208. })
  1209. },
  1210. getCurrentDayPrice(currentDay) {
  1211. const currentDayPets = this.newOrderData.pets.filter(pet => pet.serviceDate === currentDay)
  1212. // 根据是否为节假日确定基础服务价格
  1213. const isHolidayDate = this.isHoliday(currentDay)
  1214. const baseServiceCost = isHolidayDate ? parseFloat(this.holidayPrice) : parseFloat(this.normalPrice)
  1215. const largeDogCount = currentDayPets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型')).length;
  1216. let mediumDogCount = currentDayPets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('中型')).length;
  1217. let smallDogCount = currentDayPets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('小型')).length;
  1218. let catCount = currentDayPets.filter(pet => pet.petType === 'cat').length;
  1219. const additionalCostItem = []
  1220. let additionalCost = 0
  1221. // 单天总宠物费用
  1222. let totalPetCost = currentDayPets.reduce((acc, pet) => {
  1223. return acc + this.calculatePetCost(pet);
  1224. }, 0);
  1225. // 根据 freePetConfig 配置计算免费宠物数量
  1226. const freePetConfig = this.price_config.freePetConfig || {
  1227. cat: { freeCount: 1 },
  1228. smallDog: { freeCount: 0 },
  1229. mediumDog: { freeCount: 0 },
  1230. largeDog: { freeCount: 0 }
  1231. }
  1232. // 计算收费的宠物数量(扣除免费数量)
  1233. const chargeableLargeDogCount = Math.max(0, largeDogCount - freePetConfig.largeDog.freeCount)
  1234. const chargeableMediumDogCount = Math.max(0, mediumDogCount - freePetConfig.mediumDog.freeCount)
  1235. const chargeableSmallDogCount = Math.max(0, smallDogCount - freePetConfig.smallDog.freeCount)
  1236. const chargeableCatCount = Math.max(0, catCount - freePetConfig.cat.freeCount)
  1237. // 计算额外宠物费用
  1238. if (chargeableLargeDogCount > 0) {
  1239. additionalCost += (this.calculatePetCost({
  1240. petType: 'dog',
  1241. bodyType: '大型',
  1242. }) * chargeableLargeDogCount)
  1243. additionalCostItem.push({ itemName: '大型犬', price: this.calculatePetCost({
  1244. petType: 'dog',
  1245. bodyType: '大型',
  1246. }), quantity: chargeableLargeDogCount, unit: '只' })
  1247. }
  1248. if (chargeableMediumDogCount > 0) {
  1249. additionalCost += (this.calculatePetCost({
  1250. petType: 'dog',
  1251. bodyType: '中型',
  1252. }) * chargeableMediumDogCount)
  1253. additionalCostItem.push({ itemName: '中型犬', price: this.calculatePetCost({
  1254. petType: 'dog',
  1255. bodyType: '中型',
  1256. }), quantity: chargeableMediumDogCount, unit: '只' })
  1257. }
  1258. if (chargeableSmallDogCount > 0) {
  1259. additionalCost += (this.calculatePetCost({
  1260. petType: 'dog',
  1261. bodyType: '小型',
  1262. }) * chargeableSmallDogCount)
  1263. additionalCostItem.push({ itemName: '小型犬', price: this.calculatePetCost({
  1264. petType: 'dog',
  1265. bodyType: '小型',
  1266. }), quantity: chargeableSmallDogCount, unit: '只' })
  1267. }
  1268. if (chargeableCatCount > 0) {
  1269. additionalCost += (this.calculatePetCost({
  1270. petType: 'cat',
  1271. }) * chargeableCatCount)
  1272. additionalCostItem.push({ itemName: '猫猫', price: this.calculatePetCost({
  1273. petType: 'cat',
  1274. }), quantity: chargeableCatCount, unit: '只' })
  1275. }
  1276. // 当日多次服务次数 - 基础价格乘以倍数
  1277. let multServicesTotalCost = 0
  1278. const maxFeedCount = Math.max(...currentDayPets.map(pet => pet.feedCount));
  1279. if (maxFeedCount === 2) {
  1280. multServicesTotalCost += baseServiceCost * this.price_config.multiService.two.price; // 基础价格 × 2次倍数
  1281. } else if (maxFeedCount === 3) {
  1282. multServicesTotalCost += baseServiceCost * this.price_config.multiService.three.price; // 基础价格 × 3次倍数
  1283. }
  1284. // 所有宠物定制服务费用
  1285. const customServiceCost = currentDayPets.reduce((acc, pet) => acc + this.calculatePetCustomServiceCost(pet), 0)
  1286. const totalCost = baseServiceCost + additionalCost + multServicesTotalCost + customServiceCost
  1287. this.currentDayPrice = totalCost
  1288. },
  1289. calculatePetCustomServiceCost(pet) {
  1290. const customServiceCost = pet.customServices.reduce((acc, item) => acc + item.price * item.quantity, 0)
  1291. return customServiceCost
  1292. },
  1293. getCurrentPetName() {
  1294. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  1295. return currentPet.name
  1296. },
  1297. setCurrentPetIsAllSame() {
  1298. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  1299. currentPet.isAllSame = this.isAllSame
  1300. },
  1301. getCurrentPetIsAllSame() {
  1302. const currentPet = this.currentPets.find(pet => pet.id === this.currentPetId)
  1303. this.isAllSame = currentPet.isAllSame
  1304. },
  1305. },
  1306. computed: {
  1307. sortedGroupedDates() {
  1308. return this.groupedDates.sort((a, b) => {
  1309. const dateA = new Date(a.monthLabel.replace('年', '-').replace('月', '-01'))
  1310. const dateB = new Date(b.monthLabel.replace('年', '-').replace('月', '-01'))
  1311. return dateA - dateB
  1312. })
  1313. }
  1314. }
  1315. }
  1316. </script>
  1317. <style scoped lang="less">
  1318. .container {
  1319. position: relative;
  1320. height: 100%;
  1321. padding-bottom: 160rpx;
  1322. .details-subscribe {
  1323. background-color: #FFFFFF;
  1324. padding: 10px;
  1325. width: 100%;
  1326. height: 160rpx;
  1327. position: fixed;
  1328. bottom: 0;
  1329. z-index: 100;
  1330. .details-btn {
  1331. width: 100%;
  1332. border-radius: 6px;
  1333. background: #FFB13F;
  1334. font-size: 16px;
  1335. color: #FFFFFF;
  1336. }
  1337. }
  1338. }
  1339. .service-new {
  1340. .service-new-flag {
  1341. width: 8rpx;
  1342. height: 32rpx;
  1343. background: #FFBF60;
  1344. border-radius: 30rpx 30rpx 30rpx 30rpx;
  1345. margin-right: 10rpx;
  1346. }
  1347. .split-line {
  1348. width: 100%;
  1349. height: 1rpx;
  1350. background: #EFEFEF;
  1351. }
  1352. .service-new-title {
  1353. display: flex;
  1354. font-weight: 500;
  1355. font-size: 28rpx;
  1356. color: #333333;
  1357. line-height: 33rpx;
  1358. margin: 42rpx 0 30rpx;
  1359. justify-content: space-between;
  1360. .service-new-title-left {
  1361. display: flex;
  1362. align-items: center;
  1363. }
  1364. }
  1365. .service-new-pet-content {
  1366. padding: 20rpx 0;
  1367. }
  1368. .service-new-pet-item {
  1369. height: 96rpx;
  1370. width: 184rpx;
  1371. border-radius: 8rpx;
  1372. padding: 0 20rpx;
  1373. margin-right: 40rpx;
  1374. display: flex;
  1375. align-items: center;
  1376. justify-content: center;
  1377. font-size: 28rpx;
  1378. flex-shrink: 0;
  1379. }
  1380. .scroll-content {
  1381. display: inline-flex;
  1382. }
  1383. .scroll-view {
  1384. width: 100%;
  1385. white-space: nowrap;
  1386. }
  1387. .pet-selected {
  1388. background: #FFBF60;
  1389. color: #FFFFFF;
  1390. }
  1391. .pet-unselect {
  1392. background: #F5F5F7;
  1393. color: #7D8196;
  1394. }
  1395. }
  1396. .calendar-wrapper {
  1397. display: flex;
  1398. gap: 20rpx;
  1399. padding: 20rpx;
  1400. }
  1401. .scroll-view {
  1402. width: 100%;
  1403. white-space: nowrap;
  1404. }
  1405. .calendar-day {
  1406. position: relative;
  1407. width: 80rpx;
  1408. height: 80rpx;
  1409. display: flex;
  1410. align-items: center;
  1411. justify-content: center;
  1412. cursor: pointer;
  1413. margin-right: 20rpx;
  1414. flex-shrink: 0;
  1415. }
  1416. .calendar-bg {
  1417. position: absolute;
  1418. width: 88rpx;
  1419. height: 78rpx;
  1420. z-index: 1;
  1421. }
  1422. .day-text {
  1423. position: relative;
  1424. z-index: 2;
  1425. top: 5rpx;
  1426. }
  1427. .day-highlighted {
  1428. font-size: 38rpx;
  1429. font-weight: bold;
  1430. color: #FFBF60;
  1431. }
  1432. .day-normal {
  1433. color: #3E3A39;
  1434. font-size: 32rpx;
  1435. }
  1436. .month-group {
  1437. margin-bottom: 30rpx;
  1438. .month-title {
  1439. font-size: 32rpx;
  1440. color: #666;
  1441. margin-bottom: 20rpx;
  1442. }
  1443. .dates-wrapper {
  1444. display: inline-flex;
  1445. }
  1446. }
  1447. .scroll-view-vertical {
  1448. height: 100%;
  1449. }
  1450. .scroll-view-horizontal {
  1451. width: 100%;
  1452. white-space: nowrap;
  1453. }
  1454. .time-slots {
  1455. display: flex;
  1456. justify-content: space-around;
  1457. }
  1458. .time-slot-item {
  1459. display: flex;
  1460. flex-direction: column;
  1461. align-items: center;
  1462. width: 200rpx;
  1463. cursor: pointer;
  1464. }
  1465. .time-slot-icon {
  1466. width: 160rpx;
  1467. height: 160rpx;
  1468. margin-bottom: 10rpx;
  1469. }
  1470. .time-slot-info {
  1471. display: flex;
  1472. flex-direction: column;
  1473. align-items: center;
  1474. }
  1475. .time-slot-name {
  1476. font-size: 28rpx;
  1477. color: #333;
  1478. margin-bottom: 8rpx;
  1479. }
  1480. .time-slot-time {
  1481. font-size: 24rpx;
  1482. color: #666;
  1483. }
  1484. .time-slot-time-tip {
  1485. background-color: #FFECCD;
  1486. color: #A94F20;
  1487. margin-left: 10rpx;
  1488. padding: 5rpx 10rpx;
  1489. font-size: 20rpx;
  1490. }
  1491. .service-item {
  1492. margin-bottom: 20rpx;
  1493. /* 每个服务项之间的间距 */
  1494. }
  1495. .service-item-header {
  1496. display: flex;
  1497. align-items: center;
  1498. margin-bottom: 10rpx;
  1499. /* 标题与服务列表之间的间距 */
  1500. }
  1501. .service-icon {
  1502. width: 40rpx;
  1503. /* 图标大小 */
  1504. height: 40rpx;
  1505. /* 图标大小 */
  1506. margin-right: 10rpx;
  1507. /* 图标与标题之间的间距 */
  1508. }
  1509. .service-title {
  1510. font-size: 28rpx;
  1511. /* 服务标题字体大小 */
  1512. font-weight: bold;
  1513. /* 服务标题加粗 */
  1514. }
  1515. .service-row {
  1516. display: flex;
  1517. align-items: center;
  1518. /* 垂直居中对齐 */
  1519. flex-wrap: wrap;
  1520. background-color: #F9F9F9;
  1521. }
  1522. .service-row-content {
  1523. display: flex;
  1524. justify-content: space-between;
  1525. /* 每行的上下内边距 */
  1526. width: 100%;
  1527. padding: 32rpx 0rpx;
  1528. margin: 0 20rpx;
  1529. }
  1530. .service-name {
  1531. width: 50%;
  1532. white-space: nowrap;
  1533. overflow: hidden;
  1534. text-overflow: ellipsis;
  1535. font-size: 28rpx;
  1536. color: #333;
  1537. /* 服务名称颜色 */
  1538. }
  1539. .service-price {
  1540. display: flex;
  1541. align-items: center;
  1542. /* 垂直居中对齐 */
  1543. }
  1544. .service-count {
  1545. display: flex;
  1546. align-items: center;
  1547. /* 垂直居中对齐 */
  1548. margin-left: 10rpx;
  1549. /* 价格数量之间的间距 */
  1550. }
  1551. .price-details {
  1552. position: fixed;
  1553. /* 固定位置 */
  1554. bottom: 160rpx;
  1555. /* 根据需要调整位置 */
  1556. left: 0;
  1557. right: 0;
  1558. background: #FFF;
  1559. /* 背景颜色 */
  1560. padding: 10px 10px 0 10px;
  1561. /* 内边距 */
  1562. border-radius: 8rpx 8rpx 0 0;
  1563. /* 圆角 */
  1564. z-index: 1000;
  1565. /* 确保在其他元素之上 */
  1566. min-height: 600rpx;
  1567. /* 固定高度 */
  1568. overflow: hidden;
  1569. /* 隐藏超出部分 */
  1570. }
  1571. .price-details-header {
  1572. display: flex;
  1573. justify-content: space-between;
  1574. align-items: center;
  1575. }
  1576. .price-details-body {
  1577. margin-top: 10px;
  1578. max-height: 300rpx;
  1579. /* 留出头部空间 */
  1580. overflow-y: auto;
  1581. /* 允许上下滚动 */
  1582. }
  1583. .price-details-overlay {
  1584. position: fixed;
  1585. /* 固定位置 */
  1586. top: 0;
  1587. left: 0;
  1588. right: 0;
  1589. bottom: 0;
  1590. background: rgba(0, 0, 0, 0.5);
  1591. /* 半透明背景 */
  1592. z-index: 999;
  1593. /* 确保在其他元素之上 */
  1594. display: flex;
  1595. justify-content: center;
  1596. align-items: center;
  1597. }
  1598. .price-details-item {
  1599. display: flex;
  1600. justify-content: space-between;
  1601. margin-bottom: 20rpx;
  1602. .price-details-item-price-total {
  1603. display: flex;
  1604. width: 70%;
  1605. justify-content: flex-end;
  1606. flex-wrap: wrap;
  1607. }
  1608. .price-details-item-price-total-item {
  1609. color: #999999;
  1610. text-align: right;
  1611. font-size: 28rpx;
  1612. margin-right: 20rpx;
  1613. }
  1614. }
  1615. </style>