index.vue 23 KB

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