cloudroam
2025-03-28 cef2bb0eeeb91a22860cf5d23c7348af1ba921dc
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<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="loginName"></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.loginName
            }}</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/user/user/list',
        saveQuery: false,
        hasNew: false,
        hasEdit: false,
        hasDelete: false,
        hasView: false,
        columns: [
          { type: 'selection' },
          { label: 'id', prop: 'id' },
          { label: '名称', prop: 'loginName' },
          { label: '注册手机号', prop: 'tel' },
        ],
        extraButtons: [
          {
            text: '选择',
            show: (row) =>
              !this.currentValue.find((item) => item.id === row.id),
            atClick: (row) => {
              this.currentValue.push({
                id: row.id,
                userId: row.userId,
                loginName: row.loginName,
                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
            },
          },
        ],
        headerButtons: [
          {
            text: '批量选择',
            type: 'primary',
            disabled: (selected) => selected.length === 0,
            atClick: (selected) => {
              console.log(selected)
              selected.forEach(item => {
                // 检查 selected 数组的每个元素是否已在 currentValue 中
                if (!this.currentValue.some(currentItem => currentItem.id === item.id)) {
                  this.currentValue.push({
                    id: item.id,
                    userId: item.userId,
                    loginName: item.loginName,
                    tel: item.tel,
                  })
                }
              });
              return true
            },
          },
          {
            text: '批量取消',
            type: 'primary',
            disabled: (selected) => selected.length === 0,
            atClick: (selected) => {
              selected.forEach(item => {
                // 检查 selected 数组的每个元素是否存在于 currentValue 中
                const index = this.currentValue.findIndex(currentItem => currentItem.id === item.id);
                if (index !== -1) {
                  this.currentValue.splice(index, 1); // 如果存在,则移除
                }
              });
              return true
            },
          },
        ],
 
        searchFormAttrs: {
          labelWidth: 'auto',
        },
        searchForm: [
          {
            type: 'row',
            span: 12,
            items: [
              {
                label: '列表类型:',
                id: 'userType',
                type: 'bus-select-dict',
                el: {
                  code: 'USER_TYPE',
                  multiple: false,
                  style: 'width:100%',
                },
                default: 'customer',
                searchImmediately: true,
                on: {
                change: (e, updateForm, obj) => {
                  console.log(e[0])
                  // if (e[0] === 'supplier') {
                  //   this.tableConfig.url = 'flower/api/supplier/page'
                  // } else if (e[0] === 'partner') {
                  //   this.tableConfig.url = 'flower/api/partner/page'
                  // }else if(e[0]==='customer'){
                  //   this.tableConfig.url = 'flower/api/customer/page'
                  // }
                },
              },
 
              },
 
              { label: 'id:', id: 'id', type: 'input' },
              { label: '名称:', id: 'loginName', type: 'input' },
              { label: '注册手机号:', id: 'tel', type: 'input' },
            ],
          },
        ],
      },
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(value) {
        this.currentValue = cloneDeep(value || [])
      },
    },
  },
  methods: {
    handleSelectionChange(rows) {
      console.log(rows)
      alert("全选")
    },
    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>