多体系建设信息化条统-前端
zhouwx
3 days ago d4325ae343f7bfdaa8bc56b3ab72598d0072437e
src/views/work/selfProblems/internalAudit/innerReviewSheet/index.vue
@@ -2,15 +2,16 @@
  <div class="app-container">
    <div style="display: flex;justify-content: space-between">
      <el-form :inline="true" style="display: flex;align-items: center;flex-wrap: wrap;" >
        <el-form-item>
          <el-button
              type="primary"
              plain
              icon="Plus"
              @click="openDialog('add',{})"
          >新增</el-button>
        </el-form-item>
        <el-form-item v-if="isAdmin" label="企业:" >
<!--        <el-form-item>-->
<!--          <el-button-->
<!--              type="primary"-->
<!--              plain-->
<!--              icon="Plus"-->
<!--              @click="openDialog('add',{})"-->
<!--              v-hasPermi="['innerReviewSheet:list:add']"-->
<!--          >新增</el-button>-->
<!--        </el-form-item>-->
        <el-form-item v-if="isAdmin" label="单位:" >
          <el-select v-model="data.queryParams.companyId" placeholder="请选择" clearable>
            <el-option
                v-for="item in companyList"
@@ -20,25 +21,41 @@
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年份:" >
          <el-date-picker
              v-model="data.queryParams.year"
              type="year"
              value-format="YYYY"
          />
        </el-form-item>
        <el-form-item >
          <el-button v-if="isAdmin" type="primary" @click="getList">查询</el-button>
          <el-button v-if="isAdmin" type="primary" plain @click="reset">重置</el-button>
          <el-button  type="primary" @click="getList">查询</el-button>
          <el-button  type="primary" plain @click="reset">重置</el-button>
        </el-form-item>
        <el-form-item style="margin-left: -20px">
          <el-button
              type="primary"
              @click="exportData"
          >导出</el-button>
          <el-button  type="primary" plain @click="copy">复制</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList" :border="true">
      <el-table-column type="index" label="序号"></el-table-column>
    <el-table v-loading="loading" :data="dataList" :border="true"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" align="center" label="序号" width="80"></el-table-column>
      <el-table-column label="检查表" align="center">
        <template #default="scope">
          {{scope.row.deptName }}内审检查表
          {{scope.row.year}}年{{scope.row.deptName }}内审检查表
        </template>
      </el-table-column>
      <el-table-column label="受审核部门" prop="deptName" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" @click="openDialog('edit',scope.row)">编辑</el-button>
          <el-button link type="primary" @click="downloadFile(scope.row.id)">导出</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
          <el-button link type="primary" @click="openDialog('review',scope.row)">查看</el-button>
          <el-button link type="primary" @click="openDialog('edit',scope.row)" v-hasPermi="['innerReviewSheet:list:edit']">编辑</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['innerReviewSheet:list:del']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
@@ -52,6 +69,49 @@
    />
    <edit-dialog ref="dialogRef" @getList=getList></edit-dialog>
    <el-dialog
        v-model="copyVisible"
        width="500px"
        :before-close="handleCloseCopy"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <div v-if="data.isAdmin">
        <span style="display:block;margin-bottom: 8px">单位名称:</span>
        <el-select
            v-model="queryParams.companyId"
            filterable
            style="width: 100%;margin-bottom: 8px"
        >
          <el-option
              v-for="item in data.companyList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
          />
        </el-select>
      </div>
      <span style="display:block;margin-bottom: 8px">将以下年份数据:</span>
      <el-date-picker
          v-model="data.sourceYear"
          type="year"
          value-format="YYYY"
          style="margin-bottom: 8px;width: 100%;"
          placeholder="请选择"
      />
      <span style="display:block;margin-bottom: 8px">复制到:</span>
      <el-date-picker
          v-model="data.targetYear"
          type="year"
          value-format="YYYY"
          style="margin-bottom: 8px;width: 100%"
          placeholder="请选择"
      />
      <div class="dialog-footer" style="display: flex;justify-content: right">
        <el-button @click="handleCloseCopy" size="default">取 消</el-button>
        <el-button type="primary"  @click="onSubmitCopy" size="default" v-preReClick>确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>
