order.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <view class="container">
  3. <!-- 标题区域 -->
  4. <view class="title" :style="{ top: `${paddingTop * 2}rpx` }">我的出行</view>
  5. <wd-tabs v-model="tabIndex" auto-line-width custom-class="custom_class_tab" @click="handleChange">
  6. <block v-for="tab in tabs" :key="tab">
  7. <wd-tab :title="`${tab}`" :name="tab">
  8. <scroll-view scroll-y class="content" @scrolltolower="scrolltolower">
  9. <!-- 每一个订单区域 -->
  10. <view v-for="item in listData" :key="item.id" class="order_box">
  11. <view class="box_top">
  12. <view class="top_left">
  13. <image class="left_img" src="@/static/images/mine/riding.png" mode="aspectFill" />
  14. 墨轩出行
  15. </view>
  16. <view class="top_status red" v-if="item.payState==0">待支付</view>
  17. <view class="top_status red" v-if="item.payState==2">退款中</view>
  18. <view class="top_status red" v-if="item.payState==3">已取消</view>
  19. <view v-if="item.payState==1">
  20. <view class="top_status red" v-if="item.byState==1">预约成功</view>
  21. <view class="top_status red" v-if="item.byState==2">已乘车</view>
  22. <view class="top_status red" v-if="item.byState==3">未乘车</view>
  23. </view>
  24. <!-- <view class="top_status red" v-if="item.byState==5">预约失败</view> -->
  25. </view>
  26. <view class="box_center">
  27. <image class="center_img" src="@/static/images/home/line.png" mode="aspectFill" />
  28. <view class="center_text">
  29. <view class="text_start">{{getRouteParts(item.route_end).prefix}}</view>
  30. <view class="text_end">{{getRouteParts(item.route_end).suffix}}</view>
  31. </view>
  32. <view class="center_price">
  33. ¥
  34. <text class="text">{{ item.payAmount }}</text>
  35. </view>
  36. </view>
  37. <view class="box_bottom">
  38. <view class="bottom_time">出行时间:{{ item.ciDate }}</view>
  39. <view class="bottom_btns" v-if="item.payState==0">
  40. <view class="btn_item" @click="handleDetail(item)">查看详情</view>
  41. <view class="btn_item pay" @click="handlePay(item)">立即支付</view>
  42. </view>
  43. <view class="bottom_btns" v-if="item.payState==3">
  44. <view class="btn_item" @click="handleDetail(item)">查看详情</view>
  45. </view>
  46. <!-- <view class="bottom_btns" v-if="item.byState==5">
  47. <view class="btn_item" @click="handleDetail(item)">查看详情</view>
  48. </view> -->
  49. <view v-if="item.payState==1">
  50. <view class="bottom_btns" v-if="item.byState==1">
  51. <view class="btn_item" @click="handleDetail(item)">查看详情</view>
  52. </view>
  53. <view class="bottom_btns" v-if="item.byState==2">
  54. <view class="btn_item" @click="handleDetail(item)">查看详情</view>
  55. </view>
  56. <view class="bottom_btns" v-if="item.byState==3">
  57. <view class="btn_item" @click="handleDetail(item)">查看详情</view>
  58. <view class="btn_item hexiao" @click="showQrCodeDialog(item)">去核销</view>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="box_bottom">
  63. <view class="bottom_time"></view>
  64. <view v-if="item.payState==1 &&item.state!=4">
  65. <view class="bottom_btns" v-if="item.byState==3||item.byState==1">
  66. <view class="btn_item pay" @click="tuiPay(item)">退款</view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view v-if="!listData.length" style="padding-top: 100rpx">
  72. <wd-status-tip image="content" tip="暂无数据" />
  73. </view>
  74. </scroll-view>
  75. </wd-tab>
  76. </block>
  77. </wd-tabs>
  78. </view>
  79. <!-- 二维码弹框(默认隐藏) -->
  80. <wd-popup v-model="isDialogShow" safe-area-inset-bottom :close-on-click-modal="false">
  81. <view class="qr-dialog">
  82. <view class="dialog-content">
  83. <uv-qrcode ref="qrcode" size="180" class="qr-img" :value="ErorderNo"></uv-qrcode>
  84. <text class="dialog-tip">请出示此二维码给工作人员核销</text>
  85. <button class="close-btn" @click="isDialogShow = false">关闭</button>
  86. </view>
  87. </view>
  88. </wd-popup>
  89. <!-- 选择付款方式弹窗区域 -->
  90. <wd-popup v-model="popShow_pay" position="bottom" safe-area-inset-bottom :close-on-click-modal="false">
  91. <view class="pop_pay">
  92. <view class="pay_title">选择付款方式</view>
  93. <view class="pay_close" @click="handleClose">
  94. <wd-icon name="close-bold" color="#ABA6A6" size="22"></wd-icon>
  95. </view>
  96. <!-- 支付方式列表区域 -->
  97. <view class="pay_list">
  98. <!-- 每一个支付方式区域 -->
  99. <view class="list_item" v-for="(item, index) in payList" :key="index">
  100. <view class="item_left">
  101. <image class="img" :src="item.icon" mode="aspectFill"></image>
  102. {{ item.text }}
  103. </view>
  104. <view class="item_right">
  105. <radio style="scale: 0.8" color="#FF8205" :checked="item.isCheck" @click="togglePay(item)" />
  106. </view>
  107. </view>
  108. </view>
  109. <!-- 立即付款按钮区域 -->
  110. <view class="pay_btn" @click="payTime">立即付款</view>
  111. </view>
  112. </wd-popup>
  113. </template>
  114. <script setup>
  115. import { onMounted, ref, } from 'vue'
  116. import { onShow } from '@dcloudio/uni-app'
  117. import { myRequest } from '@/utils/api.ts'
  118. import debounce from 'lodash/debounce'
  119. import { useTabParamStore } from '@/utils/tabParams.js';
  120. const tabParamStore = useTabParamStore();
  121. // 用户信息
  122. const userInfo = uni.getStorageSync('carUserInfo')
  123. // 胶囊按钮距离页面顶部的距离
  124. const paddingTop = ref(0)
  125. const tabIndex = ref(0)
  126. // 控制二维码弹框显示隐藏
  127. const isDialogShow = ref(false);
  128. // 预约状态 0:全部 1:预约成功 2:已乘车 3:未乘车 4:已取消 5:预约失败6待支付
  129. const result_state = ref(0)
  130. // 时间状态 1:全部 2:当天 3:本周 4:本月
  131. const date_state = ref(1)
  132. // 每页多少条数据
  133. const pageSize = ref(6)
  134. // 当前是第几页
  135. const currentPage = ref(1)
  136. // 总共多少条数据
  137. const total = ref(0)
  138. // 预约记录数据
  139. const listData = ref([])
  140. //二维码核销数据
  141. const ErorderNo=ref('')
  142. const tabs = ref(['全部', '预约成功', '已乘车','未乘车', '已取消', '预约失败','待支付'])
  143. // 付款方式弹窗显示隐藏控制
  144. const popShow_pay = ref(false)
  145. // 支付方式列表
  146. const payList = ref([
  147. {
  148. text: '微信支付',
  149. icon: '/static/images/pay/wx.png',
  150. isCheck: false
  151. },
  152. {
  153. text: '电子交通卡支付',
  154. icon: '/static/images/pay/card.png',
  155. isCheck: false
  156. }
  157. ])
  158. // 选中的支付方式
  159. const selectedPay = ref(null);
  160. //继续支付订单
  161. const orderNo = ref('');
  162. // 存储支付参数
  163. const payParams = ref({
  164. timeStamp: '',
  165. nonceStr: '',
  166. signType: '',
  167. paySign: '',
  168. appId:'',
  169. prepay_id:'',
  170. package:''
  171. });
  172. // 截取箭头前后的文字
  173. const getRouteParts = (str) => {
  174. if (str && typeof str === 'string') {
  175. const parts = str.split('→');
  176. return {
  177. prefix: parts[0] || '', // 箭头前的文字
  178. suffix: parts[1] || '' // 箭头后的文字
  179. };
  180. }
  181. return { prefix: '', suffix: '' };
  182. };
  183. // 获取用户预约数据
  184. async function getMyData() {
  185. const res = await myRequest({
  186. url: '/tAppqueryUserBuy.action',
  187. data: {
  188. result_state: result_state.value,
  189. date_state: date_state.value,
  190. id: userInfo.id,
  191. rows: pageSize.value,
  192. page: currentPage.value
  193. }
  194. })
  195. // console.log(res)
  196. const result = JSON.parse(res.data.data)
  197. total.value = result.totalCount
  198. // 处理数据
  199. result.list.forEach((ele) => {
  200. // 如果是待支付状态,算出剩余支付时间
  201. if (ele.state === 1 && ele.payState === 0) {
  202. const temLockTime = 5
  203. // 兼容ios部分系统转换时间格式
  204. const createTime = ele.createTime.slice(0, 19).replace(/-/g, '/')
  205. ele.countDownTime = new Date(createTime).getTime() + temLockTime * 60 * 1000 - new Date().getTime()
  206. }
  207. })
  208. listData.value = [...listData.value, ...result.list]
  209. console.log(listData,'ls')
  210. }
  211. onMounted(() => {
  212. console.log(userInfo)
  213. paddingTop.value = uni.getMenuButtonBoundingClientRect().top
  214. console.log(paddingTop.value)
  215. getMyData()
  216. });
  217. onShow(() => {
  218. // 读取全局状态中的参数
  219. const type = tabParamStore.type;
  220. if (type) {
  221. console.log('接收到type参数11 :', type);
  222. tabIndex.value=type
  223. result_state.value=type
  224. listData.value =[]
  225. getMyData()
  226. }
  227. });
  228. // 页面拉到底部触发函数
  229. function scrolltolower() {
  230. if (listData.value.length < total.value) {
  231. currentPage.value++
  232. getMyData()
  233. } else {
  234. uni.showToast({
  235. title: '没有更多数据了',
  236. icon: 'none'
  237. })
  238. }
  239. }
  240. function handleChange(e) {
  241. console.log(e)
  242. result_state.value = e.index
  243. listData.value = []
  244. currentPage.value = 1
  245. total.value = 0
  246. getMyData()
  247. }
  248. function handleDetail(item) {
  249. const info = encodeURIComponent(JSON.stringify(item))
  250. uni.navigateTo({
  251. url: `/pages/orderDetail/orderDetail?info=${info}`
  252. })
  253. }
  254. // 点击支付按钮回调
  255. const handlePay = (item) => {
  256. popShow_pay.value = true
  257. orderNo.value=item.orderNo
  258. }
  259. // 点击弹窗关闭按钮回调
  260. const handleClose = () => {
  261. popShow_pay.value = false
  262. }
  263. // 切换支付方式(单选逻辑)
  264. const togglePay = (item) => {
  265. // 先重置所有支付方式为未选中
  266. payList.value.forEach(pay => {
  267. pay.isCheck = false;
  268. });
  269. // 标记当前点击的支付方式为选中
  270. item.isCheck = true;
  271. selectedPay.value = item; // 同步选中的支付方式
  272. };
  273. //立即支付
  274. const payTime = () => {
  275. if (!selectedPay.value) {
  276. uni.showModal({
  277. content:'请选择支付方式'
  278. })
  279. return;
  280. }
  281. if(selectedPay.value.text=='微信支付'){
  282. payWei()
  283. }else if(selectedPay.value.text=='电子交通卡支付'){
  284. }
  285. }
  286. //微信支付
  287. const payWei = async () => {
  288. const res = await myRequest({
  289. url: '/tAppcontinuePay.action',
  290. // method: 'POST', // 明确指定请求方法为POST
  291. data: {
  292. order_num:orderNo.value,
  293. }
  294. })
  295. if(res.code==200){
  296. payParams.value = res.data; // 存储微信支付所需参数
  297. invokeWechatPay(); // 调起支付
  298. }else{
  299. uni.showToast({ title: res.message });
  300. }
  301. }
  302. // 调起微信支付
  303. const invokeWechatPay = () => {
  304. uni.requestPayment({
  305. ...payParams.value,
  306. success: (res) => {
  307. uni.showToast({ title: '支付成功' });
  308. // 支付成功后逻辑(如跳转到订单详情)
  309. setTimeout(function() {
  310. getMyData()
  311. }, 1000)
  312. },
  313. fail: (err) => {
  314. uni.showToast({ title: '支付失败', icon: 'none' });
  315. console.error('支付失败', err);
  316. }
  317. });
  318. };
  319. // 点击“去核销”显示弹框
  320. const showQrCodeDialog = (item) => {
  321. isDialogShow.value = true;
  322. ErorderNo.value=item.id
  323. };
  324. //点击退款
  325. const tuiPay = async (item) => {
  326. const res = await myRequest({
  327. url: '/tApprefund.action',
  328. // method: 'POST', // 明确指定请求方法为POST
  329. data: {
  330. order_num:item.orderNo,
  331. id:item.id
  332. }
  333. })
  334. if(res.code==200){
  335. uni.showToast({ title: '退款成功' });
  336. setTimeout(function() {
  337. getMyData()
  338. }, 1000)
  339. }else{
  340. uni.showToast({ title: res.message });
  341. }
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. .container {
  346. position: relative;
  347. display: flex;
  348. box-sizing: border-box;
  349. padding-top: 162rpx;
  350. height: 100%;
  351. color: #001713;
  352. background-color: #fff;
  353. overflow: hidden;
  354. .title {
  355. position: absolute;
  356. left: 314rpx;
  357. font-size: 40rpx;
  358. }
  359. .content {
  360. box-sizing: border-box;
  361. padding: 30rpx;
  362. height: calc(100vh - 246rpx);
  363. color: #001713;
  364. overflow-y: auto;
  365. .order_box {
  366. margin-bottom: 20rpx;
  367. box-sizing: border-box;
  368. padding: 40rpx 20rpx;
  369. box-shadow: 0px 3px 6px #ccc;
  370. .box_top {
  371. display: flex;
  372. align-items: center;
  373. justify-content: space-between;
  374. font-size: 28rpx;
  375. color: #ff8205;
  376. .top_left {
  377. display: flex;
  378. align-items: center;
  379. .left_img {
  380. margin-right: 12rpx;
  381. width: 32rpx;
  382. height: 32rpx;
  383. }
  384. }
  385. .top_status {
  386. font-size: 32rpx;
  387. }
  388. .red {
  389. color: #dc2626;
  390. }
  391. .gray {
  392. color: #707070;
  393. }
  394. }
  395. .box_center {
  396. display: flex;
  397. align-items: center;
  398. margin-top: 40rpx;
  399. font-weight: bold;
  400. .center_img {
  401. width: 14rpx;
  402. height: 88rpx;
  403. }
  404. .center_text {
  405. margin-left: 16rpx;
  406. .text_start {
  407. margin-top: -8rpx;
  408. width: 480rpx;
  409. text-overflow: ellipsis;
  410. white-space: nowrap;
  411. overflow: hidden;
  412. }
  413. .text_end {
  414. margin-top: 30rpx;
  415. width: 480rpx;
  416. text-overflow: ellipsis;
  417. white-space: nowrap;
  418. overflow: hidden;
  419. }
  420. }
  421. .center_price {
  422. margin-left: auto;
  423. font-size: 24rpx;
  424. color: #dc2626;
  425. .text {
  426. font-size: 36rpx;
  427. }
  428. }
  429. }
  430. .box_bottom {
  431. display: flex;
  432. align-items: flex-end;
  433. justify-content: space-between;
  434. margin-top: 8rpx;
  435. font-size: 24rpx;
  436. color: #aba6a6;
  437. .bottom_btns {
  438. display: flex;
  439. align-items: center;
  440. .btn_item {
  441. display: flex;
  442. align-items: center;
  443. justify-content: center;
  444. padding: 0 15rpx;
  445. margin-left: 10rpx;
  446. height: 50rpx;
  447. font-size: 24rpx;
  448. border-radius: 32rpx;
  449. border: 2rpx solid #aba6a6;
  450. }
  451. .pay {
  452. color: #ff8205;
  453. border: 2rpx solid #ff8205;
  454. }
  455. .hexiao{
  456. background-color: #FF8205;
  457. border: 2rpx solid #ff8205;
  458. color: #fff;
  459. }
  460. .cancel {
  461. color: #fff;
  462. background-color: #ff8205;
  463. }
  464. }
  465. }
  466. /* 二维码弹框样式 */
  467. .qr-dialog {
  468. position: fixed;
  469. top: 0;
  470. left: 0;
  471. width: 100%;
  472. height: 100%;
  473. background: rgba(0, 0, 0, 0.5);
  474. display: flex;
  475. justify-content: center;
  476. align-items: center;
  477. z-index: 999;
  478. }
  479. .dialog-content {
  480. width: 600rpx;
  481. background: #fff;
  482. border-radius: 16rpx;
  483. padding: 40rpx;
  484. text-align: center;
  485. }
  486. .qr-img {
  487. width: 400rpx;
  488. margin-bottom: 20rpx;
  489. }
  490. .dialog-tip {
  491. display: block;
  492. margin-bottom: 30rpx;
  493. color: #666;
  494. }
  495. .close-btn {
  496. background: #ff7a00;
  497. color: #fff;
  498. border-radius: 8rpx;
  499. }
  500. }
  501. }
  502. }
  503. // 选择付款方式弹窗
  504. .pop_pay {
  505. height: 566rpx;
  506. color: #001713;
  507. font-size: 28rpx;
  508. .pay_title {
  509. display: flex;
  510. align-items: center;
  511. justify-content: center;
  512. height: 80rpx;
  513. font-size: 32rpx;
  514. border-bottom: 18rpx solid #ff8205;
  515. }
  516. .pay_close {
  517. position: absolute;
  518. top: 24rpx;
  519. right: 42rpx;
  520. }
  521. .pay_list {
  522. box-sizing: border-box;
  523. padding: 55rpx 0;
  524. display: flex;
  525. flex-direction: column;
  526. justify-content: space-between;
  527. height: 265rpx;
  528. .list_item {
  529. display: flex;
  530. align-items: center;
  531. justify-content: space-between;
  532. box-sizing: border-box;
  533. padding: 0 32rpx 0 46rpx;
  534. .item_left {
  535. display: flex;
  536. align-items: center;
  537. .img {
  538. margin-right: 26rpx;
  539. width: 54rpx;
  540. height: 54rpx;
  541. }
  542. }
  543. .item_right {
  544. }
  545. }
  546. }
  547. .pay_btn {
  548. display: flex;
  549. align-items: center;
  550. justify-content: center;
  551. margin: auto;
  552. width: 720rpx;
  553. height: 94rpx;
  554. font-size: 36rpx;
  555. color: #fff;
  556. border-radius: 50rpx;
  557. background-color: #ff8205;
  558. }
  559. }
  560. </style>