wh-input.vue 2.5 KB

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