pay.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. success: function (res) {
  47. //用户id
  48. let result=res.result.split(';')
  49. _this.secret=result[0]
  50. _this.userId=_this.secret.substr(0,19)
  51. _this.channelId=result[1]
  52. //处理支付
  53. _this.toPay()
  54. },
  55. fail: (res) => {
  56. if(res.errMsg!='scanCode:fail cancel'){
  57. _this.scanNotify = {scan: true,scanMessage: res.errMsg};
  58. }
  59. }
  60. });
  61. },
  62. toPay(){
  63. let expireTime=this.$dateTime.getExpireTime(5)
  64. let params={
  65. mallId:this.vuex_mallId,
  66. shopId:this.vuex_shopId,
  67. money:this.money,
  68. billsTitle:'商家扫码收款',
  69. expireTime,
  70. appId:this.$global.wxParams.clientAppId,
  71. secret:this.userId,
  72. authCode: this.secret,
  73. channelId:this.channelId
  74. }
  75. console.log(params);
  76. uni.navigateTo({
  77. url:"/pages/pay/pay-result?payParams="+JSON.stringify(params)
  78. })
  79. },
  80. show(){
  81. this.$refs.amountInput.show()
  82. },
  83. change(e){
  84. if (!e) {
  85. this.money=0
  86. }else{
  87. this.money=e
  88. }
  89. },
  90. filterMoney(value) {
  91. value=value.toString()
  92. if (!value) {
  93. return ''
  94. } else {
  95. value = value.replace(/\$\s?|(,*)/g, '')
  96. return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  97. }
  98. },
  99. }
  100. }
  101. </script>
  102. <style>
  103. page{
  104. background-color: #FFFFFF;
  105. }
  106. </style>
  107. <style lang="scss" scoped>
  108. .data{
  109. padding: 50rpx;
  110. display: flex;
  111. justify-content: flex-start;
  112. flex-direction: column;
  113. .price{
  114. &-icon{
  115. font-size: 40rpx;
  116. font-weight: 800;
  117. }
  118. }
  119. }
  120. .center{
  121. display: flex;
  122. justify-content: center;
  123. align-items: center;
  124. }
  125. .input-bar {
  126. height: 150rpx;
  127. border-bottom: 1rpx solid #DDDDDD;
  128. .icon {
  129. width: 15%;
  130. font-size: 70rpx;
  131. font-weight: 900;
  132. height: 100%;
  133. }
  134. .input {
  135. width: 85%;
  136. height: 100%;
  137. overflow: hidden;
  138. font-size: 70rpx;
  139. }
  140. .cusor {
  141. margin-left: 10rpx;
  142. width: 6rpx;
  143. border-radius: 20rpx;
  144. height: 60%;
  145. background-color: #ff9900;
  146. animation: blink 1200ms infinite ease-in-out;
  147. }
  148. }
  149. @keyframes blink {
  150. from {
  151. opacity: 0;
  152. }
  153. }
  154. </style>