goodsDetails.vue 28 KB

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