order-pay.vue 18 KB

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