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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
| <template>
| <div class="select-shop-user">
| <el-button v-if="!disabled" type="primary" @click="chooseUser"
| >指定用户</el-button
| >
| <el-table v-if="value && value.length > 0" :data="value">
| <el-table-column label="id" prop="id"></el-table-column>
| <el-table-column label="店铺名称" prop="name"></el-table-column>
| <el-table-column label="联系方式" prop="tel"></el-table-column>
| <el-table-column v-if="!disabled" label="操作">
| <template #default="{ $index }">
| <text-button type="danger" @click="deleteUser($index)"
| >删除</text-button
| >
| </template>
| </el-table-column>
| </el-table>
| <el-dialog
| :visible.sync="dialogVisible"
| title="指定用户"
| append-to-body
| :close-on-click-modal="false"
| custom-class="shop-user-dialog"
| width="80%"
| >
| <div class="dialog-container">
| <div class="dialog-container__list">
| <el-bus-crud v-bind="tableConfig" />
| </div>
| <div class="dialog-container__selected">
| <el-bus-title title="已添加用户" size="mini" />
| <el-tag
| v-for="(tag, i) in currentValue"
| :key="tag.id"
| closable
| @close="deleteCurrentUser(i)"
| >{{ tag.name }}</el-tag
| >
| </div>
| </div>
| <div slot="footer">
| <el-button @click="cancel">取消</el-button>
| <el-button type="primary" @click="confirm">确定</el-button>
| </div>
| </el-dialog>
| </div>
| </template>
|
| <script>
| import cloneDeep from 'lodash.clonedeep'
| export default {
| props: {
| value: {
| type: Array,
| default: () => [],
| },
| disabled: {
| type: Boolean,
| default: false,
| },
| },
| data() {
| return {
| dialogVisible: false,
| currentValue: [],
| tableConfig: {
| url: 'flower/api/customer/page',
| saveQuery: false,
| hasNew: false,
| hasEdit: false,
| hasDelete: false,
| hasView: false,
| columns: [
| { label: 'id', prop: 'id' },
| { label: '店铺名称', prop: 'name' },
| { label: '联系方式', prop: 'tel' },
| ],
| extraButtons: [
| {
| text: '选择',
| show: (row) =>
| !this.currentValue.find((item) => item.id === row.id),
| atClick: (row) => {
| this.currentValue.push({
| id: row.id,
| name: row.name,
| tel: row.tel,
| })
| return false
| },
| },
| {
| text: '取消选择',
| show: (row) => this.currentValue.find((item) => item.id === row.id),
| atClick: (row) => {
| const index = this.currentValue.findIndex(
| (item) => item.id === row.id
| )
| this.currentValue.splice(index, 1)
| return false
| },
| },
| ],
| searchFormAttrs: {
| labelWidth: 'auto',
| },
| searchForm: [
| {
| type: 'row',
| span: 12,
| items: [
| { label: 'id:', id: 'id', type: 'input' },
| { label: '店铺名称:', id: 'name', type: 'input' },
| { label: '联系方式:', id: 'tel', type: 'input' },
| ],
| },
| ],
| },
| }
| },
| watch: {
| value: {
| immediate: true,
| handler(value) {
| this.currentValue = cloneDeep(value || [])
| },
| },
| },
| methods: {
| chooseUser() {
| this.currentValue = cloneDeep(this.value || [])
| this.dialogVisible = true
| },
| deleteCurrentUser(i) {
| this.currentValue.splice(i, 1)
| },
| deleteUser(i) {
| this.$elBusUtil
| .confirm('确定要删除吗?')
| .then(() => {
| const userList = cloneDeep(this.value || [])
| userList.splice(i, 1)
| this.$emit('input', userList)
| this.$emit('change', userList)
| })
| .catch(() => {})
| },
| confirm() {
| this.$emit('input', this.currentValue)
| this.$emit('change', this.currentValue)
| this.dialogVisible = false
| },
| cancel() {
| this.dialogVisible = false
| },
| },
| }
| </script>
|
| <style lang="scss" scoped>
| .select-shop-user {
| }
| </style>
| <style lang="scss">
| .shop-user-dialog {
| .dialog-container {
| display: flex;
| align-items: flex-start;
| &__list {
| flex: 1;
| border-right: 1px solid #eee;
| height: 100%;
| }
| &__selected {
| width: 40%;
| height: 100%;
| padding: 24px;
| .el-bus-title {
| margin-bottom: 15px;
| }
| .el-tag {
| margin-right: 6px;
| margin-bottom: 6px;
| }
| }
| }
| }
| </style>
|
|