order-pay.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. setTimeout(()=>{
  349. this.$api.navigateTo(`/pages/user/order/order-details?state=0&orderId=${this.orderId}`)
  350. },2000)
  351. } else {
  352. this.$util.msg('复制失败',2000,true,'none')
  353. }
  354. })
  355. },
  356. discard(){
  357. //丢弃
  358. }
  359. },
  360. onShow() {
  361. }
  362. }
  363. </script>
  364. <style lang="scss">
  365. page{height: auto !important;background-color: #FFFFFF;}
  366. .container-cash{
  367. width: 100%;
  368. .container-wrapper{
  369. width:100%;
  370. margin: 0 auto;
  371. .pay-content{
  372. width: 662rpx;
  373. height: 420rpx;
  374. padding: 64rpx 44rpx 0 44rpx;
  375. background: url(https://img.caimei365.com/group1/M00/03/BD/Cmis218elN6AY6VeAAqw4n3n4nw186.png) no-repeat;
  376. background-size: cover;
  377. float: left;
  378. position: relative;
  379. .pay-top{
  380. width: 100%;
  381. height: auto;
  382. float: left;
  383. margin-bottom: 44rpx;
  384. .pay-paid{
  385. width: 100%;
  386. height: auto;
  387. margin-bottom: 38rpx;
  388. text{
  389. line-height: 48rpx;
  390. text-align: left;
  391. color: #FFFFFF;
  392. width: 100%;
  393. }
  394. .txt-m{
  395. font-size: $font-size-26;
  396. opacity: 0.7;
  397. display: inline-block;
  398. }
  399. .txt-b{
  400. font-size: $font-size-48;
  401. display: inline-block;
  402. .small{
  403. font-size: $font-size-32;
  404. }
  405. }
  406. }
  407. .pay-payd{
  408. width: 100%;
  409. height: auto;
  410. .pay-paids{
  411. height: auto;
  412. float: left;
  413. margin-right: 48rpx;
  414. text{
  415. line-height: 48rpx;
  416. text-align: left;
  417. color: #FFFFFF;
  418. }
  419. .txt-m{
  420. width: 100%;
  421. display: inline-block;
  422. font-size: $font-size-26;
  423. opacity: 0.7;
  424. }
  425. .txt-b{
  426. width: 100%;
  427. display: inline-block;
  428. font-size: $font-size-32;
  429. }
  430. }
  431. }
  432. }
  433. .pay-bot{
  434. width: 614rpx;
  435. height: 184rpx;
  436. padding: 24rpx;
  437. background: #FFFFFF;
  438. border-radius: 20rpx;
  439. box-shadow:0 2px 6px rgba(255, 77, 0, .17);
  440. position: absolute;
  441. bottom: -92rpx;
  442. left:44rpx;
  443. .bot-title{
  444. line-height: 36rpx;
  445. font-size: $font-size-26;
  446. color: #666666;
  447. }
  448. .bot-input{
  449. width: 100%;
  450. height: 66rpx;
  451. margin: 15rpx 0;
  452. border-bottom: 1px solid #EBEBEB;
  453. line-height: 66rpx;
  454. font-size: $font-size-32;
  455. color: $text-color;
  456. text{
  457. display: block;
  458. float: left;
  459. }
  460. .input{
  461. font-size: $font-size-40;
  462. width: 500rpx;
  463. height: 66rpx;
  464. padding: 0 10rpx;
  465. line-height: 66rpx;
  466. float: left;
  467. .none{
  468. color:$text-color;
  469. opacity: 0.3;
  470. }
  471. .text{
  472. color:$text-color;
  473. }
  474. }
  475. .placeholder{
  476. font-size: $font-size-26;
  477. }
  478. }
  479. .bot-resid{
  480. line-height: 36rpx;
  481. font-size: $font-size-26;
  482. color: #666666;
  483. margin-top: 24rpx;
  484. color: $color-system;
  485. }
  486. }
  487. }
  488. .pay-record{
  489. float: left;
  490. background: #FFFFFF;
  491. width: 702rpx;
  492. height: auto;
  493. padding: 0 24rpx;
  494. margin-top: 112rpx;
  495. .record-title{
  496. width: 100%;
  497. float: left;
  498. font-size: $font-size-28;
  499. color: $text-color;
  500. line-height: 80rpx;
  501. height: 80rpx;
  502. border-bottom: 1px solid #F8F8F8;
  503. }
  504. .record-list{
  505. width: 100%;
  506. height: auto;
  507. float: left;
  508. .list-none{
  509. line-height: 80rpx;
  510. font-size: $font-size-26;
  511. color: #999999;
  512. text-align: left;
  513. }
  514. .list-main{
  515. height: auto;
  516. display: flex;
  517. flex-direction:column;
  518. .list-item{
  519. width: 100%;
  520. height:80rpx;
  521. display: flex;
  522. flex: 1;
  523. line-height: 80rpx;
  524. font-size: $font-size-26;
  525. color: $text-color;
  526. .text{
  527. &.row-1{
  528. flex: 3;
  529. }
  530. &.row-2{
  531. flex: 3;
  532. }
  533. &.row-3{
  534. flex: 4;
  535. text-align: right;
  536. color: #999999;
  537. }
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. .pay-button{
  545. width: 100%;
  546. background-color: #FFFFFF;
  547. position: fixed;
  548. height: 88rpx;
  549. padding-top: 24rpx;
  550. bottom: 0;
  551. .btn{
  552. width: 702rpx;
  553. height: 88rpx;
  554. border-radius: 44rpx;
  555. font-size: $font-size-28;
  556. line-height: 88rpx;
  557. color: #FFFFFF;
  558. margin: 0 auto;
  559. text-align: center;
  560. background: $btn-confirm;
  561. }
  562. }
  563. }
  564. .freight-alert{
  565. width: 100%;
  566. height: 100%;
  567. background: rgba(0,0,0,.5);
  568. position: fixed;
  569. top: 0;
  570. left: 0;
  571. z-index: 8888;
  572. transition: all 0.4s;
  573. &.none{
  574. display: none;
  575. }
  576. &.show{
  577. display: block;
  578. }
  579. .content{
  580. width: 422rpx;
  581. height:434rpx;
  582. position: absolute;
  583. background: $bg-color;
  584. left: 0;
  585. right: 0;
  586. bottom: 0;
  587. top: 0;
  588. margin: auto;
  589. padding: 20rpx 32rpx;
  590. border-radius: 12rpx;
  591. .title{
  592. width: 100%;
  593. height: 68rpx;
  594. line-height: 68rpx;
  595. font-size: $font-size-28;
  596. color: $text-color;
  597. text-align: center;
  598. position: relative;
  599. .icon-iconfontguanbi{
  600. width: 68rpx;
  601. height: 68rpx;
  602. text-align: center;
  603. line-height: 68rpx;
  604. position: absolute;
  605. right: 0;
  606. top: 0;
  607. font-size: $font-size-36;
  608. color: #999999;
  609. }
  610. }
  611. .text-content{
  612. width: 100%;
  613. height: auto;
  614. .text{
  615. padding: 20rpx 0 0 0;
  616. line-height: 44rpx;
  617. font-size: $font-size-26;
  618. color:#666666;
  619. text-align: justify;
  620. }
  621. .text-p{
  622. width: 100%;
  623. line-height: 44rpx;
  624. font-size: $font-size-26;
  625. color:$color-system;
  626. text-align: left;
  627. text-overflow:ellipsis;
  628. display: -webkit-box;
  629. word-break: break-all;
  630. -webkit-box-orient: vertical;
  631. -webkit-line-clamp: 1;
  632. overflow: hidden;
  633. }
  634. .text-b{
  635. line-height: 44rpx;
  636. font-size: $font-size-24;
  637. color:#999999;
  638. text-align: left;
  639. }
  640. }
  641. .text-button{
  642. width: 100%;
  643. height: 88rpx;
  644. line-height: 88rpx;
  645. background: $btn-confirm;
  646. font-size: $font-size-28;
  647. border-radius: 44rpx;
  648. color:#FFFFFF;
  649. text-align: center;
  650. margin-top: 20rpx;
  651. }
  652. }
  653. }
  654. </style>