paymentOrder.vue 15 KB

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