goodsDetails.vue 28 KB

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