otherPaymentOrder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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" >{{payMoney.toFixed(2)}}</text>
  10. </view>
  11. </view>
  12. <!-- 支付方式 -->
  13. <view class="pay-type">
  14. <view class="title">支付方式</view>
  15. <radio-group >
  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 />
  23. </label>
  24. </view>
  25. </radio-group>
  26. </view>
  27. <!-- 订单详情查看 -->
  28. <view class="order-info">
  29. <view class="title">订单信息</view>
  30. <view class="item">
  31. <text class="label">订单编号</text>
  32. <view class="sn-box">
  33. <text class="text">{{order.orderCode}}</text>
  34. <view class="copy-btn" @click="copyOrderSn(order.orderCode)">复制</view>
  35. </view>
  36. </view>
  37. <view class="item">
  38. <text class="label">下单时间</text>
  39. <text class="text">{{order.createTime}}</text>
  40. </view>
  41. <view class="item">
  42. <text class="label">订单金额</text>
  43. <text class="text" v-if="order!=null">{{order.payPrice.toFixed(2)}}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="btn-box">
  48. <view class="btn" @click="pay()">帮TA支付</view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import {otherPayment,getStoreOrderById,getMyStoreOrderById,userCancelPay} from '@/api/storeOrder'
  54. import {checkpayment} from '@/api/payment'
  55. export default {
  56. data() {
  57. return {
  58. payDelivery:0,
  59. payMoney:0,
  60. config:null,
  61. payType:1,
  62. payLimitTime:null,
  63. order:null,
  64. user:null,
  65. checkTimer: null, // 轮询定时器 ID
  66. maxRetryCount: 10, // 最大轮询次数(可选)
  67. retryCount: 0 ,// 当前轮询次数(可选)
  68. timeoutTimer:null//总轮询定时器
  69. }
  70. },
  71. onLoad(option) {
  72. this.orderId=JSON.parse(option.orderId);
  73. this.getStoreOrderById();
  74. if (this.checkTimer) {
  75. clearInterval(this.checkTimer);
  76. this.checkTimer = null;
  77. }
  78. },
  79. methods: {
  80. getcanle(){
  81. var that=this;
  82. var data = {orderId:this.order.id,payType:this.order.payType};
  83. userCancelPay(data).then(res=>{
  84. if(res.code==200){
  85. console.log(res)
  86. }else{
  87. }
  88. })
  89. },
  90. copyOrderSn(text) {
  91. // 复制方法
  92. uni.setClipboardData({
  93. data:text,
  94. success:()=>{
  95. uni.showToast({
  96. title:'内容已成功复制到剪切板',
  97. icon:'none'
  98. })
  99. }
  100. });
  101. },
  102. getStoreOrderById(){
  103. var data = {orderId:this.orderId};
  104. var that=this;
  105. uni.showLoading();
  106. getStoreOrderById(data).then(
  107. res => {
  108. if(res.code==200){
  109. console.log(res);
  110. uni.hideLoading();
  111. that.order=res.order;
  112. this.payMoney=that.order.payMoney;
  113. }else{
  114. uni.showToast({
  115. icon:'none',
  116. title: res.msg,
  117. });
  118. }
  119. },
  120. rej => {}
  121. );
  122. },
  123. pay(){
  124. uni.login({
  125. success: res => {
  126. console.log(res)
  127. this.otherPayment(res.code);
  128. }
  129. });
  130. },
  131. otherPayment(code){
  132. var data = {orderId:this.order.id,code:code };
  133. var that=this;
  134. uni.showLoading();
  135. otherPayment(data).then(
  136. res => {
  137. if(res.code==200){
  138. console.log('json;;;;;',res.result)
  139. var result=res.result;
  140. // wx.navigateToMiniProgram({
  141. // appId: 'wx1b63de1096c46cde', // 收银台小程序 AppId 固定值
  142. // path: '/pages/pay/pay', // 收银台小程序 固定路径
  143. // extraData: {
  144. // orderNo: result.orderNo,
  145. // orderAmt: result.orderAmt,
  146. // platMerCstNo: result.platMerCstNo,
  147. // platMerCstName: result.platMerCstName,
  148. // businessCstNo: result.businessCstNo,
  149. // licenseCode: result.licenseCode,
  150. // },
  151. // envVersion: 'release', // 开发版 develop,体验版 trial,正式环境传 release
  152. // success(res) {
  153. // uni.showLoading({
  154. // title:"查询支付结果中..."
  155. // })
  156. // // 定义计时总变量
  157. // let timeoutFlag = false;
  158. // const timeoutTimer = setTimeout(() => {
  159. // timeoutFlag = true;
  160. // clearInterval(that.checkTimer);
  161. // uni.hideLoading();
  162. // uni.showToast({
  163. // title: '支付状态查询超时',
  164. // icon: 'none'
  165. // });
  166. // uni.redirectTo({
  167. // url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  168. // });
  169. // }, 10000); // 总时长10秒
  170. // // 启动定时器并保存 ID
  171. // that.checkTimer = setInterval(() => {
  172. // const data = { orderId: that.order.id };
  173. // checkpayment(data).then(res => {
  174. // if (timeoutFlag) return; // 如果已超时则不再处理
  175. // if (res.code == 200) {
  176. // if (res.status == 1) {
  177. // // 跳转前清除定时器
  178. // clearInterval(that.checkTimer);
  179. // clearTimeout(timeoutTimer);
  180. // uni.redirectTo({
  181. // url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  182. // });
  183. // }
  184. // // else{
  185. // // clearInterval(that.checkTimer);
  186. // // setTimeout(()=>{
  187. // // uni.navigateTo({
  188. // // url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  189. // // });
  190. // // },10000)
  191. // // }
  192. // }else{
  193. // // 接口异常时清除定时器
  194. // clearInterval(that.checkTimer);
  195. // clearTimeout(timeoutTimer);
  196. // uni.hideLoading();
  197. // uni.showToast({
  198. // title: '查询异常:' + res.msg,
  199. // icon: 'none'
  200. // });
  201. // }
  202. // });
  203. // }, 4000);
  204. // console.log(res)
  205. // // 页面卸载时清理定时器(重要!)
  206. // that.$once('hook:beforeDestroy', () => {
  207. // clearInterval(that.checkTimer);
  208. // clearTimeout(timeoutTimer);
  209. // });
  210. // // 接口调用成功的回调函数
  211. // },
  212. // fail(res) {
  213. // // 接口调用失败的回调函数
  214. // console.log(res)
  215. // if (that.checkTimer) clearInterval(that.checkTimer);
  216. // }
  217. // })
  218. // uni.requestPayment({
  219. // provider: 'wxpay',
  220. // timeStamp: result.timeStamp,
  221. // nonceStr: result.nonceStr,
  222. // package: result.package,
  223. // signType: result.signType,
  224. // paySign: result.paySign,
  225. // success: function(res) {
  226. // uni.hideLoading();
  227. // uni.redirectTo({
  228. // url:"otherPaySuccess"
  229. // })
  230. // },
  231. // fail: function(err) {
  232. // uni.showToast({
  233. // icon:'none',
  234. // title:'fail:' + JSON.stringify(err),
  235. // });
  236. // console.log('fail:' + JSON.stringify(err));
  237. // uni.hideLoading();
  238. // }
  239. // });
  240. uni.requestPayment({
  241. provider: 'wxpay',
  242. timeStamp: res.result.timeStamp,
  243. nonceStr: res.result.nonceStr,
  244. package: res.result.packageValue,
  245. signType: res.result.signType,
  246. paySign: res.result.paySign,
  247. success: function(res) {
  248. uni.hideLoading();
  249. uni.redirectTo({
  250. url:"otherPaySuccess"
  251. })
  252. },
  253. fail: function(err) {
  254. uni.showToast({
  255. icon:'none',
  256. title:'fail:' + JSON.stringify(err),
  257. });
  258. that.getcanle()
  259. // console.log('fail:' + JSON.stringify(err));
  260. uni.hideLoading();
  261. }
  262. });
  263. }else{
  264. uni.showToast({
  265. icon:'none',
  266. title: res.msg,
  267. });
  268. }
  269. },
  270. rej => {}
  271. );
  272. }
  273. }
  274. }
  275. </script>
  276. <style lang="scss">
  277. page{
  278. height: 100%;
  279. }
  280. .content{
  281. height: 100%;
  282. display: flex;
  283. flex-direction: column;
  284. justify-content: space-between;
  285. .inner{
  286. padding: 20upx;
  287. .time-price{
  288. box-sizing: border-box;
  289. padding: 50upx 0upx;
  290. background: #FFFFFF;
  291. border-radius: 16upx;
  292. display: flex;
  293. flex-direction: column;
  294. align-items: center;
  295. .time{
  296. font-size: 32upx;
  297. font-family: PingFang SC;
  298. font-weight: 500;
  299. color: #222222;
  300. line-height: 1;
  301. text-align: center;
  302. }
  303. .desc{
  304. margin: 30upx 0upx 15upx;
  305. font-size: 26upx;
  306. font-family: PingFang SC;
  307. color: #999999;
  308. line-height: 1;
  309. text-align: center;
  310. }
  311. .price-box{
  312. display: flex;
  313. align-items: flex-end;
  314. margin-top: 28upx;
  315. .unit{
  316. font-size: 32upx;
  317. font-family: PingFang SC;
  318. font-weight: bold;
  319. color: #FF6633;
  320. line-height: 1.3;
  321. margin-right: 10upx;
  322. }
  323. .num{
  324. font-size: 56upx;
  325. font-family: PingFang SC;
  326. font-weight: bold;
  327. color: #FF6633;
  328. line-height: 1;
  329. }
  330. }
  331. }
  332. .pay-type{
  333. box-sizing: border-box;
  334. background: #FFFFFF;
  335. border-radius: 16upx;
  336. margin-top: 20upx;
  337. padding: 40upx 30upx;
  338. display: flex;
  339. flex-direction: column;
  340. justify-content: space-between;
  341. .title{
  342. font-size: 28upx;
  343. font-family: PingFang SC;
  344. font-weight: 500;
  345. color: #999999;
  346. line-height: 1;
  347. margin-bottom: 10upx;
  348. }
  349. .item{
  350. padding: 15upx 0upx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: space-between;
  354. .left{
  355. display: flex;
  356. align-items: center;
  357. image{
  358. width: 44upx;
  359. height: 44upx;
  360. margin-right: 20upx;
  361. }
  362. .text{
  363. font-size: 30upx;
  364. font-family: PingFang SC;
  365. font-weight: bold;
  366. color: #222222;
  367. line-height: 1;
  368. }
  369. }
  370. }
  371. }
  372. .order-info{
  373. margin-top: 20upx;
  374. background: #FFFFFF;
  375. border-radius: 16upx;
  376. padding: 40upx 30upx;
  377. .title{
  378. font-size: 30upx;
  379. font-family: PingFang SC;
  380. font-weight: bold;
  381. color: #222222;
  382. line-height: 1;
  383. }
  384. .item{
  385. margin-top: 40upx;
  386. display: flex;
  387. align-items: center;
  388. justify-content: space-between;
  389. .label{
  390. font-size: 26upx;
  391. font-family: PingFang SC;
  392. font-weight: 500;
  393. color: #666666;
  394. line-height: 1;
  395. }
  396. .text{
  397. font-size: 26upx;
  398. font-family: PingFang SC;
  399. font-weight: 500;
  400. color: #222222;
  401. line-height: 32upx;
  402. }
  403. .cont-text{
  404. font-size: 26upx;
  405. font-family: PingFang SC;
  406. font-weight: 500;
  407. color: #666666;
  408. .bold{
  409. color: #111111;
  410. }
  411. }
  412. .sn-box{
  413. display: flex;
  414. align-items: center;
  415. .copy-btn{
  416. width: 58upx;
  417. height: 32upx;
  418. line-height: 32upx;
  419. text-align: center;
  420. font-size: 22upx;
  421. font-family: PingFang SC;
  422. font-weight: 500;
  423. color: #222222;
  424. background: #F5F5F5;
  425. border-radius: 4upx;
  426. margin-left: 24upx;
  427. }
  428. }
  429. }
  430. .line{
  431. width: 100%;
  432. height: 1px;
  433. background: #F0F0F0;
  434. margin-top: 30upx;
  435. }
  436. }
  437. }
  438. .btn-box{
  439. height: 121upx;
  440. background: #FFFFFF;
  441. display: flex;
  442. align-items: center;
  443. justify-content: center;
  444. flex-direction: column;
  445. .btn{
  446. width: 91.73%;
  447. height: 88upx;
  448. line-height: 88upx;
  449. font-size: 30upx;
  450. font-family: PingFang SC;
  451. font-weight: bold;
  452. color: #FFFFFF;
  453. text-align: center;
  454. background: #2BC7B9;
  455. border-radius: 44upx;
  456. margin-bottom: 10rpx;
  457. }
  458. }
  459. }
  460. </style>