addDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="addDialogFlag"
  6. append-to-body
  7. :title="title"
  8. :close-on-click-modal="false"
  9. width="70%"
  10. :before-close="cancel">
  11. <plan-form-table ref="planForm" :dialog-type.sync="dialogType" :dialogForm="dialogForm" :deptList="deptList"
  12. :deptTreeList="deptTreeList" :userList="userList" @changeProject="changeProject"></plan-form-table>
  13. <div slot="footer">
  14. <el-button type="primary" size="small" @click="submit">保 存</el-button>
  15. <el-button size="small" @click="cancel">关 闭</el-button>
  16. </div>
  17. </ele-modal>
  18. </template>
  19. <script>
  20. import planFormTable from "./plan-form-table.vue";
  21. import {
  22. getTargetPlanCode,
  23. projectsPlanGetByIdAPI,
  24. projectsPlanSaveAPI,
  25. projectsPlanUpdateAPI,
  26. submit
  27. } from "@/api/project-manage/plan";
  28. import {deepClone} from "@/utils";
  29. import {getUserPage, listOrganizations} from "@/api/system/organization";
  30. import {projectsTeamGetByIdAPI} from "@/api/project-manage/team";
  31. import {projectsGetByIdAPI} from "@/api/project-manage";
  32. export default {
  33. name: "addOrEditDialog",
  34. components: {
  35. planFormTable
  36. },
  37. props: {
  38. addDialogFlag: {
  39. type: Boolean,
  40. default: false,
  41. }
  42. },
  43. data() {
  44. return {
  45. title: '',
  46. dialogType: '',
  47. dialogForm: {},
  48. userList: [],
  49. deptList: [],
  50. deptTreeList: [],
  51. allUserList: [],
  52. }
  53. },
  54. async created() {
  55. this.getDeptList();
  56. let {list} = await getUserPage({pageNum: 1, size: -1});
  57. this.allUserList = list
  58. },
  59. methods: {
  60. async init(row = {}, type='add') {
  61. this.title = type === 'add' ? '新增' : '编辑';
  62. this.dialogType = type;
  63. this.dialogForm = {
  64. projectId: row.projectId,
  65. projectBomId: row.projectBomId,
  66. projectStageId: row.projectStageId,
  67. parentId: row.parentPlanId,
  68. code: await getTargetPlanCode()
  69. };
  70. if (this.dialogForm.projectId && !row.teamId) {
  71. const data = await projectsGetByIdAPI(this.dialogForm.projectId)
  72. if (data.teamId) this.getUserList(data.teamId);
  73. }else {
  74. if (row.teamId) this.getUserList(row.teamId);
  75. }
  76. },
  77. async submit(type = '') {
  78. let form = await this.$refs.planForm.validForm();
  79. // return
  80. // form.planStageList = await this.$refs.planInfoTable.getTableValidate() || [];
  81. form.realStartDate = null
  82. form.realEndDate = null
  83. for (const item of form.datasource) {
  84. item.responsibleUserList = await this.getResponsibleUserList(item.responsibleUserIds)
  85. }
  86. // form.responsibleUserList = await this.getResponsibleUserList(form.responsibleUserIds)
  87. console.log(form,'form')
  88. const API = this.dialogType === 'add' ? projectsPlanSaveAPI : projectsPlanUpdateAPI;
  89. const id = await API(form)
  90. if (type === 'sub') {
  91. this.processSubmit(id);
  92. return
  93. }
  94. this.$message.success('操作成功');
  95. this.cancel()
  96. this.$emit('reload');
  97. },
  98. async getResponsibleUserList(list = []) {
  99. console.log(list)
  100. console.log(this.allUserList)
  101. return list.map(
  102. i => {
  103. return {
  104. userId: i,
  105. userName: this.allUserList?.find(u => u.id === i).name
  106. }
  107. });
  108. },
  109. //流程提交
  110. processSubmit(id = '') {
  111. submit({
  112. planId: id || this.dialogForm.id
  113. }).then((res) => {
  114. this.$message.success('提交成功');
  115. this.cancel();
  116. this.$emit('reload');
  117. });
  118. },
  119. cancel() {
  120. this.$emit('update:addDialogFlag', false);
  121. },
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. </style>