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.

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