order-pay.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <view class="container cashier" @touchmove.stop.prevent="discard" @tap="hideKeyboard">
  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">¥{{payableAmount.toFixed(2)}}</text>
  11. </view>
  12. <view class="pay-paid">
  13. <text class="txt-m">已支付金额</text>
  14. <text class="txt-b">¥{{receiptAmount.toFixed(2)}}</text>
  15. </view>
  16. </view>
  17. <view class="pay-bot">
  18. <view class="bot-title"><text>本次支付金额</text></view>
  19. <view class="bot-input">
  20. <text>¥</text>
  21. <!-- <view class="input" @click.stop="focusInput">
  22. <text class="text" v-if="payAmount>=0">{{payAmount}}</text>
  23. <text class="none" v-else>输入金额不能大于待付金额</text>
  24. </view> -->
  25. <input class="input"
  26. type="digit"
  27. v-model="payAmount"
  28. @focus="focusInput"
  29. @blur="blurInput"
  30. placeholder="输入金额不能大于待付金额"
  31. placeholder-class="placeholder"/>
  32. </view>
  33. <view class="bot-resid">
  34. <text>订单剩余¥{{balanceAmount.toFixed(2)}}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="pay-record">
  39. <view class="record-title"><text>支付记录</text></view>
  40. <view class="record-list">
  41. <view class="list-main" v-if="discernReceipt.length>0">
  42. <view class="list-item" v-for="(item,index) in discernReceipt" :key="index">
  43. <text class="text row-1">¥{{item.receiptAmount}}</text>
  44. <text class="text row-2">{{payTypeText(item.payType)}}</text>
  45. <text class="text row-3">{{item.receiptDate}}</text>
  46. </view>
  47. </view>
  48. <view class="list-none" v-else>暂无支付记录</view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="pay-button">
  53. <view class="btn" @click.stop="buttonSubMit" :style="{'background':btnColor}">{{buttonText}}</view>
  54. </view>
  55. </view>
  56. <view class="alert spec" :class="specClass" v-if="isShowTip">
  57. <!-- 选择支付弹窗说明 -->
  58. <view class="freight-alert" @tap="hideTips">
  59. <view class="content">
  60. <view class="title">
  61. <text>生成链接</text>
  62. <text class="iconfont icon-iconfontguanbi" @click.stop="hideTips"></text>
  63. </view>
  64. <view class="text-content">
  65. <view class="text">请复制以下链接,并发送至电脑端,在浏览器访问该链接并选择银行尽快完成支付</view>
  66. <view class="text-p">{{payHttpUrl}}</view>
  67. <view class="text-b">链接有效期为24小时</view>
  68. </view>
  69. <view class="text-button" @click.stop="clipboard(payHttpUrl)">复制链接</view>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 数字键盘 -->
  74. <!-- <keyboard v-if="showDigitKeyboard"
  75. @confirmEvent="confirmEvent"
  76. :money.sync="payAmount"
  77. btn-color='linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%)'
  78. title="完成">
  79. </keyboard> -->
  80. </view>
  81. </template>
  82. <script>
  83. import authorize from '@/common/config/authorize.js'
  84. // import keyboard from "@/components/keyboard/keyboard.vue"
  85. import thorui from "@/components/clipboard/clipboard.thorui.js"
  86. import { PayOrderCheckoutCounter,WeChatMiniWxPay,PayOrderPayLink } from "@/api/order.js"
  87. export default{
  88. components: {
  89. // keyboard
  90. },
  91. data(){
  92. return{
  93. orderID:'',
  94. payType:'',
  95. payableAmount:0,
  96. receiptAmount:0,
  97. balanceAmount:0,
  98. payAmount:0,
  99. nvabarData: { //顶部自定义导航
  100. showCapsule:1, // 是否显示左上角图标 1表示显示 0表示不显示,
  101. showSearch: 0,
  102. title: '收银台', // 导航栏 中间的标题
  103. haveBack:true,
  104. textLeft:this.$store.state.isIphoneX
  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. methods:{
  122. initData(e){
  123. this.payType = e.type
  124. console.log(this.payType)
  125. this.orderID = e.orderID
  126. switch(this.payType){
  127. case '0':
  128. this.btnColor="#09BB07"
  129. this.buttonText = '去支付'
  130. break;
  131. case '1':
  132. this.btnColor="#034582"
  133. this.buttonText = '生成支付链接'
  134. break;
  135. }
  136. this.GetPayOrderInfo()
  137. },
  138. GetPayOrderInfo(){
  139. PayOrderCheckoutCounter({orderId:this.orderID}).then(response =>{
  140. console.log(response)
  141. this.discernReceipt = response.data.discernReceipt //支付记录
  142. this.receiptAmount = response.data.order.receiptAmount //已付金额
  143. this.payableAmount = response.data.order.payableAmount - this.receiptAmount //待付金额
  144. this.payAmount = this.payableAmount.toFixed(2) //自定义金额
  145. this.balanceAmount = this.payableAmount - this.payAmount// 计算剩余支付金额
  146. }).catch(error =>{
  147. this.$util.msg(error.msg,2000)
  148. })
  149. },
  150. buttonSubMit(){
  151. switch(this.payType){
  152. case '0':
  153. this.MiniWxPayFor()
  154. break;
  155. case '1':
  156. this.isShowTip = true
  157. this.BuildCatenate()
  158. break;
  159. }
  160. },
  161. BuildCatenate(){
  162. PayOrderPayLink({unpaidAmount:this.payAmount,orderId:this.orderID}).then(response =>{
  163. this.payHttpUrl = response.data
  164. })
  165. },
  166. MiniWxPayFor(){
  167. let self = this
  168. authorize.getCode('weixin').then(wechatcode =>{
  169. if(this.payAmount == 0){
  170. this.$util.msg("请输入本次支付的金额",2000)
  171. return
  172. }
  173. let params ={
  174. payAmount:this.payAmount*100,
  175. payWay:"WEIXIN",
  176. payType:"MINIAPP_WEIXIN",
  177. code:wechatcode,
  178. orderId:this.orderID
  179. }
  180. WeChatMiniWxPay(params).then(response =>{
  181. let PayInfo = JSON.parse(response.data.data.payInfo);
  182. uni.setStorageSync('payInfo',PayInfo)
  183. console.log(PayInfo)
  184. wx.requestPayment({
  185. 'timeStamp': PayInfo.timeStamp,
  186. 'nonceStr': PayInfo.nonceStr,
  187. 'package': PayInfo.package,
  188. 'signType': PayInfo.signType,
  189. 'paySign': PayInfo.paySign,
  190. 'success':function(res){
  191. console.log('支付成功');
  192. wx.reLaunch({url: '/pages/tabBar/user/user'});
  193. },
  194. 'fail':function(res){
  195. self.$util.msg('订单支付已取消')
  196. },
  197. 'complete':function(res){
  198. }
  199. })
  200. }).catch(error =>{
  201. this.$util.msg(error.msg,2000)
  202. })
  203. })
  204. },
  205. confirmEvent(value){//点击自定义键盘完成的回调函数
  206. console.log(value)
  207. this.chechValue(value)
  208. this.showDigitKeyboard = false
  209. },
  210. blurInput(e){
  211. this.chechValue(e.detail.value)
  212. },
  213. focusInput(){
  214. // this.showDigitKeyboard = true
  215. },
  216. hideKeyboard(){
  217. this.showDigitKeyboard = false
  218. },
  219. chechValue(value){
  220. if(value == 0){
  221. this.payAmount = this.payableAmount.toFixed(2)
  222. this.balanceAmount = this.payableAmount-this.payAmount
  223. }else if(parseInt(value)>this.payableAmount){
  224. this.payAmount = this.payableAmount.toFixed(2)
  225. this.balanceAmount = this.payableAmount - this.payAmount
  226. }else{
  227. this.payAmount =Number(value).toFixed(2)
  228. this.balanceAmount = this.payableAmount - this.payAmount
  229. }
  230. },
  231. hanldNavigateBack(){//页面返回
  232. uni.navigateBack({
  233. delta: 1
  234. });
  235. },
  236. payTypeText (state){//处理支付记录文字
  237. let stateText = '',
  238. stateTextObject={
  239. 12:'网银支付',
  240. 13:'微信支付',
  241. 14:'支付宝支付',
  242. 15:'微信支付',
  243. 16:'余额抵扣',
  244. }
  245. Object.keys(stateTextObject).forEach(key => {
  246. if(key == state){
  247. stateText = stateTextObject[key]
  248. }
  249. })
  250. return stateText;
  251. },
  252. hideTips(){//隐藏弹窗
  253. this.isShowTip = false
  254. },
  255. clipboard(data) {//复制链接
  256. thorui.getClipboardData(data, (res) => {
  257. // #ifdef H5
  258. if (res) {
  259. this.$util.msg("复制成功",2000);
  260. } else {
  261. this.$util.msg("复制失败",2000);
  262. }
  263. // #endif
  264. })
  265. },
  266. discard(){
  267. //丢弃
  268. }
  269. },
  270. onShow() {
  271. }
  272. }
  273. </script>
  274. <style lang="scss">
  275. page{height: auto !important;background-color: #F7F7F7;}
  276. .container-cash{
  277. width: 100%;
  278. .container-wrapper{
  279. width:100%;
  280. margin: 0 auto;
  281. .pay-content{
  282. width: 662rpx;
  283. height: 512rpx;
  284. padding: 48rpx 44rpx;
  285. background: url(https://admin-b.caimei365.com/userfiles/1/images/photo/2020/05/%E6%94%B6%E9%93%B6%E5%8F%B0bg%402x.png) no-repeat;
  286. background-size: cover;
  287. float: left;
  288. .pay-top{
  289. width: 100%;
  290. height: auto;
  291. .pay-paid{
  292. width: 100%;
  293. height: auto;
  294. margin-bottom: 38rpx;
  295. text{
  296. display: inline-block;
  297. line-height: 48rpx;
  298. text-align: left;
  299. color: #FFFFFF;
  300. width: 100%;
  301. }
  302. .txt-m{
  303. font-size: $font-size-26;
  304. opacity: 0.7;
  305. }
  306. .txt-b{
  307. font-size: $font-size-32;
  308. }
  309. }
  310. }
  311. .pay-bot{
  312. width: 614rpx;
  313. height: 184rpx;
  314. padding: 24rpx;
  315. background: #FFFFFF;
  316. border-radius: 10rpx;
  317. .bot-title{
  318. line-height: 36rpx;
  319. font-size: $font-size-26;
  320. color: #666666;
  321. }
  322. .bot-input{
  323. width: 100%;
  324. height: 66rpx;
  325. margin: 15rpx 0;
  326. border-bottom: 1px solid #EBEBEB;
  327. line-height: 66rpx;
  328. font-size: $font-size-32;
  329. color: $text-color;
  330. text{
  331. display: block;
  332. float: left;
  333. }
  334. .input{
  335. font-size: $font-size-40;
  336. width: 500rpx;
  337. height: 66rpx;
  338. padding: 0 10rpx;
  339. line-height: 66rpx;
  340. float: left;
  341. .none{
  342. color:$text-color;
  343. opacity: 0.3;
  344. }
  345. .text{
  346. color:$text-color;
  347. }
  348. }
  349. .placeholder{
  350. font-size: $font-size-26;
  351. }
  352. }
  353. .bot-resid{
  354. line-height: 36rpx;
  355. font-size: $font-size-26;
  356. color: #666666;
  357. margin-top: 24rpx;
  358. }
  359. }
  360. }
  361. .pay-record{
  362. float: left;
  363. background: #FFFFFF;
  364. width: 702rpx;
  365. height: auto;
  366. padding: 0 24rpx;
  367. .record-title{
  368. width: 100%;
  369. float: left;
  370. font-size: $font-size-28;
  371. color: $text-color;
  372. line-height: 80rpx;
  373. height: 80rpx;
  374. border-bottom: 1px solid #F8F8F8;
  375. }
  376. .record-list{
  377. width: 100%;
  378. height: auto;
  379. float: left;
  380. .list-none{
  381. line-height: 80rpx;
  382. font-size: $font-size-26;
  383. color: #999999;
  384. text-align: left;
  385. }
  386. .list-main{
  387. height: auto;
  388. display: flex;
  389. flex-direction:column;
  390. .list-item{
  391. width: 100%;
  392. height:80rpx;
  393. display: flex;
  394. flex: 1;
  395. line-height: 80rpx;
  396. font-size: $font-size-26;
  397. color: $text-color;
  398. .text{
  399. &.row-1{
  400. flex: 3;
  401. }
  402. &.row-2{
  403. flex: 3;
  404. }
  405. &.row-3{
  406. flex: 4;
  407. text-align: right;
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. .pay-button{
  416. width: 100%;
  417. position: fixed;
  418. bottom: 80rpx;
  419. .btn{
  420. width: 702rpx;
  421. height: 88rpx;
  422. border-radius: 14rpx;
  423. font-size: $font-size-28;
  424. line-height: 88rpx;
  425. color: #FFFFFF;
  426. margin: 0 auto;
  427. text-align: center;
  428. background: $btn-confirm;
  429. }
  430. }
  431. }
  432. .freight-alert{
  433. width: 100%;
  434. height: 100%;
  435. background: rgba(0,0,0,.5);
  436. position: fixed;
  437. top: 0;
  438. left: 0;
  439. z-index: 8888;
  440. transition: all 0.4s;
  441. &.none{
  442. display: none;
  443. }
  444. &.show{
  445. display: block;
  446. }
  447. .content{
  448. width: 422rpx;
  449. height:434rpx;
  450. position: absolute;
  451. background: $bg-color;
  452. left: 0;
  453. right: 0;
  454. bottom: 0;
  455. top: 0;
  456. margin: auto;
  457. padding: 20rpx 32rpx;
  458. border-radius: 12rpx;
  459. .title{
  460. width: 100%;
  461. height: 68rpx;
  462. line-height: 68rpx;
  463. font-size: $font-size-28;
  464. color: $text-color;
  465. text-align: center;
  466. position: relative;
  467. .icon-iconfontguanbi{
  468. width: 68rpx;
  469. height: 68rpx;
  470. text-align: center;
  471. line-height: 68rpx;
  472. position: absolute;
  473. right: 0;
  474. top: 0;
  475. font-size: $font-size-36;
  476. color: #999999;
  477. }
  478. }
  479. .text-content{
  480. width: 100%;
  481. height: auto;
  482. .text{
  483. padding: 20rpx 0 0 0;
  484. line-height: 44rpx;
  485. font-size: $font-size-26;
  486. color:#666666;
  487. text-align: justify;
  488. }
  489. .text-p{
  490. width: 100%;
  491. line-height: 44rpx;
  492. font-size: $font-size-26;
  493. color:$color-system;
  494. text-align: left;
  495. text-overflow:ellipsis;
  496. display: -webkit-box;
  497. word-break: break-all;
  498. -webkit-box-orient: vertical;
  499. -webkit-line-clamp: 1;
  500. overflow: hidden;
  501. }
  502. .text-b{
  503. line-height: 44rpx;
  504. font-size: $font-size-24;
  505. color:#999999;
  506. text-align: left;
  507. }
  508. }
  509. .text-button{
  510. width: 100%;
  511. height: 88rpx;
  512. line-height: 88rpx;
  513. background: $btn-confirm;
  514. font-size: $font-size-28;
  515. border-radius: 14rpx;
  516. color:#FFFFFF;
  517. text-align: center;
  518. margin-top: 20rpx;
  519. }
  520. }
  521. }
  522. </style>