order.vue 15 KB

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