projectInfoTable.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form">
  4. <el-button
  5. v-if="dialogType !== 'view'"
  6. type="primary"
  7. icon="el-icon-plus"
  8. class="ele-btn-icon"
  9. style="margin-bottom: 5px"
  10. @click="handleAddInfo"
  11. >
  12. 新增项目阶段
  13. </el-button>
  14. <el-button
  15. v-if="dialogType !== 'view'"
  16. type="primary"
  17. class="ele-btn-icon"
  18. style="margin-bottom: 5px"
  19. @click="save"
  20. >
  21. 保存
  22. </el-button>
  23. <el-button
  24. v-if="dialogType !== 'view'"
  25. type="primary"
  26. class="ele-btn-icon"
  27. style="margin-bottom: 5px"
  28. @click="updateFn"
  29. >
  30. 确认修改
  31. </el-button>
  32. <!-- 数据表格 -->
  33. <ele-pro-table
  34. ref="table"
  35. :columns="columns"
  36. :datasource="form.datasource"
  37. :needPage="false"
  38. :toolkit="[]"
  39. :minHeight="100"
  40. tool-class="ele-toolbar-form"
  41. >
  42. <template v-slot:action="{ row, $index }">
  43. <el-popconfirm
  44. class="ele-action"
  45. title="确定要删除此信息吗?"
  46. @confirm="handleDelInfo(row, $index)"
  47. >
  48. <template v-slot:reference>
  49. <el-link type="danger" :underline="false" icon="el-icon-delete">
  50. 删除
  51. </el-link>
  52. </template>
  53. </el-popconfirm>
  54. <el-link
  55. v-if="row.id"
  56. type="primary"
  57. :underline="false"
  58. icon="el-icon-edit"
  59. @click="editFn(row, $index)"
  60. >
  61. 修改
  62. </el-link>
  63. </template>
  64. <template v-slot:name="{ row, $index }" v-if="dialogType !== 'view'">
  65. <el-form-item
  66. :prop="'datasource.' + $index + '.name'"
  67. :rules="{
  68. required: true,
  69. message: '请选择',
  70. trigger: ['blur', 'change']
  71. }"
  72. >
  73. <el-input
  74. v-model="row.name"
  75. clearable
  76. :disabled="row.isEdit"
  77. ></el-input>
  78. </el-form-item>
  79. </template>
  80. <template v-slot:content="{ row, $index }" v-if="dialogType !== 'view'">
  81. <el-form-item :prop="'datasource.' + $index + '.content'">
  82. <el-input v-model="row.content" clearable></el-input>
  83. </el-form-item>
  84. </template>
  85. <template
  86. v-slot:planStartDate="{ row, $index }"
  87. v-if="dialogType !== 'view'"
  88. >
  89. <el-form-item
  90. :prop="'datasource.' + $index + '.planStartDate'"
  91. :rules="{
  92. required: true,
  93. message: '请选择',
  94. trigger: ['blur', 'change']
  95. }"
  96. >
  97. <el-date-picker
  98. style="width: 100%"
  99. :disabled="row.isEdit || dialogType == 'view'"
  100. v-model="row.planStartDate"
  101. :picker-options="{
  102. disabledDate: (time) => {
  103. return (
  104. row.isEdit &&
  105. row.planEndDate &&
  106. time.getTime() > new Date(row.planEndDate)
  107. );
  108. }
  109. }"
  110. type="date"
  111. placeholder="选择日期"
  112. >
  113. </el-date-picker>
  114. </el-form-item>
  115. </template>
  116. <template
  117. v-slot:planEndDate="{ row, $index }"
  118. v-if="dialogType !== 'view'"
  119. >
  120. <el-form-item
  121. :prop="'datasource.' + $index + '.planEndDate'"
  122. :rules="{
  123. required: true,
  124. message: '请选择',
  125. trigger: ['blur', 'change']
  126. }"
  127. >
  128. <el-date-picker
  129. style="width: 100%"
  130. :disabled="row.isEdit || dialogType == 'view'"
  131. :picker-options="{
  132. disabledDate: (time) => {
  133. return (
  134. row.planStartDate &&
  135. time.getTime() < new Date(row.planStartDate)
  136. );
  137. }
  138. }"
  139. v-model="row.planEndDate"
  140. type="date"
  141. placeholder="选择日期"
  142. >
  143. </el-date-picker>
  144. </el-form-item>
  145. </template>
  146. <template
  147. v-slot:responsibleUserId="{ row, $index }"
  148. v-if="dialogType !== 'view'"
  149. >
  150. <el-form-item :prop="'datasource.' + $index + '.responsibleUserId'">
  151. <el-select
  152. v-model="row.responsibleUserId"
  153. collapse-tags
  154. filterable
  155. placeholder="请选择"
  156. style="width: 100%"
  157. clearable
  158. size="medium"
  159. :disabled="row.isEdit || dialogType == 'view'"
  160. @change="(val) => personChange(val, $index)"
  161. >
  162. <el-option
  163. v-for="item in userList"
  164. :key="item.id"
  165. :label="item.name"
  166. :value="item.id"
  167. >
  168. </el-option>
  169. </el-select>
  170. </el-form-item>
  171. </template>
  172. <template
  173. v-slot:responsibleDeptId="{ row, $index }"
  174. v-if="dialogType !== 'view'"
  175. >
  176. <el-form-item :prop="'datasource.' + $index + '.responsibleDeptId'">
  177. <ele-tree-select
  178. :disabled="dialogType == 'view'"
  179. clearable
  180. :data="deptTreeList"
  181. :ref="'deptTreeRef' + $index"
  182. v-model="row.responsibleDeptId"
  183. valueKey="id"
  184. labelKey="name"
  185. placeholder="请选择"
  186. @change="(id) => changeDeptInfo(id, $index)"
  187. default-expand-all
  188. />
  189. </el-form-item>
  190. </template>
  191. <template
  192. v-slot:isMilepost="{ row, $index }"
  193. v-if="dialogType !== 'view'"
  194. >
  195. <el-form-item>
  196. <el-select v-model="row.isMilepost">
  197. <el-option label="否" :value="0" />
  198. <el-option label="是" :value="1" />
  199. </el-select>
  200. </el-form-item>
  201. </template>
  202. <template
  203. v-slot:milepost="{ row, $index }"
  204. v-if="dialogType !== 'view'"
  205. >
  206. <el-form-item>
  207. <el-input v-model="row.milepost" clearable></el-input>
  208. </el-form-item>
  209. </template>
  210. <template v-slot:isOverTime="{ row }">
  211. <el-tag v-if="row.isOverTime == 0" type="success">正常</el-tag>
  212. <el-tag v-else type="danger">超时</el-tag>
  213. </template>
  214. <template v-slot:proportion="{ row }">
  215. <el-input
  216. type="number"
  217. :min="0"
  218. :max="100"
  219. v-model="row.proportion"
  220. :disabled="dialogType == 'view'"
  221. >
  222. </el-input>
  223. </template>
  224. <template v-slot:speedPercent="{ row }">
  225. <el-progress
  226. :stroke-width="20"
  227. text-color="#606266"
  228. :text-inside="true"
  229. :percentage="row.speedPercent || 0"
  230. :color="customColorMethod"
  231. ></el-progress>
  232. </template>
  233. <template v-slot:remark="{ row, $index }" v-if="dialogType !== 'view'">
  234. <el-form-item>
  235. <el-input
  236. type="textarea"
  237. v-model="row.remark"
  238. clearable
  239. :disabled="row.isEdit"
  240. ></el-input>
  241. </el-form-item>
  242. </template>
  243. <template v-slot:headerRequired="{ column }">
  244. <span class="is-required">{{ column.label }}</span>
  245. </template>
  246. </ele-pro-table>
  247. </el-form>
  248. </div>
  249. </template>
  250. <script>
  251. import { mapGetters } from 'vuex';
  252. import { getByCode } from '@/api/system/dictionary-data';
  253. import fileUpload from '@/components/upload/fileUpload.vue';
  254. import { getFile } from '@/api/system/file';
  255. import PersonSelect from '@/components/CommomSelect/person-select.vue';
  256. import { proStatusEnum } from '@/enum/dict';
  257. import { listOrganizations } from '@/api/system/organization';
  258. // import { deepClone } from '@/utils';
  259. import { deepClone } from '@/components/FormGenerator/utils/index';
  260. import {
  261. projectsstageSave,
  262. projectsstageSaveBatch,
  263. projectsGetByIdDetailsAPI,
  264. projectsStageUpdateAPI,
  265. projectsStageDeleteAPI
  266. } from '@/api/project-manage';
  267. export default {
  268. name: 'stageInfoTable',
  269. components: {
  270. PersonSelect,
  271. fileUpload
  272. },
  273. props: {
  274. responsibleDeptId: {
  275. type: String
  276. },
  277. dialogForm: {
  278. type: Object,
  279. default: () => {
  280. return {
  281. ...this.form
  282. };
  283. }
  284. },
  285. dialogType: {
  286. type: String,
  287. default: ''
  288. },
  289. deptList: {
  290. type: Array,
  291. default: () => {
  292. return [];
  293. }
  294. },
  295. userList: {
  296. type: Array,
  297. default: () => {
  298. return [];
  299. }
  300. },
  301. deptTreeList: {
  302. type: Array,
  303. default: () => {
  304. return [];
  305. }
  306. }
  307. },
  308. watch: {
  309. userList: {
  310. handler(val) {
  311. console.log(val);
  312. },
  313. deep: true
  314. },
  315. dialogForm: {
  316. handler(val) {
  317. this.form.datasource = deepClone(this.dialogForm.stageList) || [];
  318. this.form.datasource.forEach((item) => {
  319. this.$set(item, 'isEdit', true);
  320. });
  321. this.$nextTick(async () => {
  322. if (this.dialogType === 'view') return;
  323. this.form.datasource.forEach((item) => {
  324. this.$set(item, 'isEdit', true);
  325. });
  326. });
  327. },
  328. deep: true
  329. },
  330. deptList: {
  331. handler(newValue, oldValue) {
  332. console.log('bianhua');
  333. console.log(newValue, oldValue);
  334. },
  335. deep: true
  336. }
  337. },
  338. data() {
  339. return {
  340. editIndex: undefined, //当前修改数据的下标
  341. form: {
  342. datasource: []
  343. },
  344. responceUserList: [],
  345. addFlag: false
  346. };
  347. },
  348. computed: {
  349. columns() {
  350. let list = [
  351. {
  352. columnKey: 'index',
  353. label: '序号',
  354. type: 'index',
  355. width: 55,
  356. align: 'center',
  357. showOverflowTooltip: true,
  358. fixed: 'left'
  359. },
  360. {
  361. prop: 'name',
  362. label: '阶段名称',
  363. align: 'center',
  364. showOverflowTooltip: true,
  365. minWidth: 120,
  366. slot: 'name',
  367. headerSlot: 'headerRequired'
  368. },
  369. // {
  370. // prop: 'responsibleDeptName',
  371. // label: '负责部门',
  372. // align: 'center',
  373. // showOverflowTooltip: true,
  374. // minWidth: 130,
  375. // slot: 'responsibleDeptId',
  376. // headerSlot: 'headerRequired',
  377. // },
  378. {
  379. prop: 'responsibleUserNames',
  380. label: '负责人',
  381. align: 'center',
  382. showOverflowTooltip: true,
  383. minWidth: 200,
  384. slot: 'responsibleUserId',
  385. headerSlot: 'headerRequired'
  386. },
  387. {
  388. prop: 'planStartDate',
  389. label: '开始时间',
  390. align: 'center',
  391. showOverflowTooltip: true,
  392. minWidth: 170,
  393. slot: 'planStartDate',
  394. headerSlot: 'headerRequired'
  395. },
  396. {
  397. prop: 'planEndDate',
  398. label: '结束时间',
  399. align: 'center',
  400. showOverflowTooltip: true,
  401. minWidth: 170,
  402. slot: 'planEndDate',
  403. headerSlot: 'headerRequired'
  404. },
  405. {
  406. prop: 'realStartTime',
  407. label: '实际开始时间',
  408. align: 'center',
  409. showOverflowTooltip: true,
  410. minWidth: 170
  411. },
  412. {
  413. prop: 'realEndTime',
  414. label: '实际结束时间',
  415. align: 'center',
  416. showOverflowTooltip: true,
  417. minWidth: 170
  418. },
  419. {
  420. prop: 'remark',
  421. label: '备注',
  422. align: 'center',
  423. showOverflowTooltip: true,
  424. minWidth: 160,
  425. slot: 'remark'
  426. },
  427. {
  428. prop: 'isOverTime',
  429. label: '是否超时',
  430. align: 'center',
  431. showOverflowTooltip: true,
  432. minWidth: 100,
  433. slot: 'isOverTime'
  434. },
  435. // {
  436. // prop: 'proportion',
  437. // label: '权重占比(%)',
  438. // align: 'center',
  439. // showOverflowTooltip: true,
  440. // minWidth: 110,
  441. // slot: 'proportion'
  442. // },
  443. {
  444. prop: 'speedPercent',
  445. label: '进度',
  446. align: 'center',
  447. showOverflowTooltip: true,
  448. minWidth: 150,
  449. slot: 'speedPercent'
  450. },
  451. {
  452. prop: 'status',
  453. label: '状态',
  454. align: 'center',
  455. showOverflowTooltip: true,
  456. minWidth: 130,
  457. formatter: (_row, _column, cellValue) => {
  458. return proStatusEnum[cellValue].label;
  459. }
  460. }
  461. ];
  462. let action = [
  463. {
  464. columnKey: 'action',
  465. slot: 'action',
  466. label: '操作',
  467. resizable: false,
  468. minWidth: 180,
  469. align: 'center',
  470. showOverflowTooltip: true,
  471. fixed: 'right'
  472. }
  473. ];
  474. this.dialogType === 'view'
  475. ? (list = [...list])
  476. : (list = [...list, ...action]);
  477. return list;
  478. }
  479. },
  480. methods: {
  481. // 选择负责人部门
  482. changeDeptInfo(id, index) {
  483. console.log(id, index);
  484. const info = this.deptList.find((e) => e.id == id) || {};
  485. this.$set(
  486. this.form.datasource[index],
  487. 'responsibleDeptName',
  488. info.name
  489. );
  490. this.$set(this.form.datasource[index], 'responsibleUserId', '');
  491. this.$set(this.form.datasource[index], 'responsibleUserName', '');
  492. // this.getUserList(id, index);
  493. },
  494. // 获取人员数据
  495. getUserList(groupId, index) {
  496. // if (groupId) {
  497. // this.$refs['directorRef' + index].getList({groupId});
  498. // }
  499. },
  500. personChange(val, index) {
  501. const info = this.userList.find((e) => e.id == val) || {};
  502. console.log(val, info, index);
  503. console.log(this.dialogForm);
  504. this.$set(
  505. this.form.datasource[index],
  506. 'responsibleUserName',
  507. info.name
  508. );
  509. // this.$set(
  510. // this.form.datasource[index],
  511. // 'responsibleDeptName',
  512. // this.dialogForm.responsibleDeptName
  513. // );
  514. },
  515. // personChange(val, index) {
  516. //
  517. // // this.$set(this.form.datasource[index], 'responsibleUserName', info.name);
  518. // },
  519. downloadFile(file) {
  520. getFile({ objectName: file.storePath }, file.name);
  521. },
  522. //新增计划数据
  523. handleAddInfo() {
  524. this.addFlag = true;
  525. this.$nextTick(() => {
  526. this.form.datasource.push({
  527. projectId: localStorage.getItem('projectId'),
  528. milepost: '',
  529. isMilepost: 0,
  530. responsibleUserList: [],
  531. responsibleUserId: '',
  532. responsibleDeptId: this.responsibleDeptId,
  533. responsibleDeptName: this.dialogForm.responsibleDeptName,
  534. planStartDate: '',
  535. planEndDate: '',
  536. name: '',
  537. content: '',
  538. status: 0,
  539. isOverTime: 0,
  540. speedPercent: 0,
  541. remark: ''
  542. });
  543. console.log(this.form.datasource);
  544. });
  545. },
  546. //
  547. clearData() {
  548. this.form.datasource.forEach((item, index) => {
  549. this.$set(this.form.datasource[index], 'milepost', '');
  550. this.$set(this.form.datasource[index], 'isMilepost', 0);
  551. this.$set(this.form.datasource[index], 'isOverTime', 0);
  552. this.$set(this.form.datasource[index], 'speedPercent', 0);
  553. this.$set(this.form.datasource[index], 'responsibleUserId', '');
  554. this.$set(this.form.datasource[index], 'responsibleUserName', '');
  555. this.$set(this.form.datasource[index], 'responsibleDeptId', '');
  556. this.$set(this.form.datasource[index], 'responsibleDeptName', '');
  557. this.$set(this.form.datasource[index], 'planStartDate', '');
  558. this.$set(this.form.datasource[index], 'planEndDate', '');
  559. this.$set(this.form.datasource[index], 'name', '');
  560. this.$set(this.form.datasource[index], 'content', '');
  561. });
  562. },
  563. //删除关联信息数据
  564. async handleDelInfo(row, index) {
  565. if (!row.id) {
  566. this.form.datasource.splice(index, 1);
  567. return;
  568. }
  569. const res = await projectsStageDeleteAPI([row.id]);
  570. this.init();
  571. },
  572. customColorMethod(percentage) {
  573. if (percentage < 30) {
  574. return '#909399';
  575. } else if (percentage < 70) {
  576. return '#e6a23c';
  577. } else {
  578. return '#67c23a';
  579. }
  580. },
  581. async save() {
  582. let form = await this.getTableValidate();
  583. let saveForm = form.filter((item) => !item.id);
  584. console.log(form);
  585. const res = await projectsstageSaveBatch(saveForm);
  586. if (res) {
  587. this.init();
  588. }
  589. },
  590. getTableValidate() {
  591. return new Promise((resolve, reject) => {
  592. // if (this.form.datasource.length == 0) return this.$message.warning('')
  593. this.$refs.form.validate((valid) => {
  594. if (!valid) {
  595. this.$message.warning('有必填项未填,请检查');
  596. reject('有必填项未填,请检查');
  597. } else {
  598. resolve(this.form.datasource);
  599. }
  600. });
  601. });
  602. },
  603. init() {
  604. this.$nextTick(async () => {
  605. const res = await projectsGetByIdDetailsAPI(
  606. localStorage.getItem('projectId')
  607. );
  608. console.log(res);
  609. this.form.datasource = res.allStageList || [];
  610. this.form.datasource.forEach((item) => {
  611. this.$set(item, 'isEdit', true);
  612. });
  613. console.log(this.form);
  614. });
  615. // projectsGetByIdDetailsAPI
  616. // this.form.datasource=
  617. },
  618. editFn(row, index) {
  619. console.log('xiugai', index, this.form.datasource);
  620. this.$nextTick(() => {
  621. this.$set(this.form.datasource[index], 'isEdit', false);
  622. });
  623. },
  624. async updateFn() {
  625. let form = await this.getTableValidate();
  626. let findItem = form.find((item) => !item.id);
  627. console.log(findItem);
  628. if (findItem) {
  629. this.$message('请先保存新增的数据');
  630. return;
  631. }
  632. let updateForm = form.filter((item) => !item.isEdit);
  633. console.log(updateForm);
  634. // const res = await projectsStageUpdateAPI(updateForm[0]);
  635. for (const item of updateForm) {
  636. await projectsStageUpdateAPI(item);
  637. }
  638. this.init();
  639. // const res = await projectsStageUpdateAPI(saveForm);
  640. // if (res) {
  641. // this.init();
  642. // }
  643. }
  644. },
  645. created() {
  646. this.init();
  647. }
  648. };
  649. </script>
  650. <style scoped lang="scss">
  651. :deep(.el-form-item) {
  652. margin-bottom: 0;
  653. }
  654. </style>