

<template>
  <Dialog title="打印预览" v-model="dialogVisible" width="1000" :before-close="(doClose) => beforeDialogClose(doClose)">
    <!-- 打印预览 -->
    <div class="print-wrap page" ref="print">
      <table border="2" cellspacing="0" id="table">
        <tbody>
          <tr>
            <td colspan="3">
              <div style="width: 100px; text-align: center;">
                <img :src="logoDataUrl" style="width:100%" alt="" />
              </div>
            </td>
            <td colspan="12">
              <span style="font-size: 20px; font-weight: 700">产品工艺流程卡</span>
            </td>
            <td colspan="3" style="padding: 5px 0">
              <div style="border-bottom: 1px solid #666; padding-bottom: 5px">项目编号</div>
              <div style="padding-top: 5px">{{ formData.projectCode }}</div>
            </td>
          </tr>
          <tr>
            <td colspan="18">
              <div style="display: flex; justify-content: space-between;padding:0 5px">
                <span>子项目编号：{{ formData.projectSubCode}}</span>
                <span>项目交期：{{formatDate(new Date(formData.projectEndTime), 'YYYY-MM-DD')}}
                </span>
              </div>
            </td>
          </tr>
        </tbody>
        <tbody>
          <tr>
            <td colspan="1" :rowspan="2"> 序号 </td>
            <td colspan="2" :rowspan="2">
              <span>名称</span>
            </td>
            <!-- <td colspan="2">毛坯</td>
            <td colspan="2">普铣</td>
            <td colspan="4">常规</td>
            <td colspan="2">数控 </td>
            <td colspan="2">电加工 </td>
            <td colspan="1">焊 </td>
            <td colspan="2">钳工</td> -->
          </tr>
          <tr>
            <!-- <td colspan="1">下料</td>
            <td colspan="1">木模</td>
            <td colspan="1">粗铣</td>
            <td colspan="1">精铣</td>
            <td colspan="1">车床</td>
            <td colspan="1">热处理</td>
            <td colspan="1">磨床</td>
            <td colspan="1">线割</td>
            <td colspan="1">开粗</td>
            <td colspan="1">精加工</td>
            <td colspan="1">火花</td>
            <td colspan="1">刻字</td>
            <td colspan="1">电焊</td>
            <td colspan="1">钻孔</td>
            <td colspan="1">抛光</td> 
            const procedureArrary = ['下料','电焊','编程','开粗','铣床','车床','磨床','数控1','数控2','刻字','网格','深钻孔','钻孔','热处理','火花']
            -->
            <td colspan="1">下料</td>
            <td colspan="1">电焊</td>
            <td colspan="1">编程</td>
            <td colspan="1">铣床</td>
            <td colspan="1">车床</td>
            <td colspan="1">开粗</td>
            <td colspan="1">热处理</td>
            <td colspan="1">磨床</td>
            <td colspan="1">数控1</td>
            <td colspan="1">数控2</td>
            <td colspan="1">火花</td>
            <td colspan="1">刻字</td>
            <td colspan="1">网格</td>
            <td colspan="1">深钻孔</td>
            <td colspan="1">钻孔</td>
          </tr>
          <tr v-for="item in formDataprocess.tablename" :key="item">
            <td colspan="1"> {{item.index}} </td>
            <td colspan="2" v-if="item.date" id="lineTd">
              <span style="float:left;margin-top:20px;"> {{item.name}}</span>
              <span style="float:right;margin-top:0px;">{{item.date}}</span>
            </td>
            <td colspan="2" v-else>{{item.name}}</td>
            <td colspan="1" class="hr-dotted"> {{item.layingoff}}</td>
            <td colspan="1" class="hr-dotted">{{item.woodformer}}</td>
            <td colspan="1" class="hr-dotted">{{item.roughmill}}</td>
            <td colspan="1" class="hr-dotted">{{item.finishmill}}</td>
            <td colspan="1" class="hr-dotted">{{item.lathe}}</td>
            <td colspan="1" class="hr-dotted">{{item.treatment}}</td>
            <td colspan="1" class="hr-dotted">{{item.grindingmachine}}</td>
            <td colspan="1" class="hr-dotted">{{item.wire}}</td>
            <td colspan="1" class="hr-dotted">{{item.rough}}</td>
            <td colspan="1" class="hr-dotted">{{item.fashioning}}</td>
            <td colspan="1" class="hr-dotted">{{item.spark}}</td>
            <td colspan="1" class="hr-dotted">{{item.lettering}}</td>
            <td colspan="1" class="hr-dotted">{{item.electrowelding}}</td>
            <td colspan="1" class="hr-dotted">{{item.drill}}</td>
            <td colspan="1" class="hr-dotted">{{item.polishing}}</td>
          </tr>
        </tbody>
        <tbody>
          <tr>
            <td colspan="18">
              <div style="display: flex; justify-content: left;">
                <span style="font-size: 16px; font-weight: 700">
                  各工序工艺要点
                </span>
              </div>
            </td>
          </tr>
          <tr v-for="item in summarylist" :key="item">
            <td colspan="3" class="hr-dotted" v-if="item.name">{{item.name}}</td>
            <td colspan="15" class="hr-dotted" v-if="item.data">{{item.data}}</td>
          </tr>
        </tbody>
        <tbody>
          <tr>
            <td colspan="10">
              <div>
                说明：自检合格后签名方可结算工时，以此卡为准
              </div>
            </td>
            <td colspan="4">
              开单人/日期：
            </td>
            <td colspan="4">
              {{formData.userNickname}}
              {{ formatDate(new Date(formData.startTime), 'YYYY-MM-DD') }}
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <template #footer>
      <!-- 【打印】 -->
      <el-button @click="onPrint" type="primary">打印</el-button>
      <el-button @click="outopen">取消</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
