riku
2024-10-22 43981545c5aefdb4248d89e3121a200d53332c7a
1. 添加子任务编辑功能(暂存)
已修改10个文件
189 ■■■■ 文件已修改
src/api/fysp/subtaskApi.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components.d.ts 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/form/FYForm.vue 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/TaskManage.vue 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/TaskProxy.js 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/components/CompDayTask.vue 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/components/CompMonitorPlan.vue 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/components/CompSubTaskEdit.vue 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/components/CompSubTaskList.vue 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/fysp/task/components/CompSubTaskSelect.vue 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/fysp/subtaskApi.js
@@ -9,4 +9,8 @@
  adjustSubtask(subtask){
    return $fysp.post(`subtask/adjust`, subtask).then((res) => res.data);
  },
  putSubtasks(subtaskList) {
    return $fysp.put(`subtask/addlist`, subtaskList).then((res) => res.data);
  }
};
src/components.d.ts
@@ -62,7 +62,6 @@
    ElTabs: typeof import('element-plus/es')['ElTabs']
    ElTag: typeof import('element-plus/es')['ElTag']
    ElText: typeof import('element-plus/es')['ElText']
    ElTooltip: typeof import('element-plus/es')['ElTooltip']
    ElTree: typeof import('element-plus/es')['ElTree']
    ElUpload: typeof import('element-plus/es')['ElUpload']
    Footer: typeof import('./components/core/Footer.vue')['default']
src/components/form/FYForm.vue
@@ -120,15 +120,13 @@
      'submit',
      formObj,
      () => {
        loading.value = false;
        resolve();
      },
      (err) => {
        loading.value = false;
        reject(err ? err : '');
      }
    );
  });
  }).finally(() => (loading.value = false));
}
//取消按钮触发
src/views/fysp/task/TaskManage.vue
@@ -41,6 +41,7 @@
              <el-row>
                <el-col :span="curSubTaskList ? 16 : 24">
                  <CompMonitorPlan
                    ref="planRef"
                    :task="curTask.data"
                    @date-change="onDateChange"
                  ></CompMonitorPlan>
@@ -52,6 +53,7 @@
                    :loading="subTaskLoading"
                    height="56vh"
                    @add="subTaskDrawer = true"
                    @submit="handleSubtaskSubmit"
                  ></CompSubTaskList>
                </el-col>
              </el-row>
@@ -242,11 +244,11 @@
      this.sideLoading = false;
      this.mainLoading = true;
      this.curSubTaskList = undefined;
      this.curTask = task;
      taskApi
        .fetchMonitorObjectVersion(task.data.tguid)
        .then((res) => {
          this.curMonitorObjList = res;
          this.curTask = task;
        })
        .finally(() => {
          this.mainLoading = false;
@@ -293,6 +295,12 @@
          task: encodeURIComponent(JSON.stringify(value))
        }
      });
    },
    handleSubtaskSubmit() {
      this.subTaskLoading = true;
      this.$refs.planRef
        .fetchDayTasks()
        .finally(() => (this.subTaskLoading = false));
    }
  },
  mounted() {
src/views/fysp/task/TaskProxy.js
@@ -4,5 +4,28 @@
   */
  ceateSubTask(){
  },
  /**
   * 根据多选下拉框的选项值,返回任务执行人对象
   * @returns
   */
  getExecutors(data, executorOptions) {
    const ids = [];
    const uNames = [];
    const rNames = [];
    executorOptions.forEach((e) => {
      const index = data.indexOf(e.value);
      if (index != -1) {
        ids.push(e.data.guid);
        uNames.push(e.data.acountname);
        rNames.push(e.data.realname);
      }
    });
    return {
      id: ids.join('#'),
      uName: uNames.join('#'),
      rName: rNames.join('#')
    };
  }
}
src/views/fysp/task/components/CompDayTask.vue
@@ -9,6 +9,7 @@
        :data="seletedSceneList"
        :dayTask="dayTask"
        @delete="deleteScene"
        @submit="createSubtasks"
      ></CompSubTaskSelect>
      <div>
        <!-- <el-scrollbar height="50vh"> -->
@@ -37,28 +38,10 @@
      </div>
    </el-col>
    <el-col :span="8">
      <el-row justify="space-between">
        <el-text>单日计划</el-text>
        <el-button type="success" size="small" @click="editTask"
          >新增</el-button
        >
      </el-row>
      <el-divider />
      <div>
        <el-scrollbar :height="height">
          <ItemSubTask
            v-for="stask in curSubTaskList"
            :key="stask.guid"
            :item="stask"
          >
            <template #default="{ item }">
              <el-button type="danger" size="small" @click="editTask"
                >移除</el-button
              >
            </template>
          </ItemSubTask>
        </el-scrollbar>
      </div>
      <CompSubTaskList
        v-model="curSubTaskList"
        :height="height"
      ></CompSubTaskList>
    </el-col>
  </el-row>
