relatedTasks.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="relatedTasks pl-4 pr-4 pt-3 pb-3 h-full flex flex-col">
  3. <div class="flex justify-between">
  4. <div class="title">相关任务</div>
  5. <div>
  6. <el-button type="primary" @click="newTask()">新建任务</el-button>
  7. </div>
  8. </div>
  9. <div class="flex-1 overflow-auto pt-3">
  10. <el-table :data="relatedTaskstable" border style="width: 100%;height: 100%;">
  11. <el-table-column prop="taskName" label="任务名称">
  12. <template #default="scope">
  13. <el-button link type="primary" size="large" @click="toTask()">{{
  14. scope.row.taskName
  15. }}</el-button>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="priorityStr" sortable label="优先级" width="130" />
  19. <el-table-column prop="statusStr" label="状态" width="130" />
  20. <el-table-column prop="executorNamesStr" label="执行人" width="130" />
  21. <el-table-column prop="startTimes" sortable label="开始时间" width="130" />
  22. <el-table-column prop="endTimes" sortable label="截至时间" width="130" />
  23. </el-table>
  24. </div>
  25. </div>
  26. <!-- 新建任务 -->
  27. <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
  28. @close="closeTaskModal" @submit="submitForm" :title="'新建任务'" :disabled-list="props.disabledList" />
  29. </template>
  30. <script lang="ts" setup>
  31. import { PRIORITY } from '../TaskModal/api';
  32. import { STATUS } from '../../pages/tasks/api';
  33. import { formatDate } from '../../utils/times';
  34. import { createTaskFromType } from '../../utils/tools';
  35. import { ElNotification, NotificationParamsTyped } from 'element-plus'
  36. import { ref, reactive, onMounted, watchEffect } from 'vue'
  37. import { useRouter } from "vue-router";
  38. import TaskModal from '../TaskModal/index.vue'
  39. import { createTask } from '../TaskModal/taskFunction';
  40. import { ITEM_RENDER_EVT } from 'element-plus/es/components/virtual-list/src/defaults';
  41. import { Props, Emits } from './type';
  42. const props = defineProps<Props>()
  43. const emits = defineEmits<Emits>();
  44. type saveLoadingType = "1" | "2" | "3" | "4"; //1是没有保存, 2是正在保存, 3是保存成功, 4是保存失败
  45. const relatedTaskstable = ref([])
  46. const information = ref<any>({})
  47. const router = useRouter()
  48. const taskLoading = ref<saveLoadingType>('1')
  49. const taskModalForm = ref({}) // 任务弹窗表单
  50. const allVisible = reactive({
  51. taskModalVisible: false
  52. })
  53. function submitForm(submitData: any, isClose: boolean) { // 任务提交
  54. taskLoading.value = '2'
  55. createTask(submitData, isClose).then((res) => {
  56. const { saveLoading, isClose } = res
  57. taskLoading.value = saveLoading
  58. allVisible.taskModalVisible = isClose
  59. globalPopup('新建成功', 'success')
  60. emits('refreshData')
  61. }).catch((err) => {
  62. const { saveLoading, isClose, message } = err
  63. taskLoading.value = saveLoading
  64. allVisible.taskModalVisible = isClose
  65. globalPopup(message, 'error')
  66. })
  67. }
  68. function globalPopup(str: string, type: string) {
  69. notificationTiop({
  70. message: str || '成功',
  71. type: type,
  72. title: "提示",
  73. duration: 2000
  74. })
  75. }
  76. const notificationTiop = (options: NotificationParamsTyped) => {
  77. ElNotification(options)
  78. }
  79. function newTask() {
  80. const { id } = information.value
  81. taskModalForm.value = { ...createTaskFromType(props.formTaskType), [props.filed as any]: id, }
  82. allVisible.taskModalVisible = true
  83. }
  84. function toTask() {
  85. router.push({
  86. path: `/tasks`
  87. })
  88. }
  89. function closeTaskModal() {
  90. allVisible.taskModalVisible = false
  91. }
  92. // 接收参数赋值
  93. function receiveAssignment(item: any) {
  94. console.log(item, '<==== 过来的值')
  95. information.value = item.information
  96. const dataVal = item.data
  97. for (let i in dataVal) {
  98. dataVal[i].executorNamesStr = (dataVal[i].executorNames || []).join(','),
  99. dataVal[i].startTimes = dataVal[i].startDate ? formatDate(new Date(dataVal[i].startDate)) : '',
  100. dataVal[i].endTimes = dataVal[i].endDate ? formatDate(new Date(dataVal[i].endDate)) : '',
  101. dataVal[i].priorityStr = PRIORITY.find(item => item.value == dataVal[i].priority)?.label || '',
  102. dataVal[i].statusStr = STATUS.find(item => item.value == dataVal[i].status)?.label || ''
  103. }
  104. relatedTaskstable.value = dataVal
  105. }
  106. watchEffect(() => {
  107. receiveAssignment(props)
  108. });
  109. // 生命周期钩子
  110. onMounted(() => {
  111. });
  112. </script>
  113. <style scoped lang="scss">
  114. .relatedTasks {
  115. .title {
  116. font-size: 18px;
  117. color: #000
  118. }
  119. }
  120. </style>