task-form.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <div>
  3. <el-form
  4. ref="form"
  5. :model="form"
  6. :rules="rules"
  7. class="el-form-box"
  8. label-width="120px"
  9. >
  10. <el-row>
  11. <el-col :span="8">
  12. <!-- prop="projectId" -->
  13. <el-form-item label="关联项目">
  14. <ele-tree-select
  15. :disabled="dialogType == 'view'"
  16. ref="projectTreeSelect"
  17. clearable
  18. filterable
  19. :data="projectList"
  20. v-model="form.projectId"
  21. childrenKey="sonTreeList"
  22. disabledKey="isChoice"
  23. valueKey="id"
  24. labelKey="name"
  25. placeholder="请选择"
  26. @change="changeProject"
  27. default-expand-all
  28. />
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="8">
  32. <el-form-item label="关联项目阶段" prop="projectStageId">
  33. <el-select
  34. v-model="form.projectStageId"
  35. :disabled="dialogType == 'view'"
  36. style="width: 100%"
  37. @change="changeProjectStage"
  38. clearable
  39. >
  40. <el-option
  41. v-for="item in projectStageList"
  42. :label="item.name"
  43. :value="item.id"
  44. :key="item.id"
  45. ></el-option>
  46. </el-select>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="8">
  50. <el-form-item label="关联项目BOM" prop="projectBomId">
  51. <ele-tree-select
  52. :disabled="dialogType == 'view'"
  53. clearable
  54. ref="projectRef"
  55. filterable
  56. :data="projectBOMList"
  57. v-model="form.projectBomId"
  58. @change="changeProjectBom"
  59. childrenKey="children"
  60. valueKey="id"
  61. labelKey="name"
  62. placeholder="请选择"
  63. default-expand-all
  64. />
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="8">
  68. <!-- <el-form-item label="关联计划" prop="targetPlanId">-->
  69. <!-- <el-select v-model="form.targetPlanId" :disabled="dialogType=='view'" style="width: 100%"-->
  70. <!-- @change="changeTargetPlan" clearable>-->
  71. <!-- <el-option v-for="item in targetPlanList" :label="item.name" :value="item.id"-->
  72. <!-- :key="item.id"></el-option>-->
  73. <!-- </el-select>-->
  74. <!-- </el-form-item>-->
  75. <el-form-item label="关联计划">
  76. <el-row>
  77. <el-col :span="24">
  78. <ele-tree-select
  79. :disabled="dialogType == 'view'"
  80. clearable
  81. ref="planTreeRef"
  82. filterable
  83. :data="targetPlanList"
  84. v-model="form.targetPlanId"
  85. childrenKey="children"
  86. @change="changeTargetPlan"
  87. node-key="id"
  88. valueKey="id"
  89. labelKey="name"
  90. placeholder="请选择"
  91. default-expand-all
  92. />
  93. </el-col>
  94. <!-- <el-col :span="1">-->
  95. <!-- <el-popover-->
  96. <!-- placement="right"-->
  97. <!-- v-model="popoverFlag"-->
  98. <!-- width="1000"-->
  99. <!-- trigger="click">-->
  100. <!-- <headerTitle title="项目信息"></headerTitle>-->
  101. <!-- <project-form ref="projectForm" dialog-type="view"></project-form>-->
  102. <!-- <el-button :disabled="!form.projectId" type="text" slot="reference"-->
  103. <!-- @click="getProjectInfo(form.projectId)">详情-->
  104. <!-- </el-button>-->
  105. <!-- </el-popover>-->
  106. <!-- </el-col>-->
  107. </el-row>
  108. </el-form-item>
  109. </el-col>
  110. <el-col :span="8">
  111. <el-form-item label="关联计划节点" prop="planStageId">
  112. <el-select
  113. v-model="form.planStageId"
  114. :disabled="dialogType == 'view'"
  115. style="width: 100%"
  116. @change="changePlanStage"
  117. clearable
  118. >
  119. <el-option
  120. v-for="item in planStageList"
  121. :label="item.name"
  122. :value="item.id"
  123. :key="item.id"
  124. ></el-option>
  125. </el-select>
  126. </el-form-item>
  127. </el-col>
  128. <el-col :span="8">
  129. <el-form-item label="关联任务" prop="taskId">
  130. <ele-tree-select
  131. :disabled="dialogType == 'view'"
  132. ref="taskTreeSelect"
  133. clearable
  134. filterable
  135. :data="taskList"
  136. v-model="form.taskId"
  137. childrenKey="sonTreeList"
  138. disabledKey="isChoice"
  139. valueKey="id"
  140. labelKey="name"
  141. placeholder="请选择"
  142. default-expand-all
  143. @change="changeTask"
  144. />
  145. </el-form-item>
  146. </el-col>
  147. <el-col :span="8">
  148. <el-form-item label="前置任务">
  149. <el-select
  150. v-model="form.beforeTaskId"
  151. :disabled="dialogType == 'view'"
  152. style="width: 100%"
  153. clearable
  154. >
  155. <el-option
  156. v-for="item in beforeTaskList"
  157. :label="item.name"
  158. :value="item.id"
  159. :key="item.id"
  160. ></el-option>
  161. </el-select>
  162. </el-form-item>
  163. </el-col>
  164. </el-row>
  165. </el-form>
  166. </div>
  167. </template>
  168. <script>
  169. import {
  170. projectsBomGetTreeDataAPI,
  171. projectsSelectTreeDataAPI
  172. } from '@/api/project-manage';
  173. import PersonSelect from '@/components/CommomSelect/person-select.vue';
  174. import { getBeforeTaskListAPI } from '@/api/project-manage/task';
  175. import { getTargetPlanTreeAPI } from '@/api/project-manage/plan';
  176. export default {
  177. name: 'task-form',
  178. components: { PersonSelect },
  179. props: {
  180. dialogType: {
  181. type: String,
  182. default: ''
  183. },
  184. dialogForm: {
  185. type: Object,
  186. default: () => {
  187. return {};
  188. }
  189. },
  190. deptList: {
  191. type: Array,
  192. default() {
  193. return [];
  194. }
  195. },
  196. userList: {
  197. type: Array,
  198. default() {
  199. return [];
  200. }
  201. },
  202. deptTreeList: {
  203. type: Array,
  204. default() {
  205. return [];
  206. }
  207. }
  208. },
  209. watch: {
  210. dialogForm: {
  211. handler(val) {
  212. for (const key in this.form) {
  213. if (key == 'relationType') {
  214. this.form[key] = this.dialogForm[key];
  215. } else {
  216. this.form[key] = this.dialogForm[key] || this.form[key];
  217. }
  218. }
  219. this.$nextTick(async () => {
  220. await this.getUserList(this.dialogForm.responsibleDeptId);
  221. //通过项目去查
  222. if (this.dialogForm.projectId) {
  223. await this.getBeforeTaskList(this.dialogForm.projectId);
  224. //查项目阶段
  225. await this.getProjectsSelectTreeData(
  226. {
  227. treeType: 0,
  228. id: this.dialogForm.projectId,
  229. isTask: 0,
  230. isPlan: 0
  231. },
  232. 'projectStageList'
  233. );
  234. //查项目BOM
  235. this.projectBOMList = await projectsBomGetTreeDataAPI(
  236. this.dialogForm.projectId
  237. );
  238. //查项目阶段关联的计划
  239. let params = {
  240. projectId: this.form.projectId,
  241. projectBomId: this.form.projectBomId,
  242. projectStageId: this.form.projectStageId,
  243. processStatus: [2],
  244. status: [0, 1]
  245. };
  246. this.targetPlanList = await this.getTargetPlanTree(params);
  247. if (!this.dialogForm.projectStageId) {
  248. //查项目关联的计划
  249. // await this.getProjectsSelectTreeData({
  250. // treeType: 0,
  251. // id: this.dialogForm.projectId,
  252. // isTask: 0,
  253. // isPlan: 1
  254. // }, 'targetPlanList')
  255. //查项目关联的任务
  256. await this.getProjectsSelectTreeData(
  257. {
  258. treeType: 0,
  259. id: this.dialogForm.projectId,
  260. isTask: 1,
  261. isPlan: 0
  262. },
  263. 'taskList'
  264. );
  265. }
  266. }
  267. //通过项目阶段去查
  268. if (this.dialogForm.projectStageId) {
  269. // await this.getProjectsSelectTreeData({
  270. // treeType: 1,
  271. // id: this.dialogForm.projectStageId,
  272. // isTask: 0,
  273. // isPlan: 1
  274. // }, 'targetPlanList')
  275. if (!this.dialogForm.targetPlanId) {
  276. //查项目阶段关联的任务
  277. await this.getProjectsSelectTreeData(
  278. {
  279. treeType: 1,
  280. id: this.dialogForm.projectStageId,
  281. isTask: 1,
  282. isPlan: 0
  283. },
  284. 'taskList'
  285. );
  286. }
  287. }
  288. //通过计划去查
  289. if (this.dialogForm.targetPlanId) {
  290. //查计划关联下的节点
  291. await this.getProjectsSelectTreeData(
  292. {
  293. treeType: 2,
  294. id: this.dialogForm.targetPlanId,
  295. isTask: 0,
  296. isPlan: 0
  297. },
  298. 'planStageList'
  299. );
  300. if (!this.dialogForm.planStageId) {
  301. //查计划关联下的任务
  302. await this.getProjectsSelectTreeData(
  303. {
  304. treeType: 2,
  305. id: this.dialogForm.targetPlanId,
  306. isTask: 1,
  307. isPlan: 0
  308. },
  309. 'taskList'
  310. );
  311. }
  312. }
  313. //通过计划节点去查
  314. if (this.dialogForm.planStageId) {
  315. //查计划关联下的任务
  316. await this.getProjectsSelectTreeData(
  317. {
  318. treeType: 3,
  319. id: this.dialogForm.planStageId,
  320. isTask: 1,
  321. isPlan: 0
  322. },
  323. 'taskList'
  324. );
  325. }
  326. });
  327. },
  328. deep: true
  329. }
  330. },
  331. data() {
  332. return {
  333. form: {
  334. beforeTaskId: '',
  335. projectId: '',
  336. projectStageId: '',
  337. projectBomId: '',
  338. targetPlanId: '',
  339. planStageId: '',
  340. taskId: '',
  341. relationType: '',
  342. relationId: '',
  343. relationName: ''
  344. },
  345. projectList: [],
  346. projectStageList: [],
  347. targetPlanList: [],
  348. planStageList: [],
  349. projectBOMList: [],
  350. taskList: [],
  351. beforeTaskList: [],
  352. rules: {
  353. type: { required: true, message: '请选择任务类型', trigger: 'change' },
  354. name: { required: true, message: '请输入任务名称', trigger: 'blur' },
  355. planStartDate: {
  356. required: true,
  357. message: '请选择计划开始日期',
  358. trigger: 'change'
  359. },
  360. projectId: {
  361. required: true,
  362. message: '请选择关联项目',
  363. trigger: ['change', 'blur']
  364. },
  365. responsibleDeptId: {
  366. required: true,
  367. message: '请选择负责部门',
  368. trigger: 'change'
  369. },
  370. cost: {
  371. required: true,
  372. message: '请输入费用',
  373. trigger: ['change', 'blur']
  374. }
  375. }
  376. };
  377. },
  378. async created() {
  379. this.targetPlanList = await this.getTargetPlanTree({
  380. projectId: '',
  381. processStatus: [2],
  382. status: [0, 1]
  383. });
  384. //查项目
  385. await this.getProjectsSelectTreeData(
  386. { treeType: 0, isTask: 0, isPlan: 0 },
  387. 'projectList'
  388. );
  389. },
  390. methods: {
  391. //关联项目改变
  392. async changeProject(val) {
  393. //项目阶段
  394. this.projectStageList = [];
  395. //项目BOM
  396. this.projectBOMList = [];
  397. //项目关联计划
  398. this.targetPlanList = [];
  399. //项目关联计划下的节点
  400. this.planStageList = [];
  401. //项目关联的任务
  402. this.taskList = [];
  403. //前置任务
  404. this.beforeTaskList = [];
  405. this.form.projectStageId = null;
  406. this.form.targetPlanId = null;
  407. this.form.planStageId = null;
  408. this.form.taskId = null;
  409. this.form.beforeTaskId = null;
  410. this.form.projectBomId = null;
  411. this.$emit('changeProject', val);
  412. //查计划
  413. let params = {
  414. projectId: val,
  415. projectBomId: this.form.projectBomId,
  416. projectStageId: this.form.projectStageId,
  417. processStatus: [2],
  418. status: [0, 1]
  419. };
  420. this.targetPlanList = await this.getTargetPlanTree(params);
  421. if (!val) return;
  422. //查前置任务
  423. await this.getBeforeTaskList(val);
  424. // let node = this.$refs.projectTreeSelect?.$refs?.tree?.getCurrentNode() || {};
  425. this.setTaskInfo(0, val, '项目');
  426. //查项目阶段
  427. await this.getProjectsSelectTreeData(
  428. { treeType: 0, id: val, isTask: 0, isPlan: 0 },
  429. 'projectStageList'
  430. );
  431. //查项目关联的计划
  432. // await this.getProjectsSelectTreeData({treeType: 0, id: val, isTask: 0, isPlan: 1}, 'targetPlanList')
  433. //查项目关联的任务
  434. await this.getProjectsSelectTreeData(
  435. { treeType: 0, id: val, isTask: 1, isPlan: 0 },
  436. 'taskList'
  437. );
  438. //查项目关联的BOM
  439. this.projectBOMList = await projectsBomGetTreeDataAPI(val);
  440. if (val) {
  441. this.$refs.form.clearValidate('projectId');
  442. } else {
  443. this.$refs.form.validateField('projectId');
  444. }
  445. },
  446. //关联项目阶段改变
  447. async changeProjectStage(val) {
  448. //项目关联计划
  449. this.targetPlanList = [];
  450. //项目关联计划下的节点
  451. this.planStageList = [];
  452. //项目关联的任务
  453. this.taskList = [];
  454. this.form.targetPlanId = null;
  455. this.form.planStageId = null;
  456. this.form.taskId = null;
  457. let params = {
  458. projectId: this.form.projectId,
  459. projectBomId: this.form.projectBomId,
  460. projectStageId: val,
  461. processStatus: [2],
  462. status: [0, 1]
  463. };
  464. this.targetPlanList = await this.getTargetPlanTree(params);
  465. if (!val) {
  466. if (this.form.projectId) {
  467. await this.changeProject(this.form.projectId);
  468. }
  469. return;
  470. }
  471. this.setTaskInfo(1, val, '项目阶段');
  472. //查项目阶段关联的计划
  473. // await this.getProjectsSelectTreeData({treeType: 1, id: val, isTask: 0, isPlan: 1}, 'targetPlanList')
  474. //查项目阶段关联的任务
  475. await this.getProjectsSelectTreeData(
  476. { treeType: 1, id: val, isTask: 1, isPlan: 0 },
  477. 'taskList'
  478. );
  479. },
  480. //关联项目BOM改变
  481. async changeProjectBom(val) {
  482. //项目关联计划
  483. this.targetPlanList = [];
  484. //项目关联计划下的节点
  485. this.planStageList = [];
  486. //项目关联的任务
  487. this.taskList = [];
  488. this.form.targetPlanId = null;
  489. this.form.planStageId = null;
  490. this.form.taskId = null;
  491. let params = {
  492. projectId: this.form.projectId,
  493. projectBomId: val,
  494. projectStageId: this.form.projectStageId,
  495. processStatus: [2],
  496. status: [0, 1]
  497. };
  498. this.targetPlanList = await this.getTargetPlanTree(params);
  499. if (!val) {
  500. if (this.form.projectId) {
  501. await this.changeProject(this.form.projectId);
  502. }
  503. return;
  504. }
  505. this.setTaskInfo(5, val, '项目BOM');
  506. //查项目BOM关联的计划
  507. // await this.getProjectsSelectTreeData({treeType: 1, id: val, isTask: 0, isPlan: 1}, 'targetPlanList')
  508. //查项目BOM关联的任务
  509. await this.getProjectsSelectTreeData(
  510. { treeType: 1, id: val, isTask: 1, isPlan: 0 },
  511. 'taskList'
  512. );
  513. },
  514. //关联计划改变
  515. async changeTargetPlan(val) {
  516. //项目关联计划下的节点
  517. this.planStageList = [];
  518. //项目关联的任务
  519. this.taskList = [];
  520. this.form.planStageId = null;
  521. this.form.taskId = null;
  522. if (!val) {
  523. if (this.form.projectStageId) {
  524. await this.changeProjectStage(this.form.projectStageId);
  525. } else if (this.form.projectId) {
  526. await this.changeProject(this.form.projectId);
  527. }
  528. return;
  529. }
  530. let nodeData =
  531. this.$refs?.planTreeRef?.$refs?.tree?.getCurrentNode() || {};
  532. await this.getProjectsSelectTreeData(
  533. {
  534. treeType: 0,
  535. id: nodeData.projectId,
  536. isTask: 0,
  537. isPlan: 0
  538. },
  539. 'projectStageList'
  540. );
  541. this.projectBOMList = await projectsBomGetTreeDataAPI(nodeData.projectId);
  542. this.form.projectId = nodeData.projectId;
  543. this.form.projectBomId = nodeData.projectBomId;
  544. this.form.projectStageId = nodeData.projectStageId;
  545. this.setTaskInfo(2, val, '计划');
  546. this.$emit('changeProject', this.form.projectId);
  547. //查项目关联的计划下的节点
  548. await this.getProjectsSelectTreeData(
  549. { treeType: 2, id: val, isTask: 0, isPlan: 0 },
  550. 'planStageList'
  551. );
  552. //查项目关联的计划的任务
  553. await this.getProjectsSelectTreeData(
  554. { treeType: 2, id: val, isTask: 1, isPlan: 0 },
  555. 'taskList'
  556. );
  557. },
  558. //关联计划节点改变
  559. async changePlanStage(val) {
  560. //项目关联的任务
  561. this.taskList = [];
  562. this.form.taskId = null;
  563. if (!val) {
  564. if (this.form.targetPlanId) {
  565. await this.changeTargetPlan(this.form.targetPlanId);
  566. } else if (this.form.projectStageId) {
  567. await this.changeProjectStage(this.form.projectStageId);
  568. } else if (this.form.projectId) {
  569. await this.changeProject(this.form.projectId);
  570. }
  571. return;
  572. }
  573. this.setTaskInfo(3, val, '计划节点');
  574. //查项目关联的任务
  575. await this.getProjectsSelectTreeData(
  576. { treeType: 3, id: val, isTask: 1, isPlan: 0 },
  577. 'taskList'
  578. );
  579. },
  580. //关联任务改变
  581. async changeTask(val) {
  582. if (!val) {
  583. if (this.form.planStageId) {
  584. this.setTaskInfo(3, this.form.planStageId, '计划节点');
  585. } else if (this.form.targetPlanId) {
  586. this.setTaskInfo(2, this.form.targetPlanId, '计划');
  587. } else if (this.form.projectStageId) {
  588. this.setTaskInfo(1, this.form.projectStageId, '项目阶段');
  589. } else if (this.form.projectBomId) {
  590. this.setTaskInfo(5, this.form.projectBomId, '项目Bom');
  591. } else if (this.form.projectId) {
  592. this.setTaskInfo(0, this.form.projectId, '项目');
  593. }
  594. return;
  595. }
  596. this.setTaskInfo(4, val, '任务');
  597. },
  598. //设置任务类型
  599. setTaskInfo(type, id, name) {
  600. this.form.relationType = type;
  601. this.form.relationId = id;
  602. this.form.relationName = name;
  603. },
  604. //查项目关联信息集合
  605. async getProjectsSelectTreeData(params, listName) {
  606. params.ifFilter = this.dialogType == 'view' ? '0' : '1';
  607. this[listName] = await projectsSelectTreeDataAPI(params);
  608. },
  609. async getBeforeTaskList(val) {
  610. this.beforeTaskList = await getBeforeTaskListAPI(val);
  611. },
  612. // 获取人员数据
  613. getUserList(groupId) {
  614. if (groupId) {
  615. this.$refs.directorRef.getList({ groupId });
  616. }
  617. },
  618. personChange(val, info) {
  619. this.form.responsibleUserName = info.name;
  620. },
  621. async getTargetPlanTree(data = {}) {
  622. return await getTargetPlanTreeAPI(data);
  623. },
  624. validForm() {
  625. return new Promise((resolve, reject) => {
  626. this.$refs.form.validate((valid) => {
  627. if (!valid) {
  628. this.$message.warning('有必填项未填,请检查');
  629. reject('有必填项未填,请检查');
  630. } else {
  631. resolve(this.form);
  632. }
  633. });
  634. });
  635. }
  636. }
  637. };
  638. </script>
  639. <style scoped lang="scss">
  640. </style>