index.vue 19 KB

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