goodsDetails.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. <template>
  2. <view>
  3. <!-- 顶部轮播图 -->
  4. <view>
  5. <Detiles :volunteerPicture="listData.volunteerPicture"></Detiles>
  6. </view>
  7. <!-- 页面背景整体定位 -->
  8. <view class="service-description-position">
  9. <!-- 价格服务介绍 -->
  10. <view class="service-description-container">
  11. <view class="service-price-top">
  12. <view class="service-price-tag1">¥</view>
  13. <view class="service-price-tag2">{{ listData.businessPrice }}</view>
  14. <view class="service-price-tag3">/{{ listData.businessUnit }}</view>
  15. </view>
  16. <view class="service-text">{{ listData.businessDescribe }}</view>
  17. </view>
  18. <!-- 预约-资质认证 -->
  19. <view class="service-description-bottom">
  20. <view class="service-item">
  21. <image src="/static/img/check-fill@1x.png" class="service-description-bottom-img"></image>
  22. <text class="service-description-bottom-text">提前预约</text>
  23. </view>
  24. <view class="service-item">
  25. <image src="/static/img/check-fill@1x.png" class="service-description-bottom-img"></image>
  26. <text class="service-description-bottom-text">通过专业资质认证</text>
  27. </view>
  28. <view class="service-item">
  29. <image src="/static/img/check-fill@1x.png" class="service-description-bottom-img"></image>
  30. <text class="service-description-bottom-text">技术人员专业培训</text>
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 志愿者介绍 -->
  35. <view class="volunteer-Introduction">
  36. <view class="volunteer-Introduction-top">
  37. <!-- 主体内容 -->
  38. <view class="volunteer-main-content">
  39. <!-- 头像 -->
  40. <image class="volunteer-image" :src="firstVolunteerPicture" mode="aspectFill"></image>
  41. <!-- 个人信息 -->
  42. <view class="volunteer-info">
  43. <view class="name-row">
  44. <text class="name">{{ listData.name || '陈阿姨' }}</text>
  45. <view class="stat-item">
  46. <image src="/static/img/Iconly@1x (1).png"></image>
  47. <text>5星好评</text>
  48. </view>
  49. <view class="stat-item">
  50. <image src="/static/img/Iconly@1x (2).png"></image>
  51. <text>{{ listData.orderCount || 0 }}总单量</text>
  52. </view>
  53. </view>
  54. <view class="contact-row">
  55. <text>{{ listData.age }}岁</text>
  56. <text>{{ listData.phonenumber || '1554****9215' }}</text>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 查看个人主页 -->
  61. <view class="view-profile">
  62. <text>查看个人主页</text>
  63. <image src="/static/img/Iconly@1x (3).png"></image>
  64. </view>
  65. <!-- 标签 -->
  66. <view class="tags-container">
  67. <view class="tag">{{ listData.projectName }}</view>
  68. <view class="tag">{{ listData.projectTypeName }}</view>
  69. </view>
  70. </view>
  71. <!-- 个人介绍 -->
  72. <view>
  73. <view class="volunteer-H1">个人介绍</view>
  74. <text class="volunteer-H1-text"> {{ listData.skillDescribe }}</text>
  75. </view>
  76. <!-- -资质证书 -->
  77. <view class="certificate-more-container">
  78. <view class="volunteer-H1">
  79. 资质证书
  80. <view class="certificate-more">
  81. <text>查看更多</text>
  82. <image src="/static/img/Iconly@1x (4).png" class="certificate-arrow-icon"></image>
  83. </view>
  84. </view>
  85. <view class="certificate-container">
  86. <image v-for="item in certificationPictures" :key="item" :src="item" class="certificate-img"
  87. mode="aspectFill"></image>
  88. </view>
  89. </view>
  90. </view>
  91. <!-- 评论 -->
  92. <view class="comment-container">
  93. <view class="comment-top">
  94. <view class="comment-top-H2">评价(1条)</view>
  95. <view class="comment-top-text">
  96. <text>好评率100%</text>
  97. <image src="/static/img/Iconly@1x (4).png" class="certificate-arrow-img"></image>
  98. </view>
  99. </view>
  100. <view class="comment-evaluate">
  101. <view class="comment-user-title">
  102. <img src="/static/img/容器 162@1x.png" alt="" class="comment-user-img1">
  103. <view class="user-rating">
  104. <view class="user-name">宋小峰</view>
  105. <view class="rating-stars">
  106. <img v-for="item in 5" :key="item" src="/static/img/容器@1x (3).png" alt="" class="comment-user-img2">
  107. </view>
  108. </view>
  109. </view>
  110. <view class="comment-evaluate-text">
  111. <text class="comment-evaluate-text-text">
  112. 重庆永川区好评重庆永川区好评重庆永川区好评
  113. 重庆永川区好评重庆永川区
  114. 重庆永川区好评重庆永川
  115. 区好评重庆永川区好评
  116. 好评重庆永川区好评
  117. </text>
  118. <img src="/static/img/矩形 55145@1x.png" alt="" class="comment-evaluate-img3">
  119. </view>
  120. </view>
  121. </view>
  122. <view class="service-description-box">
  123. <!-- 固定底部按钮区 -->
  124. <view class="Wrap-btn">
  125. <uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
  126. @buttonClick="buttonClick" />
  127. </view>
  128. </view>
  129. <!-- 底部第一层弹框 -->
  130. <view>
  131. <up-popup :show="show" @close="close" @open="open"> </up-popup>
  132. <up-popup :show="show" @open="upPopupOpen" :custom-style="popupStyle">
  133. <scroll-view scroll-y class="popup-scroll-content">
  134. <!-- <view>
  135. <view class="Wrapper">
  136. <image src="/static/img/Location.png" class="Wrapper-img" />
  137. <span class="Wrapper-content">李四</span>
  138. <span class="Wrapper-content">重庆永川区</span>
  139. </view>
  140. <span style="margin-left: 15rpx; margin-top: 50rpx">重庆永川区</span>
  141. </view>
  142. <up-divider></up-divider> -->
  143. <view class="Wrap-content1">
  144. <up-avatar :src="src"></up-avatar>
  145. <text class="service-price">¥{{ businessPrice }}</text>
  146. </view>
  147. <view class="service-info-item">
  148. <text class="service-label1">服务类别:{{ listData.businessTierName }}</text>
  149. <!-- <up-text type="info" class="service-value" text="家庭教育"></up-text> -->
  150. </view>
  151. <view class="service-info-item">
  152. <text class="service-label">上门服务次数:</text>
  153. <up-number-box v-model="singleQuantity" :min="listData.minQuantity" :max="minQuantityMax"
  154. class="service-number-box" :disabled="isChanging" :longPress="false" @change="valChange"></up-number-box>
  155. <view class="service-values">{{ listData.businessUnit }}</view>
  156. </view>
  157. <view class="service-period">
  158. <text class="service-label">服务周期:</text>
  159. <view class="date-picker-container">
  160. <uniDatetimePickerMy :modelValue="doorToDoorTime" :start="startDisabled" :end="endDisabled"
  161. type="daterange">
  162. </uniDatetimePickerMy>
  163. </view>
  164. <view>
  165. <!-- :businessDuration="listData.businessDuration" -->
  166. <its-calendar v-if="show" ref="itsCalendarRef" :businessDuration="businessDurationComputed"
  167. :minQuantity="singleQuantity" :timeArr="doorToDoorTimeArr" :timeHostArr="timeHostArr"
  168. :businessTierName="listData.businessTierName" class="calendar-component" @getByDate="getByDate"
  169. @getByTime="getByTime" @changeMinQuantityMax="changeMinQuantityMax"></its-calendar>
  170. </view>
  171. </view>
  172. <view class="remark-container">
  173. <text class="service-label">备注:</text>
  174. <up-input placeholder="请输入内容" border="surround" v-model="remark" class="remark-input"
  175. @change="change"></up-input>
  176. </view>
  177. <!-- 保持内容底部有足够的空白以避免按钮遮挡内容 -->
  178. <view style="height: 120rpx;"></view>
  179. </scroll-view>
  180. <!-- 将按钮移到scroll-view外部,但保持在popup内 -->
  181. <view class="popup-fixed-bottom">
  182. <up-button type="primary" shape="circle" :customStyle="wrapqx" @click="handlCancel">取消</up-button>
  183. <up-button type="error" shape="circle" :customStyle="wrapqx" @click="handleBuy">
  184. 预约¥{{ computeMoney.toFixed(2) }}
  185. </up-button>
  186. </view>
  187. </up-popup>
  188. </view>
  189. <!-- 第二个弹框-->
  190. <up-popup :show="showSecond">
  191. <view>
  192. <up-cell-group>
  193. <view @click="jumpToAddressSelect" style="display: flex; align-items: center; padding: 10px">
  194. <up-icon name="more-dot-fill" size="16" />
  195. <view v-if="selectedAddress" style="margin-left: 8px; flex: 1">
  196. <view class="address-display">
  197. <text class="address-line">
  198. {{ selectedAddress.provinceName }}{{ selectedAddress.cityName
  199. }}{{ selectedAddress.districtName }}
  200. </text>
  201. <view class="contact-info">
  202. <text class="contact-name">{{ selectedAddress.name }}</text>
  203. <text class="contact-phone">{{
  204. selectedAddress.telephone
  205. }}</text>
  206. </view>
  207. </view>
  208. </view>
  209. <text v-else style="margin-left: 8px; font-size: 18px">请选择服务地址</text>
  210. </view>
  211. <scroll-view scroll-y style="height: 460rpx">
  212. <view class="card-container" v-for="(item, index) in selectedTimes" :key="index">
  213. <image class="card-image" :src="listData.volunteerPicture" mode="aspectFill"></image>
  214. <view class="card-content">
  215. <view class="info-item">服务项目:{{ listData.projectName }}</view>
  216. <view class="Telephone">服务时长:{{ listData.businessDuration }}</view>
  217. <view class="date">日期:{{ item.date }}</view>
  218. <view class="time"> 时间:{{ item.time }} </view>
  219. </view>
  220. </view>
  221. </scroll-view>
  222. </up-cell-group>
  223. </view>
  224. <view class="Wrap-Payment">
  225. <!-- 支付金额 -->
  226. <view class="payment-header">
  227. <text class="payment-title">现在支付</text>
  228. <text class="payment-amount">¥{{ computeMoney }}</text>
  229. </view>
  230. <up-line></up-line>
  231. <!-- 钱包支付选项 -->
  232. <view class="payment-option">
  233. <view class="option-left">
  234. <image src="/static/钱包.png" class="payment-icon"></image>
  235. <text class="option-text">钱包</text>
  236. </view>
  237. <up-radio-group v-model="radiovalue1" placement="column" @change="handlePaymentMethodChange">
  238. <up-radio :customStyle="{ marginLeft: 'auto' }" v-for="(item, index) in radiolist1" :key="index"
  239. :label="item.name" :name="item.name"></up-radio>
  240. </up-radio-group>
  241. </view>
  242. <up-line></up-line>
  243. <!-- 微信支付选项 -->
  244. <view class="payment-option">
  245. <view class="option-left">
  246. <image src="/static/微信支付.png" class="payment-icon"></image>
  247. <text class="option-text">微信支付</text>
  248. </view>
  249. <up-radio-group v-model="radiovalue1" placement="column" @change="handlePaymentMethodChange">
  250. <up-radio :customStyle="{ marginLeft: 'auto' }" v-for="(item, index) in radiolist2" :key="index"
  251. :label="item.name" :name="item.name"></up-radio>
  252. </up-radio-group>
  253. </view>
  254. <up-line></up-line>
  255. <!-- 其他支付方式 -->
  256. <view class="other-payment">
  257. <text class="other-payment-text">其他方式支付</text>
  258. <up-icon name="arrow-right" size="14" color="#1890ff"></up-icon>
  259. </view>
  260. <!-- 条款说明 -->
  261. <view class="terms-of-service">
  262. 我同意购买守则,取消政策和退款政策,我也同意支付以下所示的总金额(含服务费)。
  263. </view>
  264. </view>
  265. <view class="Wrap-detils-btn">
  266. <up-button type="primary" shape="circle" :customStyle="wrapqx" @click="closeSecond">取消</up-button>
  267. <up-button type="error" shape="circle" :customStyle="wrapqx" @click="handlConfiRmpurchase">
  268. 购买¥{{ computeMoney }}
  269. </up-button>
  270. </view>
  271. </up-popup>
  272. <view v-if="addressFlag" class="box">
  273. <addressComponent :modelValue="addressFlag" @update:modelValue="(val) => (addressFlag = val)"
  274. :addressInfo="addressInfo" @update:addressInfo="handleAddressUpdate"></addressComponent>
  275. </view>
  276. </view>
  277. </template>
  278. <script setup>
  279. import { onLoad } from '@dcloudio/uni-app'
  280. import { onMounted, ref, reactive, computed, nextTick } from 'vue'
  281. import {
  282. getDetailsvolunteerId,
  283. volunteerwork,
  284. volunteergetTimesByDate,
  285. ordersCreateOrder,
  286. coreUsersOrdersPayCancel,
  287. } from '@/api/volunteerDetailsApi/details.js'
  288. import itsCalendar from '@/components/its-calendar/its-calendar.vue'
  289. import uniDatetimePickerMy from '@/uni_modules/lic-uni-datetime-picker/components/lic-uni-datetime-picker/lic-uni-datetime-picker.vue'
  290. import addressComponent from '@/pages_home/components/volunteerData/adresss.vue'
  291. import Detiles from './detiles.vue'
  292. // const src = ref(
  293. // 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg'
  294. // )
  295. const itsCalendarRef = ref(null)
  296. const businessPrice = ref() //价格
  297. const isChanging = ref(false) // 步进器防抖
  298. const singleQuantity = ref(1) // 购买次数,默认为1,不可为0
  299. const volunteerId = ref('') // 存储志愿者ID
  300. const serviceCategory = ref('') //存储大类别
  301. const businessManagementId = ref('') //具体分类id
  302. const doorToDoorTimeArr = ref([]) // 完整时间范围
  303. const doorToDoorTime = ref([]) // 只具备开始、结束 时间
  304. const timeHostArr = ref([]) // 时间段数组
  305. const currentDate = ref([]) // 点击过的年月日数组数据
  306. const currentTime = ref('') // 最后一次点击时间的时间节点
  307. const selectedTimes = ref([]) // 存储所有选择的时间对象
  308. const totalTimes = ref(0) // 时间点 点击的次数
  309. const startDisabled = ref('')
  310. const endDisabled = ref('')
  311. const listData = ref({})
  312. const show = ref(false) //第一层弹框
  313. const showSecond = ref(false) //第二层弹框
  314. const remark = ref('') //备注
  315. const radiovalue1 = ref(null)
  316. const selectedAddress = ref(null)
  317. const addressFlag = ref(false)
  318. const paymentMethod = ref(null) // Add payment method ref with default value 1 (wallet)
  319. const addressInfo = ref(null)
  320. const value = ref(1) // 将在onLoad中更新为listData.minQuantity
  321. const minQuantityMax = ref(99999) // 步进器最大值控制变量
  322. // Radio 单选框数据
  323. const radiolist1 = reactive([
  324. {
  325. name: '钱包支付',
  326. disabled: false,
  327. },
  328. ])
  329. const radiolist2 = reactive([
  330. {
  331. name: '微信支付',
  332. disabled: false,
  333. },
  334. ])
  335. const businessDurationComputed = computed(() => {
  336. // listData.value.businessDuration
  337. let result = 0
  338. if (listData.value.businessDuration <= 30) {
  339. result = 30
  340. } else {
  341. const num = Math.floor(listData.value.businessDuration / 30)
  342. // result = (num + 1) * 30
  343. const n = listData.value.businessDuration % 30
  344. result = (n ? (num + 1) : num) * 30
  345. }
  346. console.log(result, '>>>>>>>result')
  347. return result
  348. })
  349. // 设置第一个弹框的样式
  350. const popupStyle = {
  351. height: '80vh', // 设置为视窗高度的80%
  352. overflow: 'hidden', // 防止内容溢出
  353. position: 'relative', // 需要这个来支持内部的绝对定位元素
  354. }
  355. // 详情底部立即购买弹框
  356. const buttonClick = (e) => {
  357. show.value = true // 打开弹框
  358. }
  359. // 详情页第一层弹框
  360. function open() {
  361. show.value = true
  362. }
  363. // 第一层弹框取消
  364. function close() {
  365. // 关闭逻辑,设置 show 为 false
  366. show.value = false
  367. }
  368. // 第一个弹框逻辑
  369. const handleBuy = () => {
  370. console.log(selectedTimes.value, '>>>>>>selectedTimes.value')
  371. if (selectedTimes.value.length === 0) {
  372. uni.showToast({
  373. title: '请选择服务时间',
  374. icon: 'none',
  375. })
  376. return
  377. }
  378. show.value = false // 关闭第一个弹框
  379. showSecond.value = true // 打开第二个弹框
  380. }
  381. // 第二层弹框取消
  382. function closeSecond() {
  383. // 关闭逻辑,设置 show 为 false
  384. showSecond.value = false
  385. show.value = true // 打开第一个弹框
  386. }
  387. const handlCancel = () => {
  388. show.value = false // 关闭第一个弹框
  389. selectedTimes.value = [] // 清空已选时间
  390. totalTimes.value = 0 // 重置点击次数
  391. }
  392. const jumpToAddressSelect = () => {
  393. addressFlag.value = true
  394. }
  395. // 新增:处理子组件传回的地址数据
  396. const handleAddressUpdate = (newAddress) => {
  397. selectedAddress.value = newAddress
  398. addressFlag.value = false // 关闭选择器
  399. }
  400. // 详情底部底部数据
  401. const options = ref([
  402. // {
  403. // icon: 'headphones',
  404. // text: '客服',
  405. // },
  406. // {
  407. // icon: 'shop',
  408. // text: '收藏',
  409. // },
  410. ])
  411. // 详情底部立即购买样式
  412. const buttonGroup = ref([
  413. {
  414. text: '立即购买',
  415. backgroundColor: 'red',
  416. color: '#fff',
  417. },
  418. ])
  419. // 底部帮助客服方法
  420. const onClick = (e) => {
  421. // uni.showToast({
  422. // title: `敬请期待`,
  423. // icon: 'none',
  424. // })
  425. uni.navigateTo({
  426. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true&conversationType=3`
  427. })
  428. }
  429. const wrapqx = {
  430. // height: '70rpx',
  431. width: '240rpx',
  432. }
  433. // 获取传递的参数
  434. onLoad(async (options) => {
  435. const option = JSON.parse(decodeURIComponent(options.params))
  436. const {
  437. volunteerId: id,
  438. serviceCategory: categoy,
  439. businessManagementId: manage,
  440. } = option
  441. volunteerId.value = id
  442. serviceCategory.value = categoy
  443. businessManagementId.value = manage
  444. const res = await getDetailsvolunteerId({
  445. volunteerId: id,
  446. serviceCategory: categoy,
  447. businessManagementId: manage,
  448. })
  449. listData.value = res.data || {}
  450. // 更新步进器的初始值为listData中的minQuantity
  451. value.value = listData.value.minQuantity || 1
  452. businessPrice.value = listData.value.businessPrice || 0
  453. singleQuantity.value = listData.value.minQuantity || 1
  454. })
  455. // 添加步进器值变化处理函数
  456. const valChange = (obj) => {
  457. // const durationMs = listData.value.businessDuration * obj.value * 60
  458. const durationMs = businessDurationComputed.value * obj.value * 60
  459. const a = itsCalendarRef.value.upItem
  460. const b = itsCalendarRef.value.timeHostArr
  461. const c = itsCalendarRef.value.day_index
  462. let selectLength = [] // 所有日期選擇數組匯總
  463. const disFlag = false // 是否多选参数 / 备用禁用步进器
  464. Object.keys(itsCalendarRef.value.selectedTimeSlots).forEach(i => {
  465. selectLength.push(...itsCalendarRef.value.selectedTimeSlots[i])
  466. })
  467. if (selectLength.length > 1) {
  468. setTimeout(() => {
  469. singleQuantity.value = obj.value - 1
  470. }, 100)
  471. uni.showToast({ title: '请选择单个时间进行调整服务次数', icon: 'none' })
  472. return false
  473. }
  474. // const seconds = listData.value.businessDuration * obj.value * 60
  475. const seconds = businessDurationComputed.value * obj.value * 60
  476. const endTimestamp = a.timeStamp + durationMs
  477. // 根据当前时间分割出后续应选数据数组
  478. const filteredSlots = b[c].filter((i) => {
  479. return i.timeStamp > a.timeStamp && i.timeStamp <= endTimestamp
  480. })
  481. const timestampDifferenceValue = filteredSlots.length
  482. ? filteredSlots[filteredSlots.length - 1].timeStamp - a.timeStamp
  483. : 0
  484. // console.log(filteredSlots, '>>>>>filteredSlots')
  485. if (timestampDifferenceValue < durationMs) {
  486. minQuantityMax.value = obj.value - 1
  487. // 所选时间差值 小于 服务时间值 结束执行
  488. uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' })
  489. return false
  490. }
  491. singleQuantity.value = obj.value || 1
  492. nextTick(() => {
  493. itsCalendarRef.value.handleTimeClick2()
  494. })
  495. }
  496. // 选择日期
  497. const getListTime = async () => {
  498. const params = {
  499. volunteerId: Number(volunteerId.value),
  500. }
  501. const res = await volunteerwork(params)
  502. if (res.data && res.data.length > 0) {
  503. doorToDoorTimeArr.value = res.data
  504. const newRes = [res.data[0], res.data[res.data.length - 1]]
  505. doorToDoorTime.value = newRes
  506. startDisabled.value = doorToDoorTime.value[0]
  507. endDisabled.value = doorToDoorTime.value[1]
  508. // 默认加载第一个日期的排班时间
  509. getByDate(res.data[0])
  510. } else {
  511. console.error('接口返回的日期范围为空')
  512. doorToDoorTimeArr.value = []
  513. timeHostArr.value = [] // 清空时间段
  514. }
  515. }
  516. // 获取志愿者排班时间
  517. const getByDate = async (date = doorToDoorTimeArr.value[0]) => {
  518. // 检查日期是否为空
  519. if (!date) {
  520. coannsole.error('日期为空,跳过获取排班时间')
  521. return
  522. }
  523. if (!volunteerId.value) {
  524. console.error('volunteerId 为空')
  525. return
  526. }
  527. const params = {
  528. volunteerId: volunteerId.value,
  529. date,
  530. }
  531. try {
  532. const res = await volunteergetTimesByDate(params)
  533. const TArr = res.data.map((item) => {
  534. // 初始化disabled变量
  535. let disabled = false
  536. if (item.hasReservation === 1) disabled = true
  537. let itemTime =
  538. item.timeStamp > 9999999999 ? item.timeStamp : item.timeStamp * 1000
  539. if (new Date().getTime() > itemTime) disabled = true
  540. return {
  541. ...item,
  542. hours: item.reservationTime,
  543. timeStamp: new Date(`${date} ${item.reservationTime}`).getTime() / 1000,
  544. date: date,
  545. // checked: false, // 每次点击请求时间后,延续之前选中状态,不初始化选中
  546. disabled,
  547. }
  548. })
  549. // 如果 doorToDoorTimeArr.value 为空,直接返回
  550. if (!doorToDoorTimeArr.value.length) {
  551. console.error('可选的日期范围为空')
  552. return
  553. }
  554. // 填充时间段数组
  555. timeHostArr.value = Array(doorToDoorTimeArr.value.length).fill(TArr)
  556. } catch (error) {
  557. console.error('获取排班时间失败:', error)
  558. }
  559. }
  560. const getByTime = (timeObj) => {
  561. if (timeObj.clicked) {
  562. return
  563. }
  564. if (timeObj.checked) {
  565. // 选中 添加到已选时间数组
  566. selectedTimes.value.push({
  567. date: timeObj.date,
  568. time: timeObj.hours,
  569. timestamp: timeObj.timeStamp,
  570. })
  571. } else {
  572. // 取消选中
  573. const index = selectedTimes.value.findIndex(
  574. (item) => item.timestamp === timeObj.timeStamp
  575. )
  576. selectedTimes.value.splice(index, 1)
  577. }
  578. console.log(selectedTimes, '.>>>selectedTimes');
  579. console.log(selectedTimes.value.length, '>>>>>>selectedTimes.value.length');
  580. totalTimes.value = selectedTimes.value.length // 更新点击次数
  581. }
  582. // 立即购买显示时执行
  583. const upPopupOpen = () => {
  584. //显示时初始化预存储信息数据
  585. selectedTimes.value = []
  586. totalTimes.value = 0
  587. currentTime.value = ''
  588. currentDate.value = []
  589. // 初始化disabled/checked 数据状态
  590. getByDate()
  591. }
  592. const computeMoney = computed(() => {
  593. return totalTimes.value * businessPrice.value * singleQuantity.value
  594. })
  595. const certificationPictures = computed(() => {
  596. if (listData.value.certificationPicture) {
  597. return listData.value.certificationPicture.split(',')
  598. }
  599. return []
  600. })
  601. // 确认购买
  602. const handlConfiRmpurchase = () => {
  603. if (!selectedAddress.value) {
  604. uni.showToast({
  605. title: '请选择服务地址',
  606. icon: 'none',
  607. duration: 2000,
  608. })
  609. return // 阻止购买
  610. } else if (!paymentMethod.value) {
  611. uni.showToast({
  612. title: '请选择支付方式',
  613. icon: 'none',
  614. duration: 2000,
  615. })
  616. return // 阻止购买
  617. }
  618. // 如果有地址,执行购买逻辑
  619. proceedToPayment()
  620. }
  621. const proceedToPayment = async () => {
  622. try {
  623. // 定义要发送的数据
  624. const orderData = {
  625. orders: {
  626. // serviceOnePrice: businessPrice.value,
  627. // serviceTotalPrice: computeMoney.value,
  628. serviceCategory: serviceCategory.value,
  629. totalTimes: totalTimes.value,
  630. paymentMethod: paymentMethod.value,
  631. volunteerId: volunteerId.value,
  632. remark: remark.value,
  633. businessManagementId: businessManagementId.value,
  634. volunteerInfoId: listData.value.volunteerInfoId,
  635. addressId: selectedAddress.value.addressId,
  636. singleQuantity: singleQuantity.value,
  637. },
  638. workDateList: [],
  639. }
  640. // 转换所有选择的时间
  641. selectedTimes.value.forEach((item) => {
  642. orderData.workDateList.push({
  643. workDate: item.date,
  644. workStartTime: item.time,
  645. })
  646. })
  647. // 创建订单
  648. const res = await ordersCreateOrder(orderData)
  649. if (res.code !== 200) {
  650. throw new Error('创建订单失败')
  651. }
  652. // 保存订单号
  653. const mainOrderId = res.data.mainOrderId
  654. // console.log('创建订单成功,订单号:', mainOrderId)
  655. // 如果是微信支付
  656. if (paymentMethod.value === 2) {
  657. return new Promise((resolve, reject) => {
  658. uni.requestPayment({
  659. ...res.data,
  660. package: res.data.packageValue,
  661. success: (payRes) => {
  662. // console.log('支付成功:', payRes)
  663. if (payRes.errMsg === 'requestPayment:ok') {
  664. uni.showToast({
  665. title: '支付成功',
  666. icon: 'success',
  667. duration: 1500,
  668. mask: true,
  669. })
  670. setTimeout(() => {
  671. uni.reLaunch({
  672. url: '/pages/classify',
  673. })
  674. }, 1500)
  675. resolve(payRes)
  676. }
  677. },
  678. fail: async (payRes) => {
  679. // console.log('支付失败或取消:', payRes)
  680. try {
  681. // 调用取消支付接口
  682. const cancelRes = await coreUsersOrdersPayCancel({ mainOrderId })
  683. // console.log('取消支付接口调用成功:', cancelRes)
  684. if (payRes.errMsg === 'requestPayment:fail cancel') {
  685. uni.showToast({
  686. title: '已取消支付',
  687. icon: 'none',
  688. duration: 1500,
  689. mask: true,
  690. })
  691. } else {
  692. uni.showToast({
  693. title: error.response?.data?.msg,
  694. icon: 'error',
  695. duration: 1500,
  696. mask: true,
  697. })
  698. }
  699. reject(payRes)
  700. } catch (error) {
  701. console.error('取消支付接口调用失败:', error)
  702. uni.showToast({
  703. title: '取消支付失败',
  704. icon: 'error',
  705. duration: 1500,
  706. mask: true,
  707. })
  708. reject(error)
  709. }
  710. },
  711. })
  712. })
  713. }
  714. // 如果是钱包支付
  715. if (paymentMethod.value === 1) {
  716. uni.showToast({
  717. title: '支付成功',
  718. icon: 'success',
  719. duration: 1500,
  720. mask: true,
  721. })
  722. setTimeout(() => {
  723. uni.reLaunch({
  724. url: '/pages/classify',
  725. })
  726. }, 1500)
  727. }
  728. } catch (error) {
  729. console.error('支付失败:', error)
  730. uni.showToast({
  731. title: error.response?.data?.msg,
  732. icon: 'error',
  733. duration: 1500,
  734. mask: true,
  735. })
  736. }
  737. }
  738. // 修改支付方式
  739. const handlePaymentMethodChange = (value) => {
  740. if (value === '钱包支付') {
  741. paymentMethod.value = 1
  742. } else if (value === '微信支付') {
  743. paymentMethod.value = 2
  744. }
  745. }
  746. const changeMinQuantityMax = (val = 99999) => {
  747. minQuantityMax.value = val
  748. }
  749. // 计算属性:获取志愿者第一张图片
  750. const firstVolunteerPicture = computed(() => {
  751. const pictures = listData.value.volunteerPicture.split(',');
  752. return pictures[0];
  753. });
  754. onMounted(async () => {
  755. await getListTime()
  756. })
  757. </script>
  758. <style scoped lang="scss">
  759. @import '../../styles/goodsDetails.scss';
  760. </style>