addOrEditDialog.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="addOrEditDialogFlag"
  6. :title="title"
  7. append-to-body
  8. :close-on-click-modal="false"
  9. width="70%"
  10. :before-close="cancel">
  11. <headerTitle title="计划信息"></headerTitle>
  12. <plan-form ref="planForm" :dialog-type.sync="dialogType" :dialogForm="dialogForm" :deptList="deptList"
  13. :deptTreeList="deptTreeList" :userList="userList" @changeProject="changeProject"></plan-form>
  14. <headerTitle title="计划节点"></headerTitle>
  15. <plan-info-table ref="planInfoTable" :dialog-type.sync="dialogType" :dialogForm="dialogForm" :deptList="deptList"
  16. :deptTreeList="deptTreeList" :userList="userList"></plan-info-table>
  17. <div slot="footer">
  18. <el-button type="primary" size="small" @click="submit">保 存</el-button>
  19. <!-- <el-button type="primary" size="small" @click="submit('sub')">提 交</el-button>-->
  20. <el-button size="small" @click="cancel">关 闭</el-button>
  21. </div>
  22. </ele-modal>
  23. </template>
  24. <script>
  25. import projectForm from "./project-form.vue";
  26. import planForm from "./plan-form.vue";
  27. import planInfoTable from "./planInfoTable.vue";
  28. import {
  29. getTargetPlanCode,
  30. projectsPlanGetByIdAPI,
  31. projectsPlanSaveAPI,
  32. projectsPlanUpdateAPI,
  33. submit
  34. } from "@/api/project-manage/plan";
  35. import {deepClone} from "@/utils";
  36. import {getUserPage, listOrganizations} from "@/api/system/organization";
  37. import {projectsTeamGetByIdAPI} from "@/api/project-manage/team";
  38. import {projectsGetByIdAPI} from "@/api/project-manage";
  39. export default {
  40. name: "addOrEditDialog",
  41. components: {
  42. projectForm,
  43. planForm,
  44. planInfoTable
  45. },
  46. props: {
  47. addOrEditDialogFlag: {
  48. type: Boolean,
  49. default: false,
  50. }
  51. },
  52. data() {
  53. return {
  54. title: '',
  55. dialogType: '',
  56. dialogForm: {},
  57. userList: [],
  58. deptList: [],
  59. deptTreeList: [],
  60. allUserList: [],
  61. }
  62. },
  63. async created() {
  64. this.getDeptList();
  65. let {list} = await getUserPage({pageNum: 1, size: -1});
  66. this.allUserList = list
  67. },
  68. methods: {
  69. async init(row = {}, type) {
  70. this.title = type === 'add' ? '新增' : '编辑';
  71. this.dialogType = type;
  72. if (type !== 'add') {
  73. await this.getProjectPlanInfo(row.id)
  74. } else {
  75. this.dialogForm = {
  76. projectId: row.projectId,
  77. projectBomId: row.projectBomId,
  78. projectStageId: row.projectStageId,
  79. parentId: row.parentPlanId,
  80. code: await getTargetPlanCode()
  81. };
  82. if (this.dialogForm.projectId && !row.teamId) {
  83. const data = await projectsGetByIdAPI(this.dialogForm.projectId)
  84. if (data.teamId) this.getUserList(data.teamId);
  85. }else {
  86. if (row.teamId) this.getUserList(row.teamId);
  87. }
  88. //从项目直接新建计划,则获取项目团队
  89. }
  90. },
  91. async changeProject(id) {
  92. let projectInfo = await projectsGetByIdAPI(id)
  93. this.getUserList(projectInfo.teamId)
  94. },
  95. // 获取项目团队下团队人员集合
  96. getUserList(val) {
  97. if (!val) {
  98. this.userList = []
  99. return
  100. }
  101. projectsTeamGetByIdAPI(
  102. val
  103. ).then((list) => {
  104. this.userList = deepClone(list.teamUserList)
  105. });
  106. },
  107. // 获取部门数据
  108. getDeptList() {
  109. listOrganizations().then((list) => {
  110. this.deptList = list;
  111. this.deptTreeList = this.$util.toTreeData({
  112. data: list,
  113. idField: 'id',
  114. parentIdField: 'parentId'
  115. });
  116. });
  117. },
  118. // 获取计划信息
  119. async getProjectPlanInfo(id = '') {
  120. let res = await projectsPlanGetByIdAPI(id)
  121. this.dialogForm = deepClone(res)
  122. this.dialogForm.responsibleUserIds = this.dialogForm.responsibleUserList.map(i => i.userId) || []
  123. this.dialogForm.planStageList.forEach((item, index) => {
  124. let userIds = item.responsibleUserList.map(i => i.userId) || []
  125. this.$set(item, 'responsibleUserIds', userIds)
  126. })
  127. if (this.dialogForm.projectId) await this.changeProject(this.dialogForm.projectId)
  128. },
  129. async submit(type = '') {
  130. let form = await this.$refs.planForm.validForm();
  131. form.planStageList = await this.$refs.planInfoTable.getTableValidate() || [];
  132. form.realStartDate = null
  133. form.realEndDate = null
  134. for (const item of form.planStageList) {
  135. item.responsibleUserList = await this.getResponsibleUserList(item.responsibleUserIds)
  136. }
  137. form.responsibleUserList = await this.getResponsibleUserList(form.responsibleUserIds)
  138. const API = this.dialogType === 'add' ? projectsPlanSaveAPI : projectsPlanUpdateAPI;
  139. const id = await API(form)
  140. if (type === 'sub') {
  141. this.processSubmit(id);
  142. return
  143. }
  144. this.$message.success('操作成功');
  145. this.cancel()
  146. this.$emit('reload');
  147. },
  148. async getResponsibleUserList(list = []) {
  149. return list.map(
  150. i => {
  151. return {
  152. userId: i,
  153. userName: this.allUserList?.find(u => u.id === i).name
  154. }
  155. });
  156. },
  157. //流程提交
  158. processSubmit(id = '') {
  159. submit({
  160. planId: id || this.dialogForm.id
  161. }).then((res) => {
  162. this.$message.success('提交成功');
  163. this.cancel();
  164. this.$emit('reload');
  165. });
  166. },
  167. cancel() {
  168. this.$emit('update:addOrEditDialogFlag', false);
  169. },
  170. }
  171. }
  172. </script>
  173. <style scoped lang="scss">
  174. </style>