paymentOrder.vue 17 KB

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