goodsDetails.vue 28 KB

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