engineeringSubAccount.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <div class="app-container">
  3. <div class="setting_title">用户管理</div>
  4. <el-divider />
  5. <div class="mymain-container">
  6. <Collapse :screen-form="screenForm">
  7. <template #right_btn>
  8. <el-button size="mini" @click="resetScreenForm">清空</el-button>
  9. <el-button size="mini" type="primary" @click="submitScreenForm">搜索</el-button>
  10. </template>
  11. <template #search>
  12. <el-form ref="screenForm" :model="screenForm" label-width="150px" size="mini" label-position="left">
  13. <el-row :gutter="20">
  14. <el-col :xs="24" :sm="12" :lg="8">
  15. <el-form-item label="账号/用户名名称:" prop="userName">
  16. <el-input v-model="screenForm.userName" placeholder="请输入账号/用户名名称" />
  17. </el-form-item>
  18. </el-col>
  19. </el-row>
  20. </el-form>
  21. </template>
  22. </Collapse>
  23. <div class="btn-group clearfix">
  24. <div style="display: flex">
  25. <el-button v-if="checkBtnRole('add')" size="mini" type="primary" @click="addOrEdit('add')"
  26. >新增账号</el-button
  27. >
  28. <el-button style="margin-left: 20px" type="primary" size="mini" @click="handleExportListGongCheng"
  29. >导出数据</el-button
  30. >
  31. </div>
  32. <!-- <div class="fr">-->
  33. <!-- <ImportButton :im-url="'stock/importToll'" @importSuccess="getList" />-->
  34. <!-- </div>-->
  35. </div>
  36. <div class="table">
  37. <el-table
  38. v-loading="listLoading"
  39. :data="dataList"
  40. element-loading-text="Loading"
  41. border
  42. fit
  43. highlight-current-row
  44. stripe
  45. >
  46. <el-table-column align="left" label="序号" type="index" width="50" />
  47. <el-table-column align="left" label="账号" prop="userName" />
  48. <el-table-column align="left" label="账号名称" prop="nickName" />
  49. <el-table-column align="left" label="创建时间" prop="createTime" />
  50. <el-table-column align="left" label="最后登录时间" prop="lastLoginTime" />
  51. <el-table-column align="left" label="主帐号" prop="isMaster">
  52. <template slot-scope="scope">
  53. <el-tag v-if="scope.row.isMaster" type="success">是</el-tag>
  54. <el-tag v-else type="danger">否</el-tag>
  55. </template>
  56. </el-table-column>
  57. <el-table-column align="center" label="操作" width="180">
  58. <template slot-scope="scope">
  59. <el-button type="text" @click="addOrEdit('edit', scope.row)">编辑</el-button>
  60. <el-button type="text" @click="addOrEdit('password', scope.row)">重置密码</el-button>
  61. <el-popconfirm title="确定删除吗?" @onConfirm="handleDel(scope.row)">
  62. <el-button slot="reference" type="text" size="mini"> 删除 </el-button>
  63. </el-popconfirm>
  64. <!-- <el-button
  65. v-if="checkBtnRole('detail')"
  66. type="text"
  67. @click="setMenuRole(scope.row.adminUserId, 'role')"
  68. >设置权限</el-button> -->
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. </div>
  73. <div class="pagination clearfix">
  74. <div class="fr">
  75. <el-pagination
  76. :current-page="currentPage"
  77. :page-sizes="[10, 20, 30, 50]"
  78. :page-size="10"
  79. layout="total, sizes, prev, pager, next, jumper"
  80. :total="listTotal"
  81. @size-change="handleSizeChange"
  82. @current-change="handleCurrentChange"
  83. />
  84. </div>
  85. </div>
  86. </div>
  87. <!-- 设置权限 -->
  88. <el-dialog
  89. title="设置权限"
  90. :visible.sync="roleFormVisible"
  91. :show-close="false"
  92. width="40%"
  93. :close-on-click-modal="false"
  94. custom-class="tree-dialog"
  95. top="50px"
  96. >
  97. <el-tree
  98. ref="tree"
  99. :data="menuRoleList"
  100. show-checkbox
  101. :check-strictly="true"
  102. :default-expand-all="true"
  103. :expand-on-click-node="false"
  104. node-key="moduleId"
  105. highlight-current
  106. :props="defaultProps"
  107. >
  108. <span slot-scope="{ node, data }" class="custom-tree-node">
  109. <span>{{ node.label }}</span>
  110. <span v-if="data.type < 3">
  111. <el-button type="text" size="mini" @click="() => quickSelection(data)">一键全选</el-button>
  112. <el-button type="text" size="mini" style="color: #f56c6c" @click="() => quickCancel(data)"
  113. >一键取消</el-button
  114. >
  115. </span>
  116. </span>
  117. </el-tree>
  118. <div slot="footer" class="dialog-footer">
  119. <el-button @click="roleFormVisible = false">{{ editId != 1 ? '取 消' : '关 闭' }}</el-button>
  120. <el-button v-if="editId != 1" type="primary" @click="submitRoleForm('role')">确 定</el-button>
  121. </div>
  122. </el-dialog>
  123. <el-dialog
  124. :visible.sync="dialogVisible"
  125. :close-on-click-modal="false"
  126. width="45%"
  127. :title="'add' === addFormType ? '新增' : '修改'"
  128. @close="cancelAddForm"
  129. >
  130. <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="140px" class="demo-ruleForm">
  131. <el-form-item label="账号" prop="account">
  132. <el-input v-model="ruleForm.account" type="text" autocomplete="off" disabled placeholder="系统自动生成" />
  133. </el-form-item>
  134. <template v-if="addFormType !== 'password'">
  135. <el-form-item label="工装登录名额限制" prop="workLoginLimit">
  136. <el-input
  137. type="number"
  138. v-model.number="ruleForm.workLoginLimit"
  139. autocomplete="off"
  140. placeholder="请输入工装登录名额限制"
  141. />
  142. </el-form-item>
  143. <el-form-item label="家装登录名额限制" prop="homeLoginLimit">
  144. <el-input
  145. type="number"
  146. v-model.number="ruleForm.homeLoginLimit"
  147. autocomplete="off"
  148. placeholder="请输入家装登录名额限制"
  149. />
  150. </el-form-item>
  151. <el-form-item label="跨区登录名额限制" prop="spanLoginLimit">
  152. <el-input
  153. type="number"
  154. v-model.number="ruleForm.spanLoginLimit"
  155. autocomplete="off"
  156. placeholder="请输入跨区登录名额限制"
  157. />
  158. </el-form-item>
  159. <el-form-item label="上级经销商" prop="parentId">
  160. <el-select
  161. v-model="ruleForm.parentId"
  162. placeholder="请选择上级经销商"
  163. :disabled="addFormType === 'edit'"
  164. filterable
  165. style="width: 100%"
  166. >
  167. <el-option v-for="item in subCustomerList" :key="item.id" :label="item.name" :value="item.id" />
  168. </el-select>
  169. </el-form-item>
  170. <el-form-item label="子经销商名称" prop="nickName">
  171. <el-input v-model="ruleForm.nickName" autocomplete="off" placeholder="请输入子经销商名称" />
  172. </el-form-item>
  173. </template>
  174. <el-form-item v-if="addFormType !== 'edit'" label="密码" prop="password">
  175. <el-input v-model="ruleForm.password" type="password" autocomplete="off" placeholder="请输入密码" />
  176. </el-form-item>
  177. </el-form>
  178. <span slot="footer" class="dialog-footer">
  179. <!-- <el-button type="primary" style="float: left;" @click="setMenuRole">设置权限</el-button>-->
  180. <el-button @click="cancelAddForm">取 消</el-button>
  181. <el-button type="primary" @click="submitAddForm">确 定</el-button>
  182. </span>
  183. </el-dialog>
  184. </div>
  185. </template>
  186. <script>
  187. import { mapGetters } from 'vuex'
  188. import { getDealerListV2 } from '@/api/basic_data/dealer'
  189. import {
  190. addEngineeringUser,
  191. deleteRole,
  192. editRole,
  193. getEngineeringUserList,
  194. getMenuList,
  195. getRoleChecked,
  196. setMenuRole,
  197. editSubAccount,
  198. editEngineeringUser,
  199. getDetailGongCheng,
  200. delUserGongCheng,
  201. exportListGongCheng
  202. } from '@/api/setting'
  203. export default {
  204. data() {
  205. return {
  206. imageURL: this.$imageUrl,
  207. dataList: null, // 列表数据
  208. listLoading: true, // 列表加载loading
  209. currentPage: 1, // 当前页码
  210. pageSize: 10, // 每页数量
  211. listTotal: 0, // 列表总数
  212. editId: null,
  213. addFormType: 'add',
  214. addFormVisible: false,
  215. addForm: {
  216. name: '' // 角色名
  217. },
  218. addFormRules: {
  219. name: [{ required: true, message: '请输入角色名', trigger: 'blur' }]
  220. },
  221. roleFormVisible: false,
  222. menuRoleList: [],
  223. defaultProps: {
  224. children: 'children',
  225. label: 'moduleName'
  226. },
  227. dialogVisible: false,
  228. ruleForm: {
  229. account: '',
  230. password: '',
  231. parentId: '',
  232. nickName: '',
  233. spanLoginLimit: 5,
  234. homeLoginLimit: 5,
  235. workLoginLimit: 5
  236. },
  237. rules: {
  238. password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  239. parentId: [{ required: true, message: '请选择上级经销商', trigger: 'change' }],
  240. nickName: [{ required: true, message: '请输入子经销商名称', trigger: 'blur' }]
  241. },
  242. subCustomerList: [],
  243. screenForm: {
  244. // 筛选表单数据
  245. userName: '' // 名称
  246. }
  247. }
  248. },
  249. computed: {
  250. ...mapGetters(['userid', 'name', 'parentId']),
  251. exParams() {
  252. return {
  253. pageNum: this.currentPage,
  254. pageSize: this.pageSize,
  255. parentId: this.parentId,
  256. userName: this.screenForm.userName,
  257. isMaster: false
  258. }
  259. }
  260. },
  261. created() {
  262. this.getList()
  263. },
  264. methods: {
  265. // 查询按钮权限
  266. checkBtnRole(value) {
  267. // let btnRole = this.$route.meta.roles;
  268. // if(!btnRole) {return true}
  269. // let index = btnRole.indexOf(value);
  270. // return index >= 0 ? true : false;
  271. return true
  272. },
  273. // 获取子经销商
  274. getDealerListV2() {
  275. getDealerListV2({
  276. pageNum: 1,
  277. pageSize: -1
  278. }).then(res => {
  279. this.subCustomerList = res.data.records
  280. })
  281. },
  282. handleExportListGongCheng() {
  283. exportListGongCheng({}, `${this.$route.meta.title}`)
  284. .then(res => {
  285. console.log('chengg')
  286. this.$message({
  287. message: '下载成功',
  288. type: 'success'
  289. })
  290. })
  291. .catch(err => {
  292. this.$message.error('下载失败')
  293. })
  294. },
  295. getList() {
  296. this.listLoading = true
  297. const params = {
  298. pageNum: this.currentPage,
  299. pageSize: this.pageSize,
  300. parentId: this.parentId,
  301. userName: this.screenForm.userName,
  302. isMaster: false
  303. }
  304. getEngineeringUserList(params).then(res => {
  305. this.dataList = res.data.records
  306. this.listTotal = res.data.total
  307. this.listLoading = false
  308. })
  309. },
  310. // 更改每页数量
  311. handleSizeChange(val) {
  312. this.pageSize = val
  313. this.currentPage = 1
  314. this.getList()
  315. },
  316. // 更改当前页
  317. handleCurrentChange(val) {
  318. this.currentPage = val
  319. this.getList()
  320. },
  321. // 操作 - 删除
  322. handleDelete(id) {
  323. deleteRole({ adminRoleId: id }).then(res => {
  324. this.getList()
  325. this.$successMsg()
  326. })
  327. },
  328. handleDel(row) {
  329. delUserGongCheng({ userName: row.userName }).then(res => {
  330. this.$successMsg('删除成功')
  331. this.getList()
  332. })
  333. },
  334. // 新增编辑
  335. addOrEdit(type, row) {
  336. this.addFormType = type
  337. if (row) {
  338. getDetailGongCheng({ adminUserId: row.adminUserId }).then(res => {
  339. if (type === 'edit') {
  340. this.ruleForm = {
  341. account: res.data.userName,
  342. password: '',
  343. nickName: res.data.nickName,
  344. adminUserId: res.data.adminUserId,
  345. parentId: res.data.parentId,
  346. spanLoginLimit: res.data.spanLoginLimit,
  347. homeLoginLimit: res.data.homeLoginLimit,
  348. workLoginLimit: res.data.workLoginLimit
  349. }
  350. }
  351. if (type === 'password') {
  352. this.ruleForm = {
  353. account: res.data.userName,
  354. password: '',
  355. adminUserId: res.data.adminUserId
  356. }
  357. }
  358. })
  359. }
  360. this.dialogVisible = true
  361. this.getDealerListV2()
  362. },
  363. // 取消 新增编辑
  364. cancelAddForm() {
  365. this.$refs.ruleForm.resetFields()
  366. this.$nextTick(() => {
  367. this.dialogVisible = false
  368. })
  369. },
  370. // 提交 新增编辑
  371. submitAddForm() {
  372. this.$refs.ruleForm.validate(valid => {
  373. const params = {
  374. userName: this.ruleForm.account,
  375. password: this.ruleForm.password,
  376. parentId: this.ruleForm.parentId,
  377. nickName: this.ruleForm.nickName,
  378. spanLoginLimit: this.ruleForm.spanLoginLimit,
  379. homeLoginLimit: this.ruleForm.homeLoginLimit,
  380. workLoginLimit: this.ruleForm.workLoginLimit
  381. // adminModuleIds:this.$refs.tree ? this.$refs.tree.getCheckedKeys().join(',') :
  382. }
  383. if (valid) {
  384. if (this.addFormType === 'password') {
  385. params.adminUserId = this.ruleForm.adminUserId
  386. editSubAccount(params).then(res => {
  387. this.cancelAddForm()
  388. this.getList()
  389. this.$successMsg('重置成功')
  390. })
  391. }
  392. if (this.addFormType === 'edit') {
  393. params.adminUserId = this.ruleForm.adminUserId
  394. editEngineeringUser(params).then(res => {
  395. this.cancelAddForm()
  396. this.getList()
  397. this.$successMsg('编辑成功')
  398. })
  399. }
  400. if (this.addFormType === 'add') {
  401. addEngineeringUser(params).then(res => {
  402. this.cancelAddForm()
  403. this.getList()
  404. this.$successMsg('新增成功')
  405. })
  406. }
  407. }
  408. })
  409. },
  410. // 设置权限 - 获取列表
  411. setMenuRole(id, type) {
  412. this.roleFormVisible = true
  413. this.editId = id
  414. getMenuList({ adminUserId: this.userid }).then(res => {
  415. this.menuRoleList = res.data
  416. })
  417. getRoleChecked({ adminUserId: id }).then(res => {
  418. this.$refs.tree.setCheckedKeys(res.data)
  419. })
  420. },
  421. // 设置权限 - 提交数据
  422. submitRoleForm(type) {
  423. const params = {
  424. adminModuleIds: this.$refs.tree.getCheckedKeys().join(','),
  425. adminRoleId: this.editId
  426. }
  427. setMenuRole(params).then(res => {
  428. this.getList()
  429. this.$successMsg()
  430. })
  431. this.roleFormVisible = false
  432. },
  433. // 一键全选
  434. quickSelection(data) {
  435. const nowChecked = this.$refs.tree.getCheckedKeys()
  436. const thisId = data.moduleId
  437. let childId = []
  438. if (data.children.length) {
  439. childId = this.familyTree(data.children)
  440. }
  441. const setChecked = nowChecked.concat([thisId]).concat(childId)
  442. this.$refs.tree.setCheckedKeys(setChecked)
  443. },
  444. // 一键取消
  445. quickCancel(data) {
  446. const nowChecked = this.$refs.tree.getCheckedKeys()
  447. const thisId = data.moduleId
  448. let childId = []
  449. if (data.children.length) {
  450. childId = this.familyTree(data.children)
  451. }
  452. const setChecked = nowChecked
  453. if (setChecked.indexOf(thisId) >= 0) {
  454. setChecked.splice(setChecked.indexOf(thisId), 1)
  455. }
  456. if (childId.length) {
  457. for (var i = 0; i < childId.length; i++) {
  458. if (setChecked.indexOf(childId[i]) >= 0) {
  459. setChecked.splice(setChecked.indexOf(childId[i]), 1)
  460. }
  461. }
  462. }
  463. this.$refs.tree.setCheckedKeys(setChecked)
  464. },
  465. // 递归子id
  466. familyTree(arr) {
  467. var temp = []
  468. var forFn = function (list) {
  469. for (var i = 0; i < list.length; i++) {
  470. var item = list[i]
  471. if (item.children) {
  472. temp.push(item.moduleId)
  473. forFn(item.children)
  474. }
  475. }
  476. }
  477. forFn(arr)
  478. return temp
  479. },
  480. changeStatus(id, status) {
  481. editRole({
  482. adminRoleId: id,
  483. visitSysStatus: status
  484. }).then(res => {
  485. this.getList()
  486. this.$successMsg('编辑成功')
  487. })
  488. },
  489. // 提交筛选表单
  490. submitScreenForm() {
  491. this.currentPage = 1
  492. this.getList()
  493. },
  494. // 重置筛选表单
  495. resetScreenForm() {
  496. this.$refs.screenForm.resetFields()
  497. this.currentPage = 1
  498. this.getList()
  499. }
  500. }
  501. }
  502. </script>
  503. <style lang="scss" scoped>
  504. ::v-deep .tree-dialog {
  505. .el-dialog__body {
  506. padding: 20px;
  507. .el-tree {
  508. max-height: calc(100vh - 140px - 54px - 70px);
  509. overflow-y: scroll;
  510. padding: 0 30px;
  511. > .el-tree-node {
  512. padding: 15px 0;
  513. border: 1px dashed #ddd;
  514. margin-bottom: 15px;
  515. border-radius: 10px;
  516. }
  517. }
  518. }
  519. }
  520. ::v-deep .custom-tree-node {
  521. flex: 1;
  522. display: flex;
  523. align-items: center;
  524. justify-content: space-between;
  525. font-size: 14px;
  526. padding-right: 8px;
  527. }
  528. </style>