order-pay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <template>
  2. <view class="container cashier" v-show="isRepuest">
  3. <cu-custom :navbar-data='nvabarData' @navigateBack="hanldNavigateBack"></cu-custom>
  4. <view class="container-cash clearfix" :style="{marginTop:CustomBar+'px'}">
  5. <view class="container-wrapper">
  6. <view class="pay-content">
  7. <view class="pay-top">
  8. <view class="pay-paid">
  9. <text class="txt-m">待付金额</text>
  10. <text class="txt-b"><text class="small">¥</text>{{payableAmount | NumFormat}}</text>
  11. </view>
  12. <view class="pay-payd">
  13. <view class="pay-paids">
  14. <text class="txt-m">应付总额</text>
  15. <text class="txt-b">¥{{payableAmount | NumFormat}}</text>
  16. </view>
  17. <view class="pay-paids">
  18. <text class="txt-m">已支付金额</text>
  19. <text class="txt-b">¥{{receiptAmount | NumFormat}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="pay-bot">
  24. <view class="bot-title"><text>本次支付金额</text></view>
  25. <view class="bot-input">
  26. <text>¥</text>
  27. <!-- <view class="input" @click.stop="focusInput">
  28. <text class="text" v-if="payAmount>=0">{{payAmount}}</text>
  29. <text class="none" v-else>输入金额不能大于待付金额</text>
  30. </view> -->
  31. <input class="input"
  32. type="digit"
  33. v-model="payAmount"
  34. @focus="focusInput"
  35. @blur="blurInput"
  36. placeholder="输入金额不能大于待付金额"
  37. placeholder-class="placeholder"/>
  38. </view>
  39. <view class="bot-resid">
  40. <text>应付剩余¥{{balanceAmount|NumFormat}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="pay-record" :style="{paddingBottom:isIphoneX ? '156rpx' : '112rpx'}">
  45. <view class="record-title"><text>支付记录</text></view>
  46. <view class="record-list">
  47. <view class="list-main" v-if="discernReceipt.length>0">
  48. <view class="list-item" v-for="(item,index) in discernReceipt" :key="index">
  49. <text class="text row-1">¥{{item.receiptAmount | NumFormat}}</text>
  50. <text class="text row-2">{{payTypeText(item.payType)}}</text>
  51. <text class="text row-3">{{item.receiptDate}}</text>
  52. </view>
  53. </view>
  54. <view class="list-none" v-else>暂无支付记录</view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="pay-button" :style="{paddingBottom:isIphoneX ? '68rpx' : '24rpx'}">
  59. <view class="btn" @click.stop="buttonSubMit" :style="{'background':btnColor}">{{buttonText}}</view>
  60. </view>
  61. </view>
  62. <view class="alert spec" :class="specClass" v-if="isShowTip">
  63. <!-- 选择支付弹窗说明 -->
  64. <view class="freight-alert" @tap="hideTips">
  65. <view class="content">
  66. <view class="title">
  67. <text>支付链接</text>
  68. <text class="iconfont icon-iconfontguanbi" @click.stop="hideTips"></text>
  69. </view>
  70. <view class="text-content">
  71. <view class="text">请复制以下链接,并发送至电脑端,在浏览器访问该链接并选择银行尽快完成支付</view>
  72. <view class="text-p">{{payHttpUrl}}</view>
  73. <view class="text-b">链接有效期为24小时</view>
  74. </view>
  75. <view class="text-button" @click.stop="clipboard(payHttpUrl)">复制链接</view>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- 数字键盘 -->
  80. <!-- <keyboard v-if="showDigitKeyboard"
  81. @confirmEvent="confirmEvent"
  82. :money.sync="payAmount"
  83. btn-color='linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%)'
  84. title="完成">
  85. </keyboard> -->
  86. </view>
  87. </template>
  88. <script>
  89. import authorize from '@/common/config/authorize.js'
  90. // import keyboard from "@/components/keyboard/keyboard.vue"
  91. import thorui from "@/components/clipboard/clipboard.thorui.js"
  92. export default{
  93. components: {
  94. // keyboard
  95. },
  96. data(){
  97. return{
  98. orderID:'',
  99. payType:'',
  100. payWay:'',
  101. isRepuest:false,
  102. payableAmount:0,
  103. receiptAmount:0,
  104. balanceAmount:0,
  105. payTotalFee:0,
  106. payAmount:0,
  107. nvabarData: { //顶部自定义导航
  108. showCapsule:1, // 是否显示左上角图标 1表示显示 0表示不显示,
  109. showSearch: 0,
  110. title: '收银台', // 导航栏 中间的标题
  111. haveBack:true,
  112. textLeft:this.$store.state.isIphone
  113. },
  114. idCardList:[],
  115. isIphoneX:this.$store.state.isIphoneX,
  116. CustomBar:this.CustomBar,// 顶部导航栏高度
  117. tabCurrentIndex:0,
  118. isShowTip:false,
  119. buttonText:'去支付',
  120. btnColor:'#09BB07',
  121. discernReceipt:[],
  122. showDigitKeyboard:false,
  123. payHttpUrl:''
  124. }
  125. },
  126. onLoad(option) {
  127. this.initData(option)
  128. },
  129. filters: {
  130. NumFormat(value) {
  131. if(!value) return '0.00';
  132. /*原来用的是Number(value).toFixed(0),这样取整时有问题,例如0.51取整之后为1,感谢Nils指正*/
  133. /*后来改成了 Number(value)|0,但是输入超过十一位就为负数了,具体见评论 */
  134. var intPart = Number(value) - Number(value)%1; //获取整数部分(这里是windy93的方法)
  135. var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断
  136. var floatPart = ".00"; //预定义小数部分
  137. var value2Array = value.toString().split(".");
  138. //=2表示数据有小数位
  139. if(value2Array.length == 2) {
  140. floatPart = value2Array[1].toString(); //拿到小数部分
  141. if(floatPart.length == 1) { //补0,实际上用不着
  142. return intPartFormat + "." + floatPart + '0';
  143. } else {
  144. return intPartFormat + "." + floatPart;
  145. }
  146. } else {
  147. return intPartFormat + floatPart;
  148. }
  149. }
  150. },
  151. methods:{
  152. initData(e){
  153. this.payType = e.type
  154. console.log(this.payType)
  155. this.orderID = e.orderID
  156. switch(this.payType){
  157. case '0':
  158. this.payWay = 'WEIXIN'
  159. this.btnColor="#09BB07"
  160. this.buttonText = '去支付'
  161. break;
  162. case '1':
  163. this.payWay = 'UNIONPAY'
  164. this.btnColor="#034582"
  165. this.buttonText = '生成企业网银支付链接'
  166. break;
  167. case '2':
  168. this.payWay = 'UNIONPAY'
  169. this.btnColor="#034582"
  170. this.buttonText = '生成个人网银支付链接'
  171. break;
  172. }
  173. this.GetPayOrderInfo()
  174. },
  175. GetPayOrderInfo(){
  176. this.PayService.PayOrderCheckoutCounter({orderId:this.orderID}).then(response =>{
  177. this.isRepuest = true
  178. this.discernReceipt = response.data.discernReceipt //支付记录
  179. this.payTotalFee = response.data.order.payTotalFee //订单总额
  180. this.receiptAmount = response.data.order.receiptAmount //已付金额
  181. this.payableAmount = response.data.order.payableAmount - this.receiptAmount//已付金额
  182. this.payAmount = this.toFixedFn(this.payableAmount) //自定义金额
  183. this.balanceAmount = this.payableAmount - this.payAmount// 计算剩余支付金额
  184. }).catch(error =>{
  185. this.$util.msg(error.msg,2000)
  186. })
  187. },
  188. buttonSubMit(){
  189. switch(this.payType){
  190. case '0':
  191. this.MiniWxPayFor()
  192. break;
  193. case '1':
  194. this.BuildCatenate()
  195. break;
  196. case '2':
  197. this.BuildCatenate()
  198. break;
  199. }
  200. },
  201. BuildCatenate(){
  202. if(this.payAmount == 0){
  203. this.$util.msg("请输入本次支付的金额",2000)
  204. return
  205. }
  206. if(this.payAmount <=10){
  207. this.$util.msg("企业网银支付的金额必须大于¥10.00",2000)
  208. return
  209. }
  210. this.PayService.PayOrderPayLink({unpaidAmount:this.payAmount,orderId:this.orderID,payType:this.payType}).then(response =>{
  211. this.payHttpUrl = response.data
  212. this.isShowTip = true
  213. })
  214. },
  215. MiniWxPayFor(){
  216. authorize.getCode('weixin').then(wechatcode =>{
  217. if(this.payAmount > 5000){
  218. this.$util.modal('','本次支付金额已超出微信支付限额,请输入小于5千的金额进行支付','知道了','',false,() =>{})
  219. return
  220. }
  221. if(this.payAmount == 0){
  222. this.$util.msg("请输入本次支付的金额",2000)
  223. return
  224. }
  225. if(this.payAmount*100 < 2){
  226. this.$util.msg("本次支付的金额必须大于¥0.02",2000)
  227. return
  228. }
  229. let params ={
  230. payAmount:this.payAmount*100,
  231. payWay:"WEIXIN",
  232. code:wechatcode,
  233. orderId:this.orderID
  234. }
  235. this.PayService.WeChatMiniWxPay(params).then(response =>{
  236. let PayInfo = JSON.parse(response.data.data.payInfo);
  237. this.WxRequestPayment(PayInfo)
  238. }).catch(error =>{
  239. this.$util.msg(error.msg,2000)
  240. })
  241. })
  242. },
  243. WxRequestPayment(data){
  244. let self = this
  245. wx.requestPayment({
  246. 'timeStamp': data.timeStamp,
  247. 'nonceStr': data.nonceStr,
  248. 'package': data.package,
  249. 'signType': data.signType,
  250. 'paySign': data.paySign,
  251. 'success':function(res){
  252. wx.reLaunch({url: '/pages/tabBar/user/user'});
  253. },
  254. 'fail':function(res){
  255. self.$util.msg('用户取消支付~')
  256. },
  257. 'complete':function(res){
  258. }
  259. })
  260. },
  261. confirmEvent(value){//点击自定义键盘完成的回调函数
  262. this.chechValue(value)
  263. this.showDigitKeyboard = false
  264. },
  265. blurInput(e){
  266. this.chechValue(e.detail.value)
  267. },
  268. focusInput(){
  269. // this.showDigitKeyboard = true
  270. },
  271. hideKeyboard(){
  272. this.showDigitKeyboard = false
  273. },
  274. chechValue(value){
  275. let patern = /\d+\.\d+/g;
  276. if(value && value.split('.').length > 2) {
  277. value= patern.exec(value);
  278. }
  279. if(value == "" || value <0 ){
  280. this.payAmount = '';
  281. this.balanceAmount = this.payableAmount;
  282. }else if( value > this.payableAmount){
  283. this.payAmount = this.toFixedFn(this.payableAmount)
  284. this.balanceAmount = this.toFixedFn(this.payableAmount - this.payAmount)
  285. }else{
  286. this.payAmount = this.toFixedFn(value)
  287. this.balanceAmount = this.toFixedFn(this.payableAmount - this.payAmount)
  288. }
  289. },
  290. hanldNavigateBack(){//页面返回
  291. uni.navigateBack({
  292. delta: 1
  293. });
  294. },
  295. payTypeText (state){//处理支付记录文字
  296. let stateText = '',
  297. stateTextObject={
  298. 12:'企业网银',
  299. 13:'微信支付',
  300. 14:'支付宝',
  301. 15:'微信支付',
  302. 16:'余额抵扣',
  303. }
  304. Object.keys(stateTextObject).forEach(key => {
  305. if(key == state){
  306. stateText = stateTextObject[key]
  307. }
  308. })
  309. return stateText;
  310. },
  311. hideTips(){//隐藏弹窗
  312. this.isShowTip = false
  313. },
  314. toFixedFn(text){//处理小数点后两位数
  315. return Number(text).toFixed(2);
  316. },
  317. clipboard(data) {//复制链接
  318. thorui.getClipboardData(data, (res) => {
  319. if (res) {
  320. this.isShowTip = false;
  321. this.$util.msg("复制成功",2000,true,'success');
  322. setTimeout(()=>{
  323. this.$api.navigateTo(`/pages/user/order/order-details?state=0&orderID=${this.orderID}`)
  324. },2000)
  325. } else {
  326. this.$util.msg("复制失败",2000,true,'none');
  327. }
  328. })
  329. },
  330. discard(){
  331. //丢弃
  332. }
  333. },
  334. onShow() {
  335. }
  336. }
  337. </script>
  338. <style lang="scss">
  339. page{height: auto !important;background-color: #FFFFFF;}
  340. .container-cash{
  341. width: 100%;
  342. .container-wrapper{
  343. width:100%;
  344. margin: 0 auto;
  345. .pay-content{
  346. width: 662rpx;
  347. height: 420rpx;
  348. padding: 64rpx 44rpx 0 44rpx;
  349. background: url(https://img.caimei365.com/group1/M00/03/BD/Cmis218elN6AY6VeAAqw4n3n4nw186.png) no-repeat;
  350. background-size: cover;
  351. float: left;
  352. position: relative;
  353. .pay-top{
  354. width: 100%;
  355. height: auto;
  356. float: left;
  357. margin-bottom: 44rpx;
  358. .pay-paid{
  359. width: 100%;
  360. height: auto;
  361. margin-bottom: 38rpx;
  362. text{
  363. line-height: 48rpx;
  364. text-align: left;
  365. color: #FFFFFF;
  366. width: 100%;
  367. }
  368. .txt-m{
  369. font-size: $font-size-26;
  370. opacity: 0.7;
  371. display: inline-block;
  372. }
  373. .txt-b{
  374. font-size: $font-size-48;
  375. display: inline-block;
  376. .small{
  377. font-size: $font-size-32;
  378. }
  379. }
  380. }
  381. .pay-payd{
  382. width: 100%;
  383. height: auto;
  384. .pay-paids{
  385. height: auto;
  386. float: left;
  387. margin-right: 48rpx;
  388. text{
  389. line-height: 48rpx;
  390. text-align: left;
  391. color: #FFFFFF;
  392. }
  393. .txt-m{
  394. width: 100%;
  395. display: inline-block;
  396. font-size: $font-size-26;
  397. opacity: 0.7;
  398. }
  399. .txt-b{
  400. width: 100%;
  401. display: inline-block;
  402. font-size: $font-size-32;
  403. }
  404. }
  405. }
  406. }
  407. .pay-bot{
  408. width: 614rpx;
  409. height: 184rpx;
  410. padding: 24rpx;
  411. background: #FFFFFF;
  412. border-radius: 20rpx;
  413. box-shadow:0 2px 6px rgba(255, 77, 0, .17);
  414. position: absolute;
  415. bottom: -92rpx;
  416. left:44rpx;
  417. .bot-title{
  418. line-height: 36rpx;
  419. font-size: $font-size-26;
  420. color: #666666;
  421. }
  422. .bot-input{
  423. width: 100%;
  424. height: 66rpx;
  425. margin: 15rpx 0;
  426. border-bottom: 1px solid #EBEBEB;
  427. line-height: 66rpx;
  428. font-size: $font-size-32;
  429. color: $text-color;
  430. text{
  431. display: block;
  432. float: left;
  433. }
  434. .input{
  435. font-size: $font-size-40;
  436. width: 500rpx;
  437. height: 66rpx;
  438. padding: 0 10rpx;
  439. line-height: 66rpx;
  440. float: left;
  441. .none{
  442. color:$text-color;
  443. opacity: 0.3;
  444. }
  445. .text{
  446. color:$text-color;
  447. }
  448. }
  449. .placeholder{
  450. font-size: $font-size-26;
  451. }
  452. }
  453. .bot-resid{
  454. line-height: 36rpx;
  455. font-size: $font-size-26;
  456. color: #666666;
  457. margin-top: 24rpx;
  458. color: $color-system;
  459. }
  460. }
  461. }
  462. .pay-record{
  463. float: left;
  464. background: #FFFFFF;
  465. width: 702rpx;
  466. height: auto;
  467. padding: 0 24rpx;
  468. margin-top: 112rpx;
  469. .record-title{
  470. width: 100%;
  471. float: left;
  472. font-size: $font-size-28;
  473. color: $text-color;
  474. line-height: 80rpx;
  475. height: 80rpx;
  476. border-bottom: 1px solid #F8F8F8;
  477. }
  478. .record-list{
  479. width: 100%;
  480. height: auto;
  481. float: left;
  482. .list-none{
  483. line-height: 80rpx;
  484. font-size: $font-size-26;
  485. color: #999999;
  486. text-align: left;
  487. }
  488. .list-main{
  489. height: auto;
  490. display: flex;
  491. flex-direction:column;
  492. .list-item{
  493. width: 100%;
  494. height:80rpx;
  495. display: flex;
  496. flex: 1;
  497. line-height: 80rpx;
  498. font-size: $font-size-26;
  499. color: $text-color;
  500. .text{
  501. &.row-1{
  502. flex: 3;
  503. }
  504. &.row-2{
  505. flex: 3;
  506. }
  507. &.row-3{
  508. flex: 4;
  509. text-align: right;
  510. color: #999999;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. }
  518. .pay-button{
  519. width: 100%;
  520. background-color: #FFFFFF;
  521. position: fixed;
  522. height: 88rpx;
  523. padding-top: 24rpx;
  524. bottom: 0;
  525. .btn{
  526. width: 702rpx;
  527. height: 88rpx;
  528. border-radius: 44rpx;
  529. font-size: $font-size-28;
  530. line-height: 88rpx;
  531. color: #FFFFFF;
  532. margin: 0 auto;
  533. text-align: center;
  534. background: $btn-confirm;
  535. }
  536. }
  537. }
  538. .freight-alert{
  539. width: 100%;
  540. height: 100%;
  541. background: rgba(0,0,0,.5);
  542. position: fixed;
  543. top: 0;
  544. left: 0;
  545. z-index: 8888;
  546. transition: all 0.4s;
  547. &.none{
  548. display: none;
  549. }
  550. &.show{
  551. display: block;
  552. }
  553. .content{
  554. width: 422rpx;
  555. height:434rpx;
  556. position: absolute;
  557. background: $bg-color;
  558. left: 0;
  559. right: 0;
  560. bottom: 0;
  561. top: 0;
  562. margin: auto;
  563. padding: 20rpx 32rpx;
  564. border-radius: 12rpx;
  565. .title{
  566. width: 100%;
  567. height: 68rpx;
  568. line-height: 68rpx;
  569. font-size: $font-size-28;
  570. color: $text-color;
  571. text-align: center;
  572. position: relative;
  573. .icon-iconfontguanbi{
  574. width: 68rpx;
  575. height: 68rpx;
  576. text-align: center;
  577. line-height: 68rpx;
  578. position: absolute;
  579. right: 0;
  580. top: 0;
  581. font-size: $font-size-36;
  582. color: #999999;
  583. }
  584. }
  585. .text-content{
  586. width: 100%;
  587. height: auto;
  588. .text{
  589. padding: 20rpx 0 0 0;
  590. line-height: 44rpx;
  591. font-size: $font-size-26;
  592. color:#666666;
  593. text-align: justify;
  594. }
  595. .text-p{
  596. width: 100%;
  597. line-height: 44rpx;
  598. font-size: $font-size-26;
  599. color:$color-system;
  600. text-align: left;
  601. text-overflow:ellipsis;
  602. display: -webkit-box;
  603. word-break: break-all;
  604. -webkit-box-orient: vertical;
  605. -webkit-line-clamp: 1;
  606. overflow: hidden;
  607. }
  608. .text-b{
  609. line-height: 44rpx;
  610. font-size: $font-size-24;
  611. color:#999999;
  612. text-align: left;
  613. }
  614. }
  615. .text-button{
  616. width: 100%;
  617. height: 88rpx;
  618. line-height: 88rpx;
  619. background: $btn-confirm;
  620. font-size: $font-size-28;
  621. border-radius: 44rpx;
  622. color:#FFFFFF;
  623. text-align: center;
  624. margin-top: 20rpx;
  625. }
  626. }
  627. }
  628. </style>