// import { ref, reactive } from 'vue'
import { Check } from '@element-plus/icons-vue'
import urlimg from '@/assets/imgs/exlogo.png'
import { betweenDay, dateFormatter, formatDate } from '@/utils/formatTime'
import * as TaskDispatchApi from '@/api/heli/taskdispatch'
import * as ProcedureApi from '@/api/heli/procedure'
import * as UserApi from '@/api/system/user'
import { string } from 'vue-types'
import { log } from 'console'
import { getOperateLogPage } from '@/api/system/operatelog'
const logoDataUrl = ref('') // 存储Logo的Base64编码数据URL
const dialogVisible = ref(false) // 弹窗的是否展示
const summarylist = ref([
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  },
  {
    name: undefined,
    data: undefined
  }
])
const formDataprocess = ref({
  tablename: [
    {
      index: 1,
      name: '工序',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 2,
      name: '自检',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 3,
      name: '额定工时1',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 4,
      name: '额定工时2',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 5,
      name: '审核者',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 6,
      name: '加工工时1',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 7,
      name: '操作者1',
      date: '日',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 8,
      name: '加工工时2',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 9,
      name: '操作者2',
      date: '日',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 10,
      name: '质检1',
      date: '日',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 11,
      name: '质检2',
      date: '日',
      layingoff: undefined,
      woodformer: undefined,
      roughmill: undefined,
      finishmill: undefined,
      lathe: undefined,
      treatment: undefined,
      grindingmachine: undefined,
      wire: undefined,
      rough: undefined,
      fashioning: undefined,
      spark: undefined,
      lettering: undefined,
      electrowelding: undefined,
      drill: undefined,
      polishing: undefined
    },
    {
      index: 12,
      name: '备注'
    }
  ]
})

const formData = ref({
  id: undefined,
  code: undefined,
  dispatchType: undefined,
  taskId: undefined,
  planId: undefined,
  projectId: undefined,
  projectSubId: undefined,
  bomDetailId: undefined,
  dispatchStatus: undefined,
  remark: undefined,
  status: 1,
  taskDispatchDetails: [],
  operateLogs: undefined,
  userNickname: undefined,
  startTime: undefined,
  active: undefined,
  activeOpinion: ''
})

