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.

1097 lines
31 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="service-new container">
  3. <view class="service-new-address">
  4. <uni-card padding=0 :is-shadow="false">
  5. <view class="service-new-title" slot="title">
  6. <view class="service-new-title-left">
  7. <view class="service-new-flag"></view>
  8. <view>服务地址</view>
  9. </view>
  10. </view>
  11. <view class="split-line"></view>
  12. <view class="service-new-address-content">
  13. <view class="service-new-address-selected">
  14. <view class="personal-address-info">
  15. <view class="personal-address-text">
  16. {{currentAddress.province}} {{currentAddress.city}} {{currentAddress.detailAddress}}
  17. </view>
  18. <view class="personal-address-people">
  19. <view>
  20. {{currentAddress.name}}
  21. </view>
  22. <view style="border: solid #7D8196 1px; margin: 0 10px; height: 12px;"> </view>
  23. <view>
  24. {{currentAddress.phone}}
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </uni-card>
  31. </view>
  32. <view class="service-new-pet">
  33. <uni-card padding=0 :is-shadow="false">
  34. <view class="service-new-title" slot="title">
  35. <view class="service-new-title-left">
  36. <view class="service-new-flag">
  37. </view>
  38. <view class="service-new-title-text">
  39. 服务宠物
  40. </view>
  41. </view>
  42. </view>
  43. <view class="split-line"></view>
  44. <view class="service-new-pet-content">
  45. <view class="personal-pet-list">
  46. <view v-for="(item,index) in showPets" :key="index">
  47. <view class="personal-pet-list-item">
  48. <view class="personal-pet-info">
  49. <!-- 左侧头像 -->
  50. <view class="pet-avatar">
  51. <u-avatar :src="item.photo?item.photo:defaultPhoto" size="60"
  52. shape="circle"></u-avatar>
  53. </view>
  54. <!-- 中间内容 -->
  55. <view class="pet-info" style="flex: 1; margin: 0 20rpx; max-width: 50%;">
  56. <view class="pet-name-gender" style="display: flex; align-items: center;">
  57. <view>{{item.name}}</view>
  58. <view class="pet-gender"
  59. style="margin-left: 10rpx; display: flex;align-items: center;">
  60. <img :src="item.gender=='男生'?'../../static/images/details/boy.svg':'../../static/images/details/girl.svg'"
  61. alt="sex" style="width: 16px;height: 16px;" />
  62. </view>
  63. </view>
  64. <view class="pet-dates ellipsis">
  65. {{ item.pets.map(e=>e.serviceDate).join(';') }}
  66. </view>
  67. </view>
  68. <!-- 右侧天数统计 -->
  69. <view class="date-total" style="margin-left: auto;width: 140rpx;text-align: end;">
  70. {{item.pets.length}}
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </uni-card>
  78. </view>
  79. <view class="service-new-pet">
  80. <uni-card padding=0 :is-shadow="false">
  81. <view class="service-new-title" slot="title">
  82. <view class="service-new-title-left">
  83. <view class="service-new-flag">
  84. </view>
  85. <view class="service-new-title-text">
  86. 服务信息及费用
  87. </view>
  88. </view>
  89. </view>
  90. <view class="split-line"></view>
  91. <view class="service-new-pet-content">
  92. <view class="personal-pet-list">
  93. <view v-for="item in dailyShowData" :key="item.date" class="service-new-address">
  94. <view class="service-summary">
  95. <view style="display: flex; align-items: center;">
  96. <view style="padding-right: 10rpx;color: #7D8196;">{{ getDateText(item.date) }}</view>
  97. <!-- <view style="padding-right: 10rpx;color: #7D8196;">{{ item.date }}</view> -->
  98. <view
  99. style="margin: 0 10rpx; width: 2px; height: 20rpx; background-color: #7D8196;">
  100. </view>
  101. <view style="color: #333333; margin-left: 10rpx;">{{baseProduct}}
  102. {{item.customServicesTotalCnt? ' + 定制服务' + item.customServicesTotalCnt + '项' : '' }}
  103. </view>
  104. </view>
  105. <view style="display: flex; align-items: center;">
  106. <view style="color: #333333;margin-right: 10rpx;">¥{{ item.totalCost }}.00</view>
  107. <view>
  108. <u-icon @click="toggleExpand( item.date )"
  109. :name="expandedIndexs.includes( item.date ) ? 'arrow-up' : 'arrow-down'"
  110. color="#FFBF60" size="14"></u-icon>
  111. </view>
  112. </view>
  113. </view>
  114. <view v-if="!expandedIndexs.includes(item.date)" class="split-line"></view>
  115. <view v-show="expandedIndexs.includes(item.date)" class="service-details">
  116. <!-- 基础服务 上门次数 额外费用 -->
  117. <view>基础服务</view>
  118. <view v-for="(priceItem, priceIndex) in item.priceDetails" :key="priceIndex"
  119. class="price-details-item">
  120. <view style="display: flex;" v-for="(item2, index) in priceItem.item" :key="index">
  121. <view v-if="item2.quantity" class="service-item">
  122. <view v-if="item2.itemName != item.name"
  123. class="price-details-item-price-total-item">- {{ item2.itemName }}
  124. </view>
  125. <view class="price-details-item-price-total-item">¥{{ item2.price }} ×
  126. {{ item2.quantity }} {{ item2.unit }}</view>
  127. </view>
  128. </view>
  129. </view>
  130. <view v-if="item.customServicesTotalCnt>0" style="margin-top: 20rpx;">定制服务</view>
  131. <view v-for="(pet, petIndex) in item.pets" :key="petIndex">
  132. <view
  133. v-if="pet.customServices &&pet.customServices.filter(e=>e.quantity>0).length>0"
  134. style="display: flex; align-items: center; justify-content: flex-start; margin-top: 20rpx;">
  135. <view class="pet-avatar">
  136. <u-avatar :src="pet.photo?pet.photo:defaultPhoto" size="34"
  137. shape="circle"></u-avatar>
  138. </view>
  139. <view style="margin-left: 20rpx;">{{ pet.name}}</view>
  140. </view>
  141. <!-- 定制服务 -->
  142. <view v-for="(customItem, customIndex) in pet.customServices" :key="customIndex">
  143. <view v-if="customItem.quantity" class="service-item">
  144. <view>- {{ customItem.name }}</view>
  145. <view>¥{{ customItem.price }} × {{ customItem.quantity }} </view>
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. <view class="service-new-address">
  152. <view v-if="needPreFamiliarize.length>0" class="total-cost">
  153. <view>提前熟悉 </view>
  154. <view>¥40</view>
  155. </view>
  156. <view class="total-cost">
  157. <view>费用总计 </view>
  158. <view>¥{{ originalTotalPrice }}</view>
  159. </view>
  160. <view class="total-cost">
  161. <view>平台优惠</view>
  162. <view style="color: #FF530A;">-¥{{ discount }}
  163. <uni-icons type="right" size="28rpx" color="#AAA" @click="selectCoupon"></uni-icons>
  164. </view>
  165. </view>
  166. <view class="total-cost">
  167. <view>会员折扣</view>
  168. <view style="display: flex; align-items: center;">
  169. <view style="color: #999999;">{{ currentMember.itemType }}</view>
  170. <view style="border: solid #7D8196 1px; margin: 0 10rpx; height: 12px;"> </view>
  171. <view style="color: #FF530A;">-¥{{ memberDiscount }}</view>
  172. </view>
  173. </view>
  174. <view class="total-cost">
  175. <view>应付费用</view>
  176. <view style="font-weight: 500;font-size: 32rpx;">¥{{ finalPrice }}</view>
  177. </view>
  178. </view>
  179. </view>
  180. </view>
  181. </uni-card>
  182. </view>
  183. <view class="service-new-pet">
  184. <uni-card padding=0 :is-shadow="false">
  185. <view class="service-new-title" slot="title">
  186. <view class="service-new-title-left">
  187. <view class="service-new-flag">
  188. </view>
  189. <view class="service-new-title-text">
  190. 服务细则
  191. </view>
  192. </view>
  193. </view>
  194. <view class="split-line"></view>
  195. <view class="service-new-details-content">
  196. <view style="margin: 30rpx 0;">
  197. <u-checkbox-group @change="changePreFamiliarize" :value="needPreFamiliarize"
  198. iconPlacement="right" placement="column">
  199. <u-checkbox activeColor="#FFBF60" label="是否提前熟悉" name="是否提前熟悉" shape="circle"></u-checkbox>
  200. </u-checkbox-group>
  201. </view>
  202. <view class="split-line"></view>
  203. <view class="service-new-details-desc">
  204. <view style="display: flex;">
  205. <text style="width: 20rpx;">*</text>
  206. <text style="flex: 1;">价格40元/</text>
  207. </view>
  208. <view style="display: flex; margin: 20rpx 0;">
  209. <text style="width: 20rpx;">*</text>
  210. <text style="flex: 1;">服务内容: 购买此服务后伴宠师将在您离家前按照约定日期提前上门沟通熟悉喂养要求及宠物</text>
  211. </view>
  212. <view style="display: flex;">
  213. <text style="width: 20rpx;">*</text>
  214. <text style="flex: 1;">服务保障: 购买此服务后平台支持在提前熟悉后上门服务第一天前无理由免费更换伴宠师1次</text>
  215. </view>
  216. </view>
  217. </view>
  218. </uni-card>
  219. </view>
  220. <view class="details-subscribe">
  221. <view class="details-radio" style="width: 100%;padding-bottom: 20rpx;">
  222. <view>
  223. <u-checkbox-group v-model="isAgree" size="16" labelSize="14" labelColor="#999999">
  224. <u-checkbox activeColor="#FFBF60" label="我同意" name="我同意" labelSize="14" size="14"
  225. shape="circle"></u-checkbox>
  226. </u-checkbox-group>
  227. </view>
  228. <text style="color: #FFBF60;font-size: 28rpx;" @click="checkAgreement">猫妈狗爸用户服务协议和隐私协议</text>
  229. </view>
  230. <view style="display: flex;justify-content: space-between; align-items: center;">
  231. <view style="height: 80rpx; display: flex; align-items: center;">
  232. <text style="color: #333333;">订单总价: </text>
  233. <text style="color: #FF530A; font-size: 40rpx;">¥{{ finalPrice }} <text
  234. style="font-size: 32rpx;"></text></text>
  235. </view>
  236. <view style="display: flex;">
  237. <u-button color="#FFF4E4" customStyle="width: 200rpx; color: #FFAA48; margin-right: 20rpx;"
  238. text="上一步" @click="goBack"></u-button>
  239. <u-button color="#FFBF60" customStyle="width: 200rpx; color: #FFF;" text="支付"
  240. @click="goNext"></u-button>
  241. </view>
  242. </view>
  243. </view>
  244. <view v-if="showCoupon" class="calendar-popup">
  245. <view class="calendar-mask"></view>
  246. <view class="calendar-content">
  247. <view class="price-details">
  248. <view class="price-details-header">
  249. <text
  250. style="text-align: center; width: 100%; font-size: 32rpx; font-weight: 500; color: #333333;">优惠券</text>
  251. <u-icon name="close" @click="togglePriceDetails"></u-icon>
  252. </view>
  253. <view class="split-line"></view>
  254. <scroll-view class="price-details-body" scroll-y v-if="showCouponList">
  255. <view v-for="(item,index) in couponList" style="padding-bottom:14px;" :key="index">
  256. <view class="coupon-card">
  257. <view class="card-left"><text
  258. style="font-size: 40rpx; margin-left: 5rpx;">{{ getCouponAmountOrDiscount(item) }}</text>
  259. </view>
  260. <view class="card-right">
  261. <view class="card-content">
  262. <view class="card-info">{{item.stockName}}</view>
  263. <view class="card-time">有效期限: {{item.expireTime.slice(0, 10)}}截止</view>
  264. </view>
  265. <view style="width: 20%;">
  266. <u-checkbox-group :value="item.checked" @change="changeCoupon">
  267. <u-checkbox :disabled="item.transactionMinimum > originalTotalPrice"
  268. shape="circle" :name="item.id" activeColor="#ffbf60"></u-checkbox>
  269. </u-checkbox-group>
  270. </view>
  271. </view>
  272. </view>
  273. </view>
  274. </scroll-view>
  275. </view>
  276. <u-button color="#FFBF60" type="primary" @click="confirmCoupon">确定</u-button>
  277. </view>
  278. </view>
  279. </view>
  280. </template>
  281. <script>
  282. import {
  283. getPersonalInfo,
  284. getCouponList,
  285. getCouponListForOrder
  286. } from "@/api/system/personal.js"
  287. import {
  288. getToken,
  289. getOpenIdKey
  290. } from '@/utils/auth'
  291. import {
  292. createOrderNew
  293. } from '@/api/system/user.js'
  294. import dayjs from '@/utils/lib/dayjs.min.js'
  295. export default {
  296. data() {
  297. return {
  298. isPaying: false,
  299. currentAddress: {},
  300. currentPetsByDay: [],
  301. showPets: [],
  302. expandedIndexs: [],
  303. isAgree: false,
  304. needPreFamiliarize: [],
  305. dailyShowData: [],
  306. originalTotalPrice: 0,
  307. totalPrice: 0, // 总费用
  308. discount: 0, // 平台优惠
  309. memberDiscount: 0, // 会员折扣
  310. finalPrice: 0, // 应付费用
  311. defaultPhoto: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png',
  312. currentMember: {},
  313. memberDiscountList: [{
  314. itemType: "新晋家长9.5折优惠",
  315. discount: 0.05
  316. },
  317. {
  318. itemType: "普卡会员9折优惠",
  319. discount: 0.1
  320. },
  321. {
  322. itemType: "银卡会员8.8折优惠",
  323. discount: 0.12
  324. },
  325. {
  326. itemType: "金卡会员8.5折优惠",
  327. discount: 0.15
  328. }
  329. ],
  330. couponList: [],
  331. showCoupon: false,
  332. selectedCoupon: null,
  333. showCouponList: true,
  334. couponId: null,
  335. basePrice: 0,
  336. baseProduct: '',
  337. }
  338. },
  339. onLoad() {
  340. if (getToken() && getOpenIdKey()) {
  341. this.getPersonalInfo()
  342. }
  343. this.originalTotalPrice = this.$globalData.newOrderData.totalPrice
  344. if (this.originalTotalPrice) {
  345. this.basePrice = this.$globalData.mainSku[0].price
  346. this.baseProduct = this.$globalData.mainSku[0].name
  347. this.currentAddress = this.$globalData.newOrderData.currentAddress
  348. this.currentPetsByDay = this.$globalData.newOrderData.currentPetsByDay
  349. this.needPreFamiliarize = this.$globalData.newOrderData.needPreFamiliarize
  350. } else {
  351. // 返回首页
  352. uni.reLaunch({
  353. url: '/pages/index'
  354. });
  355. }
  356. this.getCouponList()
  357. this.getShowPets()
  358. this.groupPetsByDate()
  359. // this.totalPrice = this.$globalData.newOrderData.totalPrice
  360. },
  361. methods: {
  362. getDateText(date){
  363. return dayjs(date).format('MM-DD')
  364. },
  365. // 将currentPets转换为showPets
  366. getShowPets() {
  367. const showPets = []
  368. // 将 currentPetsByDay 通过petId分组
  369. const groupedPets = this.currentPetsByDay.reduce((acc, pet) => {
  370. pet.index = pet.petId + '-' + pet.serviceDate
  371. if (!acc[pet.petId]) {
  372. acc[pet.petId] = []; // 如果不存在,则初始化一个空数组
  373. }
  374. acc[pet.petId].push(pet); // 将当前宠物添加到对应的 petId 数组中
  375. return acc;
  376. }, {});
  377. console.log(groupedPets)
  378. // 循环将pets转换为showPets
  379. for (let petId in groupedPets) {
  380. const showPet = {
  381. petId: petId,
  382. name: groupedPets[petId][0].name,
  383. gender: groupedPets[petId][0].gender,
  384. petType: groupedPets[petId][0].petType,
  385. bodyType: groupedPets[petId][0].bodyType,
  386. photo: groupedPets[petId][0].photo,
  387. pets: groupedPets[petId]
  388. }
  389. showPets.push(showPet)
  390. }
  391. this.showPets = showPets
  392. console.log(this.showPets)
  393. },
  394. // 将宠物按天分组
  395. groupPetsByDate() {
  396. const dailyShowData = []
  397. const dailyPets = [];
  398. // 按日期分组宠物
  399. this.currentPetsByDay.forEach(pet => {
  400. const serviceDate = pet.serviceDate;
  401. if (!dailyPets[serviceDate]) {
  402. dailyPets[serviceDate] = [];
  403. }
  404. dailyPets[serviceDate].push(pet);
  405. });
  406. // 计算每日费用
  407. for (const date in dailyPets) {
  408. const pets = dailyPets[date];
  409. const priceDetails = []
  410. // 基础服务
  411. const baseServiceCost = this.basePrice
  412. const largeDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('大型')).length;
  413. let mediumDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('中型')).length;
  414. let smallDogCount = pets.filter(pet => pet.petType === 'dog' && pet.bodyType.includes('小型')).length;
  415. let catCount = pets.filter(pet => pet.petType === 'cat').length;
  416. const additionalCostItem = []
  417. let additionalCost = 0
  418. // 单天总宠物费用
  419. let totalPetCost = pets.reduce((acc, pet) => {
  420. return acc + this.calculatePetCost(pet);
  421. }, 0);
  422. // 如果总宠物费用>30
  423. if (totalPetCost > 30) {
  424. // 如果猫数量>=3,则免3只猫
  425. if (catCount >= 3) {
  426. additionalCost = totalPetCost - 30
  427. catCount = catCount - 3
  428. } else if (smallDogCount >= 2) { // 如果小型犬数量>=2,则免2只小型犬
  429. additionalCost = totalPetCost - 30
  430. smallDogCount = smallDogCount - 2
  431. } else if (mediumDogCount >= 1) { // 如果中型犬数量>=1,则免1只中型犬
  432. additionalCost = totalPetCost - 30
  433. mediumDogCount = mediumDogCount - 1
  434. } else {
  435. additionalCost = totalPetCost - 25
  436. catCount = catCount - 1
  437. smallDogCount = smallDogCount - 1
  438. }
  439. if (mediumDogCount > 0) {
  440. additionalCostItem.push({
  441. itemName: '中型犬',
  442. price: 30,
  443. quantity: mediumDogCount,
  444. unit: '只'
  445. })
  446. }
  447. if (smallDogCount > 0) {
  448. additionalCostItem.push({
  449. itemName: '小型犬',
  450. price: 15,
  451. quantity: smallDogCount,
  452. unit: '只'
  453. })
  454. }
  455. if (catCount > 0) {
  456. additionalCostItem.push({
  457. itemName: '猫猫',
  458. price: 10,
  459. quantity: catCount,
  460. unit: '只'
  461. })
  462. }
  463. }
  464. // 如果有大型犬,额外费用为40元/只
  465. if (largeDogCount > 0) {
  466. additionalCost += (40 * largeDogCount)
  467. additionalCostItem.push({
  468. itemName: '大型犬',
  469. price: 40,
  470. quantity: largeDogCount,
  471. unit: '只'
  472. })
  473. }
  474. // 当日多次服务次数
  475. let multServicesTotalCost = 0
  476. const maxFeedCount = Math.max(...pets.map(pet => pet.feedCount));
  477. if (maxFeedCount === 2) {
  478. multServicesTotalCost += 45; // 1天2次
  479. } else if (maxFeedCount === 3) {
  480. multServicesTotalCost += 130; // 1天3次
  481. }
  482. priceDetails.push({
  483. name: '专业喂养',
  484. item: [{
  485. itemName: '专业喂养',
  486. price: baseServiceCost,
  487. quantity: 1,
  488. unit: '天'
  489. }, ]
  490. })
  491. priceDetails.push({
  492. name: '上门次数',
  493. item: [{
  494. itemName: '1天2次',
  495. price: 45,
  496. quantity: maxFeedCount === 2 ? 1 : 0,
  497. unit: '天'
  498. },
  499. {
  500. itemName: '1天3次',
  501. price: 130,
  502. quantity: maxFeedCount === 3 ? 1 : 0,
  503. unit: '天'
  504. },
  505. ]
  506. })
  507. if (additionalCostItem.length > 0) {
  508. priceDetails.push({
  509. name: '额外宠物费用',
  510. item: additionalCostItem
  511. })
  512. }
  513. // 所有宠物定制服务费用
  514. const customServiceCost = pets.reduce((acc, pet) => acc + this.calculatePetCustomServiceCost(pet), 0)
  515. const totalCost = baseServiceCost + additionalCost + multServicesTotalCost + customServiceCost
  516. // 所有宠物定制服务总项数,每个类型的服务只算一次
  517. const acc = []
  518. pets.map(pet => {
  519. pet.customServices.forEach(service => {
  520. if (!acc.includes(service.skuId) && service.quantity > 0) {
  521. acc.push(service.skuId)
  522. }
  523. })
  524. })
  525. const customServicesTotalCnt = acc.length
  526. dailyShowData.push({
  527. date,
  528. pets,
  529. priceDetails,
  530. totalCost,
  531. customServicesTotalCnt
  532. })
  533. }
  534. // 将dailyShowData按日期排序
  535. this.dailyShowData = dailyShowData.sort((a, b) => new Date(a.date) - new Date(b.date))
  536. this.getShowTotalPrice()
  537. },
  538. calculatePetCost(pet) {
  539. // 宠物额外费用 不计算大型犬
  540. let petCost = 0;
  541. if (pet.petType === 'cat') {
  542. petCost += 10; // 猫额外费用
  543. } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) {
  544. petCost += 15; // 小型犬额外费用
  545. } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) {
  546. petCost += 30; // 中型犬额外费用
  547. }
  548. return petCost;
  549. },
  550. // 计算宠物定制服务费用
  551. calculatePetCustomServiceCost(pet) {
  552. const customServiceCost = pet.customServices.reduce((acc, item) => acc + item.price * item.quantity, 0)
  553. return customServiceCost
  554. },
  555. // 展开或收起服务详情
  556. toggleExpand(index) {
  557. console.log(index)
  558. this.expandedIndexs = this.expandedIndexs.includes(index) ? this.expandedIndexs.filter(i => i !== index) :
  559. [...this.expandedIndexs, index];
  560. // this.expandedIndexs.push(index)
  561. console.log(this.expandedIndexs)
  562. },
  563. goBack() {
  564. let len = getCurrentPages().length;
  565. if (len >= 2) {
  566. uni.navigateBack();
  567. } else {
  568. uni.redirectTo({
  569. url: '/pages/newOrder/serviceNew2'
  570. });
  571. }
  572. },
  573. changeAgree() {
  574. this.isAgree = !this.isAgree
  575. },
  576. checkAgreement() {
  577. uni.navigateTo({
  578. url: '/pages/details/agreement'
  579. });
  580. },
  581. // 节流
  582. throttle(func, delay) {
  583. let lastCall = 0;
  584. return function(...args) {
  585. const now = new Date().getTime();
  586. if (now - lastCall < delay) {
  587. return;
  588. }
  589. lastCall = now;
  590. func(...args);
  591. }
  592. },
  593. getPersonalInfo() {
  594. getPersonalInfo().then(res => {
  595. if (res && (res.id || res.id === 0)) {
  596. let userLevel = res.level
  597. this.currentMember = this.memberDiscountList.find(item => {
  598. if (item.itemType.includes(userLevel)) {
  599. return item
  600. }
  601. })
  602. this.getShowTotalPrice()
  603. }
  604. })
  605. },
  606. // 获取优惠券列表
  607. getCouponList() {
  608. getCouponListForOrder().then(res => {
  609. let rows = res.rows
  610. console.log(rows)
  611. this.couponList = rows.filter(item => item.couponState == "SENDED")
  612. this.couponList.forEach(item => {
  613. item.checked = []
  614. item.couponAmount = 20
  615. })
  616. })
  617. },
  618. selectCoupon() {
  619. this.showCoupon = true
  620. },
  621. changeCoupon(item) {
  622. this.showCouponList = false
  623. this.couponList.forEach(coupon => {
  624. if (coupon.id != item[0]) {
  625. coupon.checked = null
  626. } else {
  627. coupon.checked = item
  628. }
  629. })
  630. this.showCouponList = true
  631. },
  632. confirmCoupon() {
  633. this.selectedCoupon = this.couponList.find(coupon => coupon.checked && coupon.checked.length > 0)
  634. if (!this.selectedCoupon) {
  635. this.couponId = null
  636. this.discount = 0
  637. } else {
  638. this.couponId = this.selectedCoupon?.id
  639. // 如果优惠券是折扣
  640. if (this.selectedCoupon?.stockType == "PDISCOUNT" && this.selectedCoupon?.discountPercent > 0) {
  641. //保留两位小数
  642. this.discount = (this.originalTotalPrice * (1 - this.selectedCoupon.discountPercent / 100))
  643. .toFixed(2)
  644. } else {
  645. this.discount = this.selectedCoupon?.discountAmount
  646. }
  647. }
  648. this.getShowTotalPrice()
  649. this.showCoupon = false
  650. },
  651. togglePriceDetails() {
  652. this.showCoupon = !this.showCoupon
  653. },
  654. // 构造订单
  655. constructOrder() {
  656. const order = {
  657. openId: getOpenIdKey(),
  658. addressId: this.currentAddress.id,
  659. totalPrice: this.finalPrice,
  660. needPreFamiliarize: this.needPreFamiliarize.length > 0,
  661. couponId: this.couponId,
  662. petOrderServices: this.getPetOrderServices(this.currentPetsByDay),
  663. }
  664. if(this.buyInfo.teacher){
  665. order.teacherId = this.buyInfo.teacher.userId
  666. }else{
  667. //打印
  668. console.log(this.$globalData.newOrderData.companionLevel);
  669. order.companionLevel = ['', 'junior', 'senior'].indexOf(this.$globalData.newOrderData.companionLevel)
  670. }
  671. console.log(order)
  672. return order
  673. },
  674. getSkuList(customServices, feedCount) {
  675. const skuList = customServices.filter(service => service.quantity > 0).map(service2 => {
  676. return {
  677. skuId: service2.skuId,
  678. quantity: service2.quantity,
  679. isMainProduct: service2.isMainProduct
  680. }
  681. })
  682. skuList.push({
  683. skuId: this.$globalData.mainSku[0].skuId,
  684. quantity: feedCount,
  685. isMainProduct: true
  686. })
  687. return skuList
  688. },
  689. getPetOrderServices(currentPetsByDay) {
  690. const petOrderServices = currentPetsByDay.map(pet => {
  691. return {
  692. petId: pet.petId,
  693. serviceDate: pet.serviceDate,
  694. feedCount: pet.feedCount,
  695. selectedTimeSlots: pet.selectedTimeSlots.join(','),
  696. skuList: this.getSkuList(pet.customServices, pet.feedCount)
  697. }
  698. })
  699. return petOrderServices
  700. },
  701. pay(params) {
  702. if (this.isPaying) {
  703. return;
  704. }
  705. this.isPaying = true
  706. uni.requestPayment({
  707. provider: 'wxpay',
  708. timeStamp: params.timeStamp,
  709. nonceStr: params.nonceStr,
  710. package: params.package_,
  711. signType: params.signType,
  712. paySign: params.paySign,
  713. success: (res) => {
  714. this.$modal.showToast('支付成功')
  715. this.$globalData.newOrderData = {
  716. currentAddress: {},
  717. currentPets: [],
  718. totalPrice: 0,
  719. needPreFamiliarize: []
  720. }
  721. uni.reLaunch({
  722. url: '/pages_order/order/payOrderSuccessful'
  723. // url: '/pages/details/successful'
  724. });
  725. },
  726. fail: (err) => {
  727. this.loading = false
  728. console.log('支付失败', err)
  729. this.$modal.showToast('支付失败')
  730. },
  731. complete: () => {
  732. this.loading = false
  733. this.isPaying = false
  734. }
  735. })
  736. },
  737. changePreFamiliarize(name) {
  738. if (name && name.length > 0) {
  739. this.needPreFamiliarize = name
  740. this.originalTotalPrice = this.originalTotalPrice + 40
  741. } else {
  742. this.needPreFamiliarize = []
  743. this.originalTotalPrice = this.originalTotalPrice - 40
  744. }
  745. // 如果总价小于优惠券的最低消费,则不使用优惠券
  746. if (this.selectedCoupon && this.originalTotalPrice < this.selectedCoupon.transactionMinimum) {
  747. this.discount = 0
  748. this.couponId = null
  749. this.couponList.forEach(coupon => {
  750. coupon.checked = null
  751. })
  752. }
  753. this.getShowTotalPrice()
  754. },
  755. getShowTotalPrice() {
  756. //保留两位小数
  757. this.memberDiscount = ((this.originalTotalPrice - this.discount) * this.currentMember.discount).toFixed(2)
  758. this.finalPrice = (this.originalTotalPrice - this.memberDiscount - this.discount).toFixed(2)
  759. },
  760. getCouponAmountOrDiscount(item) {
  761. if (item.stockType == "PDISCOUNT") {
  762. return item.discountPercent / 10 + '折'
  763. } else {
  764. return '¥' + item.discountAmount
  765. }
  766. },
  767. goNext() {
  768. if (!this.isAgree) {
  769. uni.showToast({
  770. title: '请先同意用户协议',
  771. icon: 'none'
  772. })
  773. return
  774. }
  775. const order = this.constructOrder()
  776. createOrderNew(order).then(res => {
  777. if (res.code == 200) {
  778. this.pay(res.data)
  779. } else {
  780. this.$modal.showToast('创建订单失败,请重试');
  781. this.loading = false
  782. }
  783. })
  784. }
  785. }
  786. }
  787. </script>
  788. <style scoped lang="scss">
  789. .container {
  790. position: relative;
  791. height: 100%;
  792. padding-bottom: 200rpx;
  793. .details-subscribe {
  794. background-color: #FFFFFF;
  795. padding: 10px;
  796. width: 100%;
  797. height: 200rpx;
  798. position: fixed;
  799. bottom: 0;
  800. z-index: 100;
  801. .details-btn {
  802. width: 100%;
  803. border-radius: 6px;
  804. background: #FFB13F;
  805. font-size: 16px;
  806. color: #FFFFFF;
  807. }
  808. .details-radio {
  809. display: flex;
  810. align-items: center;
  811. justify-content: center;
  812. }
  813. }
  814. }
  815. .service-new {
  816. .service-new-flag {
  817. width: 8rpx;
  818. height: 32rpx;
  819. background: #FFBF60;
  820. border-radius: 30rpx 30rpx 30rpx 30rpx;
  821. margin-right: 10rpx;
  822. }
  823. .split-line {
  824. width: 100%;
  825. height: 1rpx;
  826. background: #EFEFEF;
  827. }
  828. .service-new-title {
  829. display: flex;
  830. font-weight: 500;
  831. font-size: 28rpx;
  832. color: #333333;
  833. line-height: 33rpx;
  834. margin: 42rpx 0 30rpx;
  835. justify-content: space-between;
  836. .service-new-title-left {
  837. display: flex;
  838. align-items: center;
  839. }
  840. }
  841. .service-new-details-desc {
  842. font-weight: 400;
  843. font-size: 24rpx;
  844. color: #A94F20;
  845. line-height: 28rpx;
  846. text-align: left;
  847. padding: 26rpx 0;
  848. }
  849. .personal-address-info {
  850. display: flex;
  851. align-items: center;
  852. justify-content: flex-start;
  853. flex-wrap: wrap;
  854. margin: 32rpx 0;
  855. width: 80%;
  856. .personal-address-text {
  857. color: #333;
  858. font-size: 28rpx;
  859. font-weight: bold;
  860. width: 100%;
  861. }
  862. .personal-address-people {
  863. color: #7D8196;
  864. font-size: 28rpx;
  865. font-weight: 400;
  866. display: flex;
  867. justify-content: flex-start;
  868. align-items: center;
  869. }
  870. }
  871. .service-new-address-selected {
  872. display: flex;
  873. justify-content: space-between;
  874. align-items: center;
  875. }
  876. }
  877. .personal-pet-list {
  878. margin-top: 20rpx;
  879. .personal-pet-list-item {
  880. margin-bottom: 20rpx;
  881. background-color: #F9F9F9;
  882. height: 172rpx;
  883. border-radius: 8rpx;
  884. .personal-pet-info {
  885. height: 100%;
  886. display: flex;
  887. align-items: center;
  888. padding: 0 20rpx;
  889. }
  890. }
  891. }
  892. .service-new-address {
  893. .service-summary {
  894. height: 90rpx;
  895. display: flex;
  896. justify-content: space-between;
  897. align-items: center;
  898. padding: 15rpx;
  899. cursor: pointer;
  900. transition: background-color 0.3s;
  901. }
  902. .service-details {
  903. padding: 10rpx 15rpx;
  904. background-color: #F9F9F9;
  905. margin-bottom: 10rpx;
  906. .pet-info {
  907. display: flex;
  908. justify-content: space-between;
  909. margin: 5rpx 0;
  910. font-size: 24rpx;
  911. color: #333;
  912. }
  913. .service-item {
  914. display: flex;
  915. justify-content: space-between;
  916. width: 100%;
  917. color: #999999;
  918. font-size: 28rpx;
  919. }
  920. }
  921. .total-cost {
  922. padding: 10rpx 15rpx;
  923. font-size: 28rpx;
  924. color: #333;
  925. display: flex;
  926. justify-content: space-between;
  927. }
  928. }
  929. .calendar-popup {
  930. position: fixed;
  931. bottom: 0;
  932. left: 0;
  933. right: 0;
  934. z-index: 999;
  935. .calendar-content {
  936. background: #F5F5F7;
  937. border-radius: 16rpx 16rpx 0 0;
  938. padding: 0 20rpx 40rpx;
  939. }
  940. }
  941. .calendar-mask {
  942. position: fixed;
  943. top: 0;
  944. left: 0;
  945. right: 0;
  946. bottom: 0;
  947. background: rgba(0, 0, 0, 0.5);
  948. /* 半透明黑色 */
  949. z-index: 998;
  950. /* 确保在内容下方 */
  951. pointer-events: none;
  952. /* 使遮罩层不阻止点击事件 */
  953. }
  954. .calendar-content {
  955. position: relative;
  956. /* 确保内容在遮罩层之上 */
  957. z-index: 999;
  958. /* 确保内容在遮罩层之上 */
  959. }
  960. .price-details {
  961. background: #F5F5F7;
  962. /* 背景颜色 */
  963. padding: 10px 10px 0 10px;
  964. /* 内边距 */
  965. z-index: 1000;
  966. /* 确保在其他元素之上 */
  967. min-height: 600rpx;
  968. /* 固定高度 */
  969. overflow: hidden;
  970. /* 隐藏超出部分 */
  971. }
  972. .price-details-header {
  973. display: flex;
  974. justify-content: space-between;
  975. align-items: center;
  976. padding-bottom: 20rpx;
  977. }
  978. .price-details-body {
  979. margin-top: 20rpx;
  980. max-height: 450rpx;
  981. /* 留出头部空间 */
  982. overflow-y: auto;
  983. /* 允许上下滚动 */
  984. }
  985. .coupon-card {
  986. display: flex;
  987. align-items: center;
  988. width: 100%;
  989. padding: 10px 0;
  990. background: #fff;
  991. border-radius: 8px;
  992. -webkit-mask-image: radial-gradient(circle at 88px 4px, transparent 4px, #d8d8d8 4.5px), radial-gradient(closest-side circle at 50%, #d8d8d8 99%, transparent 100%);
  993. -webkit-mask-size: 100%, 2px 4px;
  994. -webkit-mask-repeat: repeat, repeat-y;
  995. -webkit-mask-position: 0 -4px, 87px;
  996. -webkit-mask-composite: source-out;
  997. mask-composite: subtract;
  998. // background: linear-gradient(45deg, orange, red);
  999. }
  1000. .card-left {
  1001. width: 88px;
  1002. text-align: center;
  1003. font-size: 28rpx;
  1004. color: #FF530A;
  1005. }
  1006. .card-right {
  1007. padding: 0px 12px;
  1008. display: flex;
  1009. flex: 1;
  1010. /* flex-direction: column; */
  1011. justify-content: space-between;
  1012. align-items: center;
  1013. height: 60px;
  1014. s .card-content {
  1015. width: 80%;
  1016. }
  1017. .card-icon {
  1018. position: relative;
  1019. right: -10px;
  1020. top: -10px;
  1021. }
  1022. }
  1023. .card-info {
  1024. margin: 0;
  1025. font-size: 14px;
  1026. line-height: 20px;
  1027. color: #333333;
  1028. }
  1029. .card-time {
  1030. font-size: 12px;
  1031. line-height: 16px;
  1032. font-weight: normal;
  1033. color: #aaaaaa;
  1034. margin-top: 4px;
  1035. }
  1036. </style>