paymentOrder.vue 17 KB

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