const onPrint = () => {
  // 拿到打印页面dom节点
  const printNode = document.querySelector('.print-wrap')
  if (!printNode) return
  // 页面文档创建一个空的内框架，用于挂载打印节点，并设置一定的样式
  const newIframe: any = document.createElement('iframe')
  newIframe.setAttribute(
    'style',
    'width:0px;height:0px;position:absolute;left:-9999px;top:-9999px;'
  )
  newIframe.setAttribute('align', 'center')
  document.body.appendChild(newIframe)
  // 将打印页面设置为内框架内容
  let doc: any = null
  doc = newIframe.contentWindow.document
  doc.write(`
    <style type="text/css">
      /* 浏览器打印基本样式 */
.page {
  width: 21cm;
  min-height: 29.7cm;
  padding: 10mm;
  margin: 20px auto;
  border: 1px #d3d3d3 solid;
  border-radius: 5px;
  background: white;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  position: relative;
  font-size: 14px !important;
}

@page {
  size: A4;
  margin:1cm;
}
@media print {
  .page {
    margin: 10mm;
    border: initial;
    border-radius: initial;
    width: initial;
    min-height: initial;
    box-shadow: initial;
    background: initial;
    page-break-after: always;
  }
}
table {
  width: 100%; /* 让表格宽度100%占满其父元素宽度 */
  height: auto; /* 高度根据内容自适应 */
  font-size: 14px;
  text-align: center;
  border-collapse: collapse;
  margin-top: 5mm; /* 添加顶部外边距，替代原先的页内边距 */
  tr{
    td {
    padding: 5px 0;
    border: 1px solid #333;
  }
  }
}
.xh {
  width: 50px !important;
}
.checkbox {
  border: 2px solid #999;
  width: 10px;
  height: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left:10px ;
}
#lineTd {
  background: #fff
    url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lIHgxPSIwIiB5MT0iMCIgeDI9IjEwMCUiIHkyPSIxMDAlIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjEiLz48L3N2Zz4=)
    no-repeat 100% center;
}
.hr-dotted {
  border: 0;
  border-top: 1px dotted #a2a9b6;
  border-left: 1px dotted #a2a9b6;
}
    </style>
    <div>
      ${printNode.innerHTML}
    </div>`)
  doc.close()
  // 浏览器打印页面打开渲染
  setTimeout(() => {
    newIframe.contentWindow.focus()
    newIframe.contentWindow.print()
    document.body.removeChild(newIframe) // 移除打印内框架，下次打印下次再挂载
    dialogVisible.value = false
  }, 100)
}
// / 关闭 Dialog 前的处理逻辑
function beforeDialogClose(doClose: (shouldClose: boolean) => void): void {
  // console.log('-----');
  outopen()
}

// 页面关闭重置
const outopen = () => {
  dialogVisible.value = false
  summarylist.value = [
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    },
    {
      name: undefined,
      data: undefined
    }
  ]
  formData.value = {
    id: undefined,
    code: undefined,
    dispatchType: undefined,
    taskId: undefined,
    planId: undefined,
    projectId: undefined,
    projectSubId: undefined,
    bomDetailId: undefined,
    dispatchStatus: undefined,
    remark: undefined,
    status: 1,
    taskDispatchDetails: [],
    operateLogs: undefined,
    userNickname: undefined,
    startTime: undefined,
    active: undefined,
    activeOpinion: ''
  }
  formDataprocess.value = {
    tablename: [
      {
        index: 1,
        name: '工序',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 2,
        name: '自检',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 3,
        name: '额定工时1',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 4,
        name: '额定工时2',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 5,
        name: '审核者',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 6,
        name: '加工工时1',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 7,
        name: '操作者1',
        date: '日',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 8,
        name: '加工工时2',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 9,
        name: '操作者2',
        date: '日',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 10,
        name: '质检1',
        date: '日',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 11,
        name: '质检2',
        date: '日',
        layingoff: undefined,
        woodformer: undefined,
        roughmill: undefined,
        finishmill: undefined,
        lathe: undefined,
        treatment: undefined,
        grindingmachine: undefined,
        wire: undefined,
        rough: undefined,
        fashioning: undefined,
        spark: undefined,
        lettering: undefined,
        electrowelding: undefined,
        drill: undefined,
        polishing: undefined
      },
      {
        index: 12,
        name: '备注'
      }
    ]
  }
}
const queryParams: any = ref({
  code: undefined
})

