organizationEdit.vue 13 KB

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