order-pay.vue 17 KB

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