fei.wang
2025-03-17 afedb522ac910d1e5265ad93b9bacb1da41cfefb
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keyword" size="small" placeholder="请输入用户名称" clearable class="filter-item w-200" />
      <el-button-group class="filter-item">
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">
          搜索
        </el-button>
        <el-button size="small" type="primary" icon="el-icon-refresh" @click="refresh">
          刷新
        </el-button>
        <el-button  v-if="uadd=='Yes'" size="small" type="primary" icon="el-icon-plus" @click="add">
          新增
        </el-button>
      </el-button-group>
    </div>
 
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit height="100%"
      class="table-container" highlight-current-row>
      <el-table-column fixed label="序号" width="80" >
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="用户名" >
        <template slot-scope="scope">
          {{ scope.row.username }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="密码" >
        <template slot-scope="scope">
          {{ scope.row.password }}
        </template>
      </el-table-column> -->
      <el-table-column label="电话"  width="130">
        <template slot-scope="scope">
          {{ scope.row.adminphone }}
        </template>
      </el-table-column>
      <el-table-column label="公司名称"  width="170">
        <template slot-scope="scope">
          {{ scope.row.caname}}
        </template>
      </el-table-column>
      <el-table-column label="角色" >
        <template slot-scope="scope">
          {{ scope.row.role}}
        </template>
      </el-table-column>
       <el-table-column label="添加权限" >
        <template slot-scope="scope">
          {{ scope.row.uadd}}
        </template>
      </el-table-column>
      <el-table-column label="删除权限" >
        <template slot-scope="scope">
          {{ scope.row.udelete}}
        </template>
      </el-table-column>
      <el-table-column label="修改权限" >
        <template slot-scope="scope">
          {{ scope.row.uupdate}}
        </template>
      </el-table-column>
      <!--<el-table-column label="进入后台" >
        <template slot-scope="scope">
          {{ scope.row.addtime}}
        </template>
      </el-table-column>
      <el-table-column label="锁定状态" >
        <template slot-scope="scope">
          {{ scope.row.addtime}}
        </template>
      </el-table-column>-->
      <el-table-column label="操作时间"  width="170">
        <template slot-scope="scope">
          {{ scope.row.time}}
        </template>
      </el-table-column> 
      <el-table-column  label="操作" width="200"  v-if="uupdate=='Yes' || udelete=='Yes'">
        <template slot-scope="scope">
          <el-button-group>
            <el-button v-if="uupdate=='Yes'" type="primary" icon="el-icon-edit" size="mini" @click="edit(scope)">
              修改
            </el-button>
            <el-button v-if="udelete=='Yes'"type="danger" icon="el-icon-delete" size="mini" @click="del(scope)">
              删除
            </el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
 
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.current" :limit.sync="listQuery.size"
      @pagination="fetchData" />
 
    <el-dialog :visible.sync="dialogVisible" :title="dialogType === 'modify' ? '修改' : '新增'">
      <el-form :ref="temp" :model="temp" label-width="120px" label-position="right" :rules="rules">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="temp.username
        " placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item v-if="dialogType!='modify'" label="密码" prop="password">
          <el-input v-model="temp.password
        " placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="公司全称" prop="caname">
          <el-select style="width: 100%;" v-model="temp.caname" filterable remote placeholder="请选择公司全称"
            :remote-method="searchMethod" :loading="searchloading">
            <el-option v-for="item in options" :key="item.id" :label="item.companyname" :value="item.companyname"  >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电话" prop="adminphone">
          <el-input v-model="temp.adminphone
        " placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="角色" prop="role">
          <el-select style="width: 100%;" v-model="temp.role" placeholder="请选择角色">
            <el-option v-for="item in jueseoptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="新增权限">
          <el-switch v-model="temp.uadd" active-color="#13ce66" active-value="Yes" inactive-value="No"
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item label="删除权限">
          <el-switch v-model="temp.udelete" active-color="#13ce66" active-value="Yes" inactive-value="No"
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item label="修改权限">
          <el-switch v-model="temp.uupdate" active-color="#13ce66" active-value="Yes" inactive-value="No"
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
      </el-form>
      <div class="text-right">
        <el-button type="danger" @click="dialogVisible = false">
          取消
        </el-button>
        <el-button type="primary" @click="submit">
          确定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import Pagination from '@/components/Pagination'
import { getUserPage, delUser, addorupUser, searchUser,search,getjuese,addSystemOperationLog } from '@/api/user'
import { deepClone } from '@/utils'
 
const _temp = {
  id: '',
  username: '',
  // password: '',
  caname: '',
  adminphone: '',
  role:'',
  uadd:'',
  udelete:'',
  uupdate:'',
  csname:'',
}
 
export default {
  components: {
    Pagination
  },
  data() {
    return {
      uadd:'',
      udelete:'',
      uupdate:'',
      jueseoptions: [],
      total: 0,
      list: [],
      menus: [],
      listLoading: true,
      listQuery: {
        current: 1,
        size: 20,
        keyword: undefined,
      },
      uploadUrl: '',
      temp: Object.assign({}, _temp),
      dialogVisible: false,
      dialogType: 'create',
      loading: false,
      options: [],
      searchloading: false,
      rules: {
        username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ],
          caname: [
            {  required: true, message: '请选择公司全称', trigger: 'change' }
          ],
          adminphone: [
            {  required: true, message: '请输入电话', trigger: 'change' }
          ],
          role: [
            {  required: true, message: '请选择角色', trigger: 'change' }
          ]
        },
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
     // 远程搜索
     searchMethod(query) {
      if (query !== '') {
        this.loading = true;
        var params = { query: query }
        search(params).then(response => {
          this.options = response.data;
          this.loading = false;
        })
      } else {
        this.options = [];
      }
    },
    // 搜索
    search() {
      this.listLoading = true
      searchUser(this.listQuery).then(response => {
        if (response.data!=null) {
          this.list = response.data.records
          this.total = response.data.total
        }else{
          this.$message({
            message: '未搜索到数据',
            type: 'error'
          })
        }
      
        this.listLoading = false
      })
    },
    refresh() {
      this.listQuery = {
        current: 1,
        size: 20,
        keyword: undefined
      }
      this.fetchData()
    },
    // 分页数据
    fetchData() {
      this.uadd = localStorage.getItem('uadd') || '';
      this.udelete = localStorage.getItem('udelete') || '';
      this.uupdate = localStorage.getItem('uupdate') || '';
      this.listLoading = true
      getUserPage(this.listQuery).then(response => {
        this.list = response.data.records
        this.total = response.data.total
        this.listLoading = false
      })
      this.jueseoptions=[]
      getjuese().then(response => {
        for (let index = 0; index < response.data.length; index++) {
          var json = {
            value: '',
            label: '',
          }
          const element = response.data[index];
          json.value = element
          json.label = element
          this.jueseoptions.push(json)
        }
 
      })
    },
    resetTemp() {
      this.temp = Object.assign({}, _temp)
    },
    add() {
      this.resetTemp()
      this.dialogVisible = true
      this.dialogType = 'create'
      // this.$nextTick(() => {
      //   this.$refs['dataForm'].clearValidate()
      // })
    },
    edit(scope) {
      scope.row.password=null
      this.resetTemp()
      this.dialogVisible = true
      this.dialogType = 'modify'
      this.temp = deepClone(scope.row)
      // this.$nextTick(() => {
      //   this.$refs['dataForm'].clearValidate()
      // })
    },
    changeStatus(value, scope) {
      setTimeout(() => {
        this.list[scope.$index].status = value
        this.$message({
          message: '更新成功',
          type: 'success'
        })
      }, 300)
    },
    // 删除
    del(scope) {
      this.$confirm('确认删除该条数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        setTimeout(() => {
          const params = { id: scope.row.id };
          this.list.splice(scope.$index, 1)
          delUser(params).then(response => {
            this.temp.adminname = localStorage.getItem('username') || '';
            const params = { name:  this.temp.adminname, content: '删除了一个用户,该用户名称为:'+scope.row.username };
            addSystemOperationLog(params).then(response => {
 
                        })
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.fetchData()
          })
        }, 300)
      })
    },
    submit() {
      if (this.loading) {
        return
      }
      this.loading = true
      this.$refs[this.temp].validate((valid) => {
        if (valid) {
      addorupUser(this.temp).then(() => {
        if (this.temp.id=="") {
          this.temp.adminname = localStorage.getItem('username') || '';
            const params = { name:  this.temp.adminname, content: '新增了一个用户,该用户名称为:'+this.temp.username };
            addSystemOperationLog(params).then(response => {
 
                        })
        } else {
          this.temp.adminname = localStorage.getItem('username') || '';
            const params = { name:  this.temp.adminname, content: '修改了一个用户,该用户名称为:'+this.temp.username };
            addSystemOperationLog(params).then(response => {
 
                        })
        }
    
        this.fetchData()
        setTimeout(() => {
          this.$message({
            message: '提交成功',
            type: 'success'
          })
          this.dialogVisible = false
          this.loading = false
        }, 300)
      })
      
    } else {
            this.$message({
            message: '提交失败,请检查表单必填项是否为空',
            type: 'error'
          })
            console.log('error submit!!');
            return false;
          }
        });
    }
  }
}
</script>
 
<style lang="scss" scoped>
.el-upload {
  border: 1px dashed #d9d9d9 !important;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
 
  .el-icon-plus.avatar-uploader-icon {
    border: 1px dashed #d9d9d9 !important;
    border-radius: 6px;
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
  }
}
 
.avatar-uploader {
  height: 128px;
 
  img {
    width: 128px;
    height: 128px;
  }
}
</style>