admin
2020-12-08 7f2d1daf6af6ecebad84d80de46a0e5024bbf5da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import fmtEvent from '../_util/fmtEvent';
import fmtUnit from '../_util/fmtUnit';
Component({
  props: {
    type: 'number',
    className: '',
    focus: false,
    placeholder: '',
    value: '',
    controlled: true,
    showClear: false,
    focusAfterClear: true,
    enableNative: undefined // 兼容安卓input的输入
 
  },
  data: {
    _focus: false,
    _unit: '',
    iconSize: fmtUnit(22)
  },
  didMount: function didMount() {
    this.getMoneyUnit(this.props.value);
    this.setData({
      _focus: this.props.focus
    });
  },
  didUpdate: function didUpdate(prevProps) {
    var prevFocus = prevProps.focus;
    var nowFocus = this.props.focus;
 
    if (prevFocus !== nowFocus) {
      this.setData({
        _focus: nowFocus
      });
    }
 
    this.getMoneyUnit(this.props.value);
  },
  methods: {
    onInput: function onInput(e) {
      var event = fmtEvent(this.props, e);
 
      if (this.props.onInput) {
        this.props.onInput(event);
      }
 
      this.getMoneyUnit(e.detail.value);
    },
    onConfirm: function onConfirm(e) {
      var event = fmtEvent(this.props, e);
 
      if (this.props.onConfirm) {
        this.props.onConfirm(event);
      }
    },
    onButtonClick: function onButtonClick() {
      if (this.onButtonClick) {
        this.props.onButtonClick();
      }
    },
    onFocus: function onFocus(e) {
      this.setData({
        _focus: true
      });
      var event = fmtEvent(this.props, e);
 
      if (this.props.onFocus) {
        this.props.onFocus(event);
      }
 
      this.getMoneyUnit(e.detail.value);
    },
    onBlur: function onBlur(e) {
      this.setData({
        _focus: false
      });
      var event = fmtEvent(this.props, e);
 
      if (this.props.onBlur) {
        this.props.onBlur(event);
      }
 
      this.getMoneyUnit(e.detail.value);
    },
    onClearTap: function onClearTap() {
      if (this.props.focusAfterClear) {
        this.setData({
          _focus: true
        });
      }
 
      if (this.props.onClear) {
        this.props.onClear();
      }
    },
    getMoneyUnit: function getMoneyUnit(inputValue) {
      var value = Math.floor(inputValue);
 
      if (value > 999.99 && value <= 10000) {
        this.setData({
          _unit: '千'
        });
      } else if (value > 9999.99 && value <= 100000) {
        this.setData({
          _unit: '万'
        });
      } else if (value > 99999.99 && value <= 1000000) {
        this.setData({
          _unit: '十万'
        });
      } else if (value > 999999.99 && value <= 10000000) {
        this.setData({
          _unit: '百万'
        });
      } else if (value > 9999999.99 && value <= 100000000) {
        this.setData({
          _unit: '千万'
        });
      } else if (value > 99999999.99 && value <= 1000000000) {
        this.setData({
          _unit: '亿'
        });
      } else if (value > 999999999.99 && value <= 10000000000) {
        this.setData({
          _unit: '十亿'
        });
      } else {
        this.setData({
          _unit: ''
        });
      }
    }
  }
});