en-send.vue 2.4 KB

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