goodsDetails.vue 36 KB

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