orderPay.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <view>
  3. <view class="inner-box" v-if="order!=null">
  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.payMoney.toFixed(2)}}</text>
  10. </view>
  11. </view>
  12. <!-- 订单详情查看 -->
  13. <view class="order-info">
  14. <view class="title">订单信息</view>
  15. <view class="item">
  16. <text class="label">订单编号</text>
  17. <view class="sn-box">
  18. <text class="text">{{order.orderSn}}</text>
  19. <view class="copy-btn" @click="copyTest(order.orderSn)">复制</view>
  20. </view>
  21. </view>
  22. <view class="item">
  23. <text class="label">下单时间</text>
  24. <text class="text">{{order.createTime}}</text>
  25. </view>
  26. </view>
  27. <!-- 支付方式 -->
  28. <view class="order-info">
  29. <view class="title">选择支付方式</view>
  30. <!-- 支付宝微信选择 -->
  31. <radio-group @change="payTypeChange">
  32. <label class="item" style="justify-content: space-between;">
  33. <view class="sn-box" style="display: flex; align-items: center;">
  34. <image src="/static/image/course/vipBuy/wx.png" style="width: 48upx; height: 48upx; margin-right: 20upx;"></image>
  35. <text class="text">微信支付</text>
  36. </view>
  37. <radio value="1" :checked="payType=='1'" color="#FF5030" style="transform:scale(0.8)"/>
  38. </label>
  39. <!-- <label class="item" style="justify-content: space-between;">
  40. <view class="sn-box" style="display: flex; align-items: center;">
  41. <image src="/static/image/course/vipBuy/wx.png" style="width: 48upx; height: 48upx; margin-right: 20upx;"></image>
  42. <text class="text">微信支付备用</text>
  43. </view>
  44. <radio value="3" :checked="payType=='3'" color="#FF5030" style="transform:scale(0.8)"/>
  45. </label> -->
  46. <label class="item" style="justify-content: space-between;">
  47. <view class="sn-box" style="display: flex; align-items: center;">
  48. <image src="/static/image/course/vipBuy/zfb.png" style="width: 48upx; height: 48upx; margin-right: 20upx;"></image>
  49. <text class="text">支付宝支付</text>
  50. </view>
  51. <radio value="4" :checked="payType=='4'" color="#FF5030" style="transform:scale(0.8)"/>
  52. </label>
  53. </radio-group>
  54. </view>
  55. </view>
  56. <!-- 底部按钮 -->
  57. <view class="btn-box">
  58. <view class="btn" v-if="order!=null" @click="payOrder()">立即支付</view>
  59. </view>
  60. <uni-popup ref="popTip" type="dialog">
  61. <uni-popup-dialog cancelText="支付失败" confirmText="支付成功" mode="base" content="是否已支付成功?" title="提示" :duration="2000" :before-close="true" @close="confirmTip" @confirm="confirmTip"></uni-popup-dialog>
  62. </uni-popup>
  63. </view>
  64. </template>
  65. <script>
  66. import{orderDetail,payment}from '@/api/courseAnswer.js'
  67. export default {
  68. data() {
  69. return {
  70. payType:'1',
  71. orderId:null,
  72. order:null,
  73. tzCashier:null,
  74. userInfo: null
  75. }
  76. },
  77. onLoad(option) {
  78. this.tzCashier=uni.requireNativePlugin("TZBank-Cashier");
  79. this.orderId=option.orderId;
  80. this.userInfo=JSON.parse(uni.getStorageSync("userInfo"));
  81. if(option.payType){
  82. this.payType=option.payType;
  83. }
  84. },
  85. onShow() {
  86. this.getOrderDetail();
  87. },
  88. methods: {
  89. payTypeChange(e){
  90. this.payType = e.detail.value;
  91. },
  92. copyTest(text) {
  93. // 复制方法
  94. uni.setClipboardData({
  95. data:text,
  96. success:()=>{
  97. uni.showToast({
  98. title:'内容已成功复制到剪切板',
  99. icon:'none'
  100. })
  101. }
  102. });
  103. },
  104. getOrderDetail(type){
  105. var data={orderId:this.orderId};
  106. orderDetail(data).then(res => {
  107. if(res.code==200){
  108. this.order=res.data;
  109. if(type==1) {
  110. if(res.data.status==2){
  111. uni.showToast({title:"支付成功",icon:'success'});
  112. uni.navigateTo({
  113. url: '/pages/courseAnswer/orderPaySuccess?orderId='+this.orderId
  114. })
  115. }else{
  116. uni.showToast({title:"支付失败",icon:'error'});
  117. }
  118. }
  119. }else{
  120. uni.showToast({
  121. icon:'none',
  122. title: "请求失败",
  123. });
  124. }
  125. });
  126. },
  127. confirmTip() {
  128. // this.getUserInfo();
  129. // this.getCourseInfo();
  130. this.$refs.popTip.close();
  131. uni.showLoading({title:"请稍侯...",mask:true,duration:3000});
  132. setTimeout(()=>{
  133. this.getOrderDetail(1);
  134. },2000);
  135. },
  136. payOrder(){
  137. if(this.payType==1&&this.order.payMoney>0) {
  138. this.doWxPay();
  139. return
  140. }
  141. const param = {
  142. orderId: this.order.orderId,
  143. payType: this.payType
  144. }
  145. uni.showLoading()
  146. payment(param).then(res=>{
  147. uni.hideLoading()
  148. if(res.code ==200) {
  149. console.log("res=======:",res);
  150. if(res.isPay==1) {
  151. uni.navigateTo({
  152. url: '/pages/courseAnswer/orderPaySuccess?orderId='+this.orderId
  153. })
  154. }else {
  155. if(this.payType==1){ //微信支付
  156. this.doWxPay();
  157. }else if(this.payType==4){ //支付宝
  158. this.doAlipay(res);
  159. }else if(this.payType==3){ //微信支付app
  160. this.doWxPay1(res);
  161. }
  162. }
  163. }else {
  164. uni.showToast({
  165. icon:'none',
  166. title: res.msg,
  167. });
  168. }
  169. })
  170. },
  171. doWxPay() {
  172. var that=this;
  173. plus.share.getServices(function(res){
  174. var sweixin = null;
  175. for(var i=0;i<res.length;i++){
  176. var t = res[i];
  177. if(t.id == 'weixin'){
  178. sweixin = t;
  179. }
  180. }
  181. if(sweixin){
  182. console.log('调起小程序')
  183. that.$refs.popTip.open()
  184. //唤起微信跳转小程序
  185. sweixin.launchMiniProgram({
  186. id:"gh_feb7753a310b",//gh_7a6a32e5ef61 御君方互医
  187. path:'/pages_courseAnswer/orderPay?orderId='+that.orderId+"&payMethod=app",
  188. type:0
  189. },function(){
  190. console.log("微信唤起成功");
  191. return true;
  192. },function(e){
  193. console.log("微信唤起失败",e);
  194. uni.showToast({
  195. title:'微信唤起失败,请检查是否有微信应用',
  196. icon:'none'
  197. })
  198. return false;
  199. })
  200. }else{
  201. uni.showToast({
  202. title:'微信唤起失败,请检查是否有微信应用',
  203. icon:'none',
  204. duration:3000
  205. })
  206. return false;
  207. }
  208. },function(res){
  209. console.log(JSON.stringify(res));
  210. });
  211. },
  212. doAlipay(res){
  213. this.$refs.popTip.open();
  214. if(res.code==200){
  215. if(res.type=="tz"){
  216. const match = res.data.body.url.match(/[\?&]businessCstNo=([^&]+)/);
  217. const businessCstNo = match ? match[1] : null;
  218. console.log("qxj tzCashier:"+this.tzCashier+" businessCstNo:"+businessCstNo);
  219. this.tzCashier.pay({
  220. env:0,
  221. wxMiniProgramType:0,
  222. wxAppId:'wx703c4bd07bbd1695',
  223. wxUniversalLink:"https://yjf.runtzh.com/",
  224. orderFlowNo:res.data.body.orderFlowNo,
  225. businessCstNo:businessCstNo,
  226. platMerCstNo:res.data.body.platMerCstNo
  227. },(res)=>{
  228. console.log("qxj 支付成功:"+JSON.stringify(res));
  229. });
  230. }
  231. else if(res.type=='hf'){
  232. if (uni.getSystemInfoSync().platform == 'android') {
  233. var alipayScheme ='alipays://platformapi/startApp?&saId=10000007&qrcode=' + res.data.qr_code;
  234. }else{
  235. var alipayScheme ='alipay://platformapi/startApp?&saId=10000007&qrcode=' + res.data.qr_code;
  236. }
  237. console.log(alipayScheme)
  238. // 在uni-app中使用plus.runtime.openURL打开URL
  239. plus.runtime.openURL(alipayScheme, function(error) {
  240. // console.error('打开支付宝失败: ' + error.message);
  241. // 处理打开支付宝失败的情况,比如提示用户或者跳转到其他支付方式
  242. });
  243. }
  244. }
  245. else{
  246. uni.showToast({
  247. title:res.msg,
  248. icon:'none'
  249. });
  250. }
  251. },
  252. doWxPay1(res) {
  253. console.log("doWxPay1==",res)
  254. let that = this
  255. if(res.type=="tz"){
  256. console.log("qxj body",res.data.body);
  257. let businessCstNo=this.userInfo.userId;
  258. console.log("businessCstNo",res.data.body);
  259. if(!!res.data.body.url){
  260. const match = res.data.body.url.match(/[\?&]businessCstNo=([^&]+)/);
  261. console.log("match==",match);
  262. businessCstNo = match ? match[1] : null;
  263. }
  264. this.tzCashier.pay({
  265. env:0,
  266. wxMiniProgramType:0,
  267. wxAppId:"wx703c4bd07bbd1695",
  268. wxUniversalLink:"https://yjf.runtzh.com/",
  269. orderFlowNo:res.data.body.orderFlowNo,
  270. businessCstNo:businessCstNo,
  271. platMerCstNo:res.data.body.platMerCstNo
  272. },(res)=>{
  273. that.showPayTips=true;
  274. });
  275. }
  276. else if(res.type=='hf'){
  277. that.showPayTips=true;
  278. }
  279. }
  280. }
  281. }
  282. </script>
  283. <style lang="scss">
  284. .inner-box{
  285. padding: 20upx 20upx 300upx;
  286. .time-price{
  287. box-sizing: border-box;
  288. padding: 50upx 0upx;
  289. background: #FFFFFF;
  290. border-radius: 16upx;
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. .time{
  295. font-size: 32upx;
  296. font-family: PingFang SC;
  297. font-weight: 500;
  298. color: #222222;
  299. line-height: 1;
  300. text-align: center;
  301. }
  302. .desc{
  303. margin: 30upx 0upx 15upx;
  304. font-size: 26upx;
  305. font-family: PingFang SC;
  306. color: #999999;
  307. line-height: 1;
  308. text-align: center;
  309. }
  310. .price-box{
  311. display: flex;
  312. align-items: flex-end;
  313. margin-top: 28upx;
  314. .unit{
  315. font-size: 32upx;
  316. font-family: PingFang SC;
  317. font-weight: bold;
  318. color: #FF6633;
  319. line-height: 1.3;
  320. margin-right: 10upx;
  321. }
  322. .num{
  323. font-size: 56upx;
  324. font-family: PingFang SC;
  325. font-weight: bold;
  326. color: #FF6633;
  327. line-height: 1;
  328. }
  329. }
  330. }
  331. .order-info{
  332. margin-top: 20upx;
  333. background: #FFFFFF;
  334. border-radius: 16upx;
  335. padding: 40upx 30upx;
  336. .title{
  337. font-size: 30upx;
  338. font-family: PingFang SC;
  339. font-weight: bold;
  340. color: #222222;
  341. line-height: 1;
  342. }
  343. .item{
  344. margin-top: 40upx;
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. .label{
  349. font-size: 26upx;
  350. font-family: PingFang SC;
  351. font-weight: 500;
  352. color: #666666;
  353. line-height: 1;
  354. }
  355. .text{
  356. font-size: 26upx;
  357. font-family: PingFang SC;
  358. font-weight: 500;
  359. color: #222222;
  360. line-height: 32upx;
  361. }
  362. .cont-text{
  363. font-size: 26upx;
  364. font-family: PingFang SC;
  365. font-weight: 500;
  366. color: #666666;
  367. .bold{
  368. color: #111111;
  369. }
  370. }
  371. .sn-box{
  372. display: flex;
  373. align-items: center;
  374. .copy-btn{
  375. width: 58upx;
  376. height: 32upx;
  377. line-height: 32upx;
  378. text-align: center;
  379. font-size: 22upx;
  380. font-family: PingFang SC;
  381. font-weight: 500;
  382. color: #222222;
  383. background: #F5F5F5;
  384. border-radius: 4upx;
  385. margin-left: 24upx;
  386. }
  387. }
  388. }
  389. .line{
  390. width: 100%;
  391. height: 1px;
  392. background: #F0F0F0;
  393. margin-top: 30upx;
  394. }
  395. }
  396. }
  397. .btn-box{
  398. z-index: 9999;
  399. width: 100%;
  400. padding: 30rpx 30upx 0rpx;
  401. position: fixed;
  402. bottom: 0;
  403. left: 0;
  404. box-sizing: border-box;
  405. background-color: #ffffff;
  406. display: flex;
  407. flex-direction: column;
  408. align-items: center;
  409. justify-content: center;
  410. .btn{
  411. margin-bottom: 20rpx;
  412. width: 100%;
  413. height: 88upx;
  414. line-height: 88upx;
  415. text-align: center;
  416. font-size: 34upx;
  417. font-family: PingFang SC;
  418. font-weight: 400;
  419. color: #FFFFFF;
  420. background: #FF5030;
  421. border-radius: 10upx;
  422. position: relative;
  423. }
  424. .btn1{
  425. margin-bottom: 20rpx;
  426. width: 100%;
  427. height: 88upx;
  428. line-height: 88upx;
  429. text-align: center;
  430. font-size: 34upx;
  431. font-family: PingFang SC;
  432. font-weight: 400;
  433. color: #FF5030;
  434. border: 1rpx solid #FF5030;
  435. border-radius: 10upx;
  436. position: relative;
  437. .share-btn {
  438. top:0rpx;
  439. left:0rpx;
  440. position: absolute;
  441. width: 100%;
  442. height: 88upx;
  443. display: flex;
  444. opacity: 0;
  445. }
  446. }
  447. }
  448. </style>