paymentOrder.vue 18 KB

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