PublicWbs.vue 23 KB

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