paymentOrder.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <!-- 时间、价格 -->
  5. <view class="time-price">
  6. <text class="time">请在{{payLimitTime}}前完成支付</text>
  7. <view class="price-box">
  8. <text class="unit">¥</text>
  9. <text class="num" >{{payMoney.toFixed(2)}}</text>
  10. </view>
  11. <text class="desc" v-if="payType==2">代收金额{{payDelivery.toFixed(2)}},请您在收到快递后支付尾款给快递人员。</text>
  12. <text class="desc" v-if="payType==3">货到付款金额{{payDelivery.toFixed(2)}},请您在收到快递后支付给快递人员。</text>
  13. </view>
  14. <!-- 支付方式 -->
  15. <view class="pay-type">
  16. <view class="title">支付方式</view>
  17. <!-- 改价订单只能选择微信支付和物流代收 -->
  18. <radio-group @change="payTypeChange" v-if="order.isEditMoney!=null&&order.isEditMoney==1">
  19. <view class="item" >
  20. <view class="left" >
  21. <image src="/static/images/wecha_pay.png" mode=""></image>
  22. <text class="text">微信支付</text>
  23. </view>
  24. <label>
  25. <radio :value="1" :checked="order.payType=='1'" />
  26. </label>
  27. </view>
  28. <view class="item" >
  29. <view class="left">
  30. <image src="/static/images/pay_de.png" mode=""></image>
  31. <text class="text">物流代收</text>
  32. </view>
  33. <label>
  34. <radio :value="2" :checked="order.payType=='2'" />
  35. </label>
  36. </view>
  37. </radio-group>
  38. <radio-group @change="payTypeChange" v-else-if="order.orderCreateType!=null&& order.orderCreateType==3">
  39. <view class="item" >
  40. <view class="left" >
  41. <image src="/static/images/wecha_pay.png" mode=""></image>
  42. <text class="text">微信支付</text>
  43. </view>
  44. <label>
  45. <radio :value="1" :checked="order.payType=='1'" />
  46. </label>
  47. </view>
  48. <view class="item" >
  49. <view class="left">
  50. <image src="../../static/images/pay_de.png" mode=""></image>
  51. <text class="text">物流代收</text>
  52. </view>
  53. <label>
  54. <radio :value="2" :checked="order.payType=='2'" />
  55. </label>
  56. </view>
  57. <view class="item" v-if="user!=null&&user.level==1 ">
  58. <view class="left">
  59. <image src="../../static/images/pay_1.png" mode=""></image>
  60. <text class="text">货到付款</text>
  61. </view>
  62. <label>
  63. <radio :value="3" :checked="order.payType=='3'" />
  64. </label>
  65. </view>
  66. </radio-group>
  67. <radio-group @change="payTypeChange" v-else-if="order.orderCreateType!=null&& order.orderCreateType==2">
  68. <view class="item" v-if="payType==1||payType==4" >
  69. <view class="left" >
  70. <image src="/static/images/wecha_pay.png" mode=""></image>
  71. <text class="text">微信支付</text>
  72. </view>
  73. <label>
  74. <radio :value="1" :checked="order.payType=='1'" />
  75. </label>
  76. </view>
  77. <view class="item" v-if="payType==2||payType==4">
  78. <view class="left" >
  79. <image src="../../static/images/pay_de.png" mode=""></image>
  80. <text class="text">物流代收</text>
  81. </view>
  82. <label>
  83. <radio :value="2" :checked="order.payType=='2'" />
  84. </label>
  85. </view>
  86. <view class="item" v-if="user!=null&&user.level==1 ">
  87. <view class="left">
  88. <image src="../../static/images/pay_1.png" mode=""></image>
  89. <text class="text">货到付款</text>
  90. </view>
  91. <label>
  92. <radio :value="3" :checked="order.payType=='3'" />
  93. </label>
  94. </view>
  95. </radio-group>
  96. <radio-group @change="payTypeChange" v-else-if="order.orderCreateType!=null&&(order.orderCreateType==1)">
  97. <view class="item" >
  98. <view class="left" >
  99. <image src="/static/images/wecha_pay.png" mode=""></image>
  100. <text class="text">微信支付</text>
  101. </view>
  102. <label>
  103. <radio :value="1" checked />
  104. </label>
  105. </view>
  106. </radio-group>
  107. </view>
  108. <!-- 订单详情查看 -->
  109. <view class="order-info">
  110. <view class="title">订单信息</view>
  111. <view class="item">
  112. <text class="label">订单编号</text>
  113. <view class="sn-box">
  114. <text class="text">{{order.orderCode}}</text>
  115. <view class="copy-btn" @click="copyOrderSn(order.orderCode)">复制</view>
  116. </view>
  117. </view>
  118. <view class="item">
  119. <text class="label">下单时间</text>
  120. <text class="text">{{order.createTime}}</text>
  121. </view>
  122. <view class="item">
  123. <text class="label">订单金额</text>
  124. <text class="text" v-if="order!=null">{{order.payPrice.toFixed(2)}}</text>
  125. </view>
  126. <!-- <view class="item">
  127. <text class="label">支付方式</text>
  128. <text class="text">微信支付</text>
  129. </view> -->
  130. </view>
  131. </view>
  132. <view class="btn-box">
  133. <view class="btn" @click="payOrder()">去支付</view>
  134. <view class="other-btn" >
  135. 亲友代付
  136. <button class="share" data-name="shareBtn" open-type="share">分享</button>
  137. </view>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. import {getUserInfo} from '@/api/user'
  143. import {getStoreConfig} from '@/api/common'
  144. import {checkpayment} from '@/api/payment'
  145. import {editPayType,pay,getStoreOrderById,getMyStoreOrderById} from '@/api/storeOrder'
  146. export default {
  147. data() {
  148. return {
  149. orderId:null,
  150. payDelivery:0,
  151. payMoney:0,
  152. config:null,
  153. payType:1,
  154. payLimitTime:null,
  155. order:null,
  156. user:null,
  157. checkTimer: null, // 轮询定时器 ID
  158. maxRetryCount: 10, // 最大轮询次数(可选)
  159. retryCount: 0 ,// 当前轮询次数(可选)
  160. timeoutTimer:null//总轮询定时器
  161. }
  162. },
  163. onLoad(option) {
  164. this.orderId=JSON.parse(option.orderId);
  165. this.getStoreOrderById();
  166. this.getStoreConfig();
  167. this.getUserInfo();
  168. uni.showShareMenu({
  169. withShareTicket:true,
  170. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  171. menus:["shareAppMessage"] //不设置默认发送给朋友
  172. })
  173. if (this.checkTimer) {
  174. clearInterval(this.checkTimer);
  175. this.checkTimer = null;
  176. }
  177. },
  178. //发送给朋友
  179. onShareAppMessage(res) {
  180. return {
  181. title: "帮TA支付",
  182. path: '/pages_user/user/otherPaymentOrder?orderId='+this.orderId,
  183. imageUrl: 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20250310/aeb776c6aa174d7c94181e5fd212e0f1.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  184. }
  185. },
  186. methods: {
  187. getUserInfo(){
  188. getUserInfo().then(
  189. res => {
  190. if(res.code==200){
  191. if(res.user!=null){
  192. this.user=res.user;
  193. }
  194. }else{
  195. uni.showToast({
  196. icon:'none',
  197. title: "请求失败",
  198. });
  199. }
  200. },
  201. rej => {}
  202. );
  203. },
  204. getStoreConfig(){
  205. getStoreConfig().then(
  206. res => {
  207. if(res.code==200){
  208. this.config=res.data
  209. console.log(this.config);
  210. }
  211. },
  212. rej => {}
  213. );
  214. },
  215. payTypeChange(e){
  216. this.editPayType(e.detail.value)
  217. },
  218. copyOrderSn(text) {
  219. // 复制方法
  220. uni.setClipboardData({
  221. data:text,
  222. success:()=>{
  223. uni.showToast({
  224. title:'内容已成功复制到剪切板',
  225. icon:'none'
  226. })
  227. }
  228. });
  229. },
  230. getStoreOrderById(){
  231. var data = {orderId:this.orderId};
  232. var that=this;
  233. uni.showLoading();
  234. getStoreOrderById(data).then(
  235. res => {
  236. if(res.code==200){
  237. console.log(res);
  238. uni.hideLoading();
  239. that.order=res.order;
  240. that.payLimitTime=res.payLimitTime;
  241. //套餐订单处理
  242. if(res.productPackage!=null){
  243. this.payType=res.productPackage.payType;
  244. console.log(this.payType)
  245. if(this.order.payType==4){
  246. this.order.payType=1;
  247. }
  248. }
  249. this.editPayType(this.order.payType)
  250. }else{
  251. uni.showToast({
  252. icon:'none',
  253. title: res.msg,
  254. });
  255. }
  256. },
  257. rej => {}
  258. );
  259. },
  260. editPayType(payType){
  261. var data = {orderId:this.orderId,payType:payType};
  262. var that=this;
  263. uni.showLoading();
  264. editPayType(data).then(
  265. res => {
  266. if(res.code==200){
  267. console.log(res);
  268. uni.hideLoading();
  269. that.order=res.order;
  270. //this.payType=this.order.payType
  271. this.payMoney=this.order.payMoney;
  272. this.payDelivery=this.order.payDelivery;
  273. }else{
  274. uni.showToast({
  275. icon:'none',
  276. title: res.msg,
  277. });
  278. }
  279. },
  280. rej => {}
  281. );
  282. },
  283. otherPayOrder(){
  284. var that=this;
  285. console.log(that.order.id)
  286. var sum=that.order.id
  287. uni.navigateTo({
  288. url: '/pages_user/user/storeOrderDetail?id='+sum
  289. })
  290. },
  291. payOrder(){
  292. var data = {orderId:this.order.id,payType:this.order.payType};
  293. var that=this;
  294. uni.showLoading();
  295. pay(data).then(
  296. res => {
  297. if(res.code==200){
  298. console.log(res);
  299. if(res.payType==1||res.payType==2){
  300. var result = res.result;
  301. wx.navigateToMiniProgram({
  302. appId: 'wx1b63de1096c46cde', // 收银台小程序 AppId 固定值
  303. path: '/pages/pay/pay', // 收银台小程序 固定路径
  304. extraData: {
  305. orderNo: result.orderNo,
  306. orderAmt: result.orderAmt,
  307. platMerCstNo: result.platMerCstNo,
  308. platMerCstName: result.platMerCstName,
  309. businessCstNo: result.businessCstNo,
  310. licenseCode: result.licenseCode,
  311. },
  312. envVersion: 'release', // 开发版 develop,体验版 trial,正式环境传 release
  313. success(res) {
  314. uni.showLoading({
  315. title:"查询支付结果中...",
  316. })
  317. // 定义计时总变量
  318. let timeoutFlag = false;
  319. const timeoutTimer = setTimeout(() => {
  320. timeoutFlag = true;
  321. clearInterval(that.checkTimer);
  322. uni.hideLoading();
  323. uni.showToast({
  324. title: '支付状态查询超时',
  325. icon: 'none'
  326. });
  327. uni.redirectTo({
  328. url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  329. });
  330. }, 10000); // 总时长10秒
  331. // 启动定时器并保存 ID
  332. that.checkTimer = setInterval(() => {
  333. const data = { orderId: that.order.id };
  334. checkpayment(data).then(res => {
  335. if (timeoutFlag) return; // 如果已超时则不再处理
  336. if (res.code == 200) {
  337. if (res.status == 1) {
  338. // 跳转前清除定时器
  339. clearInterval(that.checkTimer);
  340. clearTimeout(timeoutTimer);
  341. uni.redirectTo({
  342. url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  343. });
  344. }
  345. // else if{
  346. // setTimeout(()=>{
  347. // clearInterval(that.checkTimer);
  348. // uni.navigateTo({
  349. // url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  350. // });
  351. // },10000)
  352. // }
  353. }else{
  354. // 接口异常时清除定时器
  355. clearInterval(that.checkTimer);
  356. clearTimeout(timeoutTimer);
  357. uni.hideLoading();
  358. uni.showToast({
  359. title: '查询异常:' + res.msg,
  360. icon: 'none'
  361. });
  362. }
  363. });
  364. }, 4000);
  365. // 页面卸载时清理定时器(重要!)
  366. that.$once('hook:beforeDestroy', () => {
  367. clearInterval(that.checkTimer);
  368. clearTimeout(timeoutTimer);
  369. });
  370. console.log('结果结果',res)
  371. // 接口调用成功的回调函数
  372. },
  373. fail(res) {
  374. if (that.checkTimer) clearInterval(that.checkTimer);
  375. // 接口调用失败的回调函数
  376. }
  377. })
  378. // var result=JSON.parse(res.result);
  379. // uni.requestPayment({
  380. // provider: 'wxpay',
  381. // timeStamp: result.timeStamp,
  382. // nonceStr: result.nonceStr,
  383. // package: result.package,
  384. // signType: result.signType,
  385. // paySign: result.paySign,
  386. // success: function(res) {
  387. // uni.hideLoading();
  388. // uni.redirectTo({
  389. // url:"success?order="+JSON.stringify(that.order)
  390. // })
  391. // },
  392. // fail: function(err) {
  393. // uni.showToast({
  394. // icon:'none',
  395. // title:'fail:' + JSON.stringify(err),
  396. // });
  397. // console.log('fail:' + JSON.stringify(err));
  398. // uni.hideLoading();
  399. // }
  400. // });
  401. // uni.requestPayment({
  402. // provider: 'wxpay',
  403. // timeStamp: res.result.timeStamp,
  404. // nonceStr: res.result.nonceStr,
  405. // package: res.result.packageValue,
  406. // signType: res.result.signType,
  407. // paySign: res.result.paySign,
  408. // success: function(res) {
  409. // uni.hideLoading();
  410. // uni.redirectTo({
  411. // url:"success?order="+JSON.stringify(that.order)
  412. // })
  413. // },
  414. // fail: function(err) {
  415. // uni.showToast({
  416. // icon:'none',
  417. // title:'fail:' + JSON.stringify(err),
  418. // });
  419. // console.log('fail:' + JSON.stringify(err));
  420. // uni.hideLoading();
  421. // }
  422. // });
  423. }
  424. else if(res.payType==3){
  425. uni.hideLoading();
  426. if(that.order.isPrescribe){
  427. //如果是处方订单开处方
  428. uni.redirectTo({
  429. url:"prescribe?orderId="+that.order.id
  430. })
  431. }
  432. else{
  433. //如果是普通订单
  434. uni.redirectTo({
  435. url:"success?order="+JSON.stringify(that.order)
  436. })
  437. }
  438. }
  439. }else{
  440. uni.showToast({
  441. icon:'none',
  442. title: res.msg,
  443. });
  444. }
  445. },
  446. rej => {}
  447. );
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang="scss">
  453. page{
  454. height: 100%;
  455. }
  456. .content{
  457. height: 100%;
  458. display: flex;
  459. flex-direction: column;
  460. justify-content: space-between;
  461. .inner{
  462. padding: 20upx;
  463. .time-price{
  464. box-sizing: border-box;
  465. padding: 50upx 0upx;
  466. background: #FFFFFF;
  467. border-radius: 16upx;
  468. display: flex;
  469. flex-direction: column;
  470. align-items: center;
  471. .time{
  472. font-size: 32upx;
  473. font-family: PingFang SC;
  474. font-weight: 500;
  475. color: #222222;
  476. line-height: 1;
  477. text-align: center;
  478. }
  479. .desc{
  480. margin: 30upx 0upx 15upx;
  481. font-size: 26upx;
  482. font-family: PingFang SC;
  483. color: #999999;
  484. line-height: 1;
  485. text-align: center;
  486. }
  487. .price-box{
  488. display: flex;
  489. align-items: flex-end;
  490. margin-top: 28upx;
  491. .unit{
  492. font-size: 32upx;
  493. font-family: PingFang SC;
  494. font-weight: bold;
  495. color: #FF6633;
  496. line-height: 1.3;
  497. margin-right: 10upx;
  498. }
  499. .num{
  500. font-size: 56upx;
  501. font-family: PingFang SC;
  502. font-weight: bold;
  503. color: #FF6633;
  504. line-height: 1;
  505. }
  506. }
  507. }
  508. .pay-type{
  509. box-sizing: border-box;
  510. background: #FFFFFF;
  511. border-radius: 16upx;
  512. margin-top: 20upx;
  513. padding: 40upx 30upx;
  514. display: flex;
  515. flex-direction: column;
  516. justify-content: space-between;
  517. .title{
  518. font-size: 28upx;
  519. font-family: PingFang SC;
  520. font-weight: 500;
  521. color: #999999;
  522. line-height: 1;
  523. margin-bottom: 10upx;
  524. }
  525. .item{
  526. padding: 15upx 0upx;
  527. display: flex;
  528. align-items: center;
  529. justify-content: space-between;
  530. .left{
  531. display: flex;
  532. align-items: center;
  533. image{
  534. width: 44upx;
  535. height: 44upx;
  536. margin-right: 20upx;
  537. }
  538. .text{
  539. font-size: 30upx;
  540. font-family: PingFang SC;
  541. font-weight: bold;
  542. color: #222222;
  543. line-height: 1;
  544. }
  545. }
  546. }
  547. }
  548. .order-info{
  549. margin-top: 20upx;
  550. background: #FFFFFF;
  551. border-radius: 16upx;
  552. padding: 40upx 30upx;
  553. .title{
  554. font-size: 30upx;
  555. font-family: PingFang SC;
  556. font-weight: bold;
  557. color: #222222;
  558. line-height: 1;
  559. }
  560. .item{
  561. margin-top: 40upx;
  562. display: flex;
  563. align-items: center;
  564. justify-content: space-between;
  565. .label{
  566. font-size: 26upx;
  567. font-family: PingFang SC;
  568. font-weight: 500;
  569. color: #666666;
  570. line-height: 1;
  571. }
  572. .text{
  573. font-size: 26upx;
  574. font-family: PingFang SC;
  575. font-weight: 500;
  576. color: #222222;
  577. line-height: 32upx;
  578. }
  579. .cont-text{
  580. font-size: 26upx;
  581. font-family: PingFang SC;
  582. font-weight: 500;
  583. color: #666666;
  584. .bold{
  585. color: #111111;
  586. }
  587. }
  588. .sn-box{
  589. display: flex;
  590. align-items: center;
  591. .copy-btn{
  592. width: 58upx;
  593. height: 32upx;
  594. line-height: 32upx;
  595. text-align: center;
  596. font-size: 22upx;
  597. font-family: PingFang SC;
  598. font-weight: 500;
  599. color: #222222;
  600. background: #F5F5F5;
  601. border-radius: 4upx;
  602. margin-left: 24upx;
  603. }
  604. }
  605. }
  606. .line{
  607. width: 100%;
  608. height: 1px;
  609. background: #F0F0F0;
  610. margin-top: 30upx;
  611. }
  612. }
  613. }
  614. .btn-box{
  615. height: 242upx;
  616. background: #FFFFFF;
  617. display: flex;
  618. align-items: center;
  619. justify-content: center;
  620. flex-direction: column;
  621. .btn{
  622. width: 91.73%;
  623. height: 88upx;
  624. line-height: 88upx;
  625. font-size: 30upx;
  626. font-family: PingFang SC;
  627. font-weight: bold;
  628. color: #FFFFFF;
  629. text-align: center;
  630. background: #2BC7B9;
  631. border-radius: 44upx;
  632. margin-bottom: 10rpx;
  633. }
  634. .other-btn{
  635. width: 91.73%;
  636. height: 88upx;
  637. line-height: 88upx;
  638. font-size: 30upx;
  639. font-family: PingFang SC;
  640. font-weight: bold;
  641. color: #2BC7B9;
  642. border: 1rpx solid #2BC7B9;
  643. text-align: center;
  644. background: #FFFFFF;
  645. border-radius: 44upx;
  646. margin-bottom: 10rpx;
  647. position: relative;
  648. .share{
  649. display: inline-block;
  650. position: absolute;
  651. top: 0;
  652. left: 0;
  653. width: 100%;
  654. height: 100%;
  655. opacity: 0;
  656. }
  657. }
  658. }
  659. }
  660. </style>