paymentOrder.vue 14 KB

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