index.vue 19 KB

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