pay.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view class="container">
  3. <image class="banner" src="@/static/images/mine/back.png" mode="aspectFill" />
  4. <view class="title" :style="{ top: `${paddingTop * 2}rpx` }">
  5. <view class="title_back" @click="handleBack">
  6. <wd-icon name="thin-arrow-left" color="#001713" size="18"></wd-icon>
  7. </view>
  8. 电子交通卡充值
  9. </view>
  10. <!-- 内容区域 -->
  11. <scroll-view class="body" scroll-y @scrolltolower="scrolltolower">
  12. <view class="body_title">选择充值面额</view>
  13. <!-- 每一个充值选项区域 -->
  14. <view class="body_item" :class="{ active: item.isChecked }" v-for="(item, index) in chongList" :key="index" @click="hadnleChange(item)">
  15. <view class="item_price">
  16. ¥
  17. <text class="text">{{item.account3}}</text>
  18. </view>
  19. <!-- <view class="item_msg">赠送{{item.account4}}元补贴包,立得{{item.account3+item.account4}}元出行金</view> -->
  20. <view class="item_check" v-if="item.isChecked" @click="item.isChecked!=item.isChecked">
  21. <wd-icon name="check-bold" color="#fff" size="20"></wd-icon>
  22. </view>
  23. </view>
  24. </scroll-view>
  25. <!-- 底部支付区域 -->
  26. <view class="foot">
  27. <view class="foot_left">
  28. <view class="left_top">
  29. 合计
  30. <text class="text">¥{{totalAmount}}</text>
  31. </view>
  32. <!-- <view class="left_bottom">
  33. 充值成功后赠送补贴金
  34. <text class="text">¥{{zengAmount}}</text>
  35. </view> -->
  36. </view>
  37. <view class="foot_right" @click="handlePay">点击支付</view>
  38. </view>
  39. </view>
  40. <!-- 选择付款方式弹窗区域 -->
  41. <wd-popup v-model="popShow_pay" position="bottom" safe-area-inset-bottom :close-on-click-modal="false">
  42. <view class="pop_pay">
  43. <view class="pay_title">选择付款方式</view>
  44. <view class="pay_close" @click="handleClose">
  45. <wd-icon name="close-bold" color="#ABA6A6" size="22"></wd-icon>
  46. </view>
  47. <!-- 支付方式列表区域 -->
  48. <view class="pay_list">
  49. <!-- 每一个支付方式区域 -->
  50. <view class="list_item" v-for="(item, index) in payList" :key="index">
  51. <view class="item_left">
  52. <image class="img" :src="item.icon" mode="aspectFill"></image>
  53. {{ item.text }}
  54. </view>
  55. <view class="item_right">
  56. <radio style="scale: 0.8" color="#FF8205" :checked="item.isCheck" @click="togglePay(item)" />
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 立即付款按钮区域 -->
  61. <view class="pay_btn" @click="payTime">立即付款</view>
  62. </view>
  63. </wd-popup>
  64. </template>
  65. <script setup>
  66. import { onMounted, ref } from 'vue'
  67. import { myRequest } from '@/utils/api.ts'
  68. import { useTabParamStore } from '@/utils/tabParams.js';
  69. const tabParamStore = useTabParamStore();
  70. const userInfo = uni.getStorageSync('carUserInfo')
  71. // 胶囊按钮距离页面顶部的距离
  72. const paddingTop = ref(0)
  73. // 当前选择的索引
  74. const currentIndex = ref(0)
  75. // 付款方式弹窗显示隐藏控制
  76. const popShow_pay = ref(false)
  77. //充值套餐
  78. const chongList = ref([])
  79. // 每页多少条
  80. const pageSize = ref(10)
  81. // 当前页
  82. const currentPage = ref(1)
  83. // 总条数
  84. const total = ref(0)
  85. //合计支付金额
  86. const totalAmount = ref(0)
  87. //合计赠送金额
  88. const zengAmount = ref(0)
  89. // 支付方式列表
  90. const payList = ref([
  91. {
  92. text: '微信支付',
  93. icon: '/static/images/pay/wx.png',
  94. isCheck: true
  95. },
  96. // {
  97. // text: '电子交通卡支付',
  98. // icon: '/static/images/pay/card.png',
  99. // isCheck: false
  100. // }
  101. ])
  102. // 存储支付参数
  103. const payParams = ref({
  104. timeStamp: '',
  105. nonceStr: '',
  106. signType: '',
  107. paySign: '',
  108. appId:'',
  109. // prepay_id:'',
  110. package:'',
  111. });
  112. // 选中的支付方式
  113. const selectedPay = ref(null);
  114. onMounted(() => {
  115. console.log(uni.getStorageSync('cardTypeNum'),'身份')
  116. paddingTop.value = uni.getMenuButtonBoundingClientRect().top
  117. getChongcommon()
  118. })
  119. // 点击切换选项的回调
  120. const hadnleChange = (item) => {
  121. chongList.value.forEach(item => {
  122. item.isChecked = false;
  123. });
  124. item.isChecked = true;
  125. totalAmount.value=item.account3
  126. zengAmount.value=item.account4
  127. }
  128. //交通卡充值
  129. const jiaotong = async () => {
  130. const res = await myRequest({
  131. url: '/cardrecharge.action',
  132. method: 'POST', // 明确指定请求方法为POST
  133. data: {
  134. mobile: userInfo.mobile,
  135. type: uni.getStorageSync('cardTypeNum'),
  136. account4: totalAmount.value,
  137. account5: zengAmount.value,
  138. }
  139. })
  140. if(res.code==200){
  141. payParams.value = {
  142. timeStamp: res.data.timeStamp,
  143. nonceStr: res.data.nonceStr,
  144. package: 'prepay_id=' + res.data.prepay_id,
  145. signType: res.data.signType,
  146. paySign: res.data.paySign,
  147. };
  148. invokeWechatPay(); // 调起支付
  149. }
  150. }
  151. // 调起微信支付
  152. const invokeWechatPay = () => {
  153. console.log(payParams.value,'支付')
  154. uni.requestPayment({
  155. ...payParams.value,
  156. success: (res) => {
  157. uni.showToast({ title: '支付成功' });
  158. popShow_pay.value = false
  159. setTimeout(function() {
  160. uni.navigateTo({
  161. url:'/pages/transportation/transportation'
  162. })
  163. }, 1000)
  164. // 支付成功后逻辑(如跳转到订单详情)
  165. },
  166. fail: (err) => {
  167. uni.showToast({ title: '支付失败', icon: 'none' });
  168. console.error('支付失败', err);
  169. }
  170. });
  171. };
  172. // 获取套餐列表数据
  173. const getChongcommon = async () => {
  174. let data = {
  175. page: currentPage.value,
  176. rows: pageSize.value,
  177. }
  178. try {
  179. const res = await myRequest({
  180. url: '/reBenefitlist.action',
  181. data
  182. });
  183. if (res.code === 200) {
  184. // 对返回的每一条数据添加 isCheck: false
  185. const formattedRows = res.rows.map(item => ({
  186. ...item, // 保留原有数据
  187. isCheck: false // 新增 isCheck 参数,默认 false
  188. }));
  189. // 🔴 同步已勾选状态:对比 selectedPassengers,标记匹配项的 isCheck 为 true
  190. // formattedRows.forEach(row => {
  191. // const isSelected = selectedPassengers.value.some(p => p.id === row.id);
  192. // if (isSelected) {
  193. // row.isCheck = true;
  194. // }
  195. // });
  196. if (currentPage.value === 1) {
  197. chongList.value = formattedRows;
  198. } else {
  199. chongList.value.push(...formattedRows);
  200. }
  201. total.value = res.total
  202. } else {
  203. // 接口返回非200状态时的提示(可选)
  204. uni.showToast({ title: '数据获取失败', icon: 'none' });
  205. }
  206. } catch (err) {
  207. console.error('请求异常', err);
  208. uni.showToast({ title: '网络异常', icon: 'none' });
  209. } finally {
  210. }
  211. }
  212. // 页面下滑到底部触发的回调
  213. const scrolltolower = () => {
  214. if (chongList.value.length < total.value) {
  215. currentPage.value++
  216. getChongcommon()
  217. } else {
  218. uni.showToast({
  219. title: '没有更多数据了',
  220. icon: 'none'
  221. })
  222. }
  223. }
  224. // 点击支付按钮回调
  225. const handlePay = () => {
  226. popShow_pay.value = true
  227. }
  228. // 点击弹窗关闭按钮回调
  229. const handleClose = () => {
  230. popShow_pay.value = false
  231. }
  232. // 顶部返回图标回调
  233. const handleBack = () => {
  234. uni.navigateBack()
  235. }
  236. // 切换支付方式(单选逻辑)
  237. const togglePay = (item) => {
  238. // console.log(1232228)
  239. // // 先重置所有支付方式为未选中
  240. // payList.value.forEach(pay => {
  241. // pay.isCheck = false;
  242. // });
  243. // // 标记当前点击的支付方式为选中
  244. // item.isCheck = true;
  245. selectedPay.value = true; // 同步选中的支付方式
  246. };
  247. //立即支付
  248. const payTime = () => {
  249. console.log(123222)
  250. // if (!selectedPay.value) {
  251. // uni.showModal({
  252. // content:'请选择支付方式'
  253. // })
  254. // return;
  255. // }
  256. jiaotong()
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. .container {
  261. position: relative;
  262. height: 100vh;
  263. color: #001713;
  264. background-color: #fff;
  265. overflow: hidden;
  266. .banner {
  267. width: 100%;
  268. height: 482rpx;
  269. }
  270. .title {
  271. position: absolute;
  272. display: flex;
  273. align-items: center;
  274. width: 100vh;
  275. font-size: 40rpx;
  276. .title_back {
  277. margin-left: 26rpx;
  278. margin-right: 192rpx;
  279. }
  280. }
  281. .body {
  282. position: absolute;
  283. top: 160rpx;
  284. box-sizing: border-box;
  285. padding: 0 30rpx 30rpx;
  286. width: 100%;
  287. height: calc(100vh - 406rpx);
  288. font-size: 32rpx;
  289. color: #001713;
  290. .body_title {
  291. margin-bottom: 30rpx;
  292. }
  293. .body_item {
  294. position: relative;
  295. box-sizing: border-box;
  296. padding: 30rpx;
  297. margin-bottom: 40rpx;
  298. border: 2rpx solid #aba6a6;
  299. border-radius: 16rpx;
  300. background-color: #fff;
  301. .item_price {
  302. font-size: 28rpx;
  303. .text {
  304. font-size: 40rpx;
  305. }
  306. }
  307. .item_msg {
  308. margin-top: 20rpx;
  309. }
  310. .item_check {
  311. position: absolute;
  312. top: 0;
  313. right: 0;
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. width: 60rpx;
  318. height: 44rpx;
  319. border-radius: 0 14rpx 0 16rpx;
  320. background-color: #ff8205;
  321. }
  322. }
  323. .active {
  324. background-color: #fff6ee;
  325. border: 2rpx solid #ff8205;
  326. }
  327. }
  328. .foot {
  329. position: absolute;
  330. left: 0;
  331. right: 0;
  332. bottom: 0;
  333. box-sizing: border-box;
  334. padding: 0 30rpx 30rpx;
  335. display: flex;
  336. align-items: center;
  337. justify-content: space-between;
  338. height: 244rpx;
  339. box-shadow: 0px 3px 6px #000000;
  340. .foot_left {
  341. .left_top {
  342. font-size: 32rpx;
  343. .text {
  344. font-size: 48rpx;
  345. color: #dc2626;
  346. }
  347. }
  348. .left_bottom {
  349. margin-top: 10rpx;
  350. font-size: 24rpx;
  351. .text {
  352. color: #dc2626;
  353. }
  354. }
  355. }
  356. .foot_right {
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. width: 272rpx;
  361. height: 94rpx;
  362. color: #fff;
  363. font-size: 36rpx;
  364. border-radius: 50rpx;
  365. background-color: #ff8205;
  366. }
  367. }
  368. }
  369. .pop_pay {
  370. height: 566rpx;
  371. color: #001713;
  372. font-size: 28rpx;
  373. .pay_title {
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. height: 80rpx;
  378. font-size: 32rpx;
  379. border-bottom: 18rpx solid #ff8205;
  380. }
  381. .pay_close {
  382. position: absolute;
  383. top: 24rpx;
  384. right: 42rpx;
  385. }
  386. .pay_list {
  387. box-sizing: border-box;
  388. padding: 55rpx 0;
  389. display: flex;
  390. flex-direction: column;
  391. justify-content: space-between;
  392. height: 265rpx;
  393. .list_item {
  394. display: flex;
  395. align-items: center;
  396. justify-content: space-between;
  397. box-sizing: border-box;
  398. padding: 0 32rpx 0 46rpx;
  399. .item_left {
  400. display: flex;
  401. align-items: center;
  402. .img {
  403. margin-right: 26rpx;
  404. width: 54rpx;
  405. height: 54rpx;
  406. }
  407. }
  408. .item_right {
  409. }
  410. }
  411. }
  412. .pay_btn {
  413. display: flex;
  414. align-items: center;
  415. justify-content: center;
  416. margin: auto;
  417. width: 720rpx;
  418. height: 94rpx;
  419. font-size: 36rpx;
  420. color: #fff;
  421. border-radius: 50rpx;
  422. background-color: #ff8205;
  423. }
  424. }
  425. </style>