wk-field-mobile.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="wk-field wk-field-input">
  3. <view v-if="_label" class="wk-field__label">
  4. <view v-if="field.isNull === 1" class="line" />
  5. {{ _label }}
  6. </view>
  7. <view class="wk-field__body" @click="handleClick">
  8. <input
  9. ref="core"
  10. v-model="formValue"
  11. type="number"
  12. :placeholder="_placeholder"
  13. :maxlength="11"
  14. :disabled="field.disabled"
  15. placeholder-class="wk-placeholder placeholder"
  16. class="wk-field__body-core"
  17. @input="changeText">
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import mixins from './mixins'
  23. export default {
  24. name: 'WkFieldMobile',
  25. mixins: [mixins],
  26. data() {
  27. return {}
  28. },
  29. methods: {
  30. handleClick() {
  31. if (this.field.disabled) {
  32. if (this.config && this.config.disabledMsg) {
  33. this.$toast(this.config.disabledMsg)
  34. }
  35. return
  36. }
  37. },
  38. formatValue(oldStr) {
  39. let valueStr = String(oldStr)
  40. return valueStr.replace(/[^0-9]/g, '')
  41. },
  42. changeText() {
  43. let oldStr = String(this.formValue)
  44. let valueStr = this.formatValue(this.formValue)
  45. this.formValue = oldStr
  46. this.$nextTick(function() {
  47. this.formValue = valueStr
  48. if (this.value !== this.formValue) {
  49. this.emitChangeEvt(this.formValue)
  50. }
  51. })
  52. }
  53. }
  54. }
  55. </script>
  56. <style scoped lang="scss">
  57. @import './wkField.scss';
  58. .placeholder {
  59. font-size: 26rpx;
  60. }
  61. </style>