paymentOrder.vue 16 KB

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