jiaxianSubAccount.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 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. addJiaXianUser,
  143. deleteRole,
  144. editRole,
  145. getJiaXianUserList,
  146. getMenuList,
  147. getRoleChecked,
  148. setMenuRole,
  149. changePassword
  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.higher_prant_number',
  211. // compare: 'like',
  212. // value: this.customerId
  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. getJiaXianUserList(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. changePassword({
  287. userName: this.ruleForm.account,
  288. password: this.ruleForm.password,
  289. newPassword: this.ruleForm.password
  290. }).then(res => {
  291. this.cancelAddForm()
  292. this.getList()
  293. this.$successMsg('编辑成功')
  294. })
  295. } else {
  296. addJiaXianUser(params).then(res => {
  297. this.cancelAddForm()
  298. this.getList()
  299. this.$successMsg('新增成功')
  300. })
  301. }
  302. }
  303. })
  304. },
  305. // 设置权限 - 获取列表
  306. setMenuRole(id, type) {
  307. this.roleFormVisible = true
  308. this.editId = id
  309. getMenuList({ adminUserId: this.userid }).then(res => {
  310. this.menuRoleList = res.data
  311. })
  312. getRoleChecked({ adminUserId: id }).then(res => {
  313. this.$refs.tree.setCheckedKeys(res.data)
  314. })
  315. },
  316. // 设置权限 - 提交数据
  317. submitRoleForm(type) {
  318. const params = {
  319. adminModuleIds: this.$refs.tree.getCheckedKeys().join(','),
  320. adminRoleId: this.editId
  321. }
  322. setMenuRole(params).then(res => {
  323. this.getList()
  324. this.$successMsg()
  325. })
  326. this.roleFormVisible = false
  327. },
  328. // 一键全选
  329. quickSelection(data) {
  330. const nowChecked = this.$refs.tree.getCheckedKeys()
  331. const thisId = data.moduleId
  332. let childId = []
  333. if (data.children.length) {
  334. childId = this.familyTree(data.children)
  335. }
  336. const setChecked = nowChecked.concat([thisId]).concat(childId)
  337. this.$refs.tree.setCheckedKeys(setChecked)
  338. },
  339. // 一键取消
  340. quickCancel(data) {
  341. const nowChecked = this.$refs.tree.getCheckedKeys()
  342. const thisId = data.moduleId
  343. let childId = []
  344. if (data.children.length) {
  345. childId = this.familyTree(data.children)
  346. }
  347. const setChecked = nowChecked
  348. if (setChecked.indexOf(thisId) >= 0) {
  349. setChecked.splice(setChecked.indexOf(thisId), 1)
  350. }
  351. if (childId.length) {
  352. for (var i = 0; i < childId.length; i++) {
  353. if (setChecked.indexOf(childId[i]) >= 0) {
  354. setChecked.splice(setChecked.indexOf(childId[i]), 1)
  355. }
  356. }
  357. }
  358. this.$refs.tree.setCheckedKeys(setChecked)
  359. },
  360. // 递归子id
  361. familyTree(arr) {
  362. var temp = []
  363. var forFn = function(list) {
  364. for (var i = 0; i < list.length; i++) {
  365. var item = list[i]
  366. if (item.children) {
  367. temp.push(item.moduleId)
  368. forFn(item.children)
  369. }
  370. }
  371. }
  372. forFn(arr)
  373. return temp
  374. },
  375. changeStatus(id, status) {
  376. editRole({
  377. adminRoleId: id,
  378. visitSysStatus: status
  379. }).then(res => {
  380. this.getList()
  381. this.$successMsg('编辑成功')
  382. })
  383. }
  384. }
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. ::v-deep .tree-dialog {
  389. .el-dialog__body {
  390. padding: 20px;
  391. .el-tree {
  392. max-height: calc(100vh - 140px - 54px - 70px);
  393. overflow-y: scroll;
  394. padding: 0 30px;
  395. > .el-tree-node {
  396. padding: 15px 0;
  397. border: 1px dashed #ddd;
  398. margin-bottom: 15px;
  399. border-radius: 10px;
  400. }
  401. }
  402. }
  403. }
  404. ::v-deep .custom-tree-node {
  405. flex: 1;
  406. display: flex;
  407. align-items: center;
  408. justify-content: space-between;
  409. font-size: 14px;
  410. padding-right: 8px;
  411. }
  412. </style>