goodsDetails.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <template>
  2. <view>
  3. <view>
  4. <up-card title="志愿者介绍" :head-style="{ height: '80rpx', padding: '20rpx',}">
  5. <template #body>
  6. <view class="card-container">
  7. <!-- 左侧图片 -->
  8. <image class="card-image" :src="listData.volunteerPicture" mode="aspectFill"></image>
  9. <!-- 中间信息(姓名/类别等) -->
  10. <view class="card-info">
  11. <view class="info-item">姓名:{{listData.name}}</view>
  12. <view class="info-item">服务项目:{{listData.projectName}}</view>
  13. <view v-if="serviceSubjectName != null" class="info-item">类别:{{ listData.projectTypeName }}
  14. </view>
  15. <view class="Telephone">服务时长:{{listData.businessDuration}}</view>
  16. <view class="Telephone">科目:{{listData.serviceSubjectName}}</view>
  17. <view class="Telephone">电话:{{listData.phonenumber}}</view>
  18. </view>
  19. <!-- 右上角评分 - 使用绝对定位 -->
  20. <view class="card-rating">4.5 评分</view>
  21. </view>
  22. </template>
  23. </up-card>
  24. <up-card title="技能介绍" :thumb="thumb" :head-style="{ height: '80rpx', padding: '20rpx',}">
  25. <template #body>
  26. {{listData.skillDescribe}}
  27. </template>
  28. </up-card>
  29. <up-card title="证书" :thumb="thumb" :head-style="{ height: '80rpx', padding: '20rpx',}">
  30. <template #body>
  31. <view class="certificate">
  32. <image v-for="item in certificationPictures" :key="item" :src="item" mode=""
  33. style="width: 100%;" class="certificate-img"></image>
  34. </view>
  35. </template>
  36. </up-card>
  37. <!-- 固定底部按钮区 -->
  38. <view class="Wrap-btn">
  39. <uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
  40. @buttonClick="buttonClick" />
  41. </view>
  42. </view>
  43. <!-- 底部弹框 -->
  44. <view>
  45. <up-popup :show="show" @close="close" @open="open">
  46. </up-popup>
  47. <up-popup v-model:show="show" @open="upPopupOpen">
  48. <view>
  49. <view class="Wrapper">
  50. <image src="/static/img/Location.png" class="Wrapper-img" />
  51. <span class="Wrapper-content">李四</span>
  52. <span class="Wrapper-content">重庆永川区</span>
  53. </view>
  54. <span style="margin-left: 15rpx; margin-top: 50rpx;">重庆永川区</span>
  55. </view>
  56. <up-divider></up-divider>
  57. <view class="Wrap-content1">
  58. <up-avatar :src="src"></up-avatar>
  59. <text style="margin-top: 15rpx;">¥{{listData.businessPrice}}</text>
  60. </view>
  61. <!-- -->
  62. <view class="Wrap-info">
  63. <text style="margin-left: 10rpx;">服务类别:</text>
  64. <up-text type="info" text="家庭教育"></up-text>
  65. </view>
  66. <view class="Wrap-content3">
  67. <text style="margin-left: 15rpx;">服务周期:</text>
  68. <view style="margin-top: 25rpx;">
  69. <uniDatetimePickerMy :modelValue="doorToDoorTime" :start="startDisabled" :end="endDisabled"
  70. type="daterange"></uniDatetimePickerMy>
  71. </view>
  72. <view>
  73. <its-calendar :timeArr="doorToDoorTimeArr" :timeHostArr="timeHostArr" @getByDate="getByDate"
  74. @getByTime="getByTime"></its-calendar>
  75. </view>
  76. </view>
  77. <view class="Wrap-content6">
  78. <text style="margin-left: 15rpx;">备注:</text>
  79. <up-input placeholder="请输入内容" border="surround" v-model="remark" @change="change"></up-input>
  80. </view>
  81. <view class="Wrap-detils-btn">
  82. <up-button type="primary" shape="circle" :customStyle="wrapqx" @click="handlCancel">取消</up-button>
  83. <up-button type="error" shape="circle" :customStyle="wrapqx" @click="handleBuy">
  84. 购买¥{{ computeMoney }}
  85. </up-button>
  86. </view>
  87. </up-popup>
  88. </view>
  89. <up-popup v-model:show="showSum">
  90. <view class="Wrap-Payment">
  91. <!-- 支付金额 -->
  92. <view class="payment-header">
  93. <text class="payment-title">现在支付</text>
  94. <text class="payment-amount">¥{{ computeMoney }}</text>
  95. </view>
  96. <up-line></up-line>
  97. <!-- 钱包支付选项 -->
  98. <view class="payment-option">
  99. <view class="option-left">
  100. <image src="/static/my/钱包.png" class="payment-icon"></image>
  101. <text class="option-text">钱包</text>
  102. </view>
  103. <up-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
  104. <up-radio :customStyle="{marginLeft: 'auto'}" v-for="(item, index) in radiolist1" :key="index"
  105. :label="item.name" :name="item.name"></up-radio>
  106. </up-radio-group>
  107. </view>
  108. <up-line></up-line>
  109. <!-- 微信支付选项 -->
  110. <view class="payment-option">
  111. <view class="option-left">
  112. <image src="/static/微信支付.png" class="payment-icon"></image>
  113. <text class="option-text">微信支付</text>
  114. </view>
  115. <up-radio :customStyle="{marginLeft: 'auto'}" v-for="(item, index) in radiolist2" :key="index"
  116. :label="item.name" :name="item.name"></up-radio>
  117. </view>
  118. <up-line></up-line>
  119. <!-- 其他支付方式 -->
  120. <view class="other-payment">
  121. 其他方式支付 >
  122. </view>
  123. <!-- 条款说明 -->
  124. <view class="terms-of-service">
  125. 我同意购买守则,取消政策和退款政策,我也同意支付以下所示的总金额(含服务费)。
  126. </view>
  127. <!-- 确认按钮 -->
  128. <view class="confirm-button">
  129. <up-button type="primary" :text="`确认购买 · ¥${computeMoney}`"
  130. @click="handlConfiRmpurchase"></up-button>
  131. </view>
  132. </view>
  133. </up-popup>
  134. <up-notify message="支付成功" :show="showNotify"></up-notify>
  135. </view>
  136. </template>
  137. <script setup>
  138. // 点击当前时间,后面时间禁用
  139. // workDate获取点击的精确时间
  140. import {
  141. onLoad
  142. } from '@dcloudio/uni-app'
  143. import {
  144. onMounted,
  145. ref,
  146. nextTick,
  147. reactive,
  148. computed
  149. } from "vue";
  150. import {
  151. getDetailsvolunteerId,
  152. volunteerwork,
  153. volunteergetTimesByDate,
  154. ordersCreateOrder
  155. } from "@/api/volunteerDetailsApi/details.js"
  156. import itsCalendar from '@/components/its-calendar/its-calendar.vue';
  157. import uniDatetimePickerMy from "@/uni_modules/lic-uni-datetime-picker/components/lic-uni-datetime-picker/lic-uni-datetime-picker.vue"
  158. const src = ref('http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg')
  159. const businessPrice = ref() //价格
  160. const volunteerId = ref(''); // 存储志愿者ID
  161. const serviceCategory = ref('') //存储大类别
  162. const businessManagementId = ref('') //具体分类id
  163. const doorToDoorTimeArr = ref([]) // 完整时间范围
  164. const doorToDoorTime = ref([]) // 只具备开始、结束 时间
  165. const timeHostArr = ref([]) // 时间段数组
  166. const currentDate = ref([]) // 点击过的年月日数组数据
  167. const currentTime = ref('') // 最后一次点击时间的时间节点
  168. const selectedTimes = ref([]) // 存储所有选择的时间对象
  169. const totalTimes = ref(0) // 时间点 点击的次数
  170. const startDisabled = ref('')
  171. const endDisabled = ref('')
  172. const time = ref('')
  173. const listData = ref({})
  174. const show = ref(false); //立即购买
  175. const showSum = ref(false);
  176. const showNotify = ref(false) //支付成功提示
  177. const remark = ref('') //备注
  178. const computeMoney = computed(() => {
  179. return totalTimes.value * businessPrice.value
  180. })
  181. const certificationPictures = computed(() => {
  182. if (listData.value.certificationPicture) {
  183. return listData.value.certificationPicture.split(',')
  184. }
  185. return []
  186. })
  187. // 定义方法
  188. function open() {
  189. // 打开逻辑,比如设置 show 为 true
  190. show.value = true;
  191. }
  192. function close() {
  193. // 关闭逻辑,设置 show 为 false
  194. show.value = false;
  195. }
  196. // 定义方法
  197. function openSum() {
  198. // 打开逻辑,比如设置 show 为 true
  199. showSum.value = true;
  200. }
  201. function closeSum() {
  202. // 关闭逻辑,设置 show 为 false
  203. showSum.value = false;
  204. }
  205. const handleBuy = () => {
  206. show.value = false; // 关闭第一个弹框
  207. showSum.value = true; // 打开第二个弹框
  208. };
  209. const handlCancel = () => {
  210. show.value = false; // 关闭第一个弹框
  211. selectedTimes.value = []; // 清空已选时间
  212. totalTimes.value = 0; // 重置点击次数
  213. }
  214. // 底部数据
  215. const options = ref([{
  216. icon: 'headphones',
  217. text: '客服'
  218. },
  219. {
  220. icon: 'shop',
  221. text: '收藏',
  222. },
  223. ]);
  224. const buttonGroup = ref([{
  225. text: '立即购买',
  226. backgroundColor: 'red',
  227. color: '#fff'
  228. }]);
  229. // 方法
  230. const onClick = (e) => {
  231. uni.showToast({
  232. title: `点击${e.content.text}`,
  233. icon: 'none'
  234. });
  235. };
  236. const buttonClick = (e) => {
  237. // console.log(e);
  238. // options.value[2].info++;
  239. show.value = true; // 打开弹框
  240. };
  241. // Radio 单选框数据
  242. const radiolist1 = reactive([{
  243. name: '',
  244. disabled: false,
  245. },
  246. ]);
  247. // up-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  248. const radiovalue1 = ref('苹果');
  249. const groupChange = (n) => {
  250. console.log('groupChange', n);
  251. };
  252. const radioChange = (n) => {
  253. console.log('radioChange', n);
  254. };
  255. // 修改详情页底部样式
  256. const customStyle = {
  257. height: '70rpx',
  258. paddingLeft: '30rpx',
  259. width: '540rpx'
  260. }
  261. const wrapqx = {
  262. // height: '70rpx',
  263. width: '240rpx',
  264. }
  265. // 获取传递的参数
  266. onLoad(async (options) => {
  267. const params = JSON.parse(options.params);
  268. const {
  269. volunteerId: id,
  270. serviceCategory: categoy,
  271. businessManagementId: manage
  272. } = params;
  273. volunteerId.value = id;
  274. serviceCategory.value = categoy;
  275. businessManagementId.value = manage;
  276. const res = await getDetailsvolunteerId({
  277. volunteerId: id,
  278. serviceCategory: categoy,
  279. businessManagementId: manage,
  280. });
  281. listData.value = res.data || {};
  282. businessPrice.value = listData.value.businessPrice || 0;
  283. });
  284. // 选择日期
  285. const getListTime = async () => {
  286. const params = {
  287. volunteerId: Number(volunteerId.value),
  288. };
  289. const res = await volunteerwork(params);
  290. if (res.data && res.data.length > 0) {
  291. doorToDoorTimeArr.value = res.data;
  292. const newRes = [res.data[0], res.data[res.data.length - 1]];
  293. doorToDoorTime.value = newRes;
  294. startDisabled.value = doorToDoorTime.value[0];
  295. endDisabled.value = doorToDoorTime.value[1];
  296. // 默认加载第一个日期的排班时间
  297. getByDate(res.data[0]);
  298. } else {
  299. console.error('接口返回的日期范围为空');
  300. doorToDoorTimeArr.value = [];
  301. timeHostArr.value = []; // 清空时间段
  302. }
  303. };
  304. // 获取志愿者排班时间
  305. const getByDate = async (date = doorToDoorTimeArr.value[0]) => {
  306. // 检查日期是否为空
  307. if (!date) {
  308. console.error('日期为空,跳过获取排班时间');
  309. return;
  310. }
  311. if (!volunteerId.value) {
  312. console.error('volunteerId 为空');
  313. return;
  314. }
  315. const params = {
  316. volunteerId: volunteerId.value,
  317. date,
  318. };
  319. try {
  320. const res = await volunteergetTimesByDate(params);
  321. const TArr = res.data.map((item) => ({
  322. ...item,
  323. hours: item.reservationTime,
  324. timeStamp: new Date(`${date} ${item.reservationTime}`).getTime() / 1000,
  325. }));
  326. // 如果 doorToDoorTimeArr.value 为空,直接返回
  327. if (!doorToDoorTimeArr.value.length) {
  328. console.error('可选的日期范围为空');
  329. return;
  330. }
  331. // 填充时间段数组
  332. timeHostArr.value = Array(doorToDoorTimeArr.value.length).fill(TArr);
  333. } catch (error) {
  334. console.error('获取排班时间失败:', error);
  335. }
  336. };
  337. const getByTime = (timeObj) => {
  338. if (timeObj.clicked) {
  339. console.log('>>>>>> 已经点击过此时间');
  340. return;
  341. }
  342. // 标记为已点击
  343. timeObj.clicked = true;
  344. // 添加到已选时间数组
  345. selectedTimes.value.push({
  346. date: timeObj.yearToDate,
  347. time: timeObj.hours,
  348. timestamp: timeObj.timeStamp
  349. });
  350. totalTimes.value = selectedTimes.value.length; // 更新点击次数
  351. }
  352. // 立即购买显示时执行
  353. const upPopupOpen = () => { //显示时初始化预存储信息数据
  354. selectedTimes.value = [];
  355. totalTimes.value = 0;
  356. currentTime.value = '';
  357. currentDate.value = [];
  358. }
  359. // 确认购买
  360. const handlConfiRmpurchase = async () => {
  361. // 定义要发送的数据
  362. const orderData = {
  363. orders: {
  364. serviceOnePrice: businessPrice.value,
  365. serviceTotalPrice: computeMoney.value, //需要传获取到的总价
  366. serviceCategory: serviceCategory.value, //大类别参数
  367. totalTimes: totalTimes.value, //点击的次数
  368. serviceStartDate: "2025-04-18",
  369. startTime: "8:00",
  370. serviceDuration: 4,
  371. paymentMethod: 1,
  372. addressId: 7,
  373. volunteerId: volunteerId.value,
  374. remark: remark.value,
  375. businessManagementId: businessManagementId.value,
  376. volunteerInfoId: listData.value.volunteerInfoId,
  377. },
  378. workDateList: [
  379. // {
  380. // workDate: currentDate.value,//需要传获取到的时间,就是某个月份
  381. // }
  382. ]
  383. };
  384. // currentDate.value.length && (new Set(currentDate.value)).forEach((item) => {
  385. // orderData.workDateList.push({
  386. // workDate: item,
  387. // workStartTime: currentTime.value,
  388. // })
  389. // })
  390. // 转换所有选择的时间
  391. selectedTimes.value.forEach(item => {
  392. orderData.workDateList.push({
  393. workDate: item.date,
  394. workStartTime: item.time
  395. });
  396. });
  397. try {
  398. const res = await ordersCreateOrder(orderData);
  399. if (res.code == 200) {
  400. showNotify.value = true
  401. uni.reLaunch({
  402. url: '/pages/index'
  403. });
  404. }
  405. } catch (error) {
  406. console.error('支付失败', error);
  407. }
  408. };
  409. onMounted(async () => {
  410. await getListTime()
  411. // getByDate()
  412. })
  413. </script>
  414. <style scoped>
  415. .card-container {
  416. display: flex;
  417. position: relative;
  418. padding: 20rpx;
  419. align-items: flex-start;
  420. background-color: #fff;
  421. border-radius: 12rpx;
  422. }
  423. /* 左侧图片 */
  424. .card-image {
  425. width: 240rpx;
  426. height: 340rpx;
  427. border-radius: 12rpx;
  428. margin-right: 30rpx;
  429. flex-shrink: 0;
  430. }
  431. /* 中间信息区域 */
  432. .card-info {
  433. flex: 1;
  434. padding-right: 100rpx;
  435. }
  436. .Telephone {
  437. white-space: nowrap;
  438. margin-bottom: 24rpx;
  439. font-size: 28rpx;
  440. line-height: 1.6;
  441. color: #333;
  442. }
  443. .info-item {
  444. margin-bottom: 24rpx;
  445. font-size: 28rpx;
  446. line-height: 1.6;
  447. color: #333;
  448. }
  449. /* 右上角评分 */
  450. .card-rating {
  451. position: absolute;
  452. top: 20rpx;
  453. right: 20rpx;
  454. background-color: #f8f8f8;
  455. padding: 6rpx 16rpx;
  456. border-radius: 20rpx;
  457. font-size: 24rpx;
  458. color: #ff9900;
  459. font-weight: bold;
  460. }
  461. /* 固定在页面底部 */
  462. .Wrap-btn {
  463. /* display: flex; */
  464. /* justify-content: flex-end; */
  465. /* align-items: center; */
  466. position: fixed;
  467. bottom: 0;
  468. width: 100%;
  469. background-color: white;
  470. padding: 40rpx 20rpx;
  471. box-shadow: -2rpx 5rpx rgba(0, 0, 0, 0.1);
  472. }
  473. .Wrapper {
  474. display: flex;
  475. align-items: center;
  476. gap: 10rpx;
  477. margin-top: 10rpx;
  478. }
  479. .Wrapper-img {
  480. width: 50rpx;
  481. height: 50rpx;
  482. margin-left: 10rpx;
  483. }
  484. .Wrapper-content {
  485. color: rgba(16, 16, 16, 1);
  486. font-size: 25rpx;
  487. font-family: PingFangSC-regular;
  488. line-height: 20rpx;
  489. }
  490. .Wrap-content1 {
  491. display: flex;
  492. justify-content: flex-start;
  493. margin-left: 10rpx;
  494. margin-top: 10rpx;
  495. }
  496. .Wrap-info {
  497. display: flex;
  498. justify-content: flex-start;
  499. margin-left: 10rpx;
  500. margin-top: 25rpx;
  501. }
  502. .Wrap-content3 {
  503. margin-top: 25rpx;
  504. }
  505. .Wrap-content4 {
  506. margin-top: 25rpx;
  507. }
  508. .Wrap-content5 {
  509. display: flex;
  510. justify-content: flex-start;
  511. margin-left: 10rpx;
  512. margin-top: 25rpx;
  513. }
  514. .Wrap-content6 {
  515. margin-top: 25rpx;
  516. }
  517. .Wrap-detils-btn {
  518. display: flex;
  519. justify-content: flex-end;
  520. align-items: center;
  521. margin-top: 25rpx;
  522. /* position: fixed;
  523. bottom: 0;
  524. width: 100%;
  525. background-color: white;
  526. padding: 40rpx 20rpx;
  527. box-shadow: -2rpx 5rpx rgba(0, 0, 0, 0.1); */
  528. }
  529. .Wrap-Payment {
  530. padding: 30rpx;
  531. background-color: #fff;
  532. }
  533. .payment-header {
  534. display: flex;
  535. justify-content: space-between;
  536. align-items: center;
  537. padding: 20rpx 0;
  538. }
  539. .payment-title {
  540. font-size: 32rpx;
  541. font-weight: bold;
  542. }
  543. .payment-amount {
  544. font-size: 36rpx;
  545. color: #ff4d4f;
  546. font-weight: bold;
  547. }
  548. .payment-option {
  549. display: flex;
  550. justify-content: space-between;
  551. align-items: center;
  552. padding: 30rpx 0;
  553. }
  554. .option-left {
  555. display: flex;
  556. align-items: center;
  557. }
  558. .payment-icon {
  559. width: 80rpx;
  560. height: 80rpx;
  561. margin-right: 20rpx;
  562. }
  563. .option-text {
  564. font-size: 30rpx;
  565. font-weight: bold;
  566. }
  567. .other-payment {
  568. padding: 30rpx 0;
  569. color: #1890ff;
  570. font-size: 28rpx;
  571. }
  572. .terms-of-service {
  573. padding: 30rpx 0;
  574. font-size: 24rpx;
  575. color: #999;
  576. line-height: 1.5;
  577. }
  578. .confirm-button {
  579. margin-top: 40rpx;
  580. }
  581. .certificate {
  582. display: flex;
  583. flex-direction: column;
  584. }
  585. .certificate-img {
  586. margin-bottom: 24rpx;
  587. }
  588. </style>