paymentOrder.vue 18 KB

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