order-pay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. }
  168. this.GetPayOrderInfo()
  169. },
  170. GetPayOrderInfo(){
  171. this.PayService.PayOrderCheckoutCounter({orderId:this.orderID}).then(response =>{
  172. this.isRepuest = true
  173. this.discernReceipt = response.data.discernReceipt //支付记录
  174. this.payTotalFee = response.data.order.payTotalFee //订单总额
  175. this.receiptAmount = response.data.order.receiptAmount //已付金额
  176. this.payableAmount = response.data.order.payableAmount - this.receiptAmount//已付金额
  177. this.payAmount = this.toFixedFn(this.payableAmount) //自定义金额
  178. this.balanceAmount = this.payableAmount - this.payAmount// 计算剩余支付金额
  179. }).catch(error =>{
  180. this.$util.msg(error.msg,2000)
  181. })
  182. },
  183. buttonSubMit(){
  184. switch(this.payType){
  185. case '0':
  186. this.MiniWxPayFor()
  187. break;
  188. case '1':
  189. this.BuildCatenate()
  190. break;
  191. }
  192. },
  193. BuildCatenate(){
  194. if(this.payAmount == 0){
  195. this.$util.msg("请输入本次支付的金额",2000)
  196. return
  197. }
  198. if(this.payAmount <=10){
  199. this.$util.msg("企业网银支付的金额必须大于¥10.00",2000)
  200. return
  201. }
  202. this.PayService.PayOrderPayLink({unpaidAmount:this.payAmount,orderId:this.orderID}).then(response =>{
  203. this.payHttpUrl = response.data
  204. this.isShowTip = true
  205. })
  206. },
  207. MiniWxPayFor(){
  208. authorize.getCode('weixin').then(wechatcode =>{
  209. if(this.payAmount > 10000){
  210. this.$util.modal('','本次支付金额已超出微信支付限额,请输入小于1万的金额进行支付','知道了','',false,() =>{})
  211. return
  212. }
  213. if(this.payAmount == 0){
  214. this.$util.msg("请输入本次支付的金额",2000)
  215. return
  216. }
  217. if(this.payAmount*100 < 2){
  218. this.$util.msg("本次支付的金额必须大于¥0.02",2000)
  219. return
  220. }
  221. let params ={
  222. payAmount:this.payAmount*100,
  223. payWay:"WEIXIN",
  224. code:wechatcode,
  225. orderId:this.orderID
  226. }
  227. this.PayService.WeChatMiniWxPay(params).then(response =>{
  228. let PayInfo = JSON.parse(response.data.data.payInfo);
  229. this.WxRequestPayment(PayInfo)
  230. }).catch(error =>{
  231. this.$util.msg(error.msg,2000)
  232. })
  233. })
  234. },
  235. WxRequestPayment(data){
  236. let self = this
  237. wx.requestPayment({
  238. 'timeStamp': data.timeStamp,
  239. 'nonceStr': data.nonceStr,
  240. 'package': data.package,
  241. 'signType': data.signType,
  242. 'paySign': data.paySign,
  243. 'success':function(res){
  244. wx.reLaunch({url: '/pages/tabBar/user/user'});
  245. },
  246. 'fail':function(res){
  247. self.$util.msg('用户取消支付~')
  248. },
  249. 'complete':function(res){
  250. }
  251. })
  252. },
  253. confirmEvent(value){//点击自定义键盘完成的回调函数
  254. this.chechValue(value)
  255. this.showDigitKeyboard = false
  256. },
  257. blurInput(e){
  258. this.chechValue(e.detail.value)
  259. },
  260. focusInput(){
  261. // this.showDigitKeyboard = true
  262. },
  263. hideKeyboard(){
  264. this.showDigitKeyboard = false
  265. },
  266. chechValue(value){
  267. let patern = /\d+\.\d+/g;
  268. if(value && value.split('.').length > 2) {
  269. value= patern.exec(value);
  270. }
  271. if(value == "" || value <0 ){
  272. this.payAmount = '';
  273. this.balanceAmount = this.payableAmount;
  274. }else if( value > this.payableAmount){
  275. this.payAmount = this.toFixedFn(this.payableAmount)
  276. this.balanceAmount = this.toFixedFn(this.payableAmount - this.payAmount)
  277. }else{
  278. this.payAmount = this.toFixedFn(value)
  279. this.balanceAmount = this.toFixedFn(this.payableAmount - this.payAmount)
  280. }
  281. },
  282. hanldNavigateBack(){//页面返回
  283. uni.navigateBack({
  284. delta: 1
  285. });
  286. },
  287. payTypeText (state){//处理支付记录文字
  288. let stateText = '',
  289. stateTextObject={
  290. 12:'企业网银',
  291. 13:'微信支付',
  292. 14:'支付宝',
  293. 15:'微信支付',
  294. 16:'余额抵扣',
  295. }
  296. Object.keys(stateTextObject).forEach(key => {
  297. if(key == state){
  298. stateText = stateTextObject[key]
  299. }
  300. })
  301. return stateText;
  302. },
  303. hideTips(){//隐藏弹窗
  304. this.isShowTip = false
  305. },
  306. toFixedFn(text){//处理小数点后两位数
  307. return Number(text).toFixed(2);
  308. },
  309. clipboard(data) {//复制链接
  310. thorui.getClipboardData(data, (res) => {
  311. if (res) {
  312. this.isShowTip = false;
  313. this.$util.msg("复制成功",2000,true,'success');
  314. setTimeout(()=>{
  315. this.$api.navigateTo(`/pages/user/order/order-details?state=0&orderID=${this.orderID}`)
  316. },2000)
  317. } else {
  318. this.$util.msg("复制失败",2000,true,'none');
  319. }
  320. })
  321. },
  322. discard(){
  323. //丢弃
  324. }
  325. },
  326. onShow() {
  327. }
  328. }
  329. </script>
  330. <style lang="scss">
  331. page{height: auto !important;background-color: #FFFFFF;}
  332. .container-cash{
  333. width: 100%;
  334. .container-wrapper{
  335. width:100%;
  336. margin: 0 auto;
  337. .pay-content{
  338. width: 662rpx;
  339. height: 420rpx;
  340. padding: 64rpx 44rpx 0 44rpx;
  341. background: url(https://img.caimei365.com/group1/M00/03/BD/Cmis218elN6AY6VeAAqw4n3n4nw186.png) no-repeat;
  342. background-size: cover;
  343. float: left;
  344. position: relative;
  345. .pay-top{
  346. width: 100%;
  347. height: auto;
  348. float: left;
  349. margin-bottom: 44rpx;
  350. .pay-paid{
  351. width: 100%;
  352. height: auto;
  353. margin-bottom: 38rpx;
  354. text{
  355. line-height: 48rpx;
  356. text-align: left;
  357. color: #FFFFFF;
  358. width: 100%;
  359. }
  360. .txt-m{
  361. font-size: $font-size-26;
  362. opacity: 0.7;
  363. display: inline-block;
  364. }
  365. .txt-b{
  366. font-size: $font-size-48;
  367. display: inline-block;
  368. .small{
  369. font-size: $font-size-32;
  370. }
  371. }
  372. }
  373. .pay-payd{
  374. width: 100%;
  375. height: auto;
  376. .pay-paids{
  377. height: auto;
  378. float: left;
  379. margin-right: 48rpx;
  380. text{
  381. line-height: 48rpx;
  382. text-align: left;
  383. color: #FFFFFF;
  384. }
  385. .txt-m{
  386. width: 100%;
  387. display: inline-block;
  388. font-size: $font-size-26;
  389. opacity: 0.7;
  390. }
  391. .txt-b{
  392. width: 100%;
  393. display: inline-block;
  394. font-size: $font-size-32;
  395. }
  396. }
  397. }
  398. }
  399. .pay-bot{
  400. width: 614rpx;
  401. height: 184rpx;
  402. padding: 24rpx;
  403. background: #FFFFFF;
  404. border-radius: 20rpx;
  405. box-shadow:0 2px 6px rgba(255, 77, 0, .17);
  406. position: absolute;
  407. bottom: -92rpx;
  408. left:44rpx;
  409. .bot-title{
  410. line-height: 36rpx;
  411. font-size: $font-size-26;
  412. color: #666666;
  413. }
  414. .bot-input{
  415. width: 100%;
  416. height: 66rpx;
  417. margin: 15rpx 0;
  418. border-bottom: 1px solid #EBEBEB;
  419. line-height: 66rpx;
  420. font-size: $font-size-32;
  421. color: $text-color;
  422. text{
  423. display: block;
  424. float: left;
  425. }
  426. .input{
  427. font-size: $font-size-40;
  428. width: 500rpx;
  429. height: 66rpx;
  430. padding: 0 10rpx;
  431. line-height: 66rpx;
  432. float: left;
  433. .none{
  434. color:$text-color;
  435. opacity: 0.3;
  436. }
  437. .text{
  438. color:$text-color;
  439. }
  440. }
  441. .placeholder{
  442. font-size: $font-size-26;
  443. }
  444. }
  445. .bot-resid{
  446. line-height: 36rpx;
  447. font-size: $font-size-26;
  448. color: #666666;
  449. margin-top: 24rpx;
  450. color: $color-system;
  451. }
  452. }
  453. }
  454. .pay-record{
  455. float: left;
  456. background: #FFFFFF;
  457. width: 702rpx;
  458. height: auto;
  459. padding: 0 24rpx;
  460. margin-top: 112rpx;
  461. .record-title{
  462. width: 100%;
  463. float: left;
  464. font-size: $font-size-28;
  465. color: $text-color;
  466. line-height: 80rpx;
  467. height: 80rpx;
  468. border-bottom: 1px solid #F8F8F8;
  469. }
  470. .record-list{
  471. width: 100%;
  472. height: auto;
  473. float: left;
  474. .list-none{
  475. line-height: 80rpx;
  476. font-size: $font-size-26;
  477. color: #999999;
  478. text-align: left;
  479. }
  480. .list-main{
  481. height: auto;
  482. display: flex;
  483. flex-direction:column;
  484. .list-item{
  485. width: 100%;
  486. height:80rpx;
  487. display: flex;
  488. flex: 1;
  489. line-height: 80rpx;
  490. font-size: $font-size-26;
  491. color: $text-color;
  492. .text{
  493. &.row-1{
  494. flex: 3;
  495. }
  496. &.row-2{
  497. flex: 3;
  498. }
  499. &.row-3{
  500. flex: 4;
  501. text-align: right;
  502. color: #999999;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }
  509. }
  510. .pay-button{
  511. width: 100%;
  512. background-color: #FFFFFF;
  513. position: fixed;
  514. height: 88rpx;
  515. padding-top: 24rpx;
  516. bottom: 0;
  517. .btn{
  518. width: 702rpx;
  519. height: 88rpx;
  520. border-radius: 44rpx;
  521. font-size: $font-size-28;
  522. line-height: 88rpx;
  523. color: #FFFFFF;
  524. margin: 0 auto;
  525. text-align: center;
  526. background: $btn-confirm;
  527. }
  528. }
  529. }
  530. .freight-alert{
  531. width: 100%;
  532. height: 100%;
  533. background: rgba(0,0,0,.5);
  534. position: fixed;
  535. top: 0;
  536. left: 0;
  537. z-index: 8888;
  538. transition: all 0.4s;
  539. &.none{
  540. display: none;
  541. }
  542. &.show{
  543. display: block;
  544. }
  545. .content{
  546. width: 422rpx;
  547. height:434rpx;
  548. position: absolute;
  549. background: $bg-color;
  550. left: 0;
  551. right: 0;
  552. bottom: 0;
  553. top: 0;
  554. margin: auto;
  555. padding: 20rpx 32rpx;
  556. border-radius: 12rpx;
  557. .title{
  558. width: 100%;
  559. height: 68rpx;
  560. line-height: 68rpx;
  561. font-size: $font-size-28;
  562. color: $text-color;
  563. text-align: center;
  564. position: relative;
  565. .icon-iconfontguanbi{
  566. width: 68rpx;
  567. height: 68rpx;
  568. text-align: center;
  569. line-height: 68rpx;
  570. position: absolute;
  571. right: 0;
  572. top: 0;
  573. font-size: $font-size-36;
  574. color: #999999;
  575. }
  576. }
  577. .text-content{
  578. width: 100%;
  579. height: auto;
  580. .text{
  581. padding: 20rpx 0 0 0;
  582. line-height: 44rpx;
  583. font-size: $font-size-26;
  584. color:#666666;
  585. text-align: justify;
  586. }
  587. .text-p{
  588. width: 100%;
  589. line-height: 44rpx;
  590. font-size: $font-size-26;
  591. color:$color-system;
  592. text-align: left;
  593. text-overflow:ellipsis;
  594. display: -webkit-box;
  595. word-break: break-all;
  596. -webkit-box-orient: vertical;
  597. -webkit-line-clamp: 1;
  598. overflow: hidden;
  599. }
  600. .text-b{
  601. line-height: 44rpx;
  602. font-size: $font-size-24;
  603. color:#999999;
  604. text-align: left;
  605. }
  606. }
  607. .text-button{
  608. width: 100%;
  609. height: 88rpx;
  610. line-height: 88rpx;
  611. background: $btn-confirm;
  612. font-size: $font-size-28;
  613. border-radius: 14rpx;
  614. color:#FFFFFF;
  615. text-align: center;
  616. margin-top: 20rpx;
  617. }
  618. }
  619. }
  620. </style>