en-input.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="wh-box">
  3. <view class="row p-tb30" style="line-height: 30rpx;height: 30rpx;" :class="{'bor-bottom-1':is_border}">
  4. <view class="wh-text size-28" :class="{'wh-text-long':isLong}">{{label}}<text></text></view>
  5. <view class="row-c flex" @click="inputBut">
  6. <input class="wh-input sys-size-28 text-color-12 m-l40" placeholder-class="sys-size-28 text-color-999"
  7. :maxlength="maxlength" :type="type" :focus="focus"
  8. :placeholder="is_select ? '请选择' : placeholder?placeholder:`请输入${label}`" :disabled="disabled"
  9. v-model="inputValue" @blur="nameInput" @input="nameInput"></input>
  10. <view class="" style="margin-top: 4rpx;">
  11. <uni-icons type="forward" size="18" color="#D8D8D8" v-if="is_select"></uni-icons>
  12. </view>
  13. </view>
  14. <text class="sys-size-28 m-l20" v-if="rightText">{{rightText}}</text>
  15. <slot></slot>
  16. </view>
  17. <view class="size-24 text-color-E21 p-b20 p-t10" v-if="is_requis">{{name}}为必填</view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'en-input',
  23. props: {
  24. is_select: {
  25. type: Boolean,
  26. default: false
  27. },
  28. is_border: {
  29. type: Boolean,
  30. default: true
  31. },
  32. is_requis: {
  33. type: Boolean,
  34. default: false
  35. },
  36. label: {
  37. type: String,
  38. default: '姓名'
  39. },
  40. rightText: {
  41. type: String,
  42. default: ''
  43. },
  44. type: {
  45. type: String,
  46. default: 'text'
  47. },
  48. placeholder: {
  49. type: String,
  50. default: ''
  51. },
  52. disabled: {
  53. default: false
  54. },
  55. value: {
  56. default: ''
  57. },
  58. maxlength: {
  59. default: 140
  60. },
  61. focus: {
  62. default: false
  63. }
  64. },
  65. data() {
  66. return {
  67. inputValue: '',
  68. showShake: false,
  69. isLong: false
  70. };
  71. },
  72. watch: {
  73. 'value': function() {
  74. if (this.inputValue !== this.value) {
  75. console.log(this.inputValue)
  76. this.inputValue = this.value
  77. }
  78. },
  79. 'inputValue': function() {
  80. this.$emit('input', this.inputValue)
  81. }
  82. },
  83. mounted() {
  84. this.inputValue = this.value
  85. this.setLabelWidth()
  86. },
  87. methods: {
  88. nameInput(e) {
  89. if (this.type === 'nickname') {
  90. this.inputValue = e.detail.value
  91. }
  92. },
  93. setLabelWidth() {
  94. this.isLong = this.label.length > 4
  95. },
  96. onSubmit() {},
  97. inputBut() {
  98. this.$emit('inputBut')
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .wh-box {
  105. z-index: 1;
  106. .wh-input {
  107. width: 100%;
  108. text-align: right;
  109. direction: rtl;
  110. }
  111. .wh-input-placeholder {
  112. color: #999999;
  113. font-size: 28rpx;
  114. }
  115. }
  116. .wh-text {
  117. width: 120rpx;
  118. text-align: justify;
  119. text-align-last: justify;
  120. vertical-align: top;
  121. height: 0;
  122. padding-top: 2rpx;
  123. }
  124. .wh-text:after {
  125. content: '';
  126. width: 110rpx;
  127. height: 0;
  128. display: inline-block;
  129. overflow: hidden;
  130. }
  131. .wh-text-long {
  132. width: 170rpx;
  133. }
  134. .wh-text-long:after {
  135. width: 170rpx;
  136. }
  137. </style>