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
  | <template> 
 |    <div class="member-rule"> 
 |      <div class="mr-8">消费</div> 
 |      <el-input-number 
 |        v-model="amountValue" 
 |        v-bind="inputAttrs" 
 |        @input="onAmountChange" 
 |      ></el-input-number> 
 |      <div class="mx-8">元等于</div> 
 |      <el-input-number 
 |        v-model="growthValue" 
 |        v-bind="inputAttrs" 
 |        @input="onGrowthChange" 
 |      ></el-input-number> 
 |      <div class="ml-8">成长值</div> 
 |    </div> 
 |  </template> 
 |    
 |  <script> 
 |  import { t } from 'el-business' 
 |  import utils from 'el-business-utils' 
 |    
 |  export default { 
 |    props: { 
 |      value: { 
 |        type: Array, 
 |        default: () => [], 
 |      }, 
 |    }, 
 |    rules(item) { 
 |      const errorMsg = `${t('elBus.common.pleaseEnter')}${ 
 |        item.label ? item.label.replace(/:/g, '').replace(/:/g, '') : '' 
 |      }` 
 |      return [ 
 |        { 
 |          required: true, 
 |          message: errorMsg, 
 |        }, 
 |        { 
 |          validator: (rule, value, callback) => { 
 |            if ( 
 |              Array.isArray(value) && 
 |              value.filter((i) => !utils.isTrueEmpty(i)).length === 2 
 |            ) { 
 |              callback() 
 |            } else { 
 |              callback(new Error(errorMsg)) 
 |            } 
 |          }, 
 |        }, 
 |      ] 
 |    }, 
 |    inputFormat(row, item) { 
 |      if ( 
 |        Array.isArray(item.commonFormatProps) && 
 |        item.commonFormatProps.length === 2 
 |      ) { 
 |        const amount = item.commonFormatProps[0] 
 |        const growth = item.commonFormatProps[1] 
 |        if (amount in row || growth in row) { 
 |          return [row[amount], row[growth]] 
 |        } 
 |      } else { 
 |        console.warn('please set commonFormatProps') 
 |      } 
 |    }, 
 |    outputFormat(val, item) { 
 |      if ( 
 |        Array.isArray(item.commonFormatProps) && 
 |        item.commonFormatProps.length === 2 
 |      ) { 
 |        const amount = item.commonFormatProps[0] 
 |        const growth = item.commonFormatProps[1] 
 |        return { 
 |          [amount]: !utils.isTrueEmpty(val?.[0]) ? val[0] : null, 
 |          [growth]: !utils.isTrueEmpty(val?.[1]) ? val[1] : null, 
 |        } 
 |      } else { 
 |        console.warn('please set commonFormatProps') 
 |      } 
 |    }, 
 |    data() { 
 |      return { 
 |        amountValue: null, 
 |        growthValue: null, 
 |        inputAttrs: { 
 |          precision: 0, 
 |          min: 1, 
 |          max: 99999999, 
 |          controls: false, 
 |        }, 
 |      } 
 |    }, 
 |    watch: { 
 |      value: { 
 |        immediate: true, 
 |        handler(value) { 
 |          value = value || [] 
 |          this.amountValue = value?.[0] || undefined 
 |          this.growthValue = value?.[1] || undefined 
 |        }, 
 |      }, 
 |    }, 
 |    methods: { 
 |      onAmountChange(e) { 
 |        const value = [e, this.growthValue] 
 |        this.emitValue(value) 
 |      }, 
 |      onGrowthChange(e) { 
 |        const value = [this.amountValue, e] 
 |        this.emitValue(value) 
 |      }, 
 |      emitValue(value) { 
 |        this.$emit('input', value) 
 |        this.$emit('change', value) 
 |      }, 
 |    }, 
 |  } 
 |  </script> 
 |    
 |  <style lang="scss" scoped> 
 |  .member-rule { 
 |    display: flex; 
 |    align-items: center; 
 |  } 
 |  </style> 
 |  
  |