en-send.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="box">
  3. <view class="input-box">
  4. <view class="input-box-left">
  5. {{ label }}
  6. </view>
  7. <input
  8. :name="name"
  9. :type="type"
  10. :placeholder="placeholder ? placeholder : ''"
  11. :disabled="!!disabled"
  12. v-model="inputValue"
  13. />
  14. <view class="input-box-right" v-if="timeNum<=0" @click="getCode()">
  15. 发送
  16. </view>
  17. <view class="input-box-right" v-else >
  18. {{timeNum}} s
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'en-input',
  26. props: {
  27. type: {
  28. type: String,
  29. default: 'text'
  30. },
  31. label: {
  32. type: String,
  33. default: '手机号'
  34. },
  35. placeholder: {
  36. type: String,
  37. default: '请输入手机号码'
  38. },
  39. disabled: {
  40. default: false
  41. },
  42. name: {
  43. type: String,
  44. default: 'number'
  45. },
  46. value: {
  47. default: ''
  48. },
  49. timeNumMax:{
  50. type:Number,
  51. default:90
  52. }
  53. },
  54. data() {
  55. return {
  56. inputValue: '',
  57. timer: '',
  58. timeNum:0
  59. }
  60. },
  61. components: {},
  62. mounted() {
  63. this.inputValue = this.value
  64. },
  65. watch: {
  66. 'value': function () {
  67. if (this.inputValue !== this.value) {
  68. this.inputValue = this.value
  69. }
  70. },
  71. 'inputValue': function () {
  72. this.$emit('input', this.inputValue)
  73. }
  74. },
  75. methods: {
  76. getCode(){
  77. if (this.inputValue === '') {
  78. uni.showToast({
  79. 'title': "请输入"+this.label,
  80. 'icon': 'error',
  81. 'mask': true,
  82. 'duration': 1500
  83. })
  84. return;
  85. }
  86. this.$emit('getCode')
  87. },
  88. setCodeNum(){
  89. this.timeNum = this.timeNumMax
  90. this.timer = setInterval(() => {
  91. this.timeNum--;
  92. if (this.timeNum <= 0) {
  93. clearInterval(this.timer);
  94. }
  95. }, 1000);
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. .box{
  102. background-color: #ffffff;
  103. border-bottom: 2rpx solid #F0F0F0;
  104. padding: 34rpx 0 32rpx 0;
  105. .input-box {
  106. display: flex;
  107. align-items: center;
  108. font-size: 32rpx;
  109. .input-box-left {
  110. color: #333333;
  111. width: 210rpx;
  112. }
  113. .input-box-right{
  114. width: 80rpx;
  115. color: #3169FA;
  116. }
  117. }
  118. }
  119. </style>