order-pay.vue 17 KB

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