order-pay.vue 17 KB

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