PublicWbs.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <template>
  2. <!-- 关联公共WBS模板 -->
  3. <el-dialog
  4. title="关联公共WBS模板"
  5. class="excelBox"
  6. :visible.sync="AssociatedPublicTap"
  7. modal-append-to-body
  8. append-to-body
  9. :close-on-click-modal="false"
  10. >
  11. <el-row :gutter="20">
  12. <el-col :span="12">
  13. <el-select
  14. style="width: 100%"
  15. v-model="GLExcelFrom.name"
  16. placeholder="请选择"
  17. @change="changetherr()"
  18. >
  19. <el-option
  20. v-for="(item, key) in GLExcelData"
  21. :key="key"
  22. :label="item.wbsName"
  23. :value="item.id"
  24. >
  25. </el-option>
  26. </el-select>
  27. <el-scrollbar style="height: 50vh">
  28. <div class="flex" style="margin-top: 10px" v-if="isShowInput">
  29. <el-input
  30. size="small"
  31. placeholder="输入关键字搜索"
  32. clearable
  33. @clear="clearInput"
  34. v-model="filterText1"
  35. >
  36. </el-input>
  37. <el-button size="small" class="mg-l-10" @click="treeFilter1"
  38. >搜索</el-button
  39. >
  40. </div>
  41. <el-tree
  42. v-if="GLExcelFromtag"
  43. @node-click="handleNodeClickExcel"
  44. ref="tree"
  45. class="filter-tree"
  46. style="margin-top: 10px"
  47. :props="GLExcelProps"
  48. :data="exceldata"
  49. :load="loadNodeTan"
  50. lazy
  51. node-key="id"
  52. accordion
  53. :show-checkbox="activeName == 'add'"
  54. :check-strictly="true"
  55. :default--checked-keys="selectNodeIds"
  56. >
  57. </el-tree>
  58. <el-tree
  59. style="width: 100%"
  60. ref="treeall1"
  61. v-loading="treeloading1"
  62. :data="allTreeData1"
  63. :props="treeProps1"
  64. @node-click="handleNodeClickExcel"
  65. node-key="id"
  66. :expand-on-click-node="false"
  67. :filter-node-method="filterNode1"
  68. v-show="GLExcelFromtag1"
  69. :show-checkbox="activeName == 'add'"
  70. :default--checked-keys="selectNodeIds"
  71. :check-strictly="true"
  72. >
  73. </el-tree>
  74. </el-scrollbar>
  75. </el-col>
  76. <el-col :span="12" v-if="addElementForm.wbsId">
  77. <el-tabs v-model="activeName" type="card">
  78. <el-tab-pane label="关联元素表" name="link">
  79. <el-table
  80. :data="addTableData"
  81. border
  82. style="width: 100%"
  83. class="martop20"
  84. >
  85. <el-table-column
  86. prop="tableName"
  87. label="已有元素表名称"
  88. align="center"
  89. >
  90. </el-table-column>
  91. <el-table-column prop="name" label="操作" align="center">
  92. <template slot-scope="scope">
  93. <el-button
  94. type="primary"
  95. size="mini"
  96. style="margin: 0px"
  97. @click="relationMD(scope.row, '关联')"
  98. v-show="!scope.row.checknd"
  99. :loading="scope.row.loading"
  100. >选择关联</el-button
  101. >
  102. <el-button
  103. type="danger"
  104. size="mini"
  105. style="margin: 0px"
  106. @click="relationMD(scope.row, '取消关联')"
  107. v-show="scope.row.checknd"
  108. :loading="scope.row.loading"
  109. >取消关联</el-button
  110. >
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. </el-tab-pane>
  115. <el-tab-pane label="新增元素表" name="add">
  116. <div>
  117. <div class="flexBetween martop20">
  118. <el-input
  119. v-model="addElementForm.nodeName"
  120. placeholder="请输入表名"
  121. ></el-input>
  122. <el-select
  123. class="marleft10"
  124. v-model="addElementForm.tableType"
  125. placeholder="请选择表类型"
  126. >
  127. <el-option
  128. v-for="(item, index) in exceltypeData"
  129. :key="index"
  130. :label="item.dictValue"
  131. :value="item.dictKey"
  132. ></el-option>
  133. </el-select>
  134. </div>
  135. <el-select
  136. style="width: 100%"
  137. class="martop20"
  138. v-model="addElementForm.tableOwner"
  139. placeholder="请选择所属方"
  140. >
  141. <el-option
  142. v-for="(item, index) in ownerTypeList"
  143. :key="index"
  144. :label="item.dictValue"
  145. :value="item.dictKey"
  146. ></el-option>
  147. </el-select>
  148. </div>
  149. </el-tab-pane>
  150. </el-tabs>
  151. </el-col>
  152. </el-row>
  153. <span
  154. slot="footer"
  155. class="dialog-footer"
  156. style="display: flex; justify-content: center; align-items: center"
  157. >
  158. <el-button @click="AssociatedPublicClose()">取 消</el-button>
  159. <el-button
  160. style="margin-left: 30px"
  161. type="primary"
  162. @click="saveElementMD()"
  163. >确 定</el-button
  164. >
  165. </span>
  166. </el-dialog>
  167. </template>
  168. <script>
  169. import { getAlltree } from "@/api/manager/wbstree";
  170. import { getDictionary } from "@/api/system/dict";
  171. import { dictionarydataType } from "@/api/exctab/editelement";
  172. import {
  173. excelType,
  174. excelType1,
  175. submitExcelRelationWbsTreeAndElement,
  176. getWbsTypeList,
  177. getLazytree,
  178. cancelRelation,
  179. saveRelation,
  180. searchNodeTables,
  181. savelinktableInfo,
  182. } from "@/api/exctab/excelmodel";
  183. import { getColByTabId } from "@/api/manager/AdjustForm";
  184. export default {
  185. props: {
  186. from: Object,
  187. },
  188. data() {
  189. return {
  190. AssociatedPublicTap: false,
  191. //#region 弹框属性
  192. GLExcelFrom: {
  193. id: "",
  194. name: "",
  195. search: "", //搜素框舒服的值
  196. },
  197. GLExcelData: [], //
  198. isShowInput: false,
  199. filterText1: "",
  200. GLExcelFromtag1: false,
  201. GLExcelFromtag: false,
  202. GLExcelProps: {
  203. label: "title",
  204. children: "children",
  205. isLeaf: function (data) {
  206. if (data.hasChildren && data.isExistForm != 1) {
  207. return false;
  208. } else if (data.hasChildren && data.isExistForm == 1) {
  209. return true;
  210. } else {
  211. return true;
  212. }
  213. },
  214. disabled: function (data) {
  215. if (data.hasChildren && data.isExistForm != 1) {
  216. return true;
  217. } else if (data.hasChildren && data.isExistForm == 1) {
  218. return false;
  219. } else {
  220. return false;
  221. }
  222. },
  223. },
  224. exceldata: [],
  225. selectNodeIds: [],
  226. treeloading1: false,
  227. allTreeData1: [],
  228. treeProps1: {
  229. label: "title",
  230. children: "children",
  231. isLeaf: "hasChildren",
  232. disabled: function (data) {
  233. if (data.hasChildren && data.isExistForm != 1) {
  234. return true;
  235. } else if (data.hasChildren && data.isExistForm == 1) {
  236. return false;
  237. } else {
  238. return false;
  239. }
  240. },
  241. },
  242. addElementForm: {
  243. id: "",
  244. initTableName: "",
  245. nodeName: "",
  246. tableType: "",
  247. tableOwner: "",
  248. wbsId: "",
  249. parentId: "",
  250. },
  251. nodeTypelist: [],
  252. ownerTypeList: [],
  253. addTableData: [], //新增元素信息表
  254. activeName: "link",
  255. dataType: [],
  256. addElement: false,
  257. exceltypeData: [],
  258. };
  259. },
  260. methods: {
  261. show() {
  262. console.log(this.from, "from");
  263. this.AssociatedPublicTap = true;
  264. this.addElementForm.nodeName = this.from.title;
  265. this.addElementForm.tableType = this.from.tableType + "";
  266. this.addElementForm.tableOwner = this.from.tableOwner;
  267. //清除数据
  268. this.filterText1 = "";
  269. this.exceldata = [];
  270. this.allTreeData1 = [];
  271. this.selectedId = "";
  272. this.GLExcelFrom.name = "";
  273. this.isShowInput = false;
  274. //清理之前填写的数据
  275. this.addElementForm.wbsId = "";
  276. // this.addElementForm.tableOwner = "";
  277. this.getWbsTypeList();
  278. this.getOwnerTypelist();
  279. this.getColByTabId();
  280. },
  281. addElementMD() {
  282. //新增元素信息表按钮
  283. this.excelType();
  284. this.addElement = true;
  285. },
  286. async excelType(type) {
  287. //清表类型
  288. // const { data: res } = await excelType({ code: "sys_excltab_type" });
  289. const { data: res } = await excelType1({ code: type });
  290. console.log(res);
  291. if (res.code === 200) {
  292. this.exceltypeData = res.data;
  293. }
  294. },
  295. async getWbsTypeList() {
  296. //获取清表模板信息
  297. const { data: res } = await getWbsTypeList({ wbstype: 1 });
  298. if (res.code === 200 && res.msg === "操作成功") {
  299. this.GLExcelData = res.data;
  300. }
  301. },
  302. changetherr(item) {
  303. console.log(item, "关联item");
  304. console.log(this.GLExcelFrom.name, "name");
  305. //下拉框change事件
  306. this.GLExcelFromtag = false;
  307. this.GLExcelFromtag1 = false;
  308. this.filterText1 = "";
  309. if (this.GLExcelFrom.name != "") {
  310. this.GLExcelFrom.search = "";
  311. this.exceldata = [];
  312. this.addTableData = [];
  313. this.isShowInput = false;
  314. this.addElementForm.wbsId = "";
  315. this.$nextTick(() => {
  316. this.GLExcelFromtag = true;
  317. });
  318. }
  319. },
  320. clearInput() {
  321. (this.selectedId = ""),
  322. (this.GLExcelFromtag1 = false),
  323. (this.GLExcelFromtag = true);
  324. if (this.$refs.tree) {
  325. this.nodeIds = this.$refs.tree.getCheckedKeys();
  326. }
  327. if (this.$refs.treeall1) {
  328. this.nodeIds1 = this.$refs.treeall1.getCheckedKeys();
  329. }
  330. this.selectNodeIds = this.uniqueArr(this.nodeIds, this.nodeIds1);
  331. console.log(this.selectNodeIds, "this.selectNodeIds111111");
  332. // this.$refs.tree.setCheckedKeys(this.selectNodeIds)
  333. this.$nextTick(() => {
  334. this.$refs.tree.setCheckedKeys(this.selectNodeIds);
  335. });
  336. },
  337. treeFilter1() {
  338. if (this.filterText1) {
  339. if (this.$refs.tree) {
  340. this.nodeIds = this.$refs.tree.getCheckedKeys();
  341. }
  342. if (this.$refs.treeall1) {
  343. this.nodeIds1 = this.$refs.treeall1.getCheckedKeys();
  344. }
  345. this.selectNodeIds = this.uniqueArr(this.nodeIds, this.nodeIds1);
  346. this.$refs.treeall1.setCheckedKeys(this.selectNodeIds);
  347. console.log(this.selectNodeIds, "this.selectNodeIds");
  348. this.GLExcelFromtag1 = true;
  349. this.GLExcelFromtag = false;
  350. this.treeloading1 = true;
  351. console.log(this.selectedId, "selectedId");
  352. console.log(this.GLExcelFrom.name, "this.GLExcelFrom.name");
  353. // tabLazytreeAll({
  354. // modeId: this.GLExcelFrom.name,
  355. // name: "",
  356. // })
  357. getAlltree("000000", 1, this.GLExcelFrom.name).then((res) => {
  358. this.treeloading1 = false;
  359. this.allTreeData1 = res.data.data;
  360. console.log(this.exceldata, "this.exceldata");
  361. console.log(this.GLExcelFromtag, "this.GLExcelFromtag");
  362. this.$nextTick(() => {
  363. console.log("过滤2", this.filterText1);
  364. this.$refs.treeall1.filter(this.filterText1);
  365. });
  366. });
  367. }
  368. },
  369. handleNodeClickExcel(data) {
  370. this.excelType("table_type");
  371. // if(data.wbsType===2){
  372. // this.excelType('trial_table_type');
  373. // }else{
  374. // this.excelType('table_type');
  375. // }
  376. //点击节点事件
  377. this.addElementForm.wbsId = this.GLExcelFrom.name;
  378. this.addElementForm.parentId = data.id;
  379. //this.selectByNodeTable(data.id)
  380. this.searchNodeTables(data.id);
  381. },
  382. //#region
  383. async loadNodeTan(node, resolve) {
  384. //懒加载
  385. console.log(node);
  386. this.selectedId = node.data.id;
  387. if (node.level === 0) {
  388. return resolve(await this.getLazytree(0));
  389. } else {
  390. return resolve(await this.getLazytree(node.data.id));
  391. }
  392. },
  393. // filterNode1(value, data) {
  394. // if (!value) return true;
  395. // return data.title.indexOf(value) !== -1;
  396. // },
  397. getReturnNode(node, _array, value) {
  398. let isPass =
  399. node.data && node.data.title && node.data.title.indexOf(value) !== -1;
  400. isPass ? _array.push(isPass) : "";
  401. if (!isPass && node.level != 1 && node.parent) {
  402. this.getReturnNode(node.parent, _array, value);
  403. }
  404. },
  405. filterNode1(value, data, node) {
  406. if (!value) {
  407. return true;
  408. }
  409. let level = node.level;
  410. let _array = []; //这里使用数组存储 只是为了存储值。
  411. this.getReturnNode(node, _array, value);
  412. let result = false;
  413. _array.forEach((item) => {
  414. result = result || item;
  415. });
  416. return result;
  417. },
  418. getOwnerTypelist() {
  419. if (this.ownerTypeList.length > 1) {
  420. return;
  421. }
  422. getDictionary({
  423. code: "owner_type",
  424. }).then((res) => {
  425. res.data.data.forEach((element) => {
  426. element.dictKey = Number(element.dictKey);
  427. });
  428. this.ownerTypeList = res.data.data;
  429. });
  430. },
  431. relationMD(row, type) {
  432. console.log("关联元素表", row);
  433. //关联取消关联
  434. row.loading = true;
  435. if (type == "关联") {
  436. // saveRelation(row.id, this.from.id, this.tableData)
  437. this.savelinktableInfo1({
  438. linkids: row.id,
  439. tabId: this.from.id,
  440. type: 1,
  441. wbsId: this.GLExcelFrom.name,
  442. })
  443. .then(() => {
  444. row.checknd = true;
  445. row.isLinkTable = 2;
  446. })
  447. .finally(() => {
  448. row.loading = false;
  449. });
  450. } else {
  451. this.savelinktableInfo1({
  452. linkids: row.id,
  453. tabId: this.from.id,
  454. type: 4,
  455. wbsId: this.GLExcelFrom.name,
  456. })
  457. .then(() => {
  458. row.checknd = false;
  459. row.isLinkTable = 1;
  460. })
  461. .finally(() => {
  462. row.loading = false;
  463. });
  464. }
  465. },
  466. AssociatedPublicClose() {
  467. console.log("AssociatedPublicClose");
  468. //关联公共WBS模板关闭事件
  469. this.addElementForm = {
  470. id: "",
  471. initTableName: "",
  472. nodeName: "",
  473. tableType: "",
  474. tableOwner: "",
  475. wbsId: "",
  476. parentId: "",
  477. };
  478. this.GLExcelFrom = {
  479. name: "",
  480. search: "",
  481. };
  482. this.exceldata = [];
  483. this.addElement = false;
  484. //清理之前填写的数据
  485. this.addElementForm.wbsId = "";
  486. // this.addElementForm.tableType = '';
  487. this.addElementForm.tableOwner = "";
  488. if (this.$refs.tree) {
  489. this.$refs.tree.setCheckedKeys([]);
  490. this.$refs.tree.setCurrentKey(null);
  491. }
  492. this.addTableData = [];
  493. this.AssociatedPublicTap = false;
  494. },
  495. saveElementMD() {
  496. //保存按钮
  497. if (this.addElementForm.wbsId) {
  498. console.log(this.tableData, "this.tableData");
  499. if (this.activeName == "link") {
  500. this.AssociatedPublicTap = false;
  501. this.AssociatedPublicClose();
  502. } else {
  503. if (
  504. this.addElementForm.nodeName &&
  505. this.addElementForm.tableType &&
  506. this.addElementForm.tableOwner
  507. ) {
  508. if (this.$refs.tree) {
  509. this.nodeIds = this.$refs.tree.getCheckedKeys();
  510. }
  511. if (this.$refs.treeall1) {
  512. this.nodeIds1 = this.$refs.treeall1.getCheckedKeys();
  513. }
  514. this.selectNodeIds = this.uniqueArr(this.nodeIds, this.nodeIds1);
  515. console.log(this.selectNodeIds, "去重的数组");
  516. if (this.selectNodeIds.length < 1) {
  517. this.$message({
  518. type: "warning",
  519. message: "至少勾选一个节点",
  520. });
  521. return;
  522. }
  523. this.selectNodeIds = this.selectNodeIds.join(",");
  524. this.savelinktableInfo({
  525. linkids: this.selectNodeIds,
  526. tabId: this.from.id,
  527. type: 2,
  528. wbsId: this.GLExcelFrom.name,
  529. });
  530. // this.submitExcelRelationWbsTreeAndElement({
  531. // nodeName: this.addElementForm.nodeName,
  532. // tableType: this.addElementForm.tableType,
  533. // tableOwner: this.addElementForm.tableOwner,
  534. // wbsId: this.addElementForm.wbsId,
  535. // elementList: this.tableData,
  536. // nodeIds: this.selectNodeIds,
  537. // excelTabId: this.from.id,
  538. // submitStatus: 2,
  539. // });
  540. } else {
  541. this.$message({
  542. type: "warning",
  543. message: "请填写和选择新增的表名,表类型,表所属方",
  544. });
  545. }
  546. }
  547. } else {
  548. this.$message({
  549. type: "warning",
  550. message: "请先选择WBS树节点表单",
  551. });
  552. }
  553. this.activeName = "link";
  554. },
  555. async getLazytree(parentId) {
  556. //清表树信息
  557. const { data: res } = await getLazytree({
  558. parentId: parentId,
  559. wbsId: this.GLExcelFrom.name,
  560. wbsType: "1",
  561. });
  562. console.log(res);
  563. if (res.code === 200 && res.msg === "操作成功") {
  564. this.isShowInput = true;
  565. console.log(this.isShowInput, " this.isShowInput");
  566. res.data.forEach((val) => {
  567. val.isExistForm = !!val.isExistForm;
  568. });
  569. return res.data;
  570. } else {
  571. return [];
  572. }
  573. },
  574. //查看节点下已关联的元素表信息
  575. searchNodeTables(id) {
  576. searchNodeTables(id, this.from.id).then((res) => {
  577. if (res.data.data&&res.data.data.length > 0) {
  578. res.data.data.forEach((val) => {
  579. if (val.isLinkTable == 2) {
  580. val.checknd = true;
  581. } else {
  582. val.checknd = false;
  583. }
  584. val.loading = false;
  585. });
  586. this.addTableData = res.data.data;
  587. } else {
  588. this.addTableData = [];
  589. }
  590. });
  591. },
  592. //数组去重
  593. uniqueArr(arr1, arr2) {
  594. //合并两个数组
  595. arr1.push(...arr2); //或者arr1 = [...arr1,...arr2]
  596. //去重
  597. let arr3 = Array.from(new Set(arr1)); //let arr3 = [...new Set(arr1)]
  598. return arr3;
  599. },
  600. async dictionarydataType() {
  601. //数据类型字典
  602. const { data: res } = await dictionarydataType();
  603. console.log(res);
  604. if (res.code == 200) {
  605. res.data.forEach((element) => {
  606. element.dictKey = Number(element.dictKey);
  607. });
  608. this.dataType = res.data;
  609. }
  610. },
  611. // async submitExcelRelationWbsTreeAndElement(da) {
  612. // console.log(da,'新增元素信息表');
  613. // //保存接口
  614. // da.elementList.forEach((ele) => {
  615. // ele.eName = ele.textInfo;
  616. // ele.eType = ele.textElementType;
  617. // ele.eAllowDeviation = ele.textDeviation;
  618. // });
  619. // const { data: res } = await submitExcelRelationWbsTreeAndElement(da);
  620. // if (res.code == 200) {
  621. // this.$message({
  622. // type: "success",
  623. // message: "设置成功",
  624. // });
  625. // this.AssociatedPublicTap = false;
  626. // this.AssociatedPublicClose();
  627. // }
  628. // },
  629. async savelinktableInfo(da) {
  630. console.log("新增元素表", da);
  631. const { data: res } = await savelinktableInfo(da);
  632. if (res.code == 200) {
  633. this.$message({
  634. type: "success",
  635. message: "设置成功",
  636. });
  637. this.AssociatedPublicTap = false;
  638. this.AssociatedPublicClose();
  639. }
  640. },
  641. //选择关联取消关联修改
  642. async savelinktableInfo1(da) {
  643. console.log("选择关联", da);
  644. const { data: res } = await savelinktableInfo(da);
  645. if (res.code == 200) {
  646. this.$message({
  647. type: "success",
  648. message: "设置成功",
  649. });
  650. // this.AssociatedPublicTap = false;
  651. // this.AssociatedPublicClose();
  652. }
  653. },
  654. async getColByTabId() {
  655. //获取字段信息
  656. const { data: res } = await getColByTabId({ tabId: this.from.id });
  657. // const { data: res } = await getColByTabId({tabId: '1537614072773054466' });
  658. if (res.code === 200) {
  659. res.data.forEach((element) => {
  660. //element.eName = element.textInfo;
  661. if (element.textElementType < 1) {
  662. element.textElementType = 1;
  663. }
  664. });
  665. this.tableData = res.data;
  666. console.log(this.tableData, "获取字段信息");
  667. }
  668. },
  669. },
  670. };
  671. </script>
  672. <style></style>