pay.vue 3.4 KB

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