@@ -65,6 +125,7 @@
import {getStandardTemp,delStandardTemp} from "@/api/standardSys/standardSys";
import { renderAsync } from "docx-preview";
import {
  copyCheck,
  delInternalAuditCheck,
  delMeetingsList,
  getInternalAuditCheck, getInternalAuditCheckInfo,
@@ -77,30 +138,40 @@
const { proxy } = getCurrentInstance();
const loading = ref(false);
const dialogRef = ref();
const choosedData = ref([])
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    companyId: null
    companyId: null,
    year:''
  },
  copyVisible: false,
  targetYear:'',
  sourceYear:'',
  total: 0,
  dataList: [],
  companyList: [],
  isAdmin: false
});
const { queryParams, total, dataList,companyList, isAdmin } = toRefs(data);
const { queryParams, total, dataList,companyList, isAdmin,copyVisible } = toRefs(data);
const userInfo = ref()
onMounted(async ()=>{
  if(userStore.roles.includes('admin')){
    data.isAdmin = true
    await getCompanyList()
  }else{
    data.isAdmin = false
    data.queryParams.companyId = userStore.companyId
  }
  await getNowYear()
  await getList()
})
const getNowYear = () =>{
  data.queryParams.year = new Date().getFullYear().toString()
}
onUnmounted(()=>{
@@ -112,6 +183,7 @@
  if(res.code == 200){
    data.dataList = res.data.list || []
    data.total = res.data.total
    console.log('x',data.dataList)
  }else{
    ElMessage.warning(res.message)
  }
@@ -131,82 +203,32 @@
    ElMessage.warning(res.message)
  }
}
const downloadFile = async (id)=>{
  const res = await getInternalAuditCheckInfo({id: id})
  if(res.code == 200){
    if(res.data){
      let tableData = res.data
      tableData.content = res.data.caluseNum.split('、').map((i,index)=>i + res.data.caluseContent.split(';\n')[index]).join('\n')
      tableData.interPeople = res.data.internalAuditCheckPeople.map(i=>i.auditUserName)
      try {
        generateWordDocument('/interCheck.docx', tableData, tableData.deptName +'内审检查表.docx');
      } catch (error){
        ElMessage({
          type: 'warning',
          message: '导出失败'
        });
      }
    }else{
      ElMessage.warning('暂无数据')
    }
  }else{
    ElMessage.warning(res.message)
  }
}
const openFile = async(path)=>{
  const ext = path.split('.').pop().toLowerCase();
  if (ext === 'doc') {
    ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
      window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
    }).catch(() => {
      console.log('取消预览')
    });
    return
  }
  try {
    // 1. 获取文件
    const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
    const arrayBuffer = await response.arrayBuffer();
    // 2. 创建新窗口
    const win = window.open('', '_blank');
    win.document.write(`
      <!DOCTYPE html>
      <html>
        <head>
          <title>预览</title>
          <style>
            body { margin: 20px; font-family: Arial; }
            .docx-container { width: 100%; height: 100%; }
          </style>
        </head>
        <body>
          <div id="container" class="docx-container"></div>
        </body>
      </html>
    `);
    // 3. 渲染 DOCX
    await renderAsync(arrayBuffer, win.document.getElementById('container'));
  } catch (error) {
    console.error('预览失败:', error);
    alert(`预览失败: ${error.message}`);
  }
}
const openDialog = (type, value) => {
  dialogRef.value.openDialog(type, value, data.queryParams.companyId, data.isAdmin, data.companyList);
}
/** 重置新增的表单以及其他数据  */
const reset= async()=> {
  data.queryParams = {
    pageNum: 1,
    pageSize: 10,
    companyId: null
  if(data.isAdmin){
    data.queryParams = {
      pageNum: 1,
      pageSize: 10,
      companyId: null,
      year:''
    }
    data.companyList = [];
    await getCompanyList()
  }else {
    data.queryParams = {
      companyId: data.queryParams.companyId,
      pageNum: 1,
      pageSize: 10,
      year: '',
    }
  }
  await getCompanyList()
  choosedData.value = []
  await getNowYear()
  await getList()
}
const handleDelete = (val) => {
@@ -228,5 +250,90 @@
        }
      })
}
const handleSelectionChange = (val) => {
  choosedData.value = val
}
const exportData = () => {
  if(choosedData.value && choosedData.value.length === 0){
    ElMessage.warning('请选择需要导出的数据')
  }else {
    startGeneration()
  }
}
const templatePath = ref('')
const startGeneration = async () => {
  const data = JSON.parse(JSON.stringify(choosedData.value))
  data.forEach(item => {
    templatePath.value = '/innerReviewExport.docx'
    item.tableData = item.checkCatalogues.map((i,index) => {
      return{
        ...i,
        well: i.result == 1,
        fine: i.result == 2,
        bad: i.result == 3,
      }
    })
    console.log('11',item.tableData)
    item.checkTime = item.startTime +'-'+item.endTime.slice(11)
    try {
      generateWordDocument(templatePath.value, item, item.year+'年'+item.deptName+'_内审检查表.docx',['pointKey', 'find']);
    } catch (error){
      ElMessage({
        type: 'warning',
        message: '导出失败'
      });
    }
  })
}
const handleCloseCopy = () => {
  data.targetYear=''
  data.sourceYear=''
  data.copyVisible = false
}
const copy = () => {
  data.copyVisible = true
}
const onSubmitCopy = async () => {
  if(data.isAdmin && !data.queryParams.companyId){
    ElMessage.warning('请先选择单位')
    return
  }
  if(!data.sourceYear){
    ElMessage.warning('请先选择要复制的年份')
    return
  }
  if(!data.targetYear){
    ElMessage.warning('请选择目标年份')
    return
  }
  ElMessageBox.confirm(
      '该操作将覆盖目标年份的数据,是否继续?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const param = {
          companyId: data.queryParams.companyId,
          sourceYear: data.sourceYear,
          targetYear: data.targetYear
        }
        const res = await copyCheck(param);
        if(res.code === 200){
          ElMessage({
            type: 'success',
            message: res.data
          });
          await handleCloseCopy()
          await getList();
        }else{
          ElMessage.warning(res.message)
        }
      }).catch(err => {
  })
}
</script>