order-pay.vue 17 KB

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