order.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. const onShareAppMessage = (res) => { //发送给朋友
  343. return {
  344. // title: this.tuiguang,
  345. path: '/pages/home/home',
  346. // imageUrl: this.tuiguangImg,
  347. }
  348. }
  349. </script>
  350. <style lang="scss" scoped>
  351. .container {
  352. position: relative;
  353. display: flex;
  354. box-sizing: border-box;
  355. padding-top: 162rpx;
  356. height: 100%;
  357. color: #001713;
  358. background-color: #fff;
  359. overflow: hidden;
  360. .title {
  361. position: absolute;
  362. left: 314rpx;
  363. font-size: 40rpx;
  364. }
  365. .content {
  366. box-sizing: border-box;
  367. padding: 30rpx;
  368. height: calc(100vh - 246rpx);
  369. color: #001713;
  370. overflow-y: auto;
  371. .order_box {
  372. margin-bottom: 20rpx;
  373. box-sizing: border-box;
  374. padding: 40rpx 20rpx;
  375. box-shadow: 0px 3px 6px #ccc;
  376. .box_top {
  377. display: flex;
  378. align-items: center;
  379. justify-content: space-between;
  380. font-size: 28rpx;
  381. color: #ff8205;
  382. .top_left {
  383. display: flex;
  384. align-items: center;
  385. .left_img {
  386. margin-right: 12rpx;
  387. width: 32rpx;
  388. height: 32rpx;
  389. }
  390. }
  391. .top_status {
  392. font-size: 32rpx;
  393. }
  394. .red {
  395. color: #dc2626;
  396. }
  397. .gray {
  398. color: #707070;
  399. }
  400. }
  401. .box_center {
  402. display: flex;
  403. align-items: center;
  404. margin-top: 40rpx;
  405. font-weight: bold;
  406. .center_img {
  407. width: 14rpx;
  408. height: 88rpx;
  409. }
  410. .center_text {
  411. margin-left: 16rpx;
  412. .text_start {
  413. margin-top: -8rpx;
  414. width: 480rpx;
  415. text-overflow: ellipsis;
  416. white-space: nowrap;
  417. overflow: hidden;
  418. }
  419. .app{
  420. margin-top: 1px;
  421. }
  422. .text_end {
  423. margin-top: 30rpx;
  424. width: 480rpx;
  425. text-overflow: ellipsis;
  426. white-space: nowrap;
  427. overflow: hidden;
  428. }
  429. }
  430. .center_price {
  431. margin-left: auto;
  432. font-size: 24rpx;
  433. color: #dc2626;
  434. .text {
  435. font-size: 36rpx;
  436. }
  437. }
  438. }
  439. .box_bottom {
  440. display: flex;
  441. align-items: flex-end;
  442. justify-content: space-between;
  443. margin-top: 8rpx;
  444. font-size: 24rpx;
  445. color: #aba6a6;
  446. .bottom_btns {
  447. display: flex;
  448. align-items: center;
  449. .btn_item {
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. padding: 0 15rpx;
  454. margin-left: 10rpx;
  455. height: 50rpx;
  456. font-size: 24rpx;
  457. border-radius: 32rpx;
  458. border: 2rpx solid #aba6a6;
  459. }
  460. .pay {
  461. color: #ff8205;
  462. border: 2rpx solid #ff8205;
  463. }
  464. .hexiao{
  465. background-color: #FF8205;
  466. border: 2rpx solid #ff8205;
  467. color: #fff;
  468. }
  469. .cancel {
  470. color: #fff;
  471. background-color: #ff8205;
  472. }
  473. }
  474. }
  475. /* 二维码弹框样式 */
  476. .qr-dialog {
  477. position: fixed;
  478. top: 0;
  479. left: 0;
  480. width: 100%;
  481. height: 100%;
  482. background: rgba(0, 0, 0, 0.5);
  483. display: flex;
  484. justify-content: center;
  485. align-items: center;
  486. z-index: 999;
  487. }
  488. .dialog-content {
  489. width: 600rpx;
  490. background: #fff;
  491. border-radius: 16rpx;
  492. padding: 40rpx;
  493. text-align: center;
  494. }
  495. .qr-img {
  496. width: 400rpx;
  497. margin-bottom: 20rpx;
  498. }
  499. .dialog-tip {
  500. display: block;
  501. margin-bottom: 30rpx;
  502. color: #666;
  503. }
  504. .close-btn {
  505. background: #ff7a00;
  506. color: #fff;
  507. border-radius: 8rpx;
  508. }
  509. }
  510. }
  511. }
  512. // 选择付款方式弹窗
  513. .pop_pay {
  514. height: 566rpx;
  515. color: #001713;
  516. font-size: 28rpx;
  517. .pay_title {
  518. display: flex;
  519. align-items: center;
  520. justify-content: center;
  521. height: 80rpx;
  522. font-size: 32rpx;
  523. border-bottom: 18rpx solid #ff8205;
  524. }
  525. .pay_close {
  526. position: absolute;
  527. top: 24rpx;
  528. right: 42rpx;
  529. }
  530. .pay_list {
  531. box-sizing: border-box;
  532. padding: 55rpx 0;
  533. display: flex;
  534. flex-direction: column;
  535. justify-content: space-between;
  536. height: 265rpx;
  537. .list_item {
  538. display: flex;
  539. align-items: center;
  540. justify-content: space-between;
  541. box-sizing: border-box;
  542. padding: 0 32rpx 0 46rpx;
  543. .item_left {
  544. display: flex;
  545. align-items: center;
  546. .img {
  547. margin-right: 26rpx;
  548. width: 54rpx;
  549. height: 54rpx;
  550. }
  551. }
  552. .item_right {
  553. }
  554. }
  555. }
  556. .pay_btn {
  557. display: flex;
  558. align-items: center;
  559. justify-content: center;
  560. margin: auto;
  561. width: 720rpx;
  562. height: 94rpx;
  563. font-size: 36rpx;
  564. color: #fff;
  565. border-radius: 50rpx;
  566. background-color: #ff8205;
  567. }
  568. }
  569. </style>