/** 打开弹窗 */
const open = async (id?: number) => {
  dialogVisible.value = true
  // 在组件挂载后，将Logo图片转换为Base64编码数据URL
  const logoImage = new Image()
  logoImage.src = urlimg // 替换为Logo图片路径
  logoImage.onload = () => {
    const canvas = document.createElement('canvas')
    canvas.width = logoImage.width
    canvas.height = logoImage.height
    const context = canvas.getContext('2d')
    context.drawImage(logoImage, 0, 0)
    const base64String = canvas.toDataURL('image/png')
    logoDataUrl.value = base64String
  }
  // ===================工序详情============================

  const Procedata = await ProcedureApi.getProcedurePage(queryParams)

  // ================================ 任务单详情 =============================

  // 获取数据
  if (id) {
    const data = await TaskDispatchApi.getTaskDispatch(id)
    // 操作日志
   
    formData.value.taskDispatchDetails =
      await TaskDispatchApi.getTaskDispatchDetailListByDispatchId(id)
    // console.log(data, '任务单详情')
    if (formData.value.taskDispatchDetails) {
      formData.value.taskDispatchDetails.forEach(async (taskitem: any) => {
        //  根据任务单详情子表的procedureId，找到工序详情中name
        const Procedure = await ProcedureApi.getProcedure(taskitem.procedureId)
        // 处理数据
        
        if (Procedure.name == '下料') {
          summarylist.value[0].name = Procedure.name
          console.log(';s')
          if (!summarylist.value[0].data) {
            summarylist.value[0].data = taskitem.summary
          } else if (summarylist.value[0].data && taskitem.summary) {
            summarylist.value[0].data = summarylist.value[0].data + ',' + taskitem.summary
          }
           if (!formDataprocess.value.tablename[0].layingoff) {
            formDataprocess.value.tablename[0].layingoff = taskitem.sort
          } else if (formDataprocess.value.tablename[0].layingoff && taskitem.sort) {
            formDataprocess.value.tablename[0].layingoff =
              formDataprocess.value.tablename[0].layingoff + ',' + taskitem.sort
          }
          if(taskitem.owner){
             const initialUser = await UserApi.getUser(taskitem.owner)
            if (!formDataprocess.value.tablename[6].layingoff) {
            formDataprocess.value.tablename[6].layingoff = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].layingoff &&
            !formDataprocess.value.tablename[8].layingoff
          ) {
            formDataprocess.value.tablename[8].layingoff = initialUser.nickname
          } else {
          }
          }

          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].layingoff = item.standard1Time
              formDataprocess.value.tablename[3].layingoff = item.standard2Time
            }
          })
          
        } else if (Procedure.name == '电焊') {
          summarylist.value[1].name = Procedure.name
          if (!summarylist.value[1].data) {
            summarylist.value[1].data = taskitem.summary
          } else if (summarylist.value[1].data && taskitem.summary) {
            summarylist.value[1].data = summarylist.value[1].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].woodformer) {
            formDataprocess.value.tablename[0].woodformer = taskitem.sort
          } else if (formDataprocess.value.tablename[0].woodformer && taskitem.sort) {
            formDataprocess.value.tablename[0].woodformer =
              formDataprocess.value.tablename[0].woodformer + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].woodformer = item.standard1Time
              formDataprocess.value.tablename[3].woodformer = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].woodformer) {
            formDataprocess.value.tablename[6].woodformer = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].woodformer &&
            !formDataprocess.value.tablename[8].woodformer
          ) {
            formDataprocess.value.tablename[8].woodformer = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '编程') {
          summarylist.value[2].name = Procedure.name
          if (!summarylist.value[2].data) {
            summarylist.value[2].data = taskitem.summary
          } else if (summarylist.value[2].data && taskitem.summary) {
            summarylist.value[2].data = summarylist.value[2].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].roughmill) {
            formDataprocess.value.tablename[0].roughmill = taskitem.sort
          } else if (formDataprocess.value.tablename[0].roughmill && taskitem.sort) {
            formDataprocess.value.tablename[0].roughmill =
              formDataprocess.value.tablename[0].roughmill + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].roughmill = item.standard1Time
              formDataprocess.value.tablename[3].roughmill = item.standard2Time
            }
          })
          if(taskitem.owner){
            const initialUser = await UserApi.getUser(taskitem.owner)
            if (!formDataprocess.value.tablename[6].roughmill) {
              formDataprocess.value.tablename[6].roughmill = initialUser.nickname
            } else if (
              formDataprocess.value.tablename[6].roughmill &&
              !formDataprocess.value.tablename[8].roughmill
            ) {
              formDataprocess.value.tablename[8].roughmill = initialUser.nickname
            } else {
            }
            }

        } else if (Procedure.name == '铣床') {
          summarylist.value[3].name = Procedure.name
          if (!summarylist.value[3].data) {
            summarylist.value[3].data = taskitem.summary
          } else if (summarylist.value[3].data && taskitem.summary) {
            summarylist.value[3].data = summarylist.value[3].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].finishmill) {
            formDataprocess.value.tablename[0].finishmill = taskitem.sort
          } else if (formDataprocess.value.tablename[0].finishmill && taskitem.sort) {
            formDataprocess.value.tablename[0].finishmill =
              formDataprocess.value.tablename[0].finishmill + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].finishmill = item.standard1Time
              formDataprocess.value.tablename[3].finishmill = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].finishmill) {
            formDataprocess.value.tablename[6].finishmill = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].finishmill &&
            !formDataprocess.value.tablename[8].finishmill
          ) {
            formDataprocess.value.tablename[8].finishmill = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '车床') {
          summarylist.value[4].name = Procedure.name
          if (!summarylist.value[4].data) {
            summarylist.value[4].data = taskitem.summary
          } else if (summarylist.value[4].data && taskitem.summary) {
            summarylist.value[4].data = summarylist.value[4].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].lathe) {
            formDataprocess.value.tablename[0].lathe = taskitem.sort
          } else if (formDataprocess.value.tablename[0].lathe && taskitem.sort) {
            formDataprocess.value.tablename[0].lathe =
              formDataprocess.value.tablename[0].lathe + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].lathe = item.standard1Time
              formDataprocess.value.tablename[3].lathe = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].lathe) {
            formDataprocess.value.tablename[6].lathe = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].lathe &&
            !formDataprocess.value.tablename[8].lathe
          ) {
            formDataprocess.value.tablename[8].lathe = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '开粗') {
          summarylist.value[5].name = Procedure.name
          if (!summarylist.value[5].data) {
            summarylist.value[5].data = taskitem.summary
          } else if (summarylist.value[5].data && taskitem.summary) {
            summarylist.value[5].data = summarylist.value[5].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].treatment) {
            formDataprocess.value.tablename[0].treatment = taskitem.sort
          } else if (formDataprocess.value.tablename[0].treatment && taskitem.sort) {
            formDataprocess.value.tablename[0].treatment =
              formDataprocess.value.tablename[0].treatment + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].treatment = item.standard1Time
              formDataprocess.value.tablename[3].treatment = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].treatment) {
            formDataprocess.value.tablename[6].treatment = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].treatment &&
            !formDataprocess.value.tablename[8].treatment
          ) {
            formDataprocess.value.tablename[8].treatment = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '热处理') {
          summarylist.value[5].name = Procedure.name
          if (!summarylist.value[5].data) {
            summarylist.value[5].data = taskitem.summary
          } else if (summarylist.value[5].data && taskitem.summary) {
            summarylist.value[5].data = summarylist.value[5].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].grindingmachine) {
            formDataprocess.value.tablename[0].grindingmachine = taskitem.sort
          } else if (formDataprocess.value.tablename[0].grindingmachine && taskitem.sort) {
            formDataprocess.value.tablename[0].grindingmachine =
              formDataprocess.value.tablename[0].grindingmachine + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].grindingmachine = item.standard1Time
              formDataprocess.value.tablename[3].grindingmachine = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].grindingmachine) {
            formDataprocess.value.tablename[6].grindingmachine = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].grindingmachine &&
            !formDataprocess.value.tablename[8].grindingmachine
          ) {
            formDataprocess.value.tablename[8].grindingmachine = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '数控1') {
          summarylist.value[6].name = Procedure.name
          if (!summarylist.value[6].data) {
            summarylist.value[6].data = taskitem.summary
          } else if (summarylist.value[6].data && taskitem.summary) {
            summarylist.value[6].data = summarylist.value[6].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].wire) {
            formDataprocess.value.tablename[0].wire = taskitem.sort
          } else if (formDataprocess.value.tablename[0].wire && taskitem.sort) {
            formDataprocess.value.tablename[0].wire =
              formDataprocess.value.tablename[0].wire + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].wire = item.standard1Time
              formDataprocess.value.tablename[3].wire = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].wire) {
            formDataprocess.value.tablename[6].wire = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].wire &&
            !formDataprocess.value.tablename[8].wire
          ) {
            formDataprocess.value.tablename[8].wire = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '数控2') {
          summarylist.value[7].name = Procedure.name
          if (!summarylist.value[7].data) {
            summarylist.value[7].data = taskitem.summary
          } else if (summarylist.value[7].data && taskitem.summary) {
            summarylist.value[7].data = summarylist.value[7].data + ',' + taskitem.summary
          }

          if (!formDataprocess.value.tablename[0].rough) {
            formDataprocess.value.tablename[0].rough = taskitem.sort
          } else if (formDataprocess.value.tablename[0].rough && taskitem.sort) {
            formDataprocess.value.tablename[0].rough =
              formDataprocess.value.tablename[0].rough + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].rough = item.standard1Time
              formDataprocess.value.tablename[3].rough = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].rough) {
            formDataprocess.value.tablename[6].rough = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].rough &&
            !formDataprocess.value.tablename[8].rough
          ) {
            formDataprocess.value.tablename[8].rough = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '火花') {
          summarylist.value[8].name = Procedure.name
          if (!summarylist.value[8].data) {
            summarylist.value[8].data = taskitem.summary
          } else if (summarylist.value[8].data && taskitem.summary) {
            summarylist.value[8].data = summarylist.value[8].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].fashioning) {
            formDataprocess.value.tablename[0].fashioning = taskitem.sort
          } else if (formDataprocess.value.tablename[0].fashioning && taskitem.sort) {
            formDataprocess.value.tablename[0].fashioning =
              formDataprocess.value.tablename[0].fashioning + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].fashioning = item.standard1Time
              formDataprocess.value.tablename[3].fashioning = item.standard2Time
            }
          })
          if(taskitem.owner){
            const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].fashioning) {
            formDataprocess.value.tablename[6].fashioning = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].fashioning &&
            !formDataprocess.value.tablename[8].fashioning
          ) {
            formDataprocess.value.tablename[8].fashioning = initialUser.nickname
          } else {
          }
          }
          
        } else if (Procedure.name == '刻字') {
          summarylist.value[9].name = Procedure.name
          if (!summarylist.value[9].data) {
            summarylist.value[9].data = taskitem.summary
          } else if (summarylist.value[9].data && taskitem.summary) {
            summarylist.value[9].data = summarylist.value[9].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].spark) {
            formDataprocess.value.tablename[0].spark = taskitem.sort
          } else if (formDataprocess.value.tablename[0].spark && taskitem.sort) {
            formDataprocess.value.tablename[0].spark =
              formDataprocess.value.tablename[0].spark + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].spark = item.standard1Time
              formDataprocess.value.tablename[3].spark = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].spark) {
            formDataprocess.value.tablename[6].spark = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].spark &&
            !formDataprocess.value.tablename[8].spark
          ) {
            formDataprocess.value.tablename[8].spark = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '网格') {
          summarylist.value[9].name = Procedure.name
          if (!summarylist.value[9].data) {
            summarylist.value[9].data = taskitem.summary
          } else if (summarylist.value[9].data && taskitem.summary) {
            summarylist.value[9].data = summarylist.value[9].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].lettering) {
            formDataprocess.value.tablename[0].lettering = taskitem.sort
          } else if (formDataprocess.value.tablename[0].lettering && taskitem.sort) {
            formDataprocess.value.tablename[0].lettering =
              formDataprocess.value.tablename[0].lettering + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].lettering = item.standard1Time
              formDataprocess.value.tablename[3].lettering = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].lettering) {
            formDataprocess.value.tablename[6].lettering = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].lettering &&
            !formDataprocess.value.tablename[8].lettering
          ) {
            formDataprocess.value.tablename[8].lettering = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '深钻孔') {
          summarylist.value[10].name = Procedure.name
          if (!summarylist.value[10].data) {
            summarylist.value[10].data = taskitem.summary
          } else if (summarylist.value[10].data && taskitem.summary) {
            summarylist.value[10].data = summarylist.value[10].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].electrowelding) {
            formDataprocess.value.tablename[0].electrowelding = taskitem.sort
          } else if (formDataprocess.value.tablename[0].electrowelding && taskitem.sort) {
            formDataprocess.value.tablename[0].electrowelding =
              formDataprocess.value.tablename[0].electrowelding + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].electrowelding = item.standard1Time
              formDataprocess.value.tablename[3].electrowelding = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].electrowelding) {
            formDataprocess.value.tablename[6].electrowelding = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].electrowelding &&
            !formDataprocess.value.tablename[8].electrowelding
          ) {
            formDataprocess.value.tablename[8].electrowelding = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '钻孔') {
          summarylist.value[11].name = Procedure.name
          if (!summarylist.value[11].data) {
            summarylist.value[11].data = taskitem.summary
          } else if (summarylist.value[11].data && taskitem.summary) {
            summarylist.value[11].data = summarylist.value[11].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].drill) {
            formDataprocess.value.tablename[0].drill = taskitem.sort
          } else if (formDataprocess.value.tablename[0].drill && taskitem.sort) {
            formDataprocess.value.tablename[0].drill =
              formDataprocess.value.tablename[0].drill + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].drill = item.standard1Time
              formDataprocess.value.tablename[3].drill = item.standard2Time
            }
          })
          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].drill) {
            formDataprocess.value.tablename[6].drill = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].drill &&
            !formDataprocess.value.tablename[8].drill
          ) {
            formDataprocess.value.tablename[8].drill = initialUser.nickname
          } else {
          }
          }

        } else if (Procedure.name == '磨床') {
          summarylist.value[12].name = Procedure.name
          if (!summarylist.value[12].data) {
            summarylist.value[12].data = taskitem.summary
          } else if (summarylist.value[12].data && taskitem.summary) {
            summarylist.value[12].data = summarylist.value[12].data + ',' + taskitem.summary
          }
          if (!formDataprocess.value.tablename[0].polishing) {
            formDataprocess.value.tablename[0].polishing = taskitem.sort
          } else if (formDataprocess.value.tablename[0].polishing && taskitem.sort) {
            formDataprocess.value.tablename[0].polishing =
              formDataprocess.value.tablename[0].polishing + ',' + taskitem.sort
          }
          Procedata.list.forEach((item: any) => {
            if (item.name == Procedure.name) {
              formDataprocess.value.tablename[2].polishing = item.standard1Time
              formDataprocess.value.tablename[3].polishing = item.standard2Time
            }
          })

          if(taskitem.owner){
                      const initialUser = await UserApi.getUser(taskitem.owner)
          if (!formDataprocess.value.tablename[6].polishing) {
            formDataprocess.value.tablename[6].polishing = initialUser.nickname
          } else if (
            formDataprocess.value.tablename[6].polishing &&
            !formDataprocess.value.tablename[8].polishing
          ) {
            formDataprocess.value.tablename[8].polishing = initialUser.nickname
          } else {
          }
          }

        }
      })
    }
    formData.value = data

    //获取日志 找到操作人和操作时间
     let logParams = {
      pageNo: 1,
      pageSize: 1,
      businessId: id,
      businessType: 'TASK_DISPATCH'
    }
    const operateLogs = (await getOperateLogPage(logParams)).list[0]
    formData.value.userNickname = operateLogs.userNickname
    formData.value.startTime = operateLogs.startTime
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<style scoped lang="scss">
.page {
  width: 22cm;
  min-height: 29.7cm;
  padding: 10mm;
  margin: 20px auto;
  border: 1px #d3d3d3 solid;
  border-radius: 5px;
  background: white;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  position: relative;
  font-size: 14px !important;
}

