paymentOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. }
  161. },
  162. onLoad(option) {
  163. this.orderId=JSON.parse(option.orderId);
  164. this.getStoreOrderById();
  165. this.getStoreConfig();
  166. this.getUserInfo();
  167. uni.showShareMenu({
  168. withShareTicket:true,
  169. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  170. menus:["shareAppMessage"] //不设置默认发送给朋友
  171. })
  172. if (this.checkTimer) {
  173. clearInterval(this.checkTimer);
  174. this.checkTimer = null;
  175. }
  176. },
  177. //发送给朋友
  178. onShareAppMessage(res) {
  179. return {
  180. title: "帮TA支付",
  181. path: '/pages_user/user/otherPaymentOrder?orderId='+this.orderId,
  182. imageUrl: 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20250310/aeb776c6aa174d7c94181e5fd212e0f1.png' //分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
  183. }
  184. },
  185. methods: {
  186. getUserInfo(){
  187. getUserInfo().then(
  188. res => {
  189. if(res.code==200){
  190. if(res.user!=null){
  191. this.user=res.user;
  192. }
  193. }else{
  194. uni.showToast({
  195. icon:'none',
  196. title: "请求失败",
  197. });
  198. }
  199. },
  200. rej => {}
  201. );
  202. },
  203. getStoreConfig(){
  204. getStoreConfig().then(
  205. res => {
  206. if(res.code==200){
  207. this.config=res.data
  208. console.log(this.config);
  209. }
  210. },
  211. rej => {}
  212. );
  213. },
  214. payTypeChange(e){
  215. this.editPayType(e.detail.value)
  216. },
  217. copyOrderSn(text) {
  218. // 复制方法
  219. uni.setClipboardData({
  220. data:text,
  221. success:()=>{
  222. uni.showToast({
  223. title:'内容已成功复制到剪切板',
  224. icon:'none'
  225. })
  226. }
  227. });
  228. },
  229. getStoreOrderById(){
  230. var data = {orderId:this.orderId};
  231. var that=this;
  232. uni.showLoading();
  233. getStoreOrderById(data).then(
  234. res => {
  235. if(res.code==200){
  236. console.log(res);
  237. uni.hideLoading();
  238. that.order=res.order;
  239. that.payLimitTime=res.payLimitTime;
  240. //套餐订单处理
  241. if(res.productPackage!=null){
  242. this.payType=res.productPackage.payType;
  243. console.log(this.payType)
  244. if(this.order.payType==4){
  245. this.order.payType=1;
  246. }
  247. }
  248. this.editPayType(this.order.payType)
  249. }else{
  250. uni.showToast({
  251. icon:'none',
  252. title: res.msg,
  253. });
  254. }
  255. },
  256. rej => {}
  257. );
  258. },
  259. editPayType(payType){
  260. var data = {orderId:this.orderId,payType:payType};
  261. var that=this;
  262. uni.showLoading();
  263. editPayType(data).then(
  264. res => {
  265. if(res.code==200){
  266. console.log(res);
  267. uni.hideLoading();
  268. that.order=res.order;
  269. //this.payType=this.order.payType
  270. this.payMoney=this.order.payMoney;
  271. this.payDelivery=this.order.payDelivery;
  272. }else{
  273. uni.showToast({
  274. icon:'none',
  275. title: res.msg,
  276. });
  277. }
  278. },
  279. rej => {}
  280. );
  281. },
  282. otherPayOrder(){
  283. var that=this;
  284. console.log(that.order.id)
  285. var sum=that.order.id
  286. uni.navigateTo({
  287. url: '/pages_user/user/storeOrderDetail?id='+sum
  288. })
  289. },
  290. payOrder(){
  291. var data = {orderId:this.order.id,payType:this.order.payType};
  292. var that=this;
  293. uni.showLoading();
  294. pay(data).then(
  295. res => {
  296. if(res.code==200){
  297. console.log(res);
  298. if(res.payType==1||res.payType==2){
  299. var result = res.result;
  300. wx.navigateToMiniProgram({
  301. appId: 'wx1b63de1096c46cde', // 收银台小程序 AppId 固定值
  302. path: '/pages/pay/pay', // 收银台小程序 固定路径
  303. extraData: {
  304. orderNo: result.orderNo,
  305. orderAmt: result.orderAmt,
  306. platMerCstNo: result.platMerCstNo,
  307. platMerCstName: result.platMerCstName,
  308. businessCstNo: result.businessCstNo,
  309. licenseCode: result.licenseCode,
  310. },
  311. envVersion: 'release', // 开发版 develop,体验版 trial,正式环境传 release
  312. success(res) {
  313. uni.showLoading({
  314. title:"查询支付结果中...",
  315. })
  316. // 启动定时器并保存 ID
  317. that.checkTimer = setInterval(() => {
  318. const data = { orderId: that.order.id };
  319. checkpayment(data).then(res => {
  320. if (res.code == 200) {
  321. if (res.status == 1) {
  322. // 跳转前清除定时器
  323. clearInterval(that.checkTimer);
  324. uni.navigateTo({
  325. url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  326. });
  327. }
  328. // else{
  329. // setTimeout(()=>{
  330. // clearInterval(that.checkTimer);
  331. // uni.navigateTo({
  332. // url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
  333. // });
  334. // },10000)
  335. // }
  336. }
  337. });
  338. }, 4000);
  339. // setTimeout(()=>{
  340. // that.otherPayOrder()
  341. // },4000)
  342. console.log('结果结果',res)
  343. // 接口调用成功的回调函数
  344. },
  345. fail(res) {
  346. if (that.checkTimer) clearInterval(that.checkTimer);
  347. // 接口调用失败的回调函数
  348. }
  349. })
  350. // var result=JSON.parse(res.result);
  351. // uni.requestPayment({
  352. // provider: 'wxpay',
  353. // timeStamp: result.timeStamp,
  354. // nonceStr: result.nonceStr,
  355. // package: result.package,
  356. // signType: result.signType,
  357. // paySign: result.paySign,
  358. // success: function(res) {
  359. // uni.hideLoading();
  360. // uni.redirectTo({
  361. // url:"success?order="+JSON.stringify(that.order)
  362. // })
  363. // },
  364. // fail: function(err) {
  365. // uni.showToast({
  366. // icon:'none',
  367. // title:'fail:' + JSON.stringify(err),
  368. // });
  369. // console.log('fail:' + JSON.stringify(err));
  370. // uni.hideLoading();
  371. // }
  372. // });
  373. // uni.requestPayment({
  374. // provider: 'wxpay',
  375. // timeStamp: res.result.timeStamp,
  376. // nonceStr: res.result.nonceStr,
  377. // package: res.result.packageValue,
  378. // signType: res.result.signType,
  379. // paySign: res.result.paySign,
  380. // success: function(res) {
  381. // uni.hideLoading();
  382. // uni.redirectTo({
  383. // url:"success?order="+JSON.stringify(that.order)
  384. // })
  385. // },
  386. // fail: function(err) {
  387. // uni.showToast({
  388. // icon:'none',
  389. // title:'fail:' + JSON.stringify(err),
  390. // });
  391. // console.log('fail:' + JSON.stringify(err));
  392. // uni.hideLoading();
  393. // }
  394. // });
  395. }
  396. else if(res.payType==3){
  397. uni.hideLoading();
  398. if(that.order.isPrescribe){
  399. //如果是处方订单开处方
  400. uni.redirectTo({
  401. url:"prescribe?orderId="+that.order.id
  402. })
  403. }
  404. else{
  405. //如果是普通订单
  406. uni.redirectTo({
  407. url:"success?order="+JSON.stringify(that.order)
  408. })
  409. }
  410. }
  411. }else{
  412. uni.showToast({
  413. icon:'none',
  414. title: res.msg,
  415. });
  416. }
  417. },
  418. rej => {}
  419. );
  420. }
  421. }
  422. }
  423. </script>
  424. <style lang="scss">
  425. page{
  426. height: 100%;
  427. }
  428. .content{
  429. height: 100%;
  430. display: flex;
  431. flex-direction: column;
  432. justify-content: space-between;
  433. .inner{
  434. padding: 20upx;
  435. .time-price{
  436. box-sizing: border-box;
  437. padding: 50upx 0upx;
  438. background: #FFFFFF;
  439. border-radius: 16upx;
  440. display: flex;
  441. flex-direction: column;
  442. align-items: center;
  443. .time{
  444. font-size: 32upx;
  445. font-family: PingFang SC;
  446. font-weight: 500;
  447. color: #222222;
  448. line-height: 1;
  449. text-align: center;
  450. }
  451. .desc{
  452. margin: 30upx 0upx 15upx;
  453. font-size: 26upx;
  454. font-family: PingFang SC;
  455. color: #999999;
  456. line-height: 1;
  457. text-align: center;
  458. }
  459. .price-box{
  460. display: flex;
  461. align-items: flex-end;
  462. margin-top: 28upx;
  463. .unit{
  464. font-size: 32upx;
  465. font-family: PingFang SC;
  466. font-weight: bold;
  467. color: #FF6633;
  468. line-height: 1.3;
  469. margin-right: 10upx;
  470. }
  471. .num{
  472. font-size: 56upx;
  473. font-family: PingFang SC;
  474. font-weight: bold;
  475. color: #FF6633;
  476. line-height: 1;
  477. }
  478. }
  479. }
  480. .pay-type{
  481. box-sizing: border-box;
  482. background: #FFFFFF;
  483. border-radius: 16upx;
  484. margin-top: 20upx;
  485. padding: 40upx 30upx;
  486. display: flex;
  487. flex-direction: column;
  488. justify-content: space-between;
  489. .title{
  490. font-size: 28upx;
  491. font-family: PingFang SC;
  492. font-weight: 500;
  493. color: #999999;
  494. line-height: 1;
  495. margin-bottom: 10upx;
  496. }
  497. .item{
  498. padding: 15upx 0upx;
  499. display: flex;
  500. align-items: center;
  501. justify-content: space-between;
  502. .left{
  503. display: flex;
  504. align-items: center;
  505. image{
  506. width: 44upx;
  507. height: 44upx;
  508. margin-right: 20upx;
  509. }
  510. .text{
  511. font-size: 30upx;
  512. font-family: PingFang SC;
  513. font-weight: bold;
  514. color: #222222;
  515. line-height: 1;
  516. }
  517. }
  518. }
  519. }
  520. .order-info{
  521. margin-top: 20upx;
  522. background: #FFFFFF;
  523. border-radius: 16upx;
  524. padding: 40upx 30upx;
  525. .title{
  526. font-size: 30upx;
  527. font-family: PingFang SC;
  528. font-weight: bold;
  529. color: #222222;
  530. line-height: 1;
  531. }
  532. .item{
  533. margin-top: 40upx;
  534. display: flex;
  535. align-items: center;
  536. justify-content: space-between;
  537. .label{
  538. font-size: 26upx;
  539. font-family: PingFang SC;
  540. font-weight: 500;
  541. color: #666666;
  542. line-height: 1;
  543. }
  544. .text{
  545. font-size: 26upx;
  546. font-family: PingFang SC;
  547. font-weight: 500;
  548. color: #222222;
  549. line-height: 32upx;
  550. }
  551. .cont-text{
  552. font-size: 26upx;
  553. font-family: PingFang SC;
  554. font-weight: 500;
  555. color: #666666;
  556. .bold{
  557. color: #111111;
  558. }
  559. }
  560. .sn-box{
  561. display: flex;
  562. align-items: center;
  563. .copy-btn{
  564. width: 58upx;
  565. height: 32upx;
  566. line-height: 32upx;
  567. text-align: center;
  568. font-size: 22upx;
  569. font-family: PingFang SC;
  570. font-weight: 500;
  571. color: #222222;
  572. background: #F5F5F5;
  573. border-radius: 4upx;
  574. margin-left: 24upx;
  575. }
  576. }
  577. }
  578. .line{
  579. width: 100%;
  580. height: 1px;
  581. background: #F0F0F0;
  582. margin-top: 30upx;
  583. }
  584. }
  585. }
  586. .btn-box{
  587. height: 242upx;
  588. background: #FFFFFF;
  589. display: flex;
  590. align-items: center;
  591. justify-content: center;
  592. flex-direction: column;
  593. .btn{
  594. width: 91.73%;
  595. height: 88upx;
  596. line-height: 88upx;
  597. font-size: 30upx;
  598. font-family: PingFang SC;
  599. font-weight: bold;
  600. color: #FFFFFF;
  601. text-align: center;
  602. background: #2BC7B9;
  603. border-radius: 44upx;
  604. margin-bottom: 10rpx;
  605. }
  606. .other-btn{
  607. width: 91.73%;
  608. height: 88upx;
  609. line-height: 88upx;
  610. font-size: 30upx;
  611. font-family: PingFang SC;
  612. font-weight: bold;
  613. color: #2BC7B9;
  614. border: 1rpx solid #2BC7B9;
  615. text-align: center;
  616. background: #FFFFFF;
  617. border-radius: 44upx;
  618. margin-bottom: 10rpx;
  619. position: relative;
  620. .share{
  621. display: inline-block;
  622. position: absolute;
  623. top: 0;
  624. left: 0;
  625. width: 100%;
  626. height: 100%;
  627. opacity: 0;
  628. }
  629. }
  630. }
  631. }
  632. </style>