engineeringSubAccount.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <div class="app-container">
  3. <div class="setting_title">工程子账号</div>
  4. <el-divider />
  5. <div class="mymain-container">
  6. <div class="btn-group clearfix">
  7. <div class="fl">
  8. <el-button
  9. v-if="checkBtnRole('add')"
  10. size="small"
  11. type="primary"
  12. icon="el-icon-plus"
  13. @click="addOrEdit('add')"
  14. >新增账号</el-button>
  15. </div>
  16. <!-- <div class="fr">-->
  17. <!-- <ImportButton :im-url="'stock/importToll'" @importSuccess="getList" />-->
  18. <!-- </div>-->
  19. </div>
  20. <div class="table">
  21. <el-table
  22. v-loading="listLoading"
  23. :data="dataList"
  24. element-loading-text="Loading"
  25. border
  26. fit
  27. highlight-current-row
  28. stripe
  29. >
  30. <el-table-column align="left" label="序号" type="index" width="50" />
  31. <el-table-column align="left" label="账号" prop="userName" />
  32. <el-table-column align="left" label="创建时间" prop="createTime" />
  33. <el-table-column align="left" label="最后登录时间" prop="lastLoginTime" />
  34. <el-table-column align="left" label="主帐号" prop="isMaster">
  35. <template slot-scope="scope">
  36. <el-tag v-if="scope.row.isMaster" type="success">是</el-tag>
  37. <el-tag v-else type="danger">否</el-tag>
  38. </template>
  39. </el-table-column>
  40. <el-table-column align="center" label="操作" width="180">
  41. <template slot-scope="scope">
  42. <el-button type="text" @click="addOrEdit('edit', scope.row)">重置密码</el-button>
  43. <!-- <el-button
  44. v-if="checkBtnRole('detail')"
  45. type="text"
  46. @click="setMenuRole(scope.row.adminUserId, 'role')"
  47. >设置权限</el-button> -->
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. </div>
  52. <div class="pagination clearfix">
  53. <div class="fr">
  54. <el-pagination
  55. :current-page="currentPage"
  56. :page-sizes="[10, 20, 30, 50]"
  57. :page-size="10"
  58. layout="total, sizes, prev, pager, next, jumper"
  59. :total="listTotal"
  60. @size-change="handleSizeChange"
  61. @current-change="handleCurrentChange"
  62. />
  63. </div>
  64. </div>
  65. </div>
  66. <!-- 设置权限 -->
  67. <el-dialog
  68. title="设置权限"
  69. :visible.sync="roleFormVisible"
  70. :show-close="false"
  71. width="40%"
  72. :close-on-click-modal="false"
  73. custom-class="tree-dialog"
  74. top="50px"
  75. >
  76. <el-tree
  77. ref="tree"
  78. :data="menuRoleList"
  79. show-checkbox
  80. :check-strictly="true"
  81. :default-expand-all="true"
  82. :expand-on-click-node="false"
  83. node-key="moduleId"
  84. highlight-current
  85. :props="defaultProps"
  86. >
  87. <span slot-scope="{ node, data }" class="custom-tree-node">
  88. <span>{{ node.label }}</span>
  89. <span v-if="data.type < 3">
  90. <el-button type="text" size="mini" @click="() => quickSelection(data)">一键全选</el-button>
  91. <el-button
  92. type="text"
  93. size="mini"
  94. style="color: #f56c6c"
  95. @click="() => quickCancel(data)"
  96. >一键取消</el-button>
  97. </span>
  98. </span>
  99. </el-tree>
  100. <div slot="footer" class="dialog-footer">
  101. <el-button @click="roleFormVisible = false">{{ editId != 1 ? '取 消' : '关 闭' }}</el-button>
  102. <el-button v-if="editId != 1" type="primary" @click="submitRoleForm('role')">确 定</el-button>
  103. </div>
  104. </el-dialog>
  105. <el-dialog
  106. :visible.sync="dialogVisible"
  107. :close-on-click-modal="false"
  108. width="45%"
  109. :title="'add' === addFormType ? '新增' : '修改'"
  110. @close="cancelAddForm"
  111. >
  112. <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
  113. <el-form-item v-if="addFormType !== 'edit'" label="账号" prop="account">
  114. <el-input v-model="ruleForm.account" type="text" autocomplete="off" disabled placeholder="系统自动生成" />
  115. </el-form-item>
  116. <el-form-item v-if="addFormType !== 'edit'" label="子经销商" prop="customerId">
  117. <el-select v-model="ruleForm.customerId" placeholder="请选择子经销商" filterable style="width:100%">
  118. <el-option
  119. v-for="item in subCustomerList"
  120. :key="item.id"
  121. :label="item.name"
  122. :value="item.id"
  123. />
  124. </el-select>
  125. </el-form-item>
  126. <el-form-item label="密码" prop="password">
  127. <el-input v-model="ruleForm.password" type="password" autocomplete="off" />
  128. </el-form-item>
  129. </el-form>
  130. <span slot="footer" class="dialog-footer">
  131. <!-- <el-button type="primary" style="float: left;" @click="setMenuRole">设置权限</el-button>-->
  132. <el-button @click="cancelAddForm">取 消</el-button>
  133. <el-button type="primary" @click="submitAddForm">确 定</el-button>
  134. </span>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script>
  139. import { mapGetters } from 'vuex'
  140. import { getStagecustomerListV2 } from '@/api/basic_data/dealer'
  141. import {
  142. addEngineeringUser,
  143. deleteRole,
  144. editRole,
  145. getEngineeringUserList,
  146. getMenuList,
  147. getRoleChecked,
  148. setMenuRole,
  149. editSubAccount
  150. } from '@/api/setting'
  151. export default {
  152. data() {
  153. return {
  154. imageURL: this.$imageUrl,
  155. dataList: null, // 列表数据
  156. listLoading: true, // 列表加载loading
  157. currentPage: 1, // 当前页码
  158. pageSize: 10, // 每页数量
  159. listTotal: 0, // 列表总数
  160. editId: null,
  161. addFormType: 'add',
  162. addFormVisible: false,
  163. addForm: {
  164. name: '' // 角色名
  165. },
  166. addFormRules: {
  167. name: [{ required: true, message: '请输入角色名', trigger: 'blur' }]
  168. },
  169. roleFormVisible: false,
  170. menuRoleList: [],
  171. defaultProps: {
  172. children: 'children',
  173. label: 'moduleName'
  174. },
  175. dialogVisible: false,
  176. ruleForm: {
  177. account: '',
  178. password: '',
  179. customerId: ''
  180. },
  181. rules: {
  182. password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  183. customerId: [{ required: true, message: '请选择子经销商', trigger: 'blur' }]
  184. },
  185. subCustomerList: []
  186. }
  187. },
  188. computed: {
  189. ...mapGetters(['userid', 'name', 'customerId'])
  190. },
  191. created() {
  192. this.getList()
  193. },
  194. methods: {
  195. // 查询按钮权限
  196. checkBtnRole(value) {
  197. // let btnRole = this.$route.meta.roles;
  198. // if(!btnRole) {return true}
  199. // let index = btnRole.indexOf(value);
  200. // return index >= 0 ? true : false;
  201. return true
  202. },
  203. // 获取子经销商
  204. getStagecustomerListV2() {
  205. getStagecustomerListV2({
  206. pageNum: 1,
  207. pageSize: -1,
  208. params: [
  209. {
  210. param: 'a.jiaxian_type',
  211. compare: '=',
  212. value: 'KING'
  213. }
  214. ]
  215. }).then(res => {
  216. this.subCustomerList = res.data.records
  217. })
  218. },
  219. getList() {
  220. this.listLoading = true
  221. const params = {
  222. pageNum: this.currentPage,
  223. pageSize: this.pageSize,
  224. customerId: this.customerId,
  225. isMaster: false
  226. }
  227. getEngineeringUserList(params).then(res => {
  228. this.dataList = res.data.records
  229. this.listTotal = res.data.total
  230. this.listLoading = false
  231. })
  232. },
  233. // 更改每页数量
  234. handleSizeChange(val) {
  235. this.pageSize = val
  236. this.currentPage = 1
  237. this.getList()
  238. },
  239. // 更改当前页
  240. handleCurrentChange(val) {
  241. this.currentPage = val
  242. this.getList()
  243. },
  244. // 操作 - 删除
  245. handleDelete(id) {
  246. deleteRole({ adminRoleId: id }).then(res => {
  247. this.getList()
  248. this.$successMsg()
  249. })
  250. },
  251. // 新增编辑
  252. addOrEdit(type, row) {
  253. this.addFormType = type
  254. this.dialogVisible = true
  255. if (type === 'edit') {
  256. this.$nextTick(() => {
  257. this.ruleForm = {
  258. account: row.userName,
  259. password: '',
  260. adminUserId: row.adminUserId,
  261. customerId: row.customerId
  262. }
  263. })
  264. }
  265. this.getStagecustomerListV2()
  266. },
  267. // 取消 新增编辑
  268. cancelAddForm() {
  269. this.dialogVisible = false
  270. this.$nextTick(() => {
  271. this.$refs.tree && this.$refs.tree.setCheckedKeys([])
  272. })
  273. this.$refs.ruleForm.resetFields()
  274. },
  275. // 提交 新增编辑
  276. submitAddForm() {
  277. this.$refs.ruleForm.validate(valid => {
  278. const params = {
  279. userName: this.ruleForm.account,
  280. password: this.ruleForm.password,
  281. customerId: this.ruleForm.customerId
  282. // adminModuleIds:this.$refs.tree ? this.$refs.tree.getCheckedKeys().join(',') :
  283. }
  284. if (valid) {
  285. if (this.addFormType === 'edit') {
  286. params.adminUserId = this.ruleForm.adminUserId
  287. editSubAccount(params).then(res => {
  288. this.cancelAddForm()
  289. this.getList()
  290. this.$successMsg('编辑成功')
  291. })
  292. } else {
  293. addEngineeringUser(params).then(res => {
  294. this.cancelAddForm()
  295. this.getList()
  296. this.$successMsg('新增成功')
  297. })
  298. }
  299. }
  300. })
  301. },
  302. // 设置权限 - 获取列表
  303. setMenuRole(id, type) {
  304. this.roleFormVisible = true
  305. this.editId = id
  306. getMenuList({ adminUserId: this.userid }).then(res => {
  307. this.menuRoleList = res.data
  308. })
  309. getRoleChecked({ adminUserId: id }).then(res => {
  310. this.$refs.tree.setCheckedKeys(res.data)
  311. })
  312. },
  313. // 设置权限 - 提交数据
  314. submitRoleForm(type) {
  315. const params = {
  316. adminModuleIds: this.$refs.tree.getCheckedKeys().join(','),
  317. adminRoleId: this.editId
  318. }
  319. setMenuRole(params).then(res => {
  320. this.getList()
  321. this.$successMsg()
  322. })
  323. this.roleFormVisible = false
  324. },
  325. // 一键全选
  326. quickSelection(data) {
  327. const nowChecked = this.$refs.tree.getCheckedKeys()
  328. const thisId = data.moduleId
  329. let childId = []
  330. if (data.children.length) {
  331. childId = this.familyTree(data.children)
  332. }
  333. const setChecked = nowChecked.concat([thisId]).concat(childId)
  334. this.$refs.tree.setCheckedKeys(setChecked)
  335. },
  336. // 一键取消
  337. quickCancel(data) {
  338. const nowChecked = this.$refs.tree.getCheckedKeys()
  339. const thisId = data.moduleId
  340. let childId = []
  341. if (data.children.length) {
  342. childId = this.familyTree(data.children)
  343. }
  344. const setChecked = nowChecked
  345. if (setChecked.indexOf(thisId) >= 0) {
  346. setChecked.splice(setChecked.indexOf(thisId), 1)
  347. }
  348. if (childId.length) {
  349. for (var i = 0; i < childId.length; i++) {
  350. if (setChecked.indexOf(childId[i]) >= 0) {
  351. setChecked.splice(setChecked.indexOf(childId[i]), 1)
  352. }
  353. }
  354. }
  355. this.$refs.tree.setCheckedKeys(setChecked)
  356. },
  357. // 递归子id
  358. familyTree(arr) {
  359. var temp = []
  360. var forFn = function(list) {
  361. for (var i = 0; i < list.length; i++) {
  362. var item = list[i]
  363. if (item.children) {
  364. temp.push(item.moduleId)
  365. forFn(item.children)
  366. }
  367. }
  368. }
  369. forFn(arr)
  370. return temp
  371. },
  372. changeStatus(id, status) {
  373. editRole({
  374. adminRoleId: id,
  375. visitSysStatus: status
  376. }).then(res => {
  377. this.getList()
  378. this.$successMsg('编辑成功')
  379. })
  380. }
  381. }
  382. }
  383. </script>
  384. <style lang="scss" scoped>
  385. ::v-deep .tree-dialog {
  386. .el-dialog__body {
  387. padding: 20px;
  388. .el-tree {
  389. max-height: calc(100vh - 140px - 54px - 70px);
  390. overflow-y: scroll;
  391. padding: 0 30px;
  392. > .el-tree-node {
  393. padding: 15px 0;
  394. border: 1px dashed #ddd;
  395. margin-bottom: 15px;
  396. border-radius: 10px;
  397. }
  398. }
  399. }
  400. }
  401. ::v-deep .custom-tree-node {
  402. flex: 1;
  403. display: flex;
  404. align-items: center;
  405. justify-content: space-between;
  406. font-size: 14px;
  407. padding-right: 8px;
  408. }
  409. </style>