@page {
  size: A4;
  margin: 0;
}
@media print {
  .page {
    margin: 0;
    border: initial;
    border-radius: initial;
    width: initial;
    min-height: initial;
    box-shadow: initial;
    background: initial;
    page-break-after: always;
  }
}
table {
  width: 100%; /* 让表格宽度100%占满其父元素宽度 */
  height: auto; /* 高度根据内容自适应 */
  font-size: 14px;
  text-align: center;
  border-collapse: collapse;
  margin-top: 5mm; /* 添加顶部外边距，替代原先的页内边距 */
  tr {
    td {
      padding: 2px 0;
      border: 1px solid #333;
    }
  }
}

.checkbox {
  border: 2px solid #999;
  width: 15px;
  height: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 10px;
}
#lineTd {
  background: #fff
    url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lIHgxPSIwIiB5MT0iMCIgeDI9IjEwMCUiIHkyPSIxMDAlIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjEiLz48L3N2Zz4=)
    no-repeat 100% center;
}
.hr-dotted {
  border: 0;
  border-top: 1px dotted #a2a9b6;
  border-left: 1px dotted #a2a9b6;
}
/*
	A4的大小：21cm*29.7cm（width:794px;）。
	单位换算：1 inch = 2.54 cm 1mm = 96 px 1 cm = 37.79528 px*/
</style>
