bindNumber.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view style="padding-top: 300rpx;">
  3. <view v-if="userInfo&&userInfo.mobile" class="phone">{{userInfo.mobile.substring(0,3)}}****{{userInfo.mobile.substring(userInfo.mobile.length-4,3)}}</view>
  4. <view v-else class="phone">绑定工号</view>
  5. <view class="input-box" style="margin-bottom: 30rpx;">
  6. <input v-model="saleNo" placeholder-class="input-placeholder" placeholder="请输入工号"/>
  7. </view>
  8. <view class="input-box dflex" style="margin-top: 40rpx;">
  9. <input v-model="code" type="number" maxlength="6" placeholder="请输入验证码" placeholder-class="input-placeholder"
  10. class="flex" />
  11. <view class="yzm" @click="getCode()" v-text="sendMsg"></view>
  12. </view>
  13. <view class="btn" @click="submit">确认绑定</view>
  14. </view>
  15. </template>
  16. <script>
  17. import { setTimeout } from "timers";
  18. const app = getApp();
  19. const req = require("../../utils/request.js");
  20. export default {
  21. components: {},
  22. props: {},
  23. data() {
  24. return {
  25. userInfo:{},
  26. systems: {},
  27. isTop:0,
  28. saleNo:'',
  29. code: '', //code
  30. sendMsg: '获取验证码',
  31. isGetCodeDisabled: false,
  32. }
  33. },
  34. onLoad(options) {
  35. this.userInfo = req.getStorage('userInfo')
  36. },
  37. onShow() {
  38. },
  39. methods: {
  40. submit(){
  41. if(!this.saleNo) return req.msg("请输入工号")
  42. if(!this.code) return req.msg("请输入验证码")
  43. req.postRequest('/api/user/bindSaleNo',{saleNo:this.saleNo,yzlCode:this.code},res=>{
  44. req.msg("绑定成功")
  45. req.getRequest('/api/user/info', {}, suc => {
  46. req.setStorage('userInfo', suc);
  47. });
  48. setTimeout(()=>{
  49. uni.navigateBack()
  50. },1000)
  51. })
  52. },
  53. getCode() {
  54. if (this.isGetCodeDisabled == true) return false;
  55. if (!this.saleNo) {
  56. req.msg('请输入工号');
  57. return;
  58. }
  59. req.postRequest(
  60. '/api/user/getYzlCode', {
  61. saleNo: this.saleNo,
  62. },
  63. data => {
  64. req.msg('验证码获取成功');
  65. let time = 60;
  66. let interval = setInterval(() => {
  67. time--;
  68. if (time == 0) {
  69. this.isGetCodeDisabled = false;
  70. this.sendMsg = '获取验证码';
  71. clearInterval(interval);
  72. } else {
  73. this.isGetCodeDisabled = true;
  74. this.sendMsg = time + '秒后再获取';
  75. }
  76. }, 1000);
  77. },
  78. true
  79. );
  80. },
  81. },
  82. mounted() {
  83. const systemInfo = uni.getSystemInfoSync();
  84. // px转换到rpx的比例
  85. let pxToRpxScale = 750 / systemInfo.windowWidth;
  86. let systems = {
  87. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  88. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  89. };
  90. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  91. this.systems = systems;
  92. },
  93. onPageScroll: function(e) {
  94. if (e.scrollTop > this.systems.barHeight) {
  95. this.isTop = 1;
  96. } else {
  97. this.isTop = 0;
  98. }
  99. }
  100. }
  101. </script>
  102. <style>
  103. @import "./bindNumber.css";
  104. </style>