index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="app-container">
  3. <div class="setting_title">账户管理</div>
  4. <el-divider></el-divider>
  5. <div class="mymain-container">
  6. <div class="btn-group clearfix">
  7. <div class="fl">
  8. <el-button size="small" type="primary" icon="el-icon-plus" @click="addOrEdit('add')">新增账户</el-button>
  9. </div>
  10. <div class="fr">
  11. <el-select v-model="screenForm.role" placeholder="全部" size="small" style="width: 120px; margin-right: 10px;"
  12. @change="getListByScreen">
  13. <el-option label="全部角色" value=""></el-option>
  14. <el-option :label="item.name" :value="item.adminRoleId" v-for="(item, index) in roleList"
  15. :key="index"></el-option>
  16. </el-select>
  17. <el-select v-model="screenForm.status" placeholder="全部" size="small" style="width: 120px; margin-right: 10px;"
  18. @change="getListByScreen">
  19. <el-option label="全部状态" value=""></el-option>
  20. <el-option :label="item.label" :value="item.value" v-for="(item, index) in select_status"
  21. :key="index"></el-option>
  22. </el-select>
  23. <el-input placeholder="请输入内容" v-model="screenForm.keyword" size="small" style="width: 180px;">
  24. <el-button slot="append" icon="el-icon-search" size="small" @click="getListByScreen"></el-button>
  25. </el-input>
  26. </div>
  27. </div>
  28. <div class="table">
  29. <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit highlight-current-row
  30. stripe>
  31. <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
  32. <el-table-column align="center" label="账号" prop="userName" min-width="120"></el-table-column>
  33. <el-table-column align="center" label="用户名" prop="nickName" min-width="120"></el-table-column>
  34. <el-table-column align="center" label="角色" prop="roleName" min-width="100"></el-table-column>
  35. <el-table-column align="center" label="创建时间" prop="createTime" min-width="160"></el-table-column>
  36. <el-table-column align="center" label="最后登录时间" prop="lastLoginTime" min-width="160"></el-table-column>
  37. <el-table-column align="center" label="状态" class-name="status-col">
  38. <template slot-scope="scope">
  39. <el-tag :type="scope.row.status ? 'success' : 'danger'">{{ scope.row.status ? '正常' : '冻结' }}</el-tag>
  40. </template>
  41. </el-table-column>
  42. <el-table-column align="center" label="操作" min-width="160">
  43. <template slot-scope="scope">
  44. <el-popconfirm v-if="scope.row.status" style="margin-right: 10px;" title="确定冻结吗?"
  45. @confirm="changeStatus(scope.row.adminUserId, 0)">
  46. <el-button slot="reference" type="text">冻结</el-button>
  47. </el-popconfirm>
  48. <el-popconfirm v-else style="margin-right: 10px;" title="确定恢复吗?"
  49. @confirm="changeStatus(scope.row.adminUserId, 1)">
  50. <el-button slot="reference" type="text">恢复</el-button>
  51. </el-popconfirm>
  52. <el-button type="text" @click="addOrEdit('edit', scope.row.adminUserId)">编辑</el-button>
  53. <el-button type="text" @click="handleReset(scope.row.adminUserId)">重置密码</el-button>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. </div>
  58. <div class="pagination clearfix">
  59. <div class="fr">
  60. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
  61. :page-sizes="[10, 20, 30, 50]" :page-size="10" layout="total, sizes, prev, pager, next, jumper"
  62. :total="listTotal">
  63. </el-pagination>
  64. </div>
  65. </div>
  66. </div>
  67. <!-- 重置密码 -->
  68. <el-dialog title="重置密码" :visible.sync="resetFormVisible" :show-close="false" width="40%"
  69. :close-on-click-modal="false">
  70. <el-form ref="resetForm" :model="resetForm" :rules="resetFormRules" label-position="left" label-width="100px">
  71. <el-form-item label="输入新密码" prop="newPassword">
  72. <el-input v-model="resetForm.newPassword" ref="password1" autocomplete="off" placeholder="请输入新密码"
  73. :type="passwordType1"></el-input>
  74. <span class="show-pwd" @click="showPwd(1)">
  75. <svg-icon :icon-class="passwordType1 === 'password' ? 'eye' : 'eye-open'" />
  76. </span>
  77. </el-form-item>
  78. <el-form-item label="确认密码" prop="confirmPassword">
  79. <el-input v-model="resetForm.confirmPassword" ref="password2" autocomplete="off" placeholder="请再次输入新密码"
  80. :type="passwordType2"></el-input>
  81. <span class="show-pwd" @click="showPwd(2)">
  82. <svg-icon :icon-class="passwordType2 === 'password' ? 'eye' : 'eye-open'" />
  83. </span>
  84. </el-form-item>
  85. </el-form>
  86. <div slot="footer" class="dialog-footer">
  87. <el-button @click="cancelResetForm">取 消</el-button>
  88. <el-button type="primary" @click="submitResetForm">确 定</el-button>
  89. </div>
  90. </el-dialog>
  91. <!-- 新增编辑账户 -->
  92. <el-dialog :title="addFormType == 'add' ? '新增账户' : '编辑账户'" :visible.sync="addFormVisible" :show-close="false"
  93. width="500px" :close-on-click-modal="false">
  94. <el-form ref="addForm" :model="addForm" :rules="addFormRules" label-position="left" label-width="120px">
  95. <el-form-item label="账号" prop="account">
  96. <el-input v-model="addForm.account" autocomplete="off" placeholder="请输入账号"></el-input>
  97. </el-form-item>
  98. <el-form-item label="用户名" prop="nickName">
  99. <el-input v-model="addForm.nickName" autocomplete="off" placeholder="请输入用户名"></el-input>
  100. </el-form-item>
  101. <el-form-item label="角色组" prop="role">
  102. <el-select v-model="addForm.role" placeholder="请选择角色组" style="width: 100%;">
  103. <el-option :label="item.name" :value="item.adminRoleId" v-for="(item, index) in roleList"
  104. :key="index"></el-option>
  105. </el-select>
  106. </el-form-item>
  107. <el-form-item label="网点" prop="adminWebsitId">
  108. <el-cascader style="width: 100%" :options="departmentList"
  109. :props="{ checkStrictly: true, value: 'websitId', label: 'name' }" v-model="addForm.adminWebsitId" clearable>
  110. </el-cascader>
  111. </el-form-item>
  112. <el-form-item label="密码" prop="newPassword">
  113. <el-input v-model="addForm.newPassword" ref="password1" autocomplete="off" placeholder="请输入密码"
  114. :type="passwordType1"></el-input>
  115. <span class="show-pwd" @click="showPwd(1)">
  116. <svg-icon :icon-class="passwordType1 === 'password' ? 'eye' : 'eye-open'" />
  117. </span>
  118. </el-form-item>
  119. <el-form-item label="确认密码" prop="confirmPassword">
  120. <el-input v-model="addForm.confirmPassword" ref="password2" autocomplete="off" placeholder="请再次输入密码"
  121. :type="passwordType2"></el-input>
  122. <span class="show-pwd" @click="showPwd(2)">
  123. <svg-icon :icon-class="passwordType2 === 'password' ? 'eye' : 'eye-open'" />
  124. </span>
  125. </el-form-item>
  126. <el-form-item label="是否公众号通知" prop="pubNotice">
  127. <el-switch v-model="addForm.pubNotice" active-color="#13ce66" inactive-color="#ff4949">
  128. </el-switch>
  129. </el-form-item>
  130. </el-form>
  131. <div slot="footer" class="dialog-footer">
  132. <el-button @click="cancelAddForm">取 消</el-button>
  133. <el-button type="primary" @click="submitAddForm">确 定</el-button>
  134. </div>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script>
  139. import { getAccountList, getRoleList, changeAccountStatus, resetPassword, addAccount, editAccount, getUserInfo, getDepartmentList, getMerchantList } from '@/api/setting'
  140. export default {
  141. data() {
  142. var validatePass = (rule, value, callback) => {
  143. if (value === '') {
  144. callback(new Error('请输入新密码'));
  145. } else if (value && value.length < 6) {
  146. callback(new Error('密码长度至少6位'));
  147. } else {
  148. if (this.resetForm.confirmPassword !== '') {
  149. this.$refs.resetForm.validateField('confirmPassword');
  150. }
  151. callback();
  152. }
  153. };
  154. var validatePass2 = (rule, value, callback) => {
  155. if (value === '') {
  156. callback(new Error('请再次输入密码'));
  157. } else if (value !== this.resetForm.newPassword) {
  158. callback(new Error('两次输入密码不一致'));
  159. } else {
  160. callback();
  161. }
  162. };
  163. var validatePass3 = (rule, value, callback) => {
  164. if (value === '') {
  165. callback(new Error('请输入新密码'));
  166. } else if (value && value.length < 6) {
  167. callback(new Error('密码长度至少6位'));
  168. } else {
  169. if (this.addForm.confirmPassword !== '') {
  170. this.$refs.addForm.validateField('confirmPassword');
  171. }
  172. callback();
  173. }
  174. };
  175. var validatePass4 = (rule, value, callback) => {
  176. if (value === '') {
  177. callback(new Error('请再次输入密码'));
  178. } else if (value !== this.addForm.newPassword) {
  179. callback(new Error('两次输入密码不一致'));
  180. } else {
  181. callback();
  182. }
  183. };
  184. return {
  185. dataList: null, // 列表数据
  186. listLoading: true, // 列表加载loading
  187. screenForm: { // 筛选表单数据
  188. role: '', // 角色
  189. status: '', // 状态
  190. keyword: '', // 关键词
  191. },
  192. select_status: [ // 筛选字段 - 状态
  193. { label: '正常', value: true },
  194. { label: '冻结', value: false }
  195. ],
  196. currentPage: 1, // 当前页码
  197. pageSize: 10, // 每页数量
  198. listTotal: 0, // 列表总数
  199. roleList: [], // 角色列表
  200. departmentList: [], // 部门列表
  201. props: {
  202. multiple: true,
  203. value: 'id',
  204. label: 'name',
  205. children: 'children',
  206. },
  207. merchantList: [], // 商户列表
  208. resetId: null,
  209. resetFormVisible: false,
  210. resetForm: {
  211. newPassword: '', // 新密码
  212. confirmPassword: '', // 确认密码
  213. },
  214. resetFormRules: {
  215. newPassword: [
  216. { required: true, validator: validatePass, trigger: 'blur' }
  217. ],
  218. confirmPassword: [
  219. { required: true, validator: validatePass2, trigger: 'blur' }
  220. ],
  221. },
  222. editId: null,
  223. addFormType: 'add',
  224. addFormVisible: false,
  225. addForm: {
  226. account: '', // 账号
  227. nickName: '', // 用户名
  228. role: '', // 角色组
  229. adminWebsitId: '',
  230. newPassword: '', // 新密码
  231. confirmPassword: '', // 确认密码
  232. pubNotice: true,
  233. },
  234. addFormRules: {
  235. account: [
  236. { required: true, message: '请输入账号', trigger: 'blur' }
  237. ],
  238. nickName: [
  239. { required: true, message: '请输入用户名', trigger: 'blur' }
  240. ],
  241. role: [
  242. { required: true, message: '请选择角色组', trigger: 'change' }
  243. ],
  244. adminWebsitId: [
  245. { required: true, message: '请选择网点', trigger: 'change' }
  246. ],
  247. newPassword: [
  248. { required: true, validator: validatePass3, trigger: 'blur' }
  249. ],
  250. confirmPassword: [
  251. { required: true, validator: validatePass4, trigger: 'blur' }
  252. ],
  253. },
  254. passwordType1: 'password',
  255. passwordType2: 'password',
  256. }
  257. },
  258. async created() {
  259. await this.getRoleList();
  260. if (this.$route.query.type) {
  261. let index = this.$findElem(this.roleList, 'name', '企业负责人');
  262. this.screenForm.role = this.roleList[index].adminRoleId;
  263. }
  264. this.getList();
  265. },
  266. watch: {
  267. 'addForm.role'() {
  268. if (this.addForm.role) {
  269. let index = this.$findElem(this.roleList, 'adminRoleId', this.addForm.role);
  270. }
  271. }
  272. },
  273. methods: {
  274. getList() {
  275. this.listLoading = true;
  276. let params = {
  277. roleId: this.screenForm.role,
  278. status: this.screenForm.status,
  279. userName: this.screenForm.keyword,
  280. pageNum: this.currentPage,
  281. pageSize: this.pageSize,
  282. ...(() => {
  283. if (this.$route.query.companyWechatId) {
  284. return {
  285. companyWechatId: this.$route.query.companyWechatId
  286. }
  287. }
  288. return {}
  289. })(),
  290. };
  291. getAccountList(params).then(res => {
  292. this.dataList = res.data.records;
  293. this.listTotal = res.data.total;
  294. this.listLoading = false;
  295. })
  296. },
  297. // 筛选后重新获取列表
  298. getListByScreen() {
  299. this.currentPage = 1;
  300. this.getList();
  301. },
  302. // 获取角色列表
  303. async getRoleList() {
  304. const result = await new Promise((resolve, reject) => {
  305. getRoleList({ pageNum: 1, pageSize: 1000 }).then(res => {
  306. this.roleList = res.data.records;
  307. resolve(res.data);
  308. }).catch(res => {
  309. resolve([]);
  310. })
  311. })
  312. return result;
  313. },
  314. // 获取部门列表
  315. async getDepartmentList() {
  316. const result = await new Promise((resolve, reject) => {
  317. getDepartmentList().then(res => {
  318. resolve(res.data);
  319. }).catch(res => {
  320. resolve([]);
  321. })
  322. })
  323. return result;
  324. },
  325. // 更改每页数量
  326. handleSizeChange(val) {
  327. this.pageSize = val;
  328. this.currentPage = 1;
  329. this.getList();
  330. },
  331. // 更改当前页
  332. handleCurrentChange(val) {
  333. this.currentPage = val;
  334. this.getList();
  335. },
  336. // 操作 - 更改状态(type: 禁用0,启用1)
  337. changeStatus(id, type) {
  338. type = type ? true : false
  339. changeAccountStatus({ adminUserId: id, status: type }).then(res => {
  340. this.getList();
  341. this.$successMsg();
  342. })
  343. },
  344. // 显示隐藏密码
  345. showPwd(num) {
  346. if (num == 1) {
  347. if (this.passwordType1 === 'password') {
  348. this.passwordType1 = ''
  349. } else {
  350. this.passwordType1 = 'password'
  351. }
  352. this.$nextTick(() => {
  353. this.$refs.password1.focus()
  354. })
  355. }
  356. if (num == 2) {
  357. if (this.passwordType2 === 'password') {
  358. this.passwordType2 = ''
  359. } else {
  360. this.passwordType2 = 'password'
  361. }
  362. this.$nextTick(() => {
  363. this.$refs.password2.focus()
  364. })
  365. }
  366. },
  367. // 重置密码
  368. handleReset(id) {
  369. this.resetId = id;
  370. this.resetFormVisible = true;
  371. },
  372. // 取消重置密码
  373. cancelResetForm() {
  374. this.resetFormVisible = false;
  375. this.passwordType1 = 'password';
  376. this.passwordType2 = 'password';
  377. this.$refs.resetForm.resetFields();
  378. },
  379. // 提交重置密码
  380. submitResetForm() {
  381. this.$refs.resetForm.validate((valid) => {
  382. if (valid) {
  383. let params = {
  384. password: this.resetForm.newPassword,
  385. adminUserId: this.resetId
  386. }
  387. resetPassword(params).then(res => {
  388. this.cancelResetForm();
  389. this.getList();
  390. this.$successMsg();
  391. })
  392. }
  393. })
  394. },
  395. // 新增编辑 账户
  396. async addOrEdit(type, id) {
  397. this.addFormType = type;
  398. this.addFormVisible = true;
  399. this.departmentList = await this.getDepartmentList();
  400. if (type == 'edit') {
  401. this.editId = id;
  402. getUserInfo({ adminUserId: id }).then(res => {
  403. this.addForm = {
  404. account: res.data.userName,
  405. role: res.data.roleId,
  406. nickName: res.data.nickName,
  407. pubNotice: res.data.pubNotice,
  408. adminWebsitId: res.data.adminWebsitId
  409. }
  410. })
  411. }
  412. },
  413. // 取消 新增编辑账户
  414. cancelAddForm() {
  415. this.addFormVisible = false;
  416. this.passwordType1 = 'password';
  417. this.passwordType2 = 'password';
  418. this.$refs.addForm.resetFields();
  419. },
  420. // 提交 新增编辑账户
  421. submitAddForm() {
  422. this.$refs.addForm.validate((valid) => {
  423. if (valid) {
  424. let adminWebsitId = null
  425. if (this.addForm.adminWebsitId instanceof Array) {
  426. adminWebsitId = this.addForm.adminWebsitId[this.addForm.adminWebsitId.length - 1]
  427. } else {
  428. adminWebsitId = this.addForm.adminWebsitId
  429. }
  430. let params = {
  431. userName: this.addForm.account,
  432. nickName: this.addForm.nickName,
  433. roleId: this.addForm.role,
  434. adminWebsitId: adminWebsitId,
  435. password: this.addForm.newPassword,
  436. pubNotice: this.addForm.pubNotice,
  437. }
  438. if (this.addFormType == 'edit') {
  439. params.adminUserId = this.editId;
  440. editAccount(params).then(res => {
  441. this.cancelAddForm();
  442. this.getList();
  443. this.$successMsg('编辑成功');
  444. })
  445. } else {
  446. addAccount(params).then(res => {
  447. this.cancelAddForm();
  448. this.getList();
  449. this.$successMsg('新增成功');
  450. })
  451. }
  452. }
  453. })
  454. },
  455. }
  456. }
  457. </script>
  458. <style scoped lang="scss">
  459. .show-pwd {
  460. position: absolute;
  461. right: 15px;
  462. top: 0;
  463. font-size: 16px;
  464. cursor: pointer;
  465. user-select: none;
  466. }
  467. </style>