paymentOrder.vue 18 KB

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