goodsDetails.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. <template>
  2. <view>
  3. <view>
  4. <Detiles></Detiles>
  5. <up-card
  6. title="服务描述"
  7. :thumb="thumb"
  8. :head-style="{ height: '80rpx', padding: '20rpx' }"
  9. >
  10. <template #body>
  11. <view class="service-description-container">
  12. <view class="service-text">{{ listData.businessDescribe }}</view>
  13. <view class="service-price">¥{{ listData.businessPrice }}</view>
  14. </view>
  15. </template>
  16. </up-card>
  17. </view>
  18. <view>
  19. <up-card
  20. title="志愿者介绍"
  21. :head-style="{ height: '80rpx', padding: '20rpx' }"
  22. >
  23. <template #body>
  24. <view class="card-container">
  25. <!-- 左侧图片 -->
  26. <image
  27. class="card-image"
  28. :src="listData.volunteerPicture"
  29. mode="aspectFill"
  30. ></image>
  31. <!-- 中间信息(姓名/类别等) -->
  32. <view class="card-info">
  33. <view class="info-item">姓名:{{ listData.name }}</view>
  34. <view class="info-item"
  35. >服务项目:{{ listData.businessTierName }}</view
  36. >
  37. <view v-if="serviceSubjectName != null" class="info-item"
  38. >类别:{{ listData.projectTypeName }}
  39. </view>
  40. <view class="Telephone"
  41. >服务时长:{{ listData.businessDuration }}</view
  42. >
  43. <view class="Telephone"
  44. >次/件:{{ listData.minQuantity + listData.businessUnit }}</view
  45. >
  46. <view class="Telephone">电话:{{ listData.phonenumber }}</view>
  47. </view>
  48. <!-- 右上角评分 - 使用绝对定位 -->
  49. <view class="card-rating">4.5 评分</view>
  50. </view>
  51. </template>
  52. </up-card>
  53. <up-card
  54. title="技能介绍"
  55. :thumb="thumb"
  56. :head-style="{ height: '80rpx', padding: '20rpx' }"
  57. >
  58. <template #body>
  59. {{ listData.skillDescribe }}
  60. </template>
  61. </up-card>
  62. <up-card
  63. title="证书"
  64. :thumb="thumb"
  65. :head-style="{ height: '80rpx', padding: '20rpx' }"
  66. >
  67. <template #body>
  68. <view class="certificate">
  69. <image
  70. v-for="item in certificationPictures"
  71. :key="item"
  72. :src="item"
  73. mode=""
  74. style="width: 100%"
  75. class="certificate-img"
  76. ></image>
  77. </view>
  78. </template>
  79. </up-card>
  80. <!-- 固定底部按钮区 -->
  81. <view class="Wrap-btn">
  82. <uni-goods-nav
  83. :fill="true"
  84. :options="options"
  85. :buttonGroup="buttonGroup"
  86. @click="onClick"
  87. @buttonClick="buttonClick"
  88. />
  89. </view>
  90. </view>
  91. <!-- 底部第一层弹框 -->
  92. <view>
  93. <up-popup :show="show" @close="close" @open="open"> </up-popup>
  94. <up-popup v-model:show="show" @open="upPopupOpen">
  95. <view>
  96. <view class="Wrapper">
  97. <image src="/static/img/Location.png" class="Wrapper-img" />
  98. <span class="Wrapper-content">李四</span>
  99. <span class="Wrapper-content">重庆永川区</span>
  100. </view>
  101. <span style="margin-left: 15rpx; margin-top: 50rpx">重庆永川区</span>
  102. </view>
  103. <up-divider></up-divider>
  104. <view class="Wrap-content1">
  105. <up-avatar :src="src"></up-avatar>
  106. <text style="margin-top: 15rpx">¥{{ businessPrice }}</text>
  107. </view>
  108. <view class="Wrap-info">
  109. <text style="margin-left: 10rpx">服务类别:</text>
  110. <up-text type="info" text="家庭教育"></up-text>
  111. </view>
  112. <view class="Wrap-info">
  113. <text style="margin-left: 10rpx">服务次数:</text>
  114. <up-number-box
  115. :modelValue="singleQuantity"
  116. :min="listData.minQuantity"
  117. @change="valChange"
  118. ></up-number-box>
  119. </view>
  120. <view class="Wrap-info">
  121. <text style="margin-left: 10rpx">购买规格:</text>
  122. <view>{{ listData.minQuantity + listData.businessUnit }}</view>
  123. </view>
  124. <view class="Wrap-content3">
  125. <text style="margin-left: 15rpx">服务周期:</text>
  126. <view style="margin-top: 25rpx">
  127. <uniDatetimePickerMy
  128. :modelValue="doorToDoorTime"
  129. :start="startDisabled"
  130. :end="endDisabled"
  131. type="daterange"
  132. ></uniDatetimePickerMy>
  133. </view>
  134. <view>
  135. <its-calendar
  136. v-if="show"
  137. ref="itsCalendarRef"
  138. :businessDuration="listData.businessDuration"
  139. :minQuantity="singleQuantity"
  140. :timeArr="doorToDoorTimeArr"
  141. :timeHostArr="timeHostArr"
  142. @getByDate="getByDate"
  143. @getByTime="getByTime"
  144. ></its-calendar>
  145. </view>
  146. </view>
  147. <view class="Wrap-content6">
  148. <text style="margin-left: 15rpx">备注:</text>
  149. <up-input
  150. placeholder="请输入内容"
  151. border="surround"
  152. v-model="remark"
  153. @change="change"
  154. ></up-input>
  155. </view>
  156. <view class="Wrap-detils-btn">
  157. <up-button
  158. type="primary"
  159. shape="circle"
  160. :customStyle="wrapqx"
  161. @click="handlCancel"
  162. >取消</up-button
  163. >
  164. <up-button
  165. type="error"
  166. shape="circle"
  167. :customStyle="wrapqx"
  168. @click="handleBuy"
  169. >
  170. 预约¥{{ computeMoney }}
  171. </up-button>
  172. </view>
  173. </up-popup>
  174. </view>
  175. <!-- 第二个弹框-->
  176. <up-popup v-model:show="showSecond">
  177. <view>
  178. <up-cell-group>
  179. <view
  180. @click="jumpToAddressSelect"
  181. style="display: flex; align-items: center; padding: 10px"
  182. >
  183. <up-icon name="more-dot-fill" size="16" />
  184. <view v-if="selectedAddress" style="margin-left: 8px; flex: 1">
  185. <view class="address-display">
  186. <text class="address-line">
  187. {{ selectedAddress.provinceName }}{{ selectedAddress.cityName
  188. }}{{ selectedAddress.districtName }}
  189. </text>
  190. <view class="contact-info">
  191. <text class="contact-name">{{ selectedAddress.name }}</text>
  192. <text class="contact-phone">{{
  193. selectedAddress.telephone
  194. }}</text>
  195. </view>
  196. </view>
  197. </view>
  198. <text v-else style="margin-left: 8px; font-size: 18px"
  199. >请选择服务地址</text
  200. >
  201. </view>
  202. <scroll-view scroll-y style="height: 460rpx">
  203. <view
  204. class="card-container"
  205. v-for="(item, index) in selectedTimes"
  206. :key="index"
  207. >
  208. <image
  209. class="card-image"
  210. :src="listData.volunteerPicture"
  211. mode="aspectFill"
  212. ></image>
  213. <view class="card-content">
  214. <view class="info-item"
  215. >服务项目:{{ listData.projectName }}</view
  216. >
  217. <view class="Telephone"
  218. >服务时长:{{ listData.businessDuration }}</view
  219. >
  220. <view class="date">日期:{{ item.date }}</view>
  221. <view class="time"> 时间:{{ item.time }} </view>
  222. </view>
  223. </view>
  224. </scroll-view>
  225. </up-cell-group>
  226. </view>
  227. <view class="Wrap-Payment">
  228. <!-- 支付金额 -->
  229. <view class="payment-header">
  230. <text class="payment-title">现在支付</text>
  231. <text class="payment-amount">¥{{ computeMoney }}</text>
  232. </view>
  233. <up-line></up-line>
  234. <!-- 钱包支付选项 -->
  235. <view class="payment-option">
  236. <view class="option-left">
  237. <image src="/static/钱包.png" class="payment-icon"></image>
  238. <text class="option-text">钱包</text>
  239. </view>
  240. <up-radio-group
  241. v-model="radiovalue1"
  242. placement="column"
  243. @change="handlePaymentMethodChange"
  244. >
  245. <up-radio
  246. :customStyle="{ marginLeft: 'auto' }"
  247. v-for="(item, index) in radiolist1"
  248. :key="index"
  249. :label="item.name"
  250. :name="item.name"
  251. ></up-radio>
  252. </up-radio-group>
  253. </view>
  254. <up-line></up-line>
  255. <!-- 微信支付选项 -->
  256. <view class="payment-option">
  257. <view class="option-left">
  258. <image src="/static/微信支付.png" class="payment-icon"></image>
  259. <text class="option-text">微信支付</text>
  260. </view>
  261. <up-radio-group
  262. v-model="radiovalue1"
  263. placement="column"
  264. @change="handlePaymentMethodChange"
  265. >
  266. <up-radio
  267. :customStyle="{ marginLeft: 'auto' }"
  268. v-for="(item, index) in radiolist2"
  269. :key="index"
  270. :label="item.name"
  271. :name="item.name"
  272. ></up-radio>
  273. </up-radio-group>
  274. </view>
  275. <up-line></up-line>
  276. <!-- 其他支付方式 -->
  277. <view class="other-payment"> 其他方式支付 > </view>
  278. <!-- 条款说明 -->
  279. <view class="terms-of-service">
  280. 我同意购买守则,取消政策和退款政策,我也同意支付以下所示的总金额(含服务费)。
  281. </view>
  282. </view>
  283. <view class="Wrap-detils-btn">
  284. <up-button
  285. type="primary"
  286. shape="circle"
  287. :customStyle="wrapqx"
  288. @click="closeSecond"
  289. >取消</up-button
  290. >
  291. <up-button
  292. type="error"
  293. shape="circle"
  294. :customStyle="wrapqx"
  295. @click="handlConfiRmpurchase"
  296. >
  297. 购买¥{{ computeMoney }}
  298. </up-button>
  299. </view>
  300. </up-popup>
  301. <view v-if="addressFlag" class="box">
  302. <addressComponent
  303. :modelValue="addressFlag"
  304. @update:modelValue="(val) => (addressFlag = val)"
  305. :addressInfo="addressInfo"
  306. @update:addressInfo="handleAddressUpdate"
  307. ></addressComponent>
  308. </view>
  309. </view>
  310. </template>
  311. <script setup>
  312. import { onLoad } from '@dcloudio/uni-app'
  313. import { onMounted, ref, reactive, computed, nextTick } from 'vue'
  314. import {
  315. getDetailsvolunteerId,
  316. volunteerwork,
  317. volunteergetTimesByDate,
  318. ordersCreateOrder,
  319. coreUsersOrdersPayCancel,
  320. } from '@/api/volunteerDetailsApi/details.js'
  321. import itsCalendar from '@/components/its-calendar/its-calendar.vue'
  322. import uniDatetimePickerMy from '@/uni_modules/lic-uni-datetime-picker/components/lic-uni-datetime-picker/lic-uni-datetime-picker.vue'
  323. import addressComponent from '@/pages_home/components/volunteerData/adresss.vue'
  324. import Detiles from './detiles.vue'
  325. // const src = ref(
  326. // 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg'
  327. // )
  328. const itsCalendarRef = ref(null)
  329. const businessPrice = ref() //价格
  330. const singleQuantity = ref(1) // 购买次数,默认为1,不可为0
  331. const volunteerId = ref('') // 存储志愿者ID
  332. const serviceCategory = ref('') //存储大类别
  333. const businessManagementId = ref('') //具体分类id
  334. const doorToDoorTimeArr = ref([]) // 完整时间范围
  335. const doorToDoorTime = ref([]) // 只具备开始、结束 时间
  336. const timeHostArr = ref([]) // 时间段数组
  337. const currentDate = ref([]) // 点击过的年月日数组数据
  338. const currentTime = ref('') // 最后一次点击时间的时间节点
  339. const selectedTimes = ref([]) // 存储所有选择的时间对象
  340. const totalTimes = ref(0) // 时间点 点击的次数
  341. const startDisabled = ref('')
  342. const endDisabled = ref('')
  343. const listData = ref({})
  344. const show = ref(false) //第一层弹框
  345. const showSecond = ref(false) //第二层弹框
  346. const remark = ref('') //备注
  347. const radiovalue1 = ref(null)
  348. const selectedAddress = ref(null)
  349. const addressFlag = ref(false)
  350. const paymentMethod = ref(null) // Add payment method ref with default value 1 (wallet)
  351. const addressInfo = ref(null)
  352. const value = ref(1) // 将在onLoad中更新为listData.minQuantity
  353. // Radio 单选框数据
  354. const radiolist1 = reactive([
  355. {
  356. name: '钱包支付',
  357. disabled: false,
  358. },
  359. ])
  360. const radiolist2 = reactive([
  361. {
  362. name: '微信支付',
  363. disabled: false,
  364. },
  365. ])
  366. // 详情底部立即购买弹框
  367. const buttonClick = (e) => {
  368. show.value = true // 打开弹框
  369. }
  370. // 详情页第一层弹框
  371. function open() {
  372. show.value = true
  373. }
  374. // 第一层弹框取消
  375. function close() {
  376. // 关闭逻辑,设置 show 为 false
  377. show.value = false
  378. }
  379. // 第一个弹框逻辑
  380. const handleBuy = () => {
  381. show.value = false // 关闭第一个弹框
  382. showSecond.value = true // 打开第二个弹框
  383. }
  384. // 第二层弹框取消
  385. function closeSecond() {
  386. // 关闭逻辑,设置 show 为 false
  387. showSecond.value = false
  388. show.value = true // 打开第一个弹框
  389. }
  390. const handlCancel = () => {
  391. show.value = false // 关闭第一个弹框
  392. selectedTimes.value = [] // 清空已选时间
  393. totalTimes.value = 0 // 重置点击次数
  394. }
  395. const jumpToAddressSelect = () => {
  396. addressFlag.value = true
  397. }
  398. // 新增:处理子组件传回的地址数据
  399. const handleAddressUpdate = (newAddress) => {
  400. selectedAddress.value = newAddress
  401. addressFlag.value = false // 关闭选择器
  402. }
  403. // 详情底部底部数据
  404. const options = ref([
  405. {
  406. icon: 'headphones',
  407. text: '客服',
  408. },
  409. {
  410. icon: 'shop',
  411. text: '收藏',
  412. },
  413. ])
  414. // 详情底部立即购买样式
  415. const buttonGroup = ref([
  416. {
  417. text: '立即购买',
  418. backgroundColor: 'red',
  419. color: '#fff',
  420. },
  421. ])
  422. // 底部帮助客服方法
  423. const onClick = (e) => {
  424. uni.showToast({
  425. title: `点击${e.content.text}`,
  426. icon: 'none',
  427. })
  428. }
  429. // 修改详情页底部样式
  430. const customStyle = {
  431. height: '70rpx',
  432. paddingLeft: '30rpx',
  433. width: '540rpx',
  434. }
  435. const wrapqx = {
  436. // height: '70rpx',
  437. width: '240rpx',
  438. }
  439. // 获取传递的参数
  440. onLoad(async (options) => {
  441. const option = JSON.parse(decodeURIComponent(options.params))
  442. const {
  443. volunteerId: id,
  444. serviceCategory: categoy,
  445. businessManagementId: manage,
  446. } = option
  447. volunteerId.value = id
  448. serviceCategory.value = categoy
  449. businessManagementId.value = manage
  450. const res = await getDetailsvolunteerId({
  451. volunteerId: id,
  452. serviceCategory: categoy,
  453. businessManagementId: manage,
  454. })
  455. listData.value = res.data || {}
  456. // 更新步进器的初始值为listData中的minQuantity
  457. value.value = listData.value.minQuantity || 1
  458. businessPrice.value = listData.value.businessPrice || 0
  459. singleQuantity.value = listData.value.minQuantity || 1
  460. })
  461. // 添加步进器值变化处理函数
  462. const valChange = (obj) => {
  463. const durationMs = listData.value.businessDuration * obj.value * 60
  464. const a = itsCalendarRef.value.upItem
  465. const b = itsCalendarRef.value.timeHostArr
  466. const c = itsCalendarRef.value.day_index
  467. const seconds = listData.value.businessDuration * obj.value * 60
  468. const endTimestamp = a.timeStamp + durationMs
  469. // 根据当前时间分割出后续应选数据数组
  470. const filteredSlots = b[c].filter((i) => {
  471. return i.timeStamp > a.timeStamp && i.timeStamp <= endTimestamp
  472. })
  473. const timestampDifferenceValue = filteredSlots.length
  474. ? filteredSlots[filteredSlots.length - 1].timeStamp - a.timeStamp
  475. : 0
  476. console.log(filteredSlots, '>>>>>filteredSlots')
  477. if (timestampDifferenceValue < durationMs) {
  478. // 所选时间差值 小于 服务时间值 结束执行
  479. uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' })
  480. return false
  481. }
  482. singleQuantity.value = obj.value || 1
  483. nextTick(() => {
  484. itsCalendarRef.value.handleTimeClick2()
  485. })
  486. }
  487. // 选择日期
  488. const getListTime = async () => {
  489. const params = {
  490. volunteerId: Number(volunteerId.value),
  491. }
  492. const res = await volunteerwork(params)
  493. if (res.data && res.data.length > 0) {
  494. doorToDoorTimeArr.value = res.data
  495. const newRes = [res.data[0], res.data[res.data.length - 1]]
  496. doorToDoorTime.value = newRes
  497. startDisabled.value = doorToDoorTime.value[0]
  498. endDisabled.value = doorToDoorTime.value[1]
  499. // 默认加载第一个日期的排班时间
  500. getByDate(res.data[0])
  501. } else {
  502. console.error('接口返回的日期范围为空')
  503. doorToDoorTimeArr.value = []
  504. timeHostArr.value = [] // 清空时间段
  505. }
  506. }
  507. // 获取志愿者排班时间
  508. const getByDate = async (date = doorToDoorTimeArr.value[0]) => {
  509. // 检查日期是否为空
  510. if (!date) {
  511. coannsole.error('日期为空,跳过获取排班时间')
  512. return
  513. }
  514. if (!volunteerId.value) {
  515. console.error('volunteerId 为空')
  516. return
  517. }
  518. const params = {
  519. volunteerId: volunteerId.value,
  520. date,
  521. }
  522. try {
  523. const res = await volunteergetTimesByDate(params)
  524. const TArr = res.data.map((item) => {
  525. // 初始化disabled变量
  526. let disabled = false
  527. if (item.hasReservation === 1) disabled = true
  528. let itemTime =
  529. item.timeStamp > 9999999999 ? item.timeStamp : item.timeStamp * 1000
  530. if (new Date().getTime() > itemTime) disabled = true
  531. return {
  532. ...item,
  533. hours: item.reservationTime,
  534. timeStamp: new Date(`${date} ${item.reservationTime}`).getTime() / 1000,
  535. date: date,
  536. // checked: false, // 每次点击请求时间后,延续之前选中状态,不初始化选中
  537. disabled,
  538. }
  539. })
  540. // 如果 doorToDoorTimeArr.value 为空,直接返回
  541. if (!doorToDoorTimeArr.value.length) {
  542. console.error('可选的日期范围为空')
  543. return
  544. }
  545. // 填充时间段数组
  546. timeHostArr.value = Array(doorToDoorTimeArr.value.length).fill(TArr)
  547. } catch (error) {
  548. console.error('获取排班时间失败:', error)
  549. }
  550. }
  551. const getByTime = (timeObj) => {
  552. if (timeObj.clicked) {
  553. return
  554. }
  555. if (timeObj.checked) {
  556. // 选中 添加到已选时间数组
  557. selectedTimes.value.push({
  558. date: timeObj.date,
  559. time: timeObj.hours,
  560. timestamp: timeObj.timeStamp,
  561. })
  562. } else {
  563. // 取消选中
  564. const index = selectedTimes.value.findIndex(
  565. (item) => item.timestamp === timeObj.timeStamp
  566. )
  567. selectedTimes.value.splice(index, 1)
  568. }
  569. totalTimes.value = selectedTimes.value.length // 更新点击次数
  570. }
  571. // 立即购买显示时执行
  572. const upPopupOpen = () => {
  573. //显示时初始化预存储信息数据
  574. selectedTimes.value = []
  575. totalTimes.value = 0
  576. currentTime.value = ''
  577. currentDate.value = []
  578. // 初始化disabled/checked 数据状态
  579. getByDate()
  580. }
  581. const computeMoney = computed(() => {
  582. console.log(
  583. totalTimes.value,
  584. businessPrice.value,
  585. singleQuantity.value,
  586. '>>>>>> console.log(totalTimes.value * businessPrice.value * minQuantity.value);'
  587. )
  588. return totalTimes.value * businessPrice.value * singleQuantity.value
  589. })
  590. const certificationPictures = computed(() => {
  591. if (listData.value.certificationPicture) {
  592. return listData.value.certificationPicture.split(',')
  593. }
  594. return []
  595. })
  596. // 确认购买
  597. const handlConfiRmpurchase = () => {
  598. if (!selectedAddress.value) {
  599. uni.showToast({
  600. title: '请选择服务地址',
  601. icon: 'none',
  602. duration: 2000,
  603. })
  604. return // 阻止购买
  605. } else if (!paymentMethod.value) {
  606. uni.showToast({
  607. title: '请选择支付方式',
  608. icon: 'none',
  609. duration: 2000,
  610. })
  611. return // 阻止购买
  612. }
  613. // 如果有地址,执行购买逻辑
  614. proceedToPayment()
  615. }
  616. const proceedToPayment = async () => {
  617. try {
  618. // 定义要发送的数据
  619. const orderData = {
  620. orders: {
  621. // serviceOnePrice: businessPrice.value,
  622. // serviceTotalPrice: computeMoney.value,
  623. serviceCategory: serviceCategory.value,
  624. totalTimes: totalTimes.value,
  625. paymentMethod: paymentMethod.value,
  626. volunteerId: volunteerId.value,
  627. remark: remark.value,
  628. businessManagementId: businessManagementId.value,
  629. volunteerInfoId: listData.value.volunteerInfoId,
  630. addressId: selectedAddress.value.addressId,
  631. singleQuantity: singleQuantity.value,
  632. },
  633. workDateList: [],
  634. }
  635. // 转换所有选择的时间
  636. selectedTimes.value.forEach((item) => {
  637. orderData.workDateList.push({
  638. workDate: item.date,
  639. workStartTime: item.time,
  640. })
  641. })
  642. // 创建订单
  643. const res = await ordersCreateOrder(orderData)
  644. if (res.code !== 200) {
  645. throw new Error('创建订单失败')
  646. }
  647. // 保存订单号
  648. const mainOrderId = res.data.mainOrderId
  649. console.log('创建订单成功,订单号:', mainOrderId)
  650. // 如果是微信支付
  651. if (paymentMethod.value === 2) {
  652. return new Promise((resolve, reject) => {
  653. uni.requestPayment({
  654. ...res.data,
  655. package: res.data.packageValue,
  656. success: (payRes) => {
  657. console.log('支付成功:', payRes)
  658. if (payRes.errMsg === 'requestPayment:ok') {
  659. uni.showToast({
  660. title: '支付成功',
  661. icon: 'success',
  662. duration: 1500,
  663. mask: true,
  664. })
  665. setTimeout(() => {
  666. uni.reLaunch({
  667. url: '/pages/classify',
  668. })
  669. }, 1500)
  670. resolve(payRes)
  671. }
  672. },
  673. fail: async (payRes) => {
  674. console.log('支付失败或取消:', payRes)
  675. try {
  676. // 调用取消支付接口
  677. const cancelRes = await coreUsersOrdersPayCancel({ mainOrderId })
  678. console.log('取消支付接口调用成功:', cancelRes)
  679. if (payRes.errMsg === 'requestPayment:fail cancel') {
  680. uni.showToast({
  681. title: '已取消支付',
  682. icon: 'none',
  683. duration: 1500,
  684. mask: true,
  685. })
  686. } else {
  687. uni.showToast({
  688. title: '支付失败',
  689. icon: 'error',
  690. duration: 1500,
  691. mask: true,
  692. })
  693. }
  694. reject(payRes)
  695. } catch (error) {
  696. console.error('取消支付接口调用失败:', error)
  697. uni.showToast({
  698. title: '取消支付失败',
  699. icon: 'error',
  700. duration: 1500,
  701. mask: true,
  702. })
  703. reject(error)
  704. }
  705. },
  706. })
  707. })
  708. }
  709. // 如果是钱包支付
  710. if (paymentMethod.value === 1) {
  711. uni.showToast({
  712. title: '支付成功',
  713. icon: 'success',
  714. duration: 1500,
  715. mask: true,
  716. })
  717. setTimeout(() => {
  718. uni.reLaunch({
  719. url: '/pages/classify',
  720. })
  721. }, 1500)
  722. }
  723. } catch (error) {
  724. console.error('支付失败:', error)
  725. uni.showToast({
  726. title: '余额不足',
  727. icon: 'error',
  728. duration: 1500,
  729. mask: true,
  730. })
  731. }
  732. }
  733. // 修改支付方式
  734. const handlePaymentMethodChange = (value) => {
  735. if (value === '钱包支付') {
  736. paymentMethod.value = 1
  737. } else if (value === '微信支付') {
  738. paymentMethod.value = 2
  739. }
  740. }
  741. onMounted(async () => {
  742. await getListTime()
  743. })
  744. </script>
  745. <style scoped>
  746. /* 添加卡片样式 */
  747. .card-container {
  748. display: flex;
  749. padding: 20rpx;
  750. margin: 10rpx;
  751. background-color: #fff;
  752. border-radius: 10rpx;
  753. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  754. }
  755. .card-image {
  756. width: 120rpx;
  757. height: 120rpx;
  758. border-radius: 10rpx;
  759. margin-right: 20rpx;
  760. }
  761. .card-content {
  762. flex: 1;
  763. display: flex;
  764. flex-direction: column;
  765. justify-content: space-between;
  766. }
  767. .info-item,
  768. .Telephone,
  769. .date,
  770. .time {
  771. font-size: 26rpx;
  772. margin-bottom: 8rpx;
  773. }
  774. .box {
  775. height: 100vh;
  776. width: 100vw;
  777. position: fixed;
  778. top: 0;
  779. left: 0;
  780. z-index: 999999;
  781. background: red;
  782. }
  783. .card-container {
  784. display: flex;
  785. position: relative;
  786. padding: 20rpx;
  787. align-items: flex-start;
  788. background-color: #fff;
  789. border-radius: 12rpx;
  790. }
  791. /* 左侧图片 */
  792. .card-image {
  793. width: 240rpx;
  794. height: 380rpx;
  795. border-radius: 12rpx;
  796. margin-right: 30rpx;
  797. flex-shrink: 0;
  798. }
  799. /* 中间信息区域 */
  800. .card-info {
  801. flex: 1;
  802. padding-right: 100rpx;
  803. }
  804. .Telephone {
  805. white-space: nowrap;
  806. margin-bottom: 24rpx;
  807. font-size: 28rpx;
  808. line-height: 1.6;
  809. color: #333;
  810. }
  811. .info-item {
  812. margin-bottom: 24rpx;
  813. font-size: 28rpx;
  814. line-height: 1.6;
  815. color: #333;
  816. }
  817. /* 右上角评分 */
  818. .card-rating {
  819. position: absolute;
  820. top: 20rpx;
  821. right: 20rpx;
  822. background-color: #f8f8f8;
  823. padding: 6rpx 16rpx;
  824. border-radius: 20rpx;
  825. font-size: 24rpx;
  826. color: #ff9900;
  827. font-weight: bold;
  828. }
  829. /* 固定在页面底部 */
  830. .Wrap-btn {
  831. /* display: flex; */
  832. /* justify-content: flex-end; */
  833. /* align-items: center; */
  834. position: fixed;
  835. bottom: 0;
  836. width: 100%;
  837. background-color: white;
  838. padding: 40rpx 20rpx;
  839. box-shadow: -2rpx 5rpx rgba(0, 0, 0, 0.1);
  840. }
  841. .Wrapper {
  842. display: flex;
  843. align-items: center;
  844. gap: 10rpx;
  845. margin-top: 10rpx;
  846. }
  847. .Wrapper-img {
  848. width: 50rpx;
  849. height: 50rpx;
  850. margin-left: 10rpx;
  851. }
  852. .Wrapper-content {
  853. color: rgba(16, 16, 16, 1);
  854. font-size: 25rpx;
  855. font-family: PingFangSC-regular;
  856. line-height: 20rpx;
  857. }
  858. .Wrap-content1 {
  859. display: flex;
  860. justify-content: flex-start;
  861. margin-left: 10rpx;
  862. margin-top: 10rpx;
  863. }
  864. .Wrap-info {
  865. display: flex;
  866. justify-content: flex-start;
  867. margin-left: 10rpx;
  868. margin-top: 25rpx;
  869. }
  870. .Wrap-content3 {
  871. margin-top: 25rpx;
  872. }
  873. .Wrap-content4 {
  874. margin-top: 25rpx;
  875. }
  876. .Wrap-content5 {
  877. display: flex;
  878. justify-content: flex-start;
  879. margin-left: 10rpx;
  880. margin-top: 25rpx;
  881. }
  882. .Wrap-content6 {
  883. margin-top: 25rpx;
  884. }
  885. .Wrap-detils-btn {
  886. display: flex;
  887. justify-content: flex-end;
  888. align-items: center;
  889. margin-top: 25rpx;
  890. /* position: fixed;
  891. bottom: 0;
  892. width: 100%;
  893. background-color: white;
  894. padding: 40rpx 20rpx;
  895. box-shadow: -2rpx 5rpx rgba(0, 0, 0, 0.1); */
  896. }
  897. .Wrap-Payment {
  898. padding: 30rpx;
  899. background-color: #fff;
  900. }
  901. .payment-header {
  902. display: flex;
  903. justify-content: space-between;
  904. align-items: center;
  905. padding: 20rpx 0;
  906. }
  907. .payment-title {
  908. font-size: 32rpx;
  909. font-weight: bold;
  910. }
  911. .payment-amount {
  912. font-size: 36rpx;
  913. color: #ff4d4f;
  914. font-weight: bold;
  915. }
  916. .payment-option {
  917. display: flex;
  918. justify-content: space-between;
  919. align-items: center;
  920. padding: 30rpx 0;
  921. }
  922. .option-left {
  923. display: flex;
  924. align-items: center;
  925. }
  926. .payment-icon {
  927. width: 80rpx;
  928. height: 80rpx;
  929. margin-right: 20rpx;
  930. }
  931. .option-text {
  932. font-size: 30rpx;
  933. font-weight: bold;
  934. }
  935. .other-payment {
  936. padding: 30rpx 0;
  937. color: #1890ff;
  938. font-size: 28rpx;
  939. }
  940. .terms-of-service {
  941. padding: 30rpx 0;
  942. font-size: 24rpx;
  943. color: #999;
  944. line-height: 1.5;
  945. }
  946. .confirm-button {
  947. margin-top: 40rpx;
  948. }
  949. .certificate {
  950. display: flex;
  951. flex-direction: column;
  952. }
  953. .certificate-img {
  954. margin-bottom: 24rpx;
  955. }
  956. /* 第二层弹框 */
  957. .card-container {
  958. display: flex;
  959. flex-direction: row;
  960. align-items: flex-start;
  961. padding: 10px;
  962. }
  963. .card-image {
  964. width: 100px;
  965. /* Adjust as needed */
  966. height: 100px;
  967. /* Adjust as needed */
  968. border-radius: 8px;
  969. margin-right: 15px;
  970. object-fit: cover;
  971. }
  972. .card-content {
  973. flex: 1;
  974. display: flex;
  975. flex-direction: column;
  976. }
  977. .info-item,
  978. .Telephone,
  979. .date,
  980. .time {
  981. margin-bottom: 5px;
  982. font-size: 14px;
  983. color: #333;
  984. }
  985. .time span {
  986. margin-right: 8px;
  987. }
  988. .address-line {
  989. font-size: 14px;
  990. line-height: 20rpx;
  991. /* 行高20rpx */
  992. color: #333;
  993. /* 深色文字 */
  994. display: block;
  995. /* 确保独占一行 */
  996. margin-bottom: 30rpx;
  997. /* 下边距30rpx */
  998. }
  999. /* 联系人信息容器 */
  1000. .contact-info {
  1001. display: flex;
  1002. gap: 20rpx;
  1003. /* 姓名和电话之间的间距 */
  1004. }
  1005. /* 姓名样式 */
  1006. .contact-name {
  1007. font-size: 12px;
  1008. color: #999;
  1009. /* 灰色文字 */
  1010. line-height: 20rpx;
  1011. }
  1012. /* 电话样式 */
  1013. .contact-phone {
  1014. font-size: 12px;
  1015. color: #999;
  1016. /* 灰色文字 */
  1017. line-height: 20rpx;
  1018. }
  1019. /* 服务描述卡片样式 */
  1020. .service-description-container {
  1021. display: flex;
  1022. justify-content: space-between;
  1023. align-items: flex-start;
  1024. }
  1025. .service-text {
  1026. flex: 1;
  1027. margin-right: 20rpx;
  1028. }
  1029. .service-price {
  1030. font-size: 32rpx;
  1031. font-weight: bold;
  1032. color: #ff4d4f;
  1033. white-space: nowrap;
  1034. }
  1035. </style>