</template>
@@ -67,10 +50,13 @@
import { useCloned } from '@vueuse/core';
import { useRoute, useRouter } from 'vue-router';
import taskApi from '@/api/fysp/taskApi';
import subtaskApi from '@/api/fysp/subtaskApi';
import TaskProxy from '../TaskProxy';
import CompMonitorObj from './CompMonitorObj.vue';
import CompSubTaskSelect from './CompSubTaskSelect.vue';
import CompSubTaskList from './CompSubTaskList.vue';
import dayjs from 'dayjs';
const route = useRoute();
@@ -137,5 +123,41 @@
  const index = seletedSceneList.value.indexOf(item);
  seletedSceneList.value.splice(index, 1);
}
function createSubtasks(executors) {
  const dt = props.dayTask;
  const subtasks = seletedSceneList.value.map((_) => {
    const s = _.scene
    return {
      // 主键由服务端创建
      stguid: undefined,
      tguid: dt.tsGuid,
      tsguid: dt.guid,
      name: `${s.name}巡查`,
      typeno: 1,
      type: '巡查',
      provincecode: s.provincecode,
      provincename: s.provincename,
      citycode: s.citycode,
      cityname: s.cityname,
      districtcode: s.districtcode,
      districtname: s.districtname,
      scensename: s.name,
      scenseid: s.guid,
      scenseaddress: s.location,
      planstarttime: dt.date,
      planendtime: dayjs(dt.date).endOf('day').set('millisecond', 0).toDate(),
      deployerguid: 'rAR0A4gJdlOZEqZs',
      deployerusername: 'ccheck',
      deployerrealname: '整改审核',
      executorguids: executors.ids,
      executorusernames: executors.uName,
      executorrealtimes: executors.rName,
      status: '未执行',
      remark: undefined
    };
  });
  subtaskApi.putSubtasks(subtasks)
}
</script>
<style scoped></style>
src/views/fysp/task/components/CompMonitorPlan.vue
@@ -57,7 +57,7 @@
});
const emit = defineEmits(['dateChange']);
// 选中日期
const dateValue = ref(new Date());
const dateValue = ref();
// 日历标题
const title = computed(() => {
  if (props.task) {
@@ -101,12 +101,16 @@
// 获取日任务统计信息
const dayTaskLoading = ref(false);
const dayTaskList = ref([]);
function fetchDayTasks(topTaskId) {
function fetchDayTasks() {
  dayTaskLoading.value = true;
  taskApi
    .fetchDayTasks(topTaskId)
  return taskApi
    .fetchDayTasks(props.task.tguid)
    .then((res) => {
      dayTaskList.value = res;
      // 如果已选日期存在,在重新获取日任务统计信息后,再次触发点击事件
      if (dateValue.value) {
        onDateChange(dateValue.value)
      }
    })
    .finally(() => (dayTaskLoading.value = false));
}
@@ -150,12 +154,14 @@
watch(
  () => props.task,
  (nV) => {
    if (nV.tguid) {
      fetchDayTasks(nV.tguid);
    if (nV && nV.tguid) {
      fetchDayTasks();
    }
  },
  { immediate: true }
);
defineExpose({ fetchDayTasks });
</script>
<style scoped>
.li-01 {
src/views/fysp/task/components/CompSubTaskEdit.vue
@@ -1,5 +1,6 @@
<template>
  <FYForm
    ref="formRef"
    :form-info="formInfo"
    :rules="rules"
    :useCancel="true"
@@ -23,6 +24,7 @@
        :initValue="false"
        type="date"
        v-model:value="formObj.planstarttime"
        @change="handleTimeChange"
      ></FYOptionTime>
      <el-form-item label="执行人" prop="_executors">
        <el-select
@@ -49,6 +51,7 @@
import { ref, computed, onMounted, reactive } from 'vue';
import subtaskApi from '@/api/fysp/subtaskApi';
import userApi from '@/api/fysp/userApi';
import dayjs from 'dayjs';
const props = defineProps({
  //基本信息
@@ -57,8 +60,9 @@
  create: Boolean
});
const emit = defineEmits(['submit', 'cancel']);
const emit = defineEmits(['submit', 'cancel', 'update:modelValue']);
const formRef = ref(null);
// 任务执行人选项
const executorOptions = ref([]);
const formInfo = computed(() => {
@@ -86,6 +90,10 @@
    }
  ]
});
function handleTimeChange(time) {
  formRef.value.formObj.planendtime = dayjs(time).endOf('day').set('millisecond', 0)
}
function getExecutors(data) {
  const ids = [];
@@ -123,6 +131,7 @@
  return subtaskApi
    .adjustSubtask(v)
    .then(() => {
      emit('update:modelValue', v)
      emit('submit', v);
      success();
    })
@@ -131,6 +140,10 @@
    });
}
function submit(v, success, fail) {
  const executors = getExecutors(v.value);
  v.value.executorguids = executors.id
  v.value.executorusernames = executors.uName
  v.value.executorrealtimes = executors.rName
  return props.create
    ? createScene(v.value, success, fail)
    : updateScene(v.value, success, fail);
src/views/fysp/task/components/CompSubTaskList.vue
@@ -2,7 +2,7 @@
  <el-row justify="space-between">
    <el-text>单日计划</el-text>
    <el-button
      v-show="create && modelValue && modelValue.length > 0"
      v-show="create && data && data.length > 0"
      type="success"
      size="small"
      @click="add"
@@ -13,16 +13,21 @@
  <div>
    <el-scrollbar v-loading="loading" :height="height">
      <el-space
        v-if="modelValue && modelValue.length > 0"
        v-if="data && data.length > 0"
        fill
        :fill-ratio="100"
        direction="vertical"
        style="width: 100%"
      >
        <ItemSubTask v-for="s in modelValue" :key="s.guid" :item="s">
        <ItemSubTask v-for="s in data" :key="s.guid" :item="s">
          <template #default="{ item }">
            <el-space direction="vertical">
              <el-button plain type="primary" size="small" @click="edit(item)"
              <el-button
                :disabled="item.status != '未执行'"
                plain
                type="primary"
                size="small"
                @click="edit(item)"
                >编辑</el-button
              >
              <el-button
@@ -38,7 +43,7 @@
      </el-space>
      <div v-else>
        <el-empty description="无任务记录" />
        <el-row justify="center">
        <el-row v-if="create" justify="center">
          <el-button type="success" size="small" @click="add"
            >添加任务</el-button
          >
@@ -57,7 +62,7 @@
  >
    <CompSubTaskEdit
      v-model="activeItem"
      @submit="dialogVisible = false"
      @submit="onEditSubmit"
      @cancel="dialogVisible = false"
    ></CompSubTaskEdit>
  </el-dialog>
@@ -78,11 +83,11 @@
  loading: Boolean
});
const dialogVisible = ref(false)
const activeItem = ref(null)
const dialogVisible = ref(false);
const activeItem = ref(null);
const data = computed(() => props.modelValue);
const emit = defineEmits(['edit', 'add', 'remove', 'update:modelValue']);
const emit = defineEmits(['submit', 'add', 'remove', 'update:modelValue']);
function remove(item) {
  if (item.status == '未执行') {
@@ -101,9 +106,18 @@
}
function edit(item) {
  activeItem.value = item
  dialogVisible.value = true
  emit('edit');
  activeItem.value = item;
  dialogVisible.value = true;
}
function onEditSubmit(item) {
  dialogVisible.value = false;
  const index = data.value.findIndex((v) => {
    return item.stguid == v.stguid;
  });
  data.value.splice(index, 1, item);
  emit('update:modelValue', data.value);
  emit('submit');
}
function add() {
@@ -111,6 +125,6 @@
}
onUnmounted(()=>{
  dialogVisible.value = false
})
  dialogVisible.value = false;
});
</script>
src/views/fysp/task/components/CompSubTaskSelect.vue
@@ -73,6 +73,7 @@
import { ref, reactive, watch, computed, onMounted } from 'vue';
import { ElMessageBox, ElNotification, ElMessage } from 'element-plus';
import taskApi from '@/api/fysp/taskApi';
import TaskProxy from '../TaskProxy';
onMounted(() => {
  // if (props.height) {
@@ -91,7 +92,7 @@
  dayTask: Object
});
const emit = defineEmits(['delete']);
const emit = defineEmits(['submit', 'delete']);
const scrollHeight = ref('14vh');
@@ -120,6 +121,9 @@
    fail('未选择监管场景');
  } else {
    success();
    // 将任务执行人格式化并传递
    const param = TaskProxy.getExecutors(v.value.executor, executors.value)
    emit('submit', param)
  }
}