order-pay.vue 17 KB

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