treeGroup.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <div class="grid-content bg-purple tree_group" :style="{'height': treeHeight + 'px'}">
  3. <a-card title="分工节点" style="height: 100%">
  4. <!-- 左侧树 -->
  5. <div :style="{'height': (treeHeight - 70) + 'px','overflow':'auto'}">
  6. <a-tree
  7. :tree-data="treeData"
  8. @expand="treeOpened"
  9. @select="treeNodeClickHandler"
  10. :field-names="{children: 'children', title: 'pnm', key: 'id'}"
  11. :auto-expand-parent="true"
  12. :expanded-keys="expandedKeys"
  13. @update:expandedKeys="expandedKeys = $event"
  14. ref="jigou_tree">
  15. <template #title="{ dataRef }">
  16. <span v-if="!dataRef" style="display:flex; align-items:center;"></span>
  17. <span v-else style="display:flex; align-items:center; justify-content:space-between; width:100%;">
  18. <span style="display:flex; align-items:center; min-width:0; flex:1;">
  19. <span v-if="dataRef.id && dataRef.id.length >= 12 && userInThisGroup(dataRef)" style="flex-shrink:0;">
  20. <img src="../../../assets/images/choucha.png" v-if="dataRef.chkType == '0'" style="width:25px; height:20px;"/>
  21. <img src="../../../assets/images/zicha.png" v-if="dataRef.chkType=='1'" style="width:25px; height:20px;"/>
  22. </span>
  23. <span v-if="orgType == '1110'" :style="{color: dataRef.colour, overflow:'hidden', textOverflow:'ellipsis', whiteSpace:'nowrap'}">{{ dataRef.pnm ? (dataRef.pnm.length > 12 ? (dataRef.pnm.substring(0, 10)) + '...' : dataRef.pnm) : '' }}</span>
  24. <span v-else style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">{{ dataRef.pnm ? (dataRef.pnm.length > 12 ? (dataRef.pnm.substring(0, 10)) + '...' : dataRef.pnm) : '' }}</span>
  25. <a-button
  26. v-if="dataRef.id && dataRef.id.length > 6 && userInThisGroup(dataRef)"
  27. type="danger"
  28. ghost
  29. size="small"
  30. shape="circle"
  31. @click="() => deletePICI(dataRef)"
  32. style="border:0; margin-left:4px; flex-shrink:0;"></a-button>
  33. </span>
  34. <span style="display:flex; align-items:center; gap:4px; flex-shrink:0; margin-left:8px;">
  35. <a-button
  36. v-if="dataRef.id && dataRef.id.length < 10"
  37. type="primary"
  38. ghost
  39. size="small"
  40. @click="() => addPICI(dataRef, '批次')"
  41. style="border:0;">新建</a-button>
  42. <EditOutlined @click="modifyPICI(dataRef,'批次')" style="color:#009fff; cursor:pointer;"/>
  43. <a-tooltip>
  44. <template #title>
  45. <div v-if="dataRef.sttm">{{ dataRef.sttm }} ~ {{ dataRef.entm }}</div>
  46. <div v-else>无</div>
  47. </template>
  48. <ClockCircleOutlined style="cursor:pointer;"/>
  49. </a-tooltip>
  50. </span>
  51. </span>
  52. </template>
  53. </a-tree>
  54. </div>
  55. <!-- 添加批次、添加组弹窗 -->
  56. <a-modal :title="'新建' + addTypeText" :open="addPICIDialogVisible" @ok="appendPICI" @cancel="addPICIDialogVisible = false">
  57. <a-form :model="piciForm" :label-col="{ span: 6 }" :wrapper-col="{ span: 14 }">
  58. <a-form-item :label="addTypeText + '名称'">
  59. <a-input v-model:value="piciForm.name" placeholder="请输入内容"/>
  60. </a-form-item>
  61. <a-form-item label="时间范围" v-if="currentSelectTreeNodeId.length > 3">
  62. <a-range-picker :value="createValue" format="YYYY-MM-DD" separator="至" @change="onChange"/>
  63. </a-form-item>
  64. </a-form>
  65. </a-modal>
  66. <!-- 修改批次、组信息弹窗 -->
  67. <a-modal :title="'信息修改'" :open="modifyPICIDialogVisible" @ok="modifyPICIInfo" @cancel="modifyPICIDialogVisible = false">
  68. <a-form :model="piciForm" :label-col="{ span: 6 }" :wrapper-col="{ span: 14 }">
  69. <a-form-item :label="addTypeText + '名称'">
  70. <a-input v-model:value="piciForm.name" placeholder="请输入内容"/>
  71. </a-form-item>
  72. <a-form-item label="时间范围" v-if="currentSelectTreeNodeId.length > 3">
  73. <a-range-picker :value="createValue" format="YYYY-MM-DD" separator="至" @change="onChange"/>
  74. </a-form-item>
  75. <a-form-item label="是否门户展示" v-if="isShowPortal && (orgType == '111' || orgType == '1110')">
  76. <a-switch v-model="piciForm.isPortalBool" checked-children="是" un-checked-children="否" @click="getIsPortal" />
  77. </a-form-item>
  78. </a-form>
  79. </a-modal>
  80. </a-card>
  81. </div>
  82. </template>
  83. <script>
  84. import moment from 'moment';
  85. import request from '@/utils/gw_ajax_request';
  86. import { dateFormat } from '@/utils/gw_date';
  87. import { getTrees } from '@/utils/gw_formatTree';
  88. import { EditOutlined, ClockCircleOutlined } from '@ant-design/icons-vue';
  89. export default {
  90. emits: ['sendCurrentNodeinfo'],
  91. props: ['orgType'],
  92. data() {
  93. return {
  94. treeHeight: window.innerHeight - 190,
  95. treeData: [],
  96. expandedKeys: [],
  97. treeInfoOrigin: null, // 原始后台返回的树数据结构
  98. currentSelectTreeNode: {
  99. currentSelectTreeNodeName: '',
  100. currentSelectTreeNodeCode: '',
  101. currentSelectTreeNodeType: '',
  102. currentSelectTreeNodeId: '',
  103. },
  104. deleteFlag: false,
  105. plnaTreeCode: '',
  106. plnaTreeName: '',
  107. plnaTreeType: '',
  108. addPICITreeNode: '',
  109. addPICIDialogVisible: false,
  110. isShowPortal: null,
  111. createValue: [],
  112. piciForm: {
  113. name: '',
  114. startDate: '',
  115. endDate: '',
  116. isPortal: '',
  117. isPortalBool: false,
  118. },
  119. addTypeText: '',
  120. moment,
  121. modifyPICIDialogVisible: false,
  122. addType: '',
  123. addZUTreeNode: '',
  124. addZuDialogVisible: false,
  125. };
  126. },
  127. computed: {
  128. userInAllNode() {
  129. // 当前登录用户所在的所有组信息
  130. return JSON.parse(localStorage.getItem('allNode'))
  131. ? JSON.parse(localStorage.getItem('allNode'))
  132. : [];
  133. },
  134. orgId() {
  135. return localStorage.getItem('guid') ? localStorage.getItem('guid') : '';
  136. },
  137. persId() {
  138. return localStorage.getItem('persId')
  139. ? localStorage.getItem('persId')
  140. : '';
  141. },
  142. currentSelectTreeNodeId() {
  143. return this.currentSelectTreeNode.currentSelectTreeNodeId;
  144. },
  145. },
  146. created() {},
  147. mounted() {
  148. if (this.orgType) {
  149. this.getLeftTreeData();
  150. }
  151. },
  152. methods: {
  153. searchOption(option, arr) {
  154. for (let s = 0; s < arr.length; s++) {
  155. if (arr[s].key === option.key) {
  156. arr.splice(s, 1);
  157. this.$message.success('删除成功!');
  158. break;
  159. } else if (arr[s].children && arr[s].children.length > 0) {
  160. // 递归条件
  161. this.searchOption(option, arr[s].children);
  162. } else {
  163. }
  164. }
  165. },
  166. hasPriv1(item) {
  167. return this.ownPriv(item);
  168. },
  169. getLeftTreeData() {
  170. // 根据用户id获取左侧树
  171. this.expandedKeys = [];
  172. const type = this.orgType == '1110' ? '111' : this.orgType;
  173. request
  174. .get('/dc/organization/base/getAllNode', {
  175. params: { userId: this.persId, orgType: type },
  176. })
  177. .then((res) => {
  178. let data = res.data;
  179. this.treeInfoOrigin = res.data;
  180. data.forEach((ele) => {
  181. if (!ele.sttm) {
  182. ele.sttm = '';
  183. } else if (!isNaN(ele.sttm)) {
  184. ele.sttmstamp = ele.sttm;
  185. ele.sttm = dateFormat(ele.sttm, 'yyyy-MM-dd');
  186. }
  187. if (!ele.entm) {
  188. ele.entm = '';
  189. } else if (!isNaN(ele.entm)) {
  190. ele.entmstamp = ele.entm;
  191. ele.entm = dateFormat(ele.entm, 'yyyy-MM-dd');
  192. }
  193. });
  194. data = getTrees(data);
  195. const scopedSlots = {
  196. title: 'custom',
  197. };
  198. data.forEach((item) => {
  199. item.scopedSlots = scopedSlots;
  200. if (item.children && item.children.length > 0) {
  201. item.children.forEach((item1) => {
  202. item1.scopedSlots = scopedSlots;
  203. if (item1.children && item1.children.length > 0) {
  204. item1.children.forEach((item2) => {
  205. item2.scopedSlots = scopedSlots;
  206. });
  207. }
  208. });
  209. }
  210. });
  211. this.treeData = data;
  212. this.expandedKeys.push(data[0].id);
  213. this.currentSelectTreeNode.currentSelectTreeNodeId =
  214. this.treeData[0].id;
  215. this.$emit('sendCurrentNodeinfo', this.currentSelectTreeNode);
  216. });
  217. },
  218. userInThisGroup(item) {
  219. // 判断当前用户 是否在该节点下 在 则没有删除权限
  220. if (this.userInAllNode && this.userInAllNode.length > 0) {
  221. for (var i = 0; i < this.userInAllNode.length; i++) {
  222. if (this.userInAllNode[i].id.substring(0, 3) == '001') {
  223. if (item.id.length > this.userInAllNode[i].id.length) {
  224. return true;
  225. } else {
  226. return false;
  227. }
  228. } else {
  229. return true;
  230. }
  231. }
  232. } else {
  233. return true;
  234. }
  235. },
  236. treeNodeClickHandler(selectedKeys, e) {
  237. //debugger
  238. const { dataRef: data } = e.node;
  239. if (this.deleteFlag) {
  240. // 如果点击删除节点 则不更新节点id
  241. this.deleteFlag = false;
  242. return;
  243. }
  244. // this.duChaType = data.id.substring(2,3);
  245. this.currentSelectTreeNode.currentSelectTreeNodeName = data.name;
  246. this.currentSelectTreeNode.currentSelectTreeNodeCode = data.code;
  247. this.currentSelectTreeNode.currentSelectTreeNodeType = data.type;
  248. this.currentSelectTreeNode.currentSelectTreeNodeId = data.id;
  249. this.currentSelectTreeNode.currentSelectTreeNodePsn = data.psn;
  250. this.$emit('sendCurrentNodeinfo', this.currentSelectTreeNode);
  251. if (data.type == '3') {
  252. this.plnaTreeCode = data.code;
  253. this.plnaTreeName = data.name;
  254. this.plnaTreeType = data.type;
  255. }
  256. },
  257. treeOpened(expandedKeys, e) {
  258. const { dataRef: data } = e.node;
  259. this.currentSelectTreeNode.currentSelectTreeNodeName = data.name;
  260. this.currentSelectTreeNode.currentSelectTreeNodeCode = data.code;
  261. this.currentSelectTreeNode.currentSelectTreeNodeType = data.type;
  262. this.currentSelectTreeNode.currentSelectTreeNodeId = data.id;
  263. this.$emit('sendCurrentNodeinfo', this.currentSelectTreeNode);
  264. if (data.type == '3') {
  265. this.plnaTreeCode = data.code;
  266. this.plnaTreeName = data.name;
  267. this.plnaTreeType = data.type;
  268. }
  269. },
  270. deletePICI(data) {
  271. this.deleteFlag = true;
  272. this.$confirm({
  273. title: '提示',
  274. content: '是否删除批次' + data.pnm + '及关联督查组?',
  275. okType: 'info',
  276. onOk: () => {
  277. request.post(`/dc/insp/plan/${data.id}`).then((res) => {
  278. if (res.success) {
  279. if (res.message == '请先删除人员或对象') {
  280. this.$message.warning('请先删除组内人员、对象及区域!');
  281. } else {
  282. // this.searchOption(data, this.treeData)
  283. this.$message.success('删除成功!');
  284. this.getLeftTreeData();
  285. }
  286. }
  287. });
  288. },
  289. onCancel: () => {
  290. this.$message.info('已取消删除');
  291. },
  292. });
  293. },
  294. addPICI(nodeData, addType) {
  295. this.addPICITreeNode = nodeData;
  296. this.isShowPortal = this.addPICITreeNode.id.length == 6;
  297. this.piciForm.name = '';
  298. this.piciForm.isPortal = '0';
  299. this.piciForm.isPortalBool = false;
  300. this.createValue = [];
  301. // 默认继承父节点的时间属性
  302. this.piciForm.startDate = [];
  303. if (!nodeData.sttm || !nodeData.entm) {
  304. this.piciForm.startDate = [];
  305. } else {
  306. this.piciForm.startDate = [nodeData.sttm, nodeData.entm];
  307. }
  308. this.addPICIDialogVisible = true;
  309. },
  310. appendPICI() {
  311. const params = {
  312. prsnTitle: this.piciForm.name,
  313. guid: this.addPICITreeNode.id,
  314. palnSttm: this.piciForm.startDate[0],
  315. palnEntm: this.piciForm.startDate[1],
  316. isPortal: this.piciForm.isPortal,
  317. };
  318. if (!this.piciForm.startDate.length) {
  319. this.$message.warning('请选择开始和结束时间');
  320. return;
  321. }
  322. request.post('/dc/insp/plan/addBisInspPlan', params).then((res) => {
  323. const sttmstamp =
  324. moment(params.palnSttm, 'YYYY-MM-DD').startOf('day').format('x') * 1;
  325. const entmstamp =
  326. moment(params.palnEntm, 'YYYY-MM-DD').startOf('day').format('x') * 1;
  327. const newChild = {
  328. id: res.data.code,
  329. pid: this.addPICITreeNode.id,
  330. pnm: this.piciForm.name,
  331. sttm: params.palnSttm,
  332. entm: params.palnEntm,
  333. sttmstamp: sttmstamp,
  334. entmstamp: entmstamp,
  335. children: [],
  336. isPortal: this.piciForm.isPortal,
  337. isPortalBool: this.piciForm.isPortal === '1',
  338. };
  339. newChild.scopedSlots = { title: 'custom' };
  340. newChild.key = res.data.code;
  341. if (!this.addPICITreeNode.children) {
  342. this.addPICITreeNode.children = [];
  343. }
  344. // to-do wxcwater 改这里。
  345. this.addPICITreeNode.children.push(newChild);
  346. // _self.$refs['jigou_tree'].append(newChild, _self.addPICITreeNode.id)
  347. this.addPICIDialogVisible = false;
  348. this.getLeftTreeData();
  349. });
  350. },
  351. onChange(date, dateString) {
  352. this.createValue = date;
  353. this.piciForm.startDate = dateString;
  354. },
  355. modifyPICI(nodeData, addType) {
  356. this.addPICITreeNode = nodeData;
  357. this.isShowPortal = this.addPICITreeNode.id.length == 9;
  358. this.piciForm.isPortal = nodeData.isPortal;
  359. this.piciForm.isPortalBool = nodeData.isPortal === '1';
  360. this.piciForm.name = this.addPICITreeNode.pnm;
  361. this.piciForm.startDate = [
  362. this.addPICITreeNode.sttmstamp,
  363. this.addPICITreeNode.entmstamp,
  364. ];
  365. this.createValue = [
  366. moment(this.addPICITreeNode.sttmstamp),
  367. moment(this.addPICITreeNode.entmstamp),
  368. ];
  369. this.modifyPICIDialogVisible = true;
  370. },
  371. modifyPICIInfo() {
  372. const params = {
  373. pnm: this.piciForm.name,
  374. id: this.addPICITreeNode.id,
  375. sttm:
  376. moment(this.piciForm.startDate[0], 'YYYY-MM-DD')
  377. .startOf('day')
  378. .format('x') * 1,
  379. entm:
  380. moment(this.piciForm.startDate[1], 'YYYY-MM-DD')
  381. .startOf('day')
  382. .format('x') * 1,
  383. isPortal: this.piciForm.isPortal,
  384. };
  385. if (!this.piciForm.startDate.length) {
  386. this.$message.warning('请选择开始和结束时间');
  387. return;
  388. }
  389. request.post('/dc/insp/plan/updateBisInspAll', params).then((res) => {
  390. if (res.success) {
  391. if (this.treeInfoOrigin.length) {
  392. // 修改时间后遍历更新当前节点时间信息
  393. this.treeInfoOrigin.forEach((ele) => {
  394. if (ele.id == this.addPICITreeNode.id) {
  395. ele.sttm = !isNaN(params.sttm)
  396. ? dateFormat(params.sttm, 'yyyy-MM-dd')
  397. : params.sttm;
  398. ele.entm = !isNaN(params.entm)
  399. ? dateFormat(params.entm, 'yyyy-MM-dd')
  400. : params.entm;
  401. ele.pnm = this.piciForm.name;
  402. ele.isPortal = this.piciForm.isPortal;
  403. ele.isPortalBool = this.piciForm.isPortal === '1';
  404. }
  405. });
  406. this.$message.success('修改成功');
  407. }
  408. this.modifyPICIDialogVisible = false;
  409. this.getLeftTreeData();
  410. }
  411. });
  412. },
  413. getIsPortal(checked, e) {
  414. this.piciForm.isPortal = checked === true ? '1' : '0';
  415. this.piciForm.isPortalBool = checked;
  416. },
  417. addZU(node, nodeData) {
  418. this.addZUTreeNode = node.data;
  419. this.addZuDialogVisible = true;
  420. },
  421. appendZU() {
  422. const params = {
  423. guid: this.orgId,
  424. headmanId: this.groupLeaderId,
  425. inspGroupName: this.zuForm.name,
  426. memberId: this.memberId,
  427. plnaId: this.addZUTreeNode.code,
  428. downStat: 2,
  429. note: '备注',
  430. };
  431. request.post('/dc/insp/group/insertGroup', params).then((res) => {
  432. const newChild = {
  433. code: res.data.code,
  434. type: res.data.type,
  435. name: res.data.name,
  436. };
  437. // to-do 改这里
  438. this.$refs['jigou_tree'].append(newChild, this.addZUTreeNode.code);
  439. this.addZuDialogVisible = false;
  440. this.isGroupLeader = '';
  441. this.zuForm.name = '';
  442. });
  443. },
  444. deleteZU(node, data) {
  445. this.$confirm('是否删除督查组:' + data.name + '?', '提示', {
  446. confirmButtonText: '确定',
  447. cancelButtonText: '取消',
  448. type: 'warning',
  449. })
  450. .then(() => {
  451. request
  452. .post(`/dc/insp/group/delete?id=${node.data.code}`)
  453. .then((res) => {
  454. // this.$refs.jigou_tree.remove(node)
  455. this.$message.success('删除成功');
  456. });
  457. })
  458. .catch(() => {
  459. this.$message.info('已取消删除');
  460. });
  461. },
  462. },
  463. watch: {
  464. orgType(val) {
  465. if (val) {
  466. this.getLeftTreeData();
  467. }
  468. },
  469. },
  470. };
  471. </script>
  472. <style lang='less' scoped>
  473. .tree_group{
  474. .custom-tree-node{
  475. flex: 1;
  476. display: flex;
  477. align-items: center;
  478. justify-content: space-between;
  479. font-size: 15px;
  480. padding-right: 8px;
  481. }
  482. }
  483. </style>