pay.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <!-- 扫一扫错误回调 -->
  4. <u-modal title="扫描异常" confirm-color="#EF9944" v-model="scanNotify.scan" :content="scanNotify.scanMessage"></u-modal>
  5. <view class="data">
  6. <text style="color: #000;">收款金额</text>
  7. <view class="price">
  8. <view class="input-bar center" @tap="show">
  9. <view class="icon center">¥</view>
  10. <view class="input" style="display: flex; align-items: center;">
  11. <view style="font-size: 80rpx;font-weight: 800;">{{filterMoney(money)}}</view>
  12. <view class="cusor"></view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <amountInput ref="amountInput" confirmText="收款" btnColor="#EF9944"
  18. placeholder="请输入交易金额" @change="change"
  19. @confirm="scanCode"></amountInput>
  20. </view>
  21. </template>
  22. <script>
  23. import amountInput from '@/components/amountInput/amountInput.vue';
  24. export default {
  25. components: {
  26. amountInput
  27. },
  28. data() {
  29. return {
  30. scanNotify:{scan: false,scanMessage:'扫描错误,请稍后重试!' },
  31. money:'',
  32. //向哪个用户收款
  33. channelId:'',
  34. secret:'',
  35. userId:''
  36. }
  37. },
  38. onLoad(options) {
  39. this.show()
  40. },
  41. methods: {
  42. scanCode(){
  43. const _this = this;
  44. uni.scanCode({
  45. onlyFromCamera:true,
  46. scanType: ['barCode'],
  47. success: function (res) {
  48. //用户id
  49. let result=res.result.split(';')
  50. _this.secret=result[0]
  51. _this.userId=_this.secret.substr(0,19)
  52. _this.channelId=result[1]
  53. //处理支付
  54. _this.toPay()
  55. },
  56. fail: (res) => {
  57. if(res.errMsg!='scanCode:fail cancel'){
  58. _this.scanNotify = {scan: true,scanMessage: res.errMsg};
  59. }
  60. }
  61. });
  62. },
  63. toPay(){
  64. let expireTime=this.$dateTime.getExpireTime(5)
  65. let params={
  66. mallId:this.vuex_mallId,
  67. shopId:this.vuex_shopId,
  68. money:this.money,
  69. billsTitle:'商家扫码收款',
  70. expireTime,
  71. appId:this.$global.wxParams.clientAppId,
  72. secret:this.userId,
  73. authCode: this.secret,
  74. channelId:this.channelId
  75. }
  76. console.log(params);
  77. uni.navigateTo({
  78. url:"/pages/pay/pay-result?payParams="+JSON.stringify(params)
  79. })
  80. },
  81. show(){
  82. this.$refs.amountInput.show()
  83. },
  84. change(e){
  85. if (!e) {
  86. this.money=0
  87. }else{
  88. this.money=e
  89. }
  90. },
  91. filterMoney(value) {
  92. value=value.toString()
  93. if (!value) {
  94. return ''
  95. } else {
  96. value = value.replace(/\$\s?|(,*)/g, '')
  97. return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  98. }
  99. },
  100. }
  101. }
  102. </script>
  103. <style>
  104. page{
  105. background-color: #FFFFFF;
  106. }
  107. </style>
  108. <style lang="scss" scoped>
  109. .data{
  110. padding: 50rpx;
  111. display: flex;
  112. justify-content: flex-start;
  113. flex-direction: column;
  114. .price{
  115. &-icon{
  116. font-size: 40rpx;
  117. font-weight: 800;
  118. }
  119. }
  120. }
  121. .center{
  122. display: flex;
  123. justify-content: center;
  124. align-items: center;
  125. }
  126. .input-bar {
  127. height: 150rpx;
  128. border-bottom: 1rpx solid #DDDDDD;
  129. .icon {
  130. width: 15%;
  131. font-size: 70rpx;
  132. font-weight: 900;
  133. height: 100%;
  134. }
  135. .input {
  136. width: 85%;
  137. height: 100%;
  138. overflow: hidden;
  139. font-size: 70rpx;
  140. }
  141. .cusor {
  142. margin-left: 10rpx;
  143. width: 6rpx;
  144. border-radius: 20rpx;
  145. height: 60%;
  146. background-color: #ff9900;
  147. animation: blink 1200ms infinite ease-in-out;
  148. }
  149. }
  150. @keyframes blink {
  151. from {
  152. opacity: 0;
  153. }
  154. }
  155. </style>