order-pay.vue 17 KB

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