goodsDetails.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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 }}{{ selectedAddress.districtName }}
  199. </text>
  200. <view class="contact-info">
  201. <text class="contact-name">{{ selectedAddress.name }}</text>
  202. <text class="contact-phone">{{ selectedAddress.telephone }}</text>
  203. </view>
  204. </view>
  205. </view>
  206. <text v-else style="margin-left: 8px; font-size: 18px">请选择服务地址</text>
  207. </view>
  208. <scroll-view scroll-y style="height: 460rpx">
  209. <view class="card-container" v-for="(item, index) in selectedTimes" :key="index">
  210. <image class="card-image" :src="listData.volunteerPicture" mode="aspectFill"></image>
  211. <view class="card-content">
  212. <view class="info-item">服务项目:{{ listData.projectName }}</view>
  213. <view class="Telephone">服务时长:{{ listData.businessDuration }}</view>
  214. <view class="date">日期:{{ item.date }}</view>
  215. <view class="time"> 时间:{{ item.time }} </view>
  216. </view>
  217. </view>
  218. </scroll-view>
  219. </up-cell-group>
  220. </view>
  221. <view class="Wrap-Payment">
  222. <!-- 支付金额 -->
  223. <view class="payment-header">
  224. <text class="payment-title">现在支付</text>
  225. <text class="payment-amount">¥{{ computeMoney }}</text>
  226. </view>
  227. <up-line></up-line>
  228. <!-- 钱包支付选项 -->
  229. <view class="payment-option">
  230. <view class="option-left">
  231. <image src="/static/钱包.png" class="payment-icon"></image>
  232. <text class="option-text">钱包</text>
  233. </view>
  234. <up-radio-group v-model="radiovalue1" placement="column" @change="handlePaymentMethodChange">
  235. <up-radio :customStyle="{ marginLeft: 'auto' }" v-for="(item, index) in radiolist1" :key="index"
  236. :label="item.name" :name="item.name"></up-radio>
  237. </up-radio-group>
  238. </view>
  239. <up-line></up-line>
  240. <!-- 微信支付选项 -->
  241. <view class="payment-option">
  242. <view class="option-left">
  243. <image src="/static/微信支付.png" class="payment-icon"></image>
  244. <text class="option-text">微信支付</text>
  245. </view>
  246. <up-radio-group v-model="radiovalue1" placement="column" @change="handlePaymentMethodChange">
  247. <up-radio :customStyle="{ marginLeft: 'auto' }" v-for="(item, index) in radiolist2" :key="index"
  248. :label="item.name" :name="item.name"></up-radio>
  249. </up-radio-group>
  250. </view>
  251. <up-line></up-line>
  252. <!-- 其他支付方式 -->
  253. <view class="other-payment">
  254. <text class="other-payment-text">其他方式支付</text>
  255. <up-icon name="arrow-right" size="14" color="#1890ff"></up-icon>
  256. </view>
  257. <!-- 条款说明 -->
  258. <view class="terms-of-service">
  259. 我同意购买守则,取消政策和退款政策,我也同意支付以下所示的总金额(含服务费)。
  260. </view>
  261. </view>
  262. <view class="Wrap-detils-btn">
  263. <up-button type="primary" shape="circle" :customStyle="wrapqx" @click="closeSecond">取消</up-button>
  264. <up-button type="error" shape="circle" :customStyle="wrapqx" @click="handlConfiRmpurchase">
  265. 购买¥{{ computeMoney }}
  266. </up-button>
  267. </view>
  268. </up-popup>
  269. <view v-if="addressFlag" class="box">
  270. <addressComponent :modelValue="addressFlag" @update:modelValue="(val) => (addressFlag = val)"
  271. :addressInfo="addressInfo" @update:addressInfo="handleAddressUpdate"></addressComponent>
  272. </view>
  273. </view>
  274. </template>
  275. <script setup>
  276. import { onLoad, onShow } from '@dcloudio/uni-app'
  277. import { onMounted, ref, reactive, computed, nextTick, onUnmounted } from 'vue'
  278. import {
  279. getDetailsvolunteerId,
  280. volunteerwork,
  281. volunteergetTimesByDate,
  282. ordersCreateOrder,
  283. coreUsersOrdersPayCancel,
  284. } from '@/api/volunteerDetailsApi/details.js'
  285. import itsCalendar from '@/components/its-calendar/its-calendar.vue'
  286. import uniDatetimePickerMy from '@/uni_modules/lic-uni-datetime-picker/components/lic-uni-datetime-picker/lic-uni-datetime-picker.vue'
  287. import addressComponent from '@/pages_home/components/volunteerData/adresss.vue'
  288. import Detiles from './detiles.vue'
  289. import store from '@/store'
  290. // const src = ref(
  291. // 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg'
  292. // )
  293. const itsCalendarRef = ref(null)
  294. const businessPrice = ref() //价格
  295. const isChanging = ref(false) // 步进器防抖
  296. const singleQuantity = ref(1) // 购买次数,默认为1,不可为0
  297. const volunteerId = ref('') // 存储志愿者ID
  298. const serviceCategory = ref('') //存储大类别
  299. const businessManagementId = ref('') //具体分类id
  300. const doorToDoorTimeArr = ref([]) // 完整时间范围
  301. const doorToDoorTime = ref([]) // 只具备开始、结束 时间
  302. const timeHostArr = ref([]) // 时间段数组
  303. const currentDate = ref([]) // 点击过的年月日数组数据
  304. const currentTime = ref('') // 最后一次点击时间的时间节点
  305. const selectedTimes = ref([]) // 存储所有选择的时间对象
  306. const totalTimes = ref(0) // 时间点 点击的次数
  307. const startDisabled = ref('')
  308. const endDisabled = ref('')
  309. const listData = ref({})
  310. const show = ref(false) //第一层弹框
  311. const showSecond = ref(false) //第二层弹框
  312. const remark = ref('') //备注
  313. const radiovalue1 = ref(null)
  314. const selectedAddress = ref(null)
  315. const addressFlag = ref(false)
  316. const paymentMethod = ref(null) // Add payment method ref with default value 1 (wallet)
  317. const addressInfo = ref(null)
  318. const value = ref(1) // 将在onLoad中更新为listData.minQuantity
  319. const minQuantityMax = ref(99999) // 步进器最大值控制变量
  320. // Radio 单选框数据
  321. const radiolist1 = reactive([
  322. {
  323. name: '钱包支付',
  324. disabled: false,
  325. },
  326. ])
  327. const radiolist2 = reactive([
  328. {
  329. name: '微信支付',
  330. disabled: false,
  331. },
  332. ])
  333. const businessDurationComputed = computed(() => {
  334. // listData.value.businessDuration
  335. let result = 0
  336. if (listData.value.businessDuration <= 30) {
  337. result = 30
  338. } else {
  339. const num = Math.floor(listData.value.businessDuration / 30)
  340. // result = (num + 1) * 30
  341. const n = listData.value.businessDuration % 30
  342. result = (n ? (num + 1) : num) * 30
  343. }
  344. console.log(result, '>>>>>>>result')
  345. return result
  346. })
  347. // 设置第一个弹框的样式
  348. const popupStyle = {
  349. height: '80vh', // 设置为视窗高度的80%
  350. overflow: 'hidden', // 防止内容溢出
  351. position: 'relative', // 需要这个来支持内部的绝对定位元素
  352. }
  353. // 详情底部立即购买弹框
  354. const buttonClick = (e) => {
  355. show.value = true // 打开弹框
  356. }
  357. // 详情页第一层弹框
  358. function open() {
  359. show.value = true
  360. }
  361. // 第一层弹框取消
  362. function close() {
  363. // 关闭逻辑,设置 show 为 false
  364. show.value = false
  365. }
  366. // 第一个弹框逻辑
  367. const handleBuy = () => {
  368. console.log(selectedTimes.value, '>>>>>>selectedTimes.value')
  369. if (selectedTimes.value.length === 0) {
  370. uni.showToast({
  371. title: '请选择服务时间',
  372. icon: 'none',
  373. })
  374. return
  375. }
  376. show.value = false // 关闭第一个弹框
  377. showSecond.value = true // 打开第二个弹框
  378. }
  379. // 第二层弹框取消
  380. function closeSecond() {
  381. // 关闭逻辑,设置 show 为 false
  382. showSecond.value = false
  383. show.value = true // 打开第一个弹框
  384. }
  385. const handlCancel = () => {
  386. show.value = false // 关闭第一个弹框
  387. selectedTimes.value = [] // 清空已选时间
  388. totalTimes.value = 0 // 重置点击次数
  389. }
  390. // 新增:处理子组件传回的地址数据
  391. const handleAddressUpdate = (newAddress) => {
  392. selectedAddress.value = newAddress
  393. // 保存到store中
  394. store.dispatch('SetTempAddress', newAddress)
  395. addressFlag.value = false // 关闭选择器
  396. }
  397. // 详情底部底部数据
  398. const options = ref([
  399. // {
  400. // icon: 'headphones',
  401. // text: '客服',
  402. // },
  403. // {
  404. // icon: 'shop',
  405. // text: '收藏',
  406. // },
  407. ])
  408. // 详情底部立即购买样式
  409. const buttonGroup = ref([
  410. {
  411. text: '立即购买',
  412. backgroundColor: 'red',
  413. color: '#fff',
  414. },
  415. ])
  416. // 底部帮助客服方法
  417. const onClick = (e) => {
  418. // uni.showToast({
  419. // title: `敬请期待`,
  420. // icon: 'none',
  421. // })
  422. uni.navigateTo({
  423. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true&conversationType=3`
  424. })
  425. }
  426. const wrapqx = {
  427. // height: '70rpx',
  428. width: '240rpx',
  429. }
  430. // 获取传递的参数
  431. onLoad(async (options) => {
  432. const option = JSON.parse(decodeURIComponent(options.params))
  433. const {
  434. volunteerId: id,
  435. serviceCategory: categoy,
  436. businessManagementId: manage,
  437. } = option
  438. volunteerId.value = id
  439. serviceCategory.value = categoy
  440. businessManagementId.value = manage
  441. const res = await getDetailsvolunteerId({
  442. volunteerId: id,
  443. serviceCategory: categoy,
  444. businessManagementId: manage,
  445. })
  446. listData.value = res.data || {}
  447. // 更新步进器的初始值为listData中的minQuantity
  448. value.value = listData.value.minQuantity || 1
  449. businessPrice.value = listData.value.businessPrice || 0
  450. singleQuantity.value = listData.value.minQuantity || 1
  451. })
  452. // 添加步进器值变化处理函数
  453. const valChange = (obj) => {
  454. // const durationMs = listData.value.businessDuration * obj.value * 60
  455. const durationMs = businessDurationComputed.value * obj.value * 60
  456. const a = itsCalendarRef.value.upItem
  457. const b = itsCalendarRef.value.timeHostArr
  458. const c = itsCalendarRef.value.day_index
  459. let selectLength = [] // 所有日期選擇數組匯總
  460. const disFlag = false // 是否多选参数 / 备用禁用步进器
  461. Object.keys(itsCalendarRef.value.selectedTimeSlots).forEach(i => {
  462. selectLength.push(...itsCalendarRef.value.selectedTimeSlots[i])
  463. })
  464. if (selectLength.length > 1) {
  465. setTimeout(() => {
  466. singleQuantity.value = obj.value - 1
  467. }, 100)
  468. uni.showToast({ title: '请选择单个时间进行调整服务次数', icon: 'none' })
  469. return false
  470. }
  471. // const seconds = listData.value.businessDuration * obj.value * 60
  472. const seconds = businessDurationComputed.value * obj.value * 60
  473. const endTimestamp = a.timeStamp + durationMs
  474. // 根据当前时间分割出后续应选数据数组
  475. const filteredSlots = b[c].filter((i) => {
  476. return i.timeStamp > a.timeStamp && i.timeStamp <= endTimestamp
  477. })
  478. const timestampDifferenceValue = filteredSlots.length
  479. ? filteredSlots[filteredSlots.length - 1].timeStamp - a.timeStamp
  480. : 0
  481. // console.log(filteredSlots, '>>>>>filteredSlots')
  482. if (timestampDifferenceValue < durationMs) {
  483. minQuantityMax.value = obj.value - 1
  484. // 所选时间差值 小于 服务时间值 结束执行
  485. uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' })
  486. return false
  487. }
  488. singleQuantity.value = obj.value || 1
  489. nextTick(() => {
  490. itsCalendarRef.value.handleTimeClick2()
  491. })
  492. }
  493. // 选择日期
  494. const getListTime = async () => {
  495. const params = {
  496. volunteerId: Number(volunteerId.value),
  497. }
  498. const res = await volunteerwork(params)
  499. if (res.data && res.data.length > 0) {
  500. doorToDoorTimeArr.value = res.data
  501. const newRes = [res.data[0], res.data[res.data.length - 1]]
  502. doorToDoorTime.value = newRes
  503. startDisabled.value = doorToDoorTime.value[0]
  504. endDisabled.value = doorToDoorTime.value[1]
  505. // 默认加载第一个日期的排班时间
  506. getByDate(res.data[0])
  507. } else {
  508. console.error('接口返回的日期范围为空')
  509. doorToDoorTimeArr.value = []
  510. timeHostArr.value = [] // 清空时间段
  511. }
  512. }
  513. // 获取志愿者排班时间
  514. const getByDate = async (date = doorToDoorTimeArr.value[0]) => {
  515. // 检查日期是否为空
  516. if (!date) {
  517. coannsole.error('日期为空,跳过获取排班时间')
  518. return
  519. }
  520. if (!volunteerId.value) {
  521. console.error('volunteerId 为空')
  522. return
  523. }
  524. const params = {
  525. volunteerId: volunteerId.value,
  526. date,
  527. }
  528. try {
  529. const res = await volunteergetTimesByDate(params)
  530. const TArr = res.data.map((item) => {
  531. // 初始化disabled变量
  532. let disabled = false
  533. if (item.hasReservation === 1) disabled = true
  534. let itemTime =
  535. item.timeStamp > 9999999999 ? item.timeStamp : item.timeStamp * 1000
  536. if (new Date().getTime() > itemTime) disabled = true
  537. return {
  538. ...item,
  539. hours: item.reservationTime,
  540. timeStamp: new Date(`${date} ${item.reservationTime}`).getTime() / 1000,
  541. date: date,
  542. // checked: false, // 每次点击请求时间后,延续之前选中状态,不初始化选中
  543. disabled,
  544. }
  545. })
  546. // 如果 doorToDoorTimeArr.value 为空,直接返回
  547. if (!doorToDoorTimeArr.value.length) {
  548. console.error('可选的日期范围为空')
  549. return
  550. }
  551. // 填充时间段数组
  552. timeHostArr.value = Array(doorToDoorTimeArr.value.length).fill(TArr)
  553. } catch (error) {
  554. console.error('获取排班时间失败:', error)
  555. }
  556. }
  557. const getByTime = (timeObj) => {
  558. if (timeObj.clicked) {
  559. return
  560. }
  561. if (timeObj.checked) {
  562. // 选中 添加到已选时间数组
  563. selectedTimes.value.push({
  564. date: timeObj.date,
  565. time: timeObj.hours,
  566. timestamp: timeObj.timeStamp,
  567. })
  568. } else {
  569. // 取消选中
  570. const index = selectedTimes.value.findIndex(
  571. (item) => item.timestamp === timeObj.timeStamp
  572. )
  573. selectedTimes.value.splice(index, 1)
  574. }
  575. console.log(selectedTimes, '.>>>selectedTimes');
  576. console.log(selectedTimes.value.length, '>>>>>>selectedTimes.value.length');
  577. totalTimes.value = selectedTimes.value.length // 更新点击次数
  578. }
  579. // 立即购买显示时执行
  580. const upPopupOpen = () => {
  581. //显示时初始化预存储信息数据
  582. selectedTimes.value = []
  583. totalTimes.value = 0
  584. currentTime.value = ''
  585. currentDate.value = []
  586. // 初始化disabled/checked 数据状态
  587. getByDate()
  588. }
  589. const computeMoney = computed(() => {
  590. return totalTimes.value * businessPrice.value * singleQuantity.value
  591. })
  592. const certificationPictures = computed(() => {
  593. if (listData.value.certificationPicture) {
  594. return listData.value.certificationPicture.split(',')
  595. }
  596. return []
  597. })
  598. // 确认购买
  599. const handlConfiRmpurchase = () => {
  600. if (!selectedAddress.value) {
  601. uni.showToast({
  602. title: '请选择服务地址',
  603. icon: 'none',
  604. duration: 2000,
  605. })
  606. return // 阻止购买
  607. } else if (!paymentMethod.value) {
  608. uni.showToast({
  609. title: '请选择支付方式',
  610. icon: 'none',
  611. duration: 2000,
  612. })
  613. return // 阻止购买
  614. }
  615. // 如果有地址,执行购买逻辑
  616. proceedToPayment()
  617. }
  618. const proceedToPayment = async () => {
  619. try {
  620. // 定义要发送的数据
  621. const orderData = {
  622. orders: {
  623. // serviceOnePrice: businessPrice.value,
  624. // serviceTotalPrice: computeMoney.value,
  625. serviceCategory: serviceCategory.value,
  626. totalTimes: totalTimes.value,
  627. paymentMethod: paymentMethod.value,
  628. volunteerId: volunteerId.value,
  629. remark: remark.value,
  630. businessManagementId: businessManagementId.value,
  631. volunteerInfoId: listData.value.volunteerInfoId,
  632. addressId: selectedAddress.value.addressId,
  633. singleQuantity: singleQuantity.value,
  634. },
  635. workDateList: [],
  636. }
  637. // 转换所有选择的时间
  638. selectedTimes.value.forEach((item) => {
  639. orderData.workDateList.push({
  640. workDate: item.date,
  641. workStartTime: item.time,
  642. })
  643. })
  644. // 创建订单
  645. const res = await ordersCreateOrder(orderData)
  646. if (res.code !== 200) {
  647. throw new Error('创建订单失败')
  648. }
  649. // 保存订单号
  650. const mainOrderId = res.data.mainOrderId
  651. // console.log('创建订单成功,订单号:', mainOrderId)
  652. // 如果是微信支付
  653. if (paymentMethod.value === 2) {
  654. return new Promise((resolve, reject) => {
  655. uni.requestPayment({
  656. ...res.data,
  657. package: res.data.packageValue,
  658. success: (payRes) => {
  659. // console.log('支付成功:', payRes)
  660. if (payRes.errMsg === 'requestPayment:ok') {
  661. uni.showToast({
  662. title: '支付成功',
  663. icon: 'success',
  664. duration: 1500,
  665. mask: true,
  666. })
  667. setTimeout(() => {
  668. uni.reLaunch({
  669. url: '/pages/classify',
  670. })
  671. }, 1500)
  672. resolve(payRes)
  673. }
  674. },
  675. fail: async (payRes) => {
  676. // console.log('支付失败或取消:', payRes)
  677. try {
  678. // 调用取消支付接口
  679. const cancelRes = await coreUsersOrdersPayCancel({ mainOrderId })
  680. // console.log('取消支付接口调用成功:', cancelRes)
  681. if (payRes.errMsg === 'requestPayment:fail cancel') {
  682. uni.showToast({
  683. title: '已取消支付',
  684. icon: 'none',
  685. duration: 1500,
  686. mask: true,
  687. })
  688. } else {
  689. uni.showToast({
  690. title: error.response?.data?.msg,
  691. icon: 'error',
  692. duration: 1500,
  693. mask: true,
  694. })
  695. }
  696. reject(payRes)
  697. } catch (error) {
  698. console.error('取消支付接口调用失败:', error)
  699. uni.showToast({
  700. title: '取消支付失败',
  701. icon: 'error',
  702. duration: 1500,
  703. mask: true,
  704. })
  705. reject(error)
  706. }
  707. },
  708. })
  709. })
  710. }
  711. // 如果是钱包支付
  712. if (paymentMethod.value === 1) {
  713. uni.showToast({
  714. title: '支付成功',
  715. icon: 'success',
  716. duration: 1500,
  717. mask: true,
  718. })
  719. setTimeout(() => {
  720. uni.reLaunch({
  721. url: '/pages/classify',
  722. })
  723. }, 1500)
  724. }
  725. } catch (error) {
  726. console.error('支付失败:', error)
  727. uni.showToast({
  728. title: error.response?.data?.msg,
  729. icon: 'error',
  730. duration: 1500,
  731. mask: true,
  732. })
  733. }
  734. }
  735. // 修改支付方式
  736. const handlePaymentMethodChange = (value) => {
  737. if (value === '钱包支付') {
  738. paymentMethod.value = 1
  739. } else if (value === '微信支付') {
  740. paymentMethod.value = 2
  741. }
  742. }
  743. const changeMinQuantityMax = (val = 99999) => {
  744. minQuantityMax.value = val
  745. }
  746. // 计算属性:获取志愿者第一张图片
  747. const firstVolunteerPicture = computed(() => {
  748. const pictures = listData.value.volunteerPicture.split(',');
  749. return pictures[0];
  750. });
  751. // 添加 onShow 生命周期钩子
  752. onShow(() => {
  753. // 从 store 获取临时地址
  754. const tempAddress = store.state.user.tempSelectedAddress
  755. if (tempAddress) {
  756. selectedAddress.value = tempAddress
  757. console.log('地址已更新:', selectedAddress.value)
  758. }
  759. })
  760. // 修改地址显示部分
  761. const jumpToAddressSelect = () => {
  762. uni.navigateTo({
  763. url: '/pages_mine/pages/selectAddress/index'
  764. })
  765. }
  766. onMounted(async () => {
  767. await getListTime()
  768. // 检查store中是否有临时地址
  769. const tempAddress = store.state.user.tempSelectedAddress
  770. if (tempAddress) {
  771. selectedAddress.value = tempAddress
  772. }
  773. })
  774. // 在页面卸载时清除临时地址
  775. onUnmounted(() => {
  776. store.dispatch('ClearTempAddress')
  777. })
  778. </script>
  779. <style scoped lang="scss">
  780. @import '../../styles/goodsDetails.scss';
  781. </style>