en-send.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="box">
  3. <view class="input-box">
  4. <view class="input-box-left" :style="{'letter-spacing':labelWidth}">
  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-send',
  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. labelWidth:0
  60. }
  61. },
  62. components: {},
  63. mounted() {
  64. this.inputValue = this.value
  65. this.setLabelWidth()
  66. },
  67. watch: {
  68. 'value': function () {
  69. if (this.inputValue !== this.value) {
  70. this.inputValue = this.value
  71. }
  72. },
  73. 'inputValue': function () {
  74. this.$emit('input', this.inputValue)
  75. }
  76. },
  77. methods: {
  78. getCode(){
  79. if (this.inputValue === '') {
  80. uni.showToast({
  81. 'title': "请输入"+this.label,
  82. 'icon': 'error',
  83. 'mask': true,
  84. 'duration': 1500
  85. })
  86. return;
  87. }
  88. this.$emit('getCode')
  89. },
  90. setCodeNum(){
  91. this.timeNum = this.timeNumMax
  92. this.timer = setInterval(() => {
  93. this.timeNum--;
  94. if (this.timeNum <= 0) {
  95. clearInterval(this.timer);
  96. }
  97. }, 1000);
  98. },
  99. setLabelWidth(){
  100. let differenceNum=4- this.label.length;
  101. if(differenceNum===2){
  102. this.labelWidth='2em'
  103. }else if(differenceNum===1){
  104. this.labelWidth='0.5em'
  105. }
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. @import url("../../../static/css/en-common.css");
  112. .box{
  113. .input-box {
  114. display: flex;
  115. align-items: center;
  116. font-size: 32rpx;
  117. .input-box-left {
  118. color: #333333;
  119. width: 210rpx;
  120. }
  121. .input-box-right{
  122. width: 80rpx;
  123. color: #3169FA;
  124. }
  125. }
  126. }
  127. </style>