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
| <template>
| <div class="input-select">
| <el-input-number
| v-model="inputValue"
| v-bind="inputAttrs"
| class="input-select__input"
| @input="onInputChange"
| />
| <el-bus-select-dict
| v-model="selectValue"
| v-bind="selectAttrs"
| class="input-select__select"
| @change="onSelectChange"
| />
| </div>
| </template>
|
| <script>
| import { t } from 'el-business'
| import utils from 'el-business-utils'
| export default {
| props: {
| value: {
| type: Array,
| default: () => [],
| },
| inputAttrs: {
| type: Object,
| default: () => ({}),
| },
| selectAttrs: {
| type: Object,
| 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 input = item.commonFormatProps[0]
| const select = item.commonFormatProps[1]
| if (select in row || input in row) {
| return [row[input], row[select]]
| }
| } else {
| console.warn('please set commonFormatProps')
| }
| },
| outputFormat(val, item) {
| if (
| Array.isArray(item.commonFormatProps) &&
| item.commonFormatProps.length === 2
| ) {
| const input = item.commonFormatProps[0]
| const select = item.commonFormatProps[1]
| return {
| [input]: !utils.isTrueEmpty(val?.[0]) ? val[0] : null,
| [select]: !utils.isTrueEmpty(val?.[1]) ? val[1] : null,
| }
| } else {
| console.warn('please set commonFormatProps')
| }
| },
| data() {
| return {
| inputValue: null,
| selectValue: null,
| }
| },
| watch: {
| value: {
| immediate: true,
| handler(value) {
| value = value || []
| this.inputValue = value?.[0] || undefined
| this.selectValue = value?.[1] || null
| },
| },
| },
| methods: {
| onInputChange(e) {
| const value = [e, this.selectValue]
| this.emitValue(value)
| },
| onSelectChange(e) {
| const value = [this.inputValue, e]
| this.emitValue(value)
| },
| emitValue(value) {
| this.$emit('input', value)
| this.$emit('change', value)
| },
| },
| }
| </script>
|
| <style lang="scss" scoped>
| .input-select {
| display: flex;
| align-items: center;
| &__input {
| margin-right: 8px;
| }
| }
| </style>
|
|