index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="main">
  3. <el-container>
  4. <el-aside width="500px">
  5. <el-input placeholder="请输入机构名称" class="search-input" v-model="treeSearch"></el-input>
  6. <div class="organ-wrap">
  7. <div class="tree">
  8. <el-tree
  9. :data="organList"
  10. ref="tree1"
  11. node-key="id"
  12. :props="defaultProps"
  13. :highlight-current="highlightCurrent"
  14. check-strictly
  15. :expand-on-click-node="false"
  16. @node-click="treeClick"
  17. default-expand-all
  18. accordion
  19. :filter-node-method="filterNode"
  20. >
  21. <span class="ellipsis" slot-scope="{ node, data }">
  22. {{ node.label }}
  23. <img
  24. class="dmp-icon-btn"
  25. title="编辑"
  26. v-if="data.productCategoryId == -1 || (!data.productCategoryId && data.id !== 0)"
  27. @click.stop="editMenu(data)"
  28. src="@assets/img/newImg/icon_bianji.png"
  29. alt=""
  30. />
  31. <img
  32. class="dmp-icon-btn"
  33. title="删除"
  34. v-if="!data.productCategoryId && data.id !== 0"
  35. @click.stop="deleteMenus(data)"
  36. src="@assets/img/newImg/icon_shanjian.png"
  37. alt=""
  38. />
  39. <img
  40. class="dmp-icon-btn"
  41. title="添加"
  42. v-if="!data.productCategoryId && (node.level == 1 || node.level == 2) && data.id !== 0"
  43. @click.stop="addOrEdit(data)"
  44. src="@assets/img/newImg/icon_tianjia.png"
  45. alt=""
  46. />
  47. </span>
  48. </el-tree>
  49. </div>
  50. </div>
  51. </el-aside>
  52. <el-main>
  53. <h3>
  54. <span v-if="isEdit == 'add'">添加</span>
  55. <!-- <span v-else-if="isEdit == 'edit'">编辑-{{ title }}</span> -->
  56. <span v-else>{{ title }}</span>
  57. </h3>
  58. <rightFrom :menuList="menuList" :formData="rightData" ref="form" :isEdit="isEdit" @getList="getList" />
  59. </el-main>
  60. </el-container>
  61. </div>
  62. </template>
  63. <script>
  64. import list from '@utils/list.js';
  65. import rightFrom from './popups/EditForm.vue';
  66. export const familyTree = (arr1 = [], id) => {
  67. if (!(arr1 && arr1.length)) return [];
  68. const temp = [];
  69. const forFn = (arr, id1) => {
  70. for (let i = 0; i < arr.length; i += 1) {
  71. const item = arr[i];
  72. if (item.id == id1) {
  73. temp.push(item);
  74. forFn(arr1, item.parentId);
  75. break;
  76. } else if (item.orgs) {
  77. forFn(item.orgs, id1);
  78. }
  79. }
  80. };
  81. forFn(arr1, id);
  82. return temp.reverse();
  83. };
  84. export default {
  85. mixins: [list],
  86. components: {
  87. rightFrom
  88. },
  89. data() {
  90. return {
  91. organList: [],
  92. defaultProps: {
  93. children: 'orgs',
  94. label: 'orgName'
  95. },
  96. treeSearch: '',
  97. highlightCurrent: true,
  98. arr: [],
  99. isEdit: false,
  100. title: '',
  101. rightData: {
  102. id: '',
  103. orgType: '', //机构类型
  104. parentOrgId: '', //上级机构
  105. orgAreaId: '', //所属区域
  106. orgName: '', //机构名称
  107. orgState: 1, //状态
  108. orgLeaderName: '', //负责人
  109. orgLeaderPhone: '', //手机号
  110. orgLeaderSex: '', //性别
  111. orgLeaderEmail: '', //邮箱
  112. remark: '' //备注
  113. }
  114. };
  115. },
  116. watch: {
  117. treeSearch(val) {
  118. this.$refs.tree1.filter(val);
  119. }
  120. },
  121. methods: {
  122. filterNode(value, data) {
  123. if (!value) return true;
  124. if (data.orgName.indexOf(value) !== -1) return data.orgName;
  125. },
  126. addOrEdit(params) {
  127. let data = JSON.parse(JSON.stringify(params));
  128. if (params.id == 0) {
  129. this.$message.error('组织机构不能编辑!');
  130. return;
  131. }
  132. new Promise((resolve, reject) => {
  133. if (this.isEdit) {
  134. this.$msgBox('您编辑的内容尚未保存,是否继续?', ' ')
  135. .then(() => {
  136. resolve();
  137. })
  138. .catch(() => {
  139. reject();
  140. });
  141. } else {
  142. resolve();
  143. }
  144. })
  145. .then(() => {
  146. this.isEdit = 'add';
  147. const params = JSON.parse(
  148. JSON.stringify({
  149. id: '',
  150. orgType: '', //机构类型
  151. parentOrgId: '', //上级机构
  152. orgAreaId: '', //所属区域
  153. orgName: '', //机构名称
  154. orgState: 1, //状态
  155. orgLeaderName: '', //负责人
  156. orgLeaderPhone: '', //手机号
  157. orgLeaderSex: '', //性别
  158. orgLeaderEmail: '', //邮箱
  159. remark: '' //备注
  160. })
  161. );
  162. this.rightData = params;
  163. })
  164. .catch(() => {});
  165. },
  166. editMenu(data) {
  167. new Promise((resolve, reject) => {
  168. if (this.isEdit) {
  169. this.$msgBox('您编辑的内容尚未保存,是否继续?', ' ')
  170. .then(() => {
  171. resolve();
  172. })
  173. .catch(() => {
  174. reject();
  175. });
  176. } else {
  177. resolve();
  178. }
  179. })
  180. .then(() => {
  181. this.title = data.orgName;
  182. this.fun(data);
  183. this.isEdit = 'edit';
  184. this.$nextTick(() => {
  185. this.$refs.tree1.setCurrentKey(data.id);
  186. });
  187. })
  188. .catch(() => {});
  189. },
  190. deleteMenus(data) {
  191. const { id, orgName } = data;
  192. this.treeClick(data);
  193. this.$msgBox(`刪除机构 "${orgName}"`, '删除后将无法恢复,请问是否继续?')
  194. .then(() => {
  195. this.$http.post('/org/deleteAll', [id]).then(({ status, data, msg }) => {
  196. if (status === 0 && data) {
  197. if (data.length) {
  198. this.$message.error('删除失败,请先删除机构下的用户!');
  199. return;
  200. } else {
  201. this.$message({
  202. type: 'success',
  203. message: '删除成功!'
  204. });
  205. this.getList();
  206. }
  207. }
  208. });
  209. })
  210. .catch(() => {});
  211. },
  212. fun(params) {
  213. this.$refs['form'].$children[0].resetFields();
  214. const {
  215. id = '',
  216. orgType = '', //机构类型
  217. parentOrgId = '', //上级机构
  218. orgAreaId = '', //所属区域
  219. orgName = '', //机构名称
  220. orgState = 1, //状态
  221. orgLeaderName = '', //负责人
  222. orgLeaderPhone = '', //手机号
  223. orgLeaderSex = '', //性别
  224. orgLeaderEmail = '', //邮箱
  225. remark = '' //备注
  226. } = params;
  227. Object.assign(this.rightData, {
  228. id,
  229. orgType, //机构类型
  230. parentOrgId, //上级机构
  231. orgAreaId, //所属区域
  232. orgName, //机构名称
  233. orgState, //状态
  234. orgLeaderName, //负责人
  235. orgLeaderPhone, //手机号
  236. orgLeaderSex, //性别
  237. orgLeaderEmail, //邮箱
  238. remark //备注
  239. });
  240. this.$nextTick(() => {
  241. this.$refs.tree1.setCurrentKey(this.rightData.id);
  242. });
  243. },
  244. treeClick(params) {
  245. if (this.rightData.id == params.id) return;
  246. if (this.isEdit) {
  247. this.$msgBox('您编辑的内容尚未保存,是否继续?', ' ')
  248. .then(() => {
  249. this.title = params.orgName;
  250. this.isEdit = false;
  251. this.fun(params);
  252. })
  253. .catch(() => {});
  254. return;
  255. }
  256. this.isEdit = false;
  257. this.fun(params);
  258. this.title = params.orgName;
  259. },
  260. getList() {
  261. this.$http.postForm('/org/getOrgTree', { orgType: '' }).then(({ status, data, msg }) => {
  262. if (status === 0 && data) {
  263. this.organList = [{ orgs: data, orgName: '组织机构', id: 0 }];
  264. this.isEdit = false;
  265. this.treeClick(data[0]);
  266. }
  267. });
  268. }
  269. },
  270. created() {
  271. this.getList();
  272. }
  273. };
  274. </script>
  275. <style lang="scss" scoped>
  276. .main {
  277. display: flex;
  278. flex-direction: column;
  279. height: 100%;
  280. .el-aside {
  281. background: white;
  282. /deep/ .el-tree--highlight-current {
  283. padding: 0 20px;
  284. .el-tree-node.is-current > .el-tree-node__content {
  285. // color: #1fcff5 !important;
  286. // background: #f8fcff !important;
  287. }
  288. .el-tree-node__content {
  289. margin-bottom: 10px;
  290. }
  291. }
  292. }
  293. .el-main {
  294. margin-left: 10px;
  295. background-color: #fff;
  296. border-radius: 0 6px 6px 0;
  297. overflow: hidden;
  298. padding: 20px;
  299. h3 {
  300. padding: 0 20px 20px 0;
  301. }
  302. }
  303. .dmp-icon-btn {
  304. margin-left: 10px;
  305. color: #0eaeff;
  306. }
  307. .search-input {
  308. padding: 20px;
  309. }
  310. }
  311. </style>