organizationEdit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 11:26:07
  4. * @LastEditTime: 2022-04-11 14:35:27
  5. * @LastEditors: your name
  6. * @Description:新增组织
  7. * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\authorityPower.vue
  8. -->
  9. <template>
  10. <div class="authorityPower">
  11. <!--新增组织-->
  12. <div class="addApp-form">
  13. <div class="addApp-form-title flex">
  14. <div class="title">编辑组织</div>
  15. <div v-is="['organ_btn_edit']" class="btn">
  16. <el-button @click="saveBtn('form')" type="primary">保存</el-button>
  17. </div>
  18. </div>
  19. <div class="addApp-form-content dialog-public-background">
  20. <el-form :inline="true" ref="form" :rules="rules" class="form" :model="form">
  21. <el-form-item prop="name" label="组织名称">
  22. <el-input placeholder="请输入组织名称" v-model.trim="form.name"></el-input>
  23. </el-form-item>
  24. <el-form-item prop="id" label="组织类型">
  25. <el-select v-model="form.id" placeholder="请选择">
  26. <el-option label="集团内" :value="1"></el-option>
  27. <el-option label="集团外" :value="0"></el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item prop="desc" label="描述">
  31. <el-input style="width: 1050px" placeholder="请输入描述" v-model.trim="form.desc"></el-input>
  32. </el-form-item>
  33. <div class="top24">
  34. <el-form-item class="oneCode" prop="oneCode" label="1级编码">
  35. <el-input placeholder="请输入编码" v-model.trim="form.oneCode"></el-input>
  36. </el-form-item>
  37. <el-form-item prop="twoCode" class="twoCode" label="2级编码">
  38. <el-input placeholder="请输入编码" style="width: 202px" v-model.trim="form.twoCode"></el-input>
  39. </el-form-item>
  40. <el-form-item prop="threeCode" label="3级编码">
  41. <el-input placeholder="请输入编码" v-model.trim="form.threeCode"></el-input>
  42. </el-form-item>
  43. <el-form-item prop="fourCode" label="4级编码">
  44. <el-input placeholder="请输入编码" v-model.trim="form.fourCode"></el-input>
  45. </el-form-item>
  46. <el-form-item prop="fiveCode" label="5级编码">
  47. <el-input placeholder="请输入编码" v-model.trim="form.fiveCode"></el-input>
  48. </el-form-item>
  49. <el-form-item prop="bmCode" label="编码类型">
  50. <el-input placeholder="请输入编码类型" v-model.trim="form.bmCode"></el-input>
  51. </el-form-item>
  52. </div>
  53. </el-form>
  54. </div>
  55. </div>
  56. <div class="power-content flex-wrap">
  57. <div class="flex1 part">
  58. <Organization :defaultProps="defaultProps" :data="data" node-key="OrganId" up-node-key="OrganUpid" @getTreeData="getTreeData" :checkedKeys="checkedKeys" :orgList="orgList" title="上级组织" />
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import Permissiontree from "@/components/permissiontree";
  65. import Rulesofcompetency from "@/components/rulesofcompetency";
  66. import Organization from "@/components/organization";
  67. import Permissionlist from "@/components/permissionlist";
  68. import Rolelist from "@/components/rolelist";
  69. import treeData from "../minixs/treeData";
  70. import roleData from "../minixs/roleData";
  71. import { mapGetters } from "vuex";
  72. import { RoleAuths } from "@/api/apiAuthority";
  73. import { newOrganmod, newOrganall } from "@/api/postInterface";
  74. import { lengthValidator, checkDx } from '@/utils/validate'
  75. export default {
  76. name: "AuthorityPower",
  77. mixins: [treeData, roleData],
  78. components: {
  79. Rulesofcompetency,
  80. Organization,
  81. Permissiontree,
  82. Permissionlist,
  83. Rolelist,
  84. },
  85. data () {
  86. return {
  87. Status: null,
  88. AppId: null,
  89. form: {
  90. //应用表单
  91. name: "",
  92. id: "",
  93. desc: "",
  94. oneCode: "",
  95. twoCode: "",
  96. threeCode: "",
  97. fourCode: "",
  98. fiveCode: "",
  99. bmCode: ""
  100. },
  101. title: "角色",
  102. rules: {
  103. //表单验证
  104. name: [
  105. { required: true, message: "请输入组织名称", trigger: "blur" },
  106. { validator: lengthValidator, max: 128, message: '长度在 1 到 128 个字符', trigger: ['change', 'blur'] }
  107. ],
  108. id: [{ required: true, message: "请输入标识符", trigger: "blur" }],
  109. desc: [{ validator: lengthValidator, max: 256, message: '长度在 1 到 256 个字符', trigger: ['change', 'blur'] }],
  110. oneCode: [
  111. { required: true, message: "请输入组织名称", trigger: "blur" },
  112. { validator: lengthValidator, max: 2, message: '长度在 1 到 2 个字符', trigger: ['change', 'blur'] }],
  113. twoCode: [{ validator: lengthValidator, max: 3, message: '长度在 1 到 3 个字符', trigger: ['change', 'blur'] }],
  114. threeCode: [{ validator: lengthValidator, max: 8, message: '长度在 1 到 8 个字符', trigger: ['change', 'blur'] }],
  115. fourCode: [{ validator: lengthValidator, max: 2, message: '长度在 1 到 2 个字符', trigger: ['change', 'blur'] }],
  116. fiveCode: [{ validator: lengthValidator, max: 2, message: '长度在 1 到 2 个字符', trigger: ['change', 'blur'] }],
  117. bmCode: [
  118. { validator: lengthValidator, max: 1, message: '长度在 1 个字符', trigger: ['change', 'blur'] },
  119. { validator: checkDx, trigger: ['change', 'blur'] }
  120. ],
  121. },
  122. defaultProps: {
  123. children: "children",
  124. label: "OrganName",
  125. },
  126. queryType: null,
  127. checkBoxList: [], //角色列表选中
  128. Status: null,
  129. OrganUpid: null,
  130. checkedKeys: [], //上级组织选中
  131. RoleList: [],
  132. checkedBoxs: [],
  133. arrs: [],
  134. authId: [], //权限树默认选中ID
  135. authList: [],
  136. authTo: {},
  137. openRole: null,
  138. OpenGroup: null,
  139. dataObj: {}, //上级权限指定树数据
  140. data: [], //上级权限
  141. roleList: [], //角色
  142. checkRoles: [], //选中的角色
  143. checkTrees: [], //上级权限选中树数据
  144. rulesObj: {}, //权限规则数据
  145. upRoleList: [],
  146. orgList: []
  147. };
  148. },
  149. computed: {
  150. ...mapGetters(["systemSet"]),
  151. },
  152. watch: {
  153. //监听上级组织数据
  154. dataList: {
  155. handler (val) {
  156. const arr = [val];
  157. // this.data = arr;
  158. this.decompose(arr, this.AppId);
  159. this.data = arr;
  160. this.checkedKeys = [this.OrganUpid];
  161. },
  162. deep: true,
  163. },
  164. arrs: {
  165. handler (arr) {
  166. if (this.openRole) {
  167. this.defaultChecked(arr, "RoleId");
  168. } else if (this.OpenGroup) {
  169. this.defaultChecked(arr, "GroupId");
  170. }
  171. },
  172. deep: true,
  173. },
  174. },
  175. created () {
  176. const { OrganId, OrganUpid } = this.$route.query;
  177. const { OpenRole, OpenGroup } =
  178. typeof this.systemSet === "string"
  179. ? JSON.parse(this.systemSet)
  180. : this.systemSet; //1是请求角色 0是请求用户
  181. this.OrganUpid = OrganUpid;
  182. this.AppId = OrganId;
  183. this.openRole = OpenRole;
  184. this.OpenGroup = OpenGroup;
  185. this.getOrganTree();
  186. this.getOrganDetails(this.AppId);
  187. },
  188. methods: {
  189. //获取选中的树数据
  190. getTreeData (arr) {
  191. if (arr.length === 1) {
  192. const { OrganId } = arr[0];
  193. this.OrganUpid = OrganId;
  194. } else if (arr.length === 0) {
  195. this.OrganUpid = -1
  196. }
  197. },
  198. //获取指定数据
  199. decompose (data, id) {
  200. for (let i = 0; i < data.length; i++) {
  201. if (data[i].OrganId == id) {
  202. if (data[i].children && data[i].children.length) {
  203. data.splice(i, 1);
  204. } else {
  205. data.splice(i, 1);
  206. }
  207. this.dataObj = data[i];
  208. } else if (data[i].children && data[i].children.length > 0) {
  209. this.decompose(data[i].children, id);
  210. }
  211. }
  212. },
  213. // 默认选中
  214. defaultChecked (arr, id) {
  215. const datas = [];
  216. arr.forEach((item, index) => {
  217. this.checkRoles.forEach((p) => {
  218. if (item[id] == p[id]) {
  219. datas.push(index);
  220. }
  221. });
  222. });
  223. this.checkBoxList = datas;
  224. },
  225. //权限树点击
  226. nodeClick (obj) {
  227. const arr = this.$store.getters.authArrs;
  228. arr.push(obj);
  229. this.$store.dispatch("auth/changeAuthArrs", arr);
  230. },
  231. //角色点击回调
  232. checkClick (item) {
  233. this.roleAuths(item.RoleId);
  234. },
  235. //岗位点击回调
  236. checkGroup (item) {
  237. this.groupAuths(item.GroupId);
  238. },
  239. //根据角色查看权限列表
  240. async roleAuths (id) {
  241. try {
  242. let params = {
  243. RoleId: id,
  244. };
  245. const res = await RoleAuths(params);
  246. if (res.code === 0) {
  247. this.RoleList = res.returnData;
  248. } else {
  249. this.$message.error(res.message);
  250. }
  251. } catch (error) {
  252. console.log("出错了", error);
  253. }
  254. },
  255. //组织详情查询
  256. async getOrganDetails (id) {
  257. try {
  258. let params = {
  259. OrganId: id,
  260. };
  261. const res = await newOrganall(params);
  262. if (res.code === 0) {
  263. const {
  264. AuthList,
  265. OrganDesc,
  266. OrganName,
  267. OrganType,
  268. RoleList,
  269. Status,
  270. GroupList,
  271. L1,
  272. L2,
  273. L3,
  274. L4,
  275. L5,
  276. Type
  277. } = res.returnData;
  278. this.form.name = OrganName;
  279. this.form.id = Number(OrganType);
  280. this.form.desc = OrganDesc;
  281. this.form.oneCode = L1;
  282. this.form.twoCode = L2;
  283. this.form.threeCode = L3;
  284. this.form.fourCode = L4;
  285. this.form.fiveCode = L5;
  286. this.form.bmCode = Type;
  287. this.Status = Status;
  288. if (AuthList && AuthList.length) {
  289. AuthList.forEach((item) => {
  290. this.authId.push(item.AuthId);
  291. });
  292. this.authList = _.cloneDeep(AuthList);
  293. this.authTo = AuthList[0];
  294. this.checkedBoxs = this.authId;
  295. }
  296. if (RoleList && RoleList.length) {
  297. const [checkRoles, checkBoxs] = [[], []];
  298. RoleList.forEach((item, index) => {
  299. if (item.IsSelected == 1) {
  300. checkRoles.push(item);
  301. checkBoxs.push(index);
  302. }
  303. });
  304. if (checkRoles.length && checkBoxs.length) {
  305. this.checkRoles = checkRoles;
  306. this.roleAuths(RoleList[0].RoleId);
  307. }
  308. }
  309. if (GroupList && GroupList.length) {
  310. const [checkRoles, checkBoxs] = [[], []];
  311. GroupList.forEach((item, index) => {
  312. if (item.IsSelected == 1) {
  313. checkRoles.push(item);
  314. checkBoxs.push(index);
  315. }
  316. });
  317. if (checkRoles.length && checkBoxs.length) {
  318. this.checkRoles = checkRoles;
  319. this.groupAuths(GroupList[0].GroupId);
  320. }
  321. }
  322. } else {
  323. this.$message.error(res.message);
  324. }
  325. } catch (error) {
  326. console.log("出错了", error);
  327. }
  328. },
  329. //角色选取
  330. checkChange (arr) {
  331. const datas = [];
  332. for (let i = 0; i < arr.length; i++) {
  333. datas.push(this.arrs[arr[i]]);
  334. }
  335. datas.forEach((item) => {
  336. item.IsSelected = "1";
  337. });
  338. this.checkRoles = datas;
  339. },
  340. //获取权限规则
  341. getData (obj) {
  342. this.rulesObj = obj;
  343. },
  344. //保存
  345. saveBtn (formName) {
  346. this.$refs[formName].validate((valid) => {
  347. if (valid) {
  348. this.saveOrgan();
  349. } else {
  350. console.log("error submit!!");
  351. return false;
  352. }
  353. });
  354. },
  355. //组织新增保存
  356. async saveOrgan () {
  357. try {
  358. const caps = [];
  359. const newDatas = [];
  360. const arr = this.$store.getters.authArrs;
  361. this.checkTrees.forEach((item) => {
  362. caps.push(item.AuthList);
  363. });
  364. arr.forEach((item) => {
  365. newDatas.push(item.AuthList);
  366. });
  367. const newMsg = newDatas.concat(caps);
  368. newMsg.forEach((item) => {
  369. item["AuthId"] = Number(item["AuthId"]);
  370. });
  371. const datas = _.unionBy(newMsg, "AuthId");
  372. const res = await newOrganmod({
  373. OrganName: this.form.name,
  374. OrganType: this.form.id,
  375. OrganDesc: this.form.desc,
  376. OrganUpid: this.OrganUpid,
  377. OrganId: this.AppId,
  378. Status: this.Status,
  379. RoleList: this.openRole ? this.checkRoles : [],
  380. AuthList: this.openRole ? [] : datas,
  381. GroupList: this.OpenGroup ? this.checkRoles : [],
  382. L1: this.form.oneCode,
  383. L2: this.form.twoCode,
  384. L3: this.form.threeCode,
  385. L4: this.form.fourCode,
  386. L5: this.form.fiveCode,
  387. Type: this.form.bmCode
  388. });
  389. if (res.code === 0) {
  390. this.$message.success(res.message);
  391. this.$store.dispatch("tagsView/delView", this.$route);
  392. this.$router.push("/organization");
  393. } else {
  394. this.$message.error(res.message);
  395. }
  396. } catch (error) {
  397. console.log("出错了", error);
  398. }
  399. },
  400. },
  401. };
  402. </script>
  403. <style lang="scss" scoped>
  404. .authorityPower {
  405. padding: 0 64px;
  406. padding-top: 32px;
  407. }
  408. .addApp-form {
  409. background: #ffffff;
  410. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  411. border-radius: 16px;
  412. padding: 32px 32px 40px 32px;
  413. .title {
  414. font-size: 24px;
  415. font-family: Microsoft YaHei;
  416. font-weight: bold;
  417. color: #303133;
  418. .isqy {
  419. span {
  420. font-weight: 400;
  421. font-size: 14px;
  422. margin: 0 28px 0 42px;
  423. }
  424. }
  425. }
  426. .addApp-form-content {
  427. margin-top: 40px;
  428. ::v-deep .form {
  429. .el-form-item {
  430. margin-bottom: 0;
  431. }
  432. .el-input__inner {
  433. height: 32px;
  434. line-height: 32px;
  435. min-width: 184px;
  436. }
  437. .content {
  438. .el-form-item__content {
  439. flex: 1;
  440. }
  441. .el-form-item__label {
  442. margin-left: 27px;
  443. }
  444. }
  445. .top24 {
  446. margin-top: 24px;
  447. .el-form-item__label {
  448. margin-left: 16px;
  449. }
  450. .oneCode {
  451. .el-form-item__label {
  452. margin-left: 0px;
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. .power-content {
  460. margin-top: 24px;
  461. height: 704px;
  462. .part {
  463. height: 704px;
  464. }
  465. }
  466. </style>