paymentOrder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <!-- 时间、价格 -->
  5. <view class="time-price">
  6. <text class="time">待支付</text>
  7. <view class="price-box">
  8. <text class="unit">¥</text>
  9. <text class="num">{{order ? (Number(order.payMoney) || 0).toFixed(2) : "0.00"}}</text>
  10. </view>
  11. </view>
  12. <!-- 支付方式 -->
  13. <view class="pay-type">
  14. <view class="title">支付方式</view>
  15. <radio-group @change="handlePayTypeChange">
  16. <view class="item">
  17. <view class="left">
  18. <image src="/static/images/wecha_pay.png" mode=""></image>
  19. <text class="text">微信支付</text>
  20. </view>
  21. <label>
  22. <radio :value="1" :checked="payType === 1" />
  23. </label>
  24. </view>
  25. <!-- #ifdef APP-PLUS||H5 -->
  26. <view class="item">
  27. <view class="left">
  28. <image src="/static/images/zfb.png" mode=""></image>
  29. <text class="text">支付宝</text>
  30. </view>
  31. <label>
  32. <radio :value="2" :checked="payType === 2" />
  33. </label>
  34. </view>
  35. <!-- #endif -->
  36. </radio-group>
  37. </view>
  38. <!-- 订单详情查看 -->
  39. <view class="order-info">
  40. <view class="title">订单信息</view>
  41. <view class="item">
  42. <text class="label">订单编号</text>
  43. <view class="sn-box">
  44. <view>
  45. <view class="text">{{order.orderCode}}</view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="item">
  50. <text class="label">下单时间</text>
  51. <text class="text">{{ formattedDate}} </text>
  52. </view>
  53. <view class="item">
  54. <text class="label">订单金额</text>
  55. <text class="text"
  56. v-if="order!=null">{{order ? (Number(order.totalPrice) || 0).toFixed(2) : "0.00"}}</text>
  57. </view>
  58. <view class="item">
  59. <text class="label">优惠券</text>
  60. <text class="text">-¥{{order ? (Number(order.discountMoney) || 0).toFixed(2) : "0.00"}} </text>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="btn-box">
  65. <view class="btn" @click="payOrder()">去支付</view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import dayjs from 'dayjs';
  71. import {
  72. weChatPayment
  73. } from '@/api/pay_new'
  74. import {
  75. zfbPayment,
  76. // weChatPayment
  77. } from '@/api/pay'
  78. export default {
  79. data() {
  80. return {
  81. payPrice: null,
  82. newOrder: {},
  83. payType: 2,
  84. order: null,
  85. orderId: null,
  86. payDelivery: 0,
  87. payMoney: 0,
  88. config: null,
  89. payType: 1,
  90. user: null,
  91. couponUserId: null
  92. }
  93. },
  94. computed: {
  95. formattedDate() {
  96. return this.order?.createTime ? dayjs(this.order.createTime).format('YYYY-MM-DD HH:mm:ss') : '';
  97. },
  98. payLimitTime() {
  99. return this.order?.updateTime ?
  100. dayjs(this.order.updateTime).add(2, 'day').format('YYYY-MM-DD HH:mm:ss') :
  101. '';
  102. }
  103. },
  104. onLoad(options) {
  105. // if (options.payPrice) {
  106. // this.payPrice = options.payPrice;
  107. // }
  108. if (options.couponUserId) {
  109. this.couponUserId = options.couponUserId;
  110. }
  111. console.log("支付订单是>>", options)
  112. // this.orderKey = options.orderKey;
  113. // this.liveId = options.liveId
  114. // this.productId=options.productId
  115. // console.log("支付订单",options)
  116. if (options.orderList) {
  117. try {
  118. const decoded = decodeURIComponent(options.orderList);
  119. this.order = JSON.parse(decoded) || {}; // 默认空对象
  120. } catch (e) {
  121. console.error('参数解析失败:', e);
  122. this.order = {}; // 显式赋默认值
  123. }
  124. }
  125. },
  126. // //发送给朋友
  127. // onShareAppMessage(res) {
  128. // const combinationOrderId = this.combinationOrderId ?
  129. // `&combinationOrderId=${encodeURIComponent(this.combinationOrderId)}` : ''
  130. // return {
  131. // title: "帮TA支付",
  132. // path: '/pages_user/user/otherPaymentOrder?orderId=' + this.orderId + combinationOrderId,
  133. // imageUrl: '/static/images/logo.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  134. // }
  135. // },
  136. methods: {
  137. weixinPayOrder() {
  138. var data = {
  139. orderId: this.order.orderId,
  140. payType: 1
  141. // payType: this.order.payType
  142. };
  143. var that = this;
  144. uni.showLoading();
  145. weChatPayment(data).then(
  146. res => {
  147. if (res.code == 200) {
  148. console.log(res);
  149. if (res.payType == 1 || res.payType == 2) {
  150. var result = JSON.parse(res.result);
  151. uni.requestPayment({
  152. provider: 'wxpay',
  153. timeStamp: result.timeStamp,
  154. nonceStr: result.nonceStr,
  155. package: result.package,
  156. signType: result.signType,
  157. paySign: result.paySign,
  158. success: function(res) {
  159. uni.hideLoading();
  160. uni.redirectTo({
  161. url: "./success?order=" + JSON.stringify(that.newOrder)
  162. })
  163. },
  164. fail: function(err) {
  165. uni.showToast({
  166. icon: 'none',
  167. title: 'fail:' + JSON.stringify(err),
  168. });
  169. uni.hideLoading();
  170. }
  171. });
  172. }
  173. } else {
  174. uni.showToast({
  175. icon: 'none',
  176. title: res.msg,
  177. });
  178. }
  179. },
  180. rej => {}
  181. );
  182. },
  183. payOrder() {
  184. if (this.payType == 1) {
  185. // this.doWechatPay()
  186. console.log("这个order", this.order)
  187. const {
  188. itemJson,
  189. ...newOrder
  190. } = this.order;
  191. this.newOrder = newOrder;
  192. console.log("这个newOrder", this.newOrder)
  193. this.weixinPayOrder()
  194. } else if (this.payType == 2) {
  195. this.doAlipay()
  196. } else {
  197. uni.showToast({
  198. title: "暂时无可用支付",
  199. icon: 'none'
  200. })
  201. }
  202. },
  203. // 选微信支付或者支付宝支付
  204. handlePayTypeChange(e) {
  205. this.payType = e.detail.value; // 获取选中的 value
  206. console.log('当前选中:', this.payType);
  207. },
  208. // async doWechatPay() {
  209. // try {
  210. // uni.showLoading({
  211. // title: '发起支付中...',
  212. // mask: true
  213. // });
  214. // let data = {
  215. // orderId: this.order.orderId
  216. // }
  217. // await weChatPayment(data);
  218. // uni.redirectTo({
  219. // url: '/pages_shopping/live/success'
  220. // });
  221. // } catch (err) {
  222. // console.error('支付流程异常:', err);
  223. // } finally {
  224. // uni.hideLoading();
  225. // }
  226. // },
  227. // 支付宝支付
  228. // doAlipay() {
  229. // var data = {
  230. // orderId: this.order.orderId
  231. // };
  232. // console.log("orderId>>", this.order.orderId)
  233. // let that = this;
  234. // // #ifdef H5||APP-PLUS
  235. // // #ifdef APP-PLUS
  236. // const tzCashier = uni.requireNativePlugin("TZBank-Cashier");
  237. // // #endif
  238. // uni.showLoading();
  239. // zfbPayment(data).then(res => {
  240. // console.log("支付开始", res)
  241. // uni.hideLoading();
  242. // if (res.code == 200) {
  243. // console.log("支付在这里", res)
  244. // if (res.type == "tz") {
  245. // //console.log("qxj orderFlowNo:"+res.data.body.orderFlowNo+" businessCstNo:"+res.data.body.orderNo+" platMerCstNo:"+res.data.body.platMerCstNo);
  246. // const match = res.data.body.url.match(/[\?&]businessCstNo=([^&]+)/);
  247. // const businessCstNo = match ? match[1] : null;
  248. // console.log("qxj tzCashier:" + tzCashier + " businessCstNo:" + businessCstNo);
  249. // tzCashier.pay({
  250. // env: 0,
  251. // wxMiniProgramType: 0,
  252. // // wxAppId: 'wx703c4bd07bbd1695',
  253. // wxAppId: 'wx9ea36eecd281bcd3',
  254. // wxUniversalLink: "https://yjf.runtzh.com/",
  255. // orderFlowNo: res.data.body.orderFlowNo,
  256. // businessCstNo: businessCstNo,
  257. // platMerCstNo: res.data.body.platMerCstNo
  258. // }, (res) => {
  259. // // uni.showToast({
  260. // // title:'收银台回调:'+JSON.stringify(res),
  261. // // icon:'none'
  262. // // })
  263. // uni.$emit('closePrivilege', {});
  264. // that.showPayTips = true;
  265. // });
  266. // } else if (res.type == 'hf') {
  267. // if (uni.getWindowInfo().platform == 'android') {
  268. // var alipayScheme = 'alipays://platformapi/startApp?&saId=10000007&qrcode=' + res
  269. // .data.qr_code;
  270. // } else {
  271. // var alipayScheme = 'alipay://platformapi/startApp?&saId=10000007&qrcode=' + res
  272. // .data.qr_code;
  273. // }
  274. // // 在uni-app中使用plus.runtime.openURL打开URL
  275. // plus.runtime.openURL(alipayScheme, function(error) {
  276. // });
  277. // uni.$emit('closePrivilege', {});
  278. // that.showPayTips = true;
  279. // }
  280. // } else {
  281. // uni.showToast({
  282. // title: res.msg,
  283. // icon: 'none'
  284. // })
  285. // }
  286. // },
  287. // rej => {}
  288. // );
  289. // // #endif
  290. // },
  291. getUserInfo() {
  292. getUserInfo().then(
  293. res => {
  294. if (res.code == 200) {
  295. if (res.user != null) {
  296. this.user = res.user;
  297. }
  298. } else {
  299. uni.showToast({
  300. icon: 'none',
  301. title: "请求失败",
  302. });
  303. }
  304. },
  305. rej => {}
  306. );
  307. },
  308. getStoreConfig() {
  309. getStoreConfig().then(
  310. res => {
  311. if (res.code == 200) {
  312. this.config = res.data
  313. console.log(this.config);
  314. }
  315. },
  316. rej => {}
  317. );
  318. },
  319. payTypeChange(e) {
  320. if (this.combinationOrderId) {
  321. this.editPayTypeByCombinationId(e.detail.value)
  322. } else {
  323. this.editPayType(e.detail.value)
  324. }
  325. },
  326. editPayType(payType) {
  327. var data = {
  328. orderId: this.orderId,
  329. payType: payType
  330. };
  331. var that = this;
  332. uni.showLoading();
  333. editPayType(data).then(
  334. res => {
  335. if (res.code == 200) {
  336. console.log(res);
  337. uni.hideLoading();
  338. that.order = res.order;
  339. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : []
  340. that.orderCode = that.order.orderCode
  341. // this.payType=this.order.payType
  342. this.payMoney = this.order.payMoney;
  343. this.payDelivery = this.order.payDelivery;
  344. } else {
  345. uni.showToast({
  346. icon: 'none',
  347. title: res.msg,
  348. });
  349. }
  350. },
  351. rej => {}
  352. );
  353. },
  354. }
  355. }
  356. </script>
  357. <style lang="scss">
  358. page {
  359. height: 100%;
  360. }
  361. .content {
  362. height: 100%;
  363. display: flex;
  364. flex-direction: column;
  365. justify-content: space-between;
  366. .inner {
  367. padding: 20upx;
  368. .time-price {
  369. box-sizing: border-box;
  370. padding: 50upx 0upx;
  371. background: #FFFFFF;
  372. border-radius: 16upx;
  373. display: flex;
  374. flex-direction: column;
  375. align-items: center;
  376. .time {
  377. font-size: 32upx;
  378. font-family: PingFang SC;
  379. font-weight: 500;
  380. color: #222222;
  381. line-height: 1;
  382. text-align: center;
  383. }
  384. .desc {
  385. margin: 30upx 0upx 15upx;
  386. font-size: 26upx;
  387. font-family: PingFang SC;
  388. color: #999999;
  389. line-height: 1;
  390. text-align: center;
  391. }
  392. .price-box {
  393. display: flex;
  394. align-items: flex-end;
  395. margin-top: 28upx;
  396. .unit {
  397. font-size: 32upx;
  398. font-family: PingFang SC;
  399. font-weight: bold;
  400. color: #FF6633;
  401. line-height: 1.3;
  402. margin-right: 10upx;
  403. }
  404. .num {
  405. font-size: 56upx;
  406. font-family: PingFang SC;
  407. font-weight: bold;
  408. color: #FF6633;
  409. line-height: 1;
  410. }
  411. }
  412. }
  413. .pay-type {
  414. box-sizing: border-box;
  415. background: #FFFFFF;
  416. border-radius: 16upx;
  417. margin-top: 20upx;
  418. padding: 40upx 30upx;
  419. display: flex;
  420. flex-direction: column;
  421. justify-content: space-between;
  422. .title {
  423. font-size: 28upx;
  424. font-family: PingFang SC;
  425. font-weight: 500;
  426. color: #999999;
  427. line-height: 1;
  428. margin-bottom: 10upx;
  429. }
  430. .item {
  431. padding: 15upx 0upx;
  432. display: flex;
  433. align-items: center;
  434. justify-content: space-between;
  435. .left {
  436. display: flex;
  437. align-items: center;
  438. image {
  439. width: 44upx;
  440. height: 44upx;
  441. margin-right: 20upx;
  442. }
  443. .text {
  444. font-size: 30upx;
  445. font-family: PingFang SC;
  446. font-weight: bold;
  447. color: #222222;
  448. line-height: 1;
  449. }
  450. }
  451. }
  452. }
  453. .order-info {
  454. margin-top: 20upx;
  455. background: #FFFFFF;
  456. border-radius: 16upx;
  457. padding: 40upx 30upx;
  458. .title {
  459. font-size: 30upx;
  460. font-family: PingFang SC;
  461. font-weight: bold;
  462. color: #222222;
  463. line-height: 1;
  464. }
  465. .item {
  466. margin-top: 40upx;
  467. display: flex;
  468. align-items: center;
  469. justify-content: space-between;
  470. .label {
  471. font-size: 26upx;
  472. font-family: PingFang SC;
  473. font-weight: 500;
  474. color: #666666;
  475. line-height: 1;
  476. }
  477. .text {
  478. font-size: 26upx;
  479. font-family: PingFang SC;
  480. font-weight: 500;
  481. color: #222222;
  482. line-height: 32upx;
  483. }
  484. .cont-text {
  485. font-size: 26upx;
  486. font-family: PingFang SC;
  487. font-weight: 500;
  488. color: #666666;
  489. .bold {
  490. color: #111111;
  491. }
  492. }
  493. .sn-box {
  494. display: flex;
  495. align-items: center;
  496. .copy-btn {
  497. width: 58upx;
  498. height: 32upx;
  499. line-height: 32upx;
  500. text-align: center;
  501. font-size: 22upx;
  502. font-weight: 500;
  503. color: #222222;
  504. background: #F5F5F5;
  505. border-radius: 4upx;
  506. margin-left: 24upx;
  507. }
  508. }
  509. }
  510. .line {
  511. width: 100%;
  512. height: 1px;
  513. background: #F0F0F0;
  514. margin-top: 30upx;
  515. }
  516. }
  517. }
  518. .btn-box {
  519. height: 242upx;
  520. background: #FFFFFF;
  521. display: flex;
  522. align-items: center;
  523. justify-content: center;
  524. flex-direction: column;
  525. .btn {
  526. width: 91.73%;
  527. height: 88upx;
  528. line-height: 88upx;
  529. font-size: 30upx;
  530. font-family: PingFang SC;
  531. font-weight: bold;
  532. color: #FFFFFF;
  533. text-align: center;
  534. background: #2BC7B9;
  535. border-radius: 44upx;
  536. margin-bottom: 10rpx;
  537. }
  538. .other-btn {
  539. width: 91.73%;
  540. height: 88upx;
  541. line-height: 88upx;
  542. font-size: 30upx;
  543. font-family: PingFang SC;
  544. font-weight: bold;
  545. color: #2BC7B9;
  546. border: 1rpx solid #2BC7B9;
  547. text-align: center;
  548. background: #FFFFFF;
  549. border-radius: 44upx;
  550. margin-bottom: 10rpx;
  551. position: relative;
  552. .share {
  553. display: inline-block;
  554. position: absolute;
  555. top: 0;
  556. left: 0;
  557. width: 100%;
  558. height: 100%;
  559. opacity: 0;
  560. }
  561. }
  562. }
  563. }
  564. </style>