paymentOrder.vue 17 KB

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