rk
2025-09-22 cf2391a86bdea88196d49cd33949570f74c0985d
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
<template>
  <TableLayout :permissions="['system:user:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="80px" inline>
      <el-form-item label="用户名称" prop="username">
        <el-input v-model="searchForm.username" v-trim placeholder="请输入用户名" @keypress.enter.native="search"/>
      </el-form-item>
      <el-form-item label="所属省份" prop="cityId">
        <div style="display:flex">
          <el-select v-model="searchForm.provinceId" placeholder="请选择省份" @change="selectProvince">
            <el-option
              v-for="item in province"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </div>
      </el-form-item>
      <el-form-item label="所属城市" prop="cityId">
        <el-select v-model="searchForm.cityId" placeholder="请选择城市">
          <el-option
            v-for="item in cities"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <section>
        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar">
        <li v-permissions="['system:user:create']"><el-button icon="el-icon-plus" type="primary" @click="$refs.operaCityUserWindow.open('新建用户')">新建</el-button></li>
        <li><el-button type="primary" @click="resetUserPwd">重置密码</el-button></li>
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        @selection-change="handleSelectionChange"
        @sort-change="handleSortChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="username" label="市局用户名称" align="center" min-width="140px" fixed="left" show-overflow-tooltip></el-table-column>
        <el-table-column prop="address" label="所属城市" align="center" min-width="140px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="realname" label="姓名" align="center" min-width="100px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mobile" label="手机号" align="center" min-width="120px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mobile" label="状态" align="center" min-width="120px">
          <template slot-scope="{row}">
            <el-switch
              v-model="row.status"
              active-color="#13ce66"
              inactive-color="#999"
              :active-value="0"
              :inactive-value="1"
              @change="changeStatus(row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center" min-width="140px"></el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="120"
          fixed="right"
        >
          <template v-if="isAdmin || (row.id !== userInfo.id && row.roles.findIndex(r => r.code === adminCode) === -1)" slot-scope="{row}">
            <el-button type="text" @click="$refs.sjChildrenListWindow.open(`${row.username}的子账号`, { parentId: row.id})">查看子账号</el-button>
            <el-button type="text" @click="$refs.operaCityUserWindow.open('编辑用户', row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      ></pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaCityUserWindow ref="operaCityUserWindow" @success="handlePageChange(tableData.pagination.pageIndex)"/>
    <SjChildrenListWindow ref="sjChildrenListWindow" />
  </TableLayout>
</template>
 
<script>
import Pagination from '@/components/common/Pagination'
import TableLayout from '@/layouts/TableLayout'
import BaseTable from '@/components/base/BaseTable'
import OperaCityUserWindow from '@/components/business/user/OperaCityUserWindow'
import SjChildrenListWindow from '@/components/business/user/SjChildrenListWindow'
import { treeList } from '@/api/business/areas'
import { resetPwd, changeStatus } from '@/api/business/account'
 
export default {
  name: 'SystemUser',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaCityUserWindow, SjChildrenListWindow },
  data () {
    return {
      // 搜索
      searchForm: {
        username: '', // 名字
        provinceId: '', // 姓名
        cityId: null,
        type: '8' //市局
      
      },
      province: [],
      cities: []
    }
  },
  provide() {
    return {
      province: () => this.province
    }
  },
  created () {
    
    this.config({
      module: '用户',
      api: '/business/account',
      'field.main': 'realname',
      sorts: [{
        property: 'CREATE_TIME',
        direction: 'DESC'
      }]
    })
    // 地区
    treeList({ type: 0 })
      .then(res => {
        // console.log(res)
        this.province = res
      })
      .catch(e => {
        this.$message.error(e)
      })
    this.search()
  },
  methods: {
    changeStatus({id, status}) {
      changeStatus({ id, value:status })
        .then(res => {
          this.$message.success('修改成功')
        })
        .catch(e => {
          this.$message.error(e)
        })
        .finally(() => {
          this.handlePageChange()
        })
    },
    // 选择省份
    selectProvince(val) {
      this.cities = []
      this.searchForm.cityId = ''
      treeList({ type: 1, parentId: val })
        .then(res => {
          this.cities = res
          
        })
      // const tempProvince = this.province.find(item => item.id === val)
      // if (tempProvince) {
      //   this.cities = tempProvince.childList
      // }
    },
    resetUserPwd() {
      if (this.tableData.selectedRows.length === 0) {
        this.$message.warning('请至少选择一条数据')
        return
      }
      let message = `确认重置已选中的 ${this.tableData.selectedRows.length} 个账号密码吗?`
      this.$dialog.resetConfirm(message)
        .then(() => {
          this.isWorking.delete = true
          resetPwd({ ids: this.tableData.selectedRows.map(row => row.id).join(',') })
            .then(() => {
              this.$message.success('重置成功')
              this.handlePageChange()
            })
            .catch(e => {
              this.$message.error(e)
            })
            .finally(() => {
              this.isWorking.delete = false
            })
        })
        .catch(() => {})
    }
  },
}
</script>
 
<style scoped lang="scss">
@import "@/assets/style/variables.scss";
// 列表头像处理
.table-column-avatar {
  img {
    width: 48px;
  }
}
</style>