paymentOrder.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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="3" :checked="payType === 3" />
  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?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 ? order.totalPrice : "0.00"}}</text>
  57. </view>
  58. <view class="item">
  59. <text class="label">优惠券</text>
  60. <text class="text">-¥{{order ? order.discountMoney: "0.00"}} </text>
  61. </view>
  62. </view>
  63. </view>
  64. <uni-popup ref="popTip" type="dialog">
  65. <uni-popup-dialog cancelText="支付失败" confirmText="支付成功" mode="base" content="是否已支付成功?" title="提示" :duration="2000" :before-close="true" @close="confirmTip" @confirm="confirmTip"></uni-popup-dialog>
  66. </uni-popup>
  67. <view class="btn-box">
  68. <view class="btn" @click="payOrder()">去支付</view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import { H5AliPayment, aliPayment, appWxPayment, H5WxPayment } from '@/api/pay_new'
  74. import dayjs from 'dayjs';
  75. //import * as jweixin from 'weixin-js-sdk'
  76. import { payConfirmReward, getMyStoreOrderById} from '@/api/liveOrder'
  77. export default {
  78. data() {
  79. return {
  80. type:'',
  81. payPrice: null,
  82. newOrder: {},
  83. order: null,
  84. orderId: null,
  85. payDelivery: 0,
  86. payMoney: 0,
  87. config: null,
  88. payType: 1,
  89. user: null,
  90. couponUserId: null,
  91. showPayTips:false,
  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.type = options.type;
  113. // this.liveId = options.liveId
  114. // this.productId=options.productId
  115. // console.log("支付订单",options)
  116. if (options.orderList) {
  117. this.order=JSON.parse(options.orderList)
  118. // try {
  119. // const decoded = decodeURIComponent(options.orderList);
  120. // this.order = JSON.parse(decoded) || {}; // 默认空对象
  121. // } catch (e) {
  122. // console.error('参数解析失败:', e);
  123. // this.order = {}; // 显式赋默认值
  124. // }
  125. }
  126. },
  127. onShow() {
  128. if(this.showPayTips){
  129. //this.$refs.popPayType.close();
  130. this.$refs.popTip.open();
  131. this.showPayTips=false;
  132. }
  133. // this.getOrderInfo();
  134. },
  135. // //发送给朋友
  136. // onShareAppMessage(res) {
  137. // const combinationOrderId = this.combinationOrderId ?
  138. // `&combinationOrderId=${encodeURIComponent(this.combinationOrderId)}` : ''
  139. // return {
  140. // title: "帮TA支付",
  141. // path: '/pages_user/user/otherPaymentOrder?orderId=' + this.orderId + combinationOrderId,
  142. // imageUrl: '/static/images/live/logo.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  143. // }
  144. // },
  145. methods: {
  146. closeTip(){
  147. this.$refs.popTip.close()
  148. },
  149. confirmTip() {
  150. uni.showLoading({title:"请稍侯...",mask:true});
  151. setTimeout(()=>{
  152. uni.hideLoading();
  153. this.getOrderInfo();
  154. },2000);
  155. },
  156. getOrderInfo(){
  157. getMyStoreOrderById(this.order.orderId).then(res => {
  158. this.$refs.popTip.close();
  159. if(res.code==200){
  160. this.order=res.data;
  161. if(res.data.status==1){ //1:代付款 2:已支付
  162. uni.showToast({title: '未支付成功',icon: 'none'});
  163. }
  164. else if(res.data.status==2){ //1:代付款 2:已支付
  165. this.$refs.popTip.close();
  166. uni.redirectTo({
  167. url:"./success?order="+JSON.stringify(this.order)
  168. });
  169. }
  170. }
  171. },
  172. rej => {}
  173. );
  174. },
  175. weixinPayOrder() {
  176. //console.log("支付时候",JSON.stringify(this.order))
  177. //console.log("app订单数据",this.order)
  178. const data = {
  179. orderId: this.order?.orderId,
  180. userId: this.order?.userId,
  181. payType: 1
  182. };
  183. const that = this;
  184. uni.showLoading();
  185. const orderList={
  186. orderCode:this.order.orderCode,
  187. payPrice:this.order.totalPrice,
  188. orderId:this.order.orderId,
  189. createTime:this.order.createTime,
  190. updateTime:this.order.updateTime,
  191. discountMoney:this.order.discountMoney,
  192. }
  193. // #ifdef APP-PLUS
  194. // 优先尝试小程序唤起支付(与 packageOrderPay 逻辑一致)
  195. plus.share.getServices(function(res){
  196. console.log('去支付',res)
  197. let sweixin = null;
  198. for(let i=0;i<res.length;i++){
  199. const t = res[i];
  200. if(t.id == 'weixin'){
  201. sweixin = t;
  202. }
  203. }
  204. if(sweixin){
  205. that.$refs.popTip.open()
  206. sweixin.launchMiniProgram({
  207. id:"gh_fd0ff58d3f4d",
  208. path:'pages_shopping/live/paymentOrder?orderList='+JSON.stringify(orderList)+'&payMethod=app',
  209. type:0
  210. },function(e){
  211. console.log("微信唤起成功");
  212. return true;
  213. },function(e){
  214. console.log("微信唤起失败",e);
  215. uni.showToast({
  216. title:'微信唤起失败,请检查是否有微信应用',
  217. icon:'none'
  218. })
  219. return false;
  220. })
  221. }else{
  222. //console.log('去支付++++++++++++',sweixin)
  223. uni.showToast({
  224. title:'微信唤起失败,请检查是否有微信应用',
  225. icon:'none',
  226. duration:3000
  227. });
  228. return false;
  229. }
  230. },function(res){
  231. console.log('错误:',JSON.stringify(res));
  232. });
  233. // #endif
  234. // #ifdef H5
  235. // H5 环境使用直播订单 H5 微信支付接口
  236. console.log("H5 WX payload", JSON.stringify(data))
  237. H5WxPayment(data).then(res => {
  238. uni.hideLoading();
  239. console.log("H5 WX response", JSON.stringify(res))
  240. if (res.code == 200) {
  241. if (res.type == "tz") {
  242. console.log("H5 WX redirect url", res.data.body.url)
  243. window.location.href = res.data.body.url;
  244. } else if (res.type == 'hf') {
  245. const payObj = JSON.parse(res.data.pay_info);
  246. console.log("H5 WX payObj", JSON.stringify(payObj))
  247. jweixin.config({
  248. debug: false,
  249. appId: payObj.appId,
  250. timestamp: payObj.timeStamp,
  251. nonceStr: payObj.nonceStr,
  252. signature: payObj.paySign,
  253. jsApiList: ['chooseWXPay']
  254. });
  255. jweixin.ready(() => {
  256. jweixin.chooseWXPay({
  257. timestamp: payObj.timeStamp,
  258. nonceStr: payObj.nonceStr,
  259. package: payObj.package,
  260. signType: payObj.signType,
  261. paySign: payObj.paySign,
  262. success: () => {
  263. console.log("H5 WX chooseWXPay success")
  264. uni.redirectTo({
  265. url: "./success?order=" + JSON.stringify(that.order)
  266. })
  267. },
  268. fail: (err) => {
  269. console.log("H5 WX chooseWXPay fail", JSON.stringify(err))
  270. uni.showToast({
  271. icon: 'none',
  272. title: '支付失败:' + JSON.stringify(err),
  273. });
  274. }
  275. });
  276. });
  277. }
  278. } else {
  279. uni.showToast({
  280. icon: 'none',
  281. title: res.msg,
  282. });
  283. }
  284. }
  285. ).catch(() => {
  286. uni.hideLoading();
  287. });
  288. // #endif
  289. },
  290. aliPayOrder() {
  291. console.log("选了支付宝", this.order)
  292. const data = {
  293. orderId: this.order.orderId
  294. // userId: this.order?.userId
  295. };
  296. const that = this;
  297. uni.showLoading();
  298. // #ifdef APP-PLUS
  299. console.log("APP Ali payload", JSON.stringify(data))
  300. aliPayment(data).then(res => {
  301. uni.hideLoading();
  302. console.log("APP Ali response", JSON.stringify(res))
  303. if (res.code == 200) {
  304. if (res.type == "tz") {
  305. const match = res.data.body.url.match(/[\?&]businessCstNo=([^&]+)/);
  306. const businessCstNo = match ? match[1] : null;
  307. const tzCashier = uni.requireNativePlugin("TZBank-Cashier");
  308. tzCashier.pay({
  309. env: 0,
  310. wxMiniProgramType: 0,
  311. wxAppId: 'wx776d6bd6848eec49',
  312. wxUniversalLink: "https://yjf.runtzh.com/",
  313. orderFlowNo: res.data.body.orderFlowNo,
  314. businessCstNo: businessCstNo,
  315. platMerCstNo: res.data.body.platMerCstNo
  316. }, (ret) => {
  317. console.log("APP Ali tzCashier result", JSON.stringify(ret))
  318. if (ret && ret.errCode == 0) {
  319. uni.redirectTo({
  320. url: "./success?order=" + JSON.stringify(that.order)
  321. })
  322. }
  323. });
  324. } else if (res.type == 'hf') {
  325. const qr = res.data.qr_code;
  326. let alipayScheme = '';
  327. if (uni.getSystemInfoSync().platform == 'android') {
  328. alipayScheme = 'alipays://platformapi/startApp?&saId=10000007&qrcode=' + qr;
  329. } else {
  330. alipayScheme = 'alipay://platformapi/startApp?&saId=10000007&qrcode=' + qr;
  331. }
  332. console.log("APP Ali openURL", alipayScheme)
  333. plus.runtime.openURL(alipayScheme, function() {});
  334. }
  335. } else {
  336. uni.showToast({
  337. icon: 'none',
  338. title: res.msg,
  339. });
  340. }
  341. }
  342. ).catch(() => {
  343. console.log("APP Ali catch error")
  344. uni.hideLoading();
  345. });
  346. // #endif
  347. // #ifdef H5
  348. console.log("H5 Ali payload", JSON.stringify(data))
  349. H5AliPayment(data).then(res => {
  350. uni.hideLoading();
  351. console.log("H5 Ali response", JSON.stringify(res))
  352. if (res.code == 200) {
  353. if (res.type == "tz") {
  354. console.log("H5 Ali redirect url", res.data.body.url)
  355. window.location.href = res.data.body.url;
  356. } else if (res.type == 'hf') {
  357. const payUrl = res.data.pay_info || res.data.qr_code;
  358. console.log("H5 Ali payUrl", payUrl)
  359. window.location.href = payUrl;
  360. }
  361. } else {
  362. uni.showToast({
  363. icon: 'none',
  364. title: res.msg,
  365. });
  366. }
  367. }
  368. ).catch(() => {
  369. console.log("H5 Ali catch error")
  370. uni.hideLoading();
  371. });
  372. // #endif
  373. },
  374. payOrder() {
  375. if (this.type == 'win') {
  376. this.toPayConfirmReward()
  377. } else {
  378. if (this.payType == 1) {
  379. this.weixinPayOrder()
  380. } else if (this.payType ==3) {
  381. this.aliPayOrder()
  382. } else {
  383. uni.showToast({
  384. title: "暂时无可用支付",
  385. icon: 'none'
  386. })
  387. }
  388. }
  389. },
  390. // 选微信支付或者支付宝支付
  391. handlePayTypeChange(e) {
  392. this.payType = e.detail.value; // 获取选中的 value
  393. console.log('当前选中:', this.payType);
  394. },
  395. toPayConfirmReward() {
  396. let data={
  397. orderId:this.order.orderId
  398. }
  399. payConfirmReward(data).then(
  400. res => {
  401. if (res.code == 200) {
  402. uni.showToast({
  403. icon: 'none',
  404. title: res.msg,
  405. });
  406. const {
  407. itemJson,
  408. ...newOrder
  409. } = this.order;
  410. uni.redirectTo({
  411. url: "./success?order=" + JSON.stringify(newOrder)
  412. })
  413. } else {
  414. uni.showToast({
  415. icon: 'none',
  416. title: "请求失败",
  417. });
  418. }
  419. },
  420. rej => {}
  421. );
  422. },
  423. getUserInfo() {
  424. getUserInfo().then(
  425. res => {
  426. if (res.code == 200) {
  427. if (res.user != null) {
  428. this.user = res.user;
  429. }
  430. } else {
  431. uni.showToast({
  432. icon: 'none',
  433. title: "请求失败",
  434. });
  435. }
  436. },
  437. rej => {}
  438. );
  439. },
  440. getStoreConfig() {
  441. getStoreConfig().then(
  442. res => {
  443. if (res.code == 200) {
  444. this.config = res.data
  445. console.log(this.config);
  446. }
  447. },
  448. rej => {}
  449. );
  450. },
  451. payTypeChange(e) {
  452. if (this.combinationOrderId) {
  453. this.editPayTypeByCombinationId(e.detail.value)
  454. } else {
  455. // this.editPayType(e.detail.value)
  456. }
  457. },
  458. editPayType(payType) {
  459. var data = {
  460. orderId: this.orderId,
  461. payType: payType
  462. };
  463. var that = this;
  464. uni.showLoading();
  465. editPayType(data).then(
  466. res => {
  467. if (res.code == 200) {
  468. console.log(res);
  469. uni.hideLoading();
  470. that.order = res.order;
  471. that.order.orderCodes = that.order.orderCode ? [that.order.orderCode] : []
  472. that.orderCode = that.order.orderCode
  473. // this.payType=this.order.payType
  474. this.payMoney = this.order.payMoney;
  475. this.payDelivery = this.order.payDelivery;
  476. } else {
  477. uni.showToast({
  478. icon: 'none',
  479. title: res.msg,
  480. });
  481. }
  482. },
  483. rej => {}
  484. );
  485. },
  486. }
  487. }
  488. </script>
  489. <style lang="scss">
  490. page {
  491. height: 100%;
  492. }
  493. .content {
  494. height: 100%;
  495. display: flex;
  496. flex-direction: column;
  497. justify-content: space-between;
  498. .inner {
  499. padding: 20upx;
  500. .time-price {
  501. box-sizing: border-box;
  502. padding: 50upx 0upx;
  503. background: #FFFFFF;
  504. border-radius: 16upx;
  505. display: flex;
  506. flex-direction: column;
  507. align-items: center;
  508. .time {
  509. font-size: 32upx;
  510. font-family: PingFang SC;
  511. font-weight: 500;
  512. color: #222222;
  513. line-height: 1;
  514. text-align: center;
  515. }
  516. .desc {
  517. margin: 30upx 0upx 15upx;
  518. font-size: 26upx;
  519. font-family: PingFang SC;
  520. color: #999999;
  521. line-height: 1;
  522. text-align: center;
  523. }
  524. .price-box {
  525. display: flex;
  526. align-items: flex-end;
  527. margin-top: 28upx;
  528. .unit {
  529. font-size: 32upx;
  530. font-family: PingFang SC;
  531. font-weight: bold;
  532. color: #FF6633;
  533. line-height: 1.3;
  534. margin-right: 10upx;
  535. }
  536. .num {
  537. font-size: 56upx;
  538. font-family: PingFang SC;
  539. font-weight: bold;
  540. color: #FF6633;
  541. line-height: 1;
  542. }
  543. }
  544. }
  545. .pay-type {
  546. box-sizing: border-box;
  547. background: #FFFFFF;
  548. border-radius: 16upx;
  549. margin-top: 20upx;
  550. padding: 40upx 30upx;
  551. display: flex;
  552. flex-direction: column;
  553. justify-content: space-between;
  554. .title {
  555. font-size: 28upx;
  556. font-family: PingFang SC;
  557. font-weight: 500;
  558. color: #999999;
  559. line-height: 1;
  560. margin-bottom: 10upx;
  561. }
  562. .item {
  563. padding: 15upx 0upx;
  564. display: flex;
  565. align-items: center;
  566. justify-content: space-between;
  567. .left {
  568. display: flex;
  569. align-items: center;
  570. image {
  571. width: 44upx;
  572. height: 44upx;
  573. margin-right: 20upx;
  574. }
  575. .text {
  576. font-size: 30upx;
  577. font-family: PingFang SC;
  578. font-weight: bold;
  579. color: #222222;
  580. line-height: 1;
  581. }
  582. }
  583. }
  584. }
  585. .order-info {
  586. margin-top: 20upx;
  587. background: #FFFFFF;
  588. border-radius: 16upx;
  589. padding: 40upx 30upx;
  590. .title {
  591. font-size: 30upx;
  592. font-family: PingFang SC;
  593. font-weight: bold;
  594. color: #222222;
  595. line-height: 1;
  596. }
  597. .item {
  598. margin-top: 40upx;
  599. display: flex;
  600. align-items: center;
  601. justify-content: space-between;
  602. .label {
  603. font-size: 26upx;
  604. font-family: PingFang SC;
  605. font-weight: 500;
  606. color: #666666;
  607. line-height: 1;
  608. }
  609. .text {
  610. font-size: 26upx;
  611. font-family: PingFang SC;
  612. font-weight: 500;
  613. color: #222222;
  614. line-height: 32upx;
  615. }
  616. .cont-text {
  617. font-size: 26upx;
  618. font-family: PingFang SC;
  619. font-weight: 500;
  620. color: #666666;
  621. .bold {
  622. color: #111111;
  623. }
  624. }
  625. .sn-box {
  626. display: flex;
  627. align-items: center;
  628. .copy-btn {
  629. width: 58upx;
  630. height: 32upx;
  631. line-height: 32upx;
  632. text-align: center;
  633. font-size: 22upx;
  634. font-weight: 500;
  635. color: #222222;
  636. background: #F5F5F5;
  637. border-radius: 4upx;
  638. margin-left: 24upx;
  639. }
  640. }
  641. }
  642. .line {
  643. width: 100%;
  644. height: 1px;
  645. background: #F0F0F0;
  646. margin-top: 30upx;
  647. }
  648. }
  649. }
  650. .btn-box {
  651. height: 242upx;
  652. background: #FFFFFF;
  653. display: flex;
  654. align-items: center;
  655. justify-content: center;
  656. flex-direction: column;
  657. .btn {
  658. width: 91.73%;
  659. height: 88upx;
  660. line-height: 88upx;
  661. font-size: 30upx;
  662. font-family: PingFang SC;
  663. font-weight: bold;
  664. color: #FFFFFF;
  665. text-align: center;
  666. background: #FF5030;
  667. border-radius: 44upx;
  668. margin-bottom: 10rpx;
  669. }
  670. .other-btn {
  671. width: 91.73%;
  672. height: 88upx;
  673. line-height: 88upx;
  674. font-size: 30upx;
  675. font-family: PingFang SC;
  676. font-weight: bold;
  677. color: #FF5030;
  678. border: 1rpx solid #FF5030;
  679. text-align: center;
  680. background: #FFFFFF;
  681. border-radius: 44upx;
  682. margin-bottom: 10rpx;
  683. position: relative;
  684. .share {
  685. display: inline-block;
  686. position: absolute;
  687. top: 0;
  688. left: 0;
  689. width: 100%;
  690. height: 100%;
  691. opacity: 0;
  692. }
  693. }
  694. }
  695. }
  696. </style>