index.vue 20 KB

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