<template>
  <div>
    <layout>
      <layout-header>
        <div class="">
          <!--按钮部分-->
          <el-form ref="elSearchFormRef" inline class="demo-form-inline" @submit.native.prevent>
            <el-form-item>
              <el-input v-model="searchInfo" placeholder="搜索工单编号或产品名称 " clearable  style="width: 180px"/>
              <el-button type="primary" icon="search" class="search"  @click="handleSearch"/>
              <el-button type="primary"icon="edit"class="bt"@click=" () => { dialogDetail = true; } "><i class="el-icon-edit" />查改</el-button>
              <!--<el-button type="primary" disabled icon="edit" @click="" style="margin-left: 10px">工艺方案复制</el-button>-->
              <el-button type="primary" icon="edit" class="bt" @click=" () => { dialogGdcjstj = true; }">工单超节损统计</el-button>

              <el-button type="primary" icon="edit" class="bt" @click=" () => { dialogKhsz = true}">考核设置</el-button>

              <el-button type="primary" icon="edit" class="bt"@click=" () => { dialogXzgdtl = true; }">修正工单投料</el-button>

              <el-button type="primary" icon="edit" class="bt"@click=" () => { dialogGxclhc = true;}">工序产量核查</el-button>

              <el-button type="primary"icon="edit"class="bt"@click="() => {dialogGdzjfptj = true;}">工单质检废品统计</el-button>

              <el-button type="primary" icon="edit" class="bt"@click="() => {dialogHjfpfb = true;}">核检废品分布</el-button>

              <el-button type="primary" icon="edit" class="bt"@click="handleGddy">工单打印</el-button>

              <el-button type="primary" icon="edit" class="bt" @click="() => { pd_lcdlist = true; pd_lcdProductValue();}">流程单查询</el-button>

              <el-button type="primary" icon="edit" class="bt" @click="exportExcel">导出Excel</el-button>

              <el-button type="primary" icon="edit" class="bt" @click="ygdy">超节损员工打印</el-button>
            </el-form-item>
          </el-form>

          <!-- 弹窗 -->
          <div>
            <!-- 查改 -->
            <Detail v-if="dialogDetail" :is-show="dialogDetail" :gdbh="gdbh"
            :yjno="yjno"
            @destroy="() => {dialogDetail = false;}"/>

            <!-- 工单超节损统计 -->
            <el-dialog v-model="dialogGdcjstj"  title="工单超节损统计" destroy-on-close >
              <Gdcjstj :gdbh="gdbh" :yjno ="yjno" />
            </el-dialog>

            <!-- 员工打印 -->
            <el-dialog v-model="dialogygdy"  title="员工打印" destroy-on-close style="height: 40%;">
			  <el-date-picker
			    v-model="ygdy_formData['ygriqi']"
			    type="month"
			    placeholder="选择年月"
			    :default-value="new Date()"
			    style="width: 500px"
			  />
              <el-button type="primary" icon="edit" class="bt" @click="onclick_ygdy">按员工打印</el-button>
            </el-dialog>

            <!-- 修正工单印件质量考核设置 -->
            <Khsz v-if="dialogKhsz" v-model="dialogKhsz" :gdbh="gdbh" :yjno="yjno" />

            <!-- 修正工单投料 -->
            <Xzgdtl v-if="dialogXzgdtl" v-model="dialogXzgdtl" @update-data = "exitXzgdtl" :gdbh="gdbh" :yjno="yjno"/>

            <!-- 工序产量核查 -->
            <Gxclhc v-if="dialogGxclhc"  v-model="dialogGxclhc"
              :gdbh="gdbh" :jjcp_yjno = "jjcp_yjno"
            />

            <!-- 工单质检废品统计 -->
            <Gongdanzhijianfeipintongji
              v-if="dialogGdzjfptj"
              v-model="dialogGdzjfptj"
              :val="gdbh"
            />

            <!-- 核检废品分布 -->
            <Hjfpfb
              v-if="dialogHjfpfb"
              v-model="dialogHjfpfb"
              :val="gdbh"
			   :jjcp_yjno="jjcp_yjno"
            />

            <!-- 工单打印 -->
            <PrintPage ref="printPageRef" />

            <!--流程单查询【弹窗】-->
            <el-dialog v-model="pd_lcdlist" title="工单工序生产进程" fullscreen>
              <div style="width: 100%; height: 100%">
                <el-button type="" @click=" () => {pd_lcdlist = false;}">退出</el-button>
              </div>
              <div style=" width: 100%; height: 100%; display: flex; align-items: center;">
                <el-form-item label="工单编号" style="margin-right: 20px; padding: 0">
                  <el-input v-model="pd_lcdformData['gdbh']" @keyup.enter="pd_lcdProductValue" placeholder="Enter回车"/>
                </el-form-item>
                <el-form-item label="" style="margin-right: 5px; padding: 0">
                  <el-input v-model="pd_lcdformData['code']" disabled/>
                </el-form-item>
                <el-form-item label="" style="margin-right: 5px; padding: 0">
                  <el-input v-model="pd_lcdformData['name']" disabled style="width: 500px" />
                </el-form-item>
              </div>
              <div style="width: 100%; height: 70vh; display: flex">
                <layout>
                  <layout-sider
                    :resize-directions="['right']"
                    :width="240"
                    style="margin-right: 10px; height: 70vh"
                  >
                    <div class="JKWTree-tree">
                      <el-tree
                        :data="pd_lcd_treeData"
                        default-expand-all
                        @node-click="pd_lcd_handleNodeClick"
                      />
                    </div>
                  </layout-sider>
                  <layout-main>
                    <!-- 这里放右侧的内容 -->
                    <el-space wrap>
                      <!-- 右侧内容 -->
                      <template v-for="item in processList.total_process">
                        <el-button
                          disabled
                          :type="
                            !processList.process.includes(item)
                              ? 'danger'
                              : 'info'
                          "
                          plain
                          style="width: 50px"
                        >{{ item }}</el-button>
                      </template>
                    </el-space>
                  </layout-main>
                </layout>
              </div>
            </el-dialog>
          </div>
        </div>
      </layout-header>

      <layout>
        <!--    左侧树侧形结构-->
        <layout-sider
          :resize-directions="['right']"
          :width="190"
          style="margin-right: 10px"
        >
          <div class="JKWTree-tree" style="height: 70vh" >
            <h3>工单超节损核算</h3>
            <el-tree :data="treeData" highlight-current @node-click="handleNodeClick"/>
          </div>
        </layout-sider>

        <!--  右侧内容区域 -->
        <layout-content>
          <!-- 上方列表 -->
          <div class="gva-table-box">
            <el-table
              style="width: 100%; height: 30vh"
              :data="tableData1"
              row-key="ID"
              highlight-current-row
              border
              :row-class-name="rowClassName"
              :cell-class-name="cellClassName"
              :row-style="{ height: '20px' }"
              :cell-style="{ padding: '0px' }"
              :header-row-style="{ height: '20px' }"
              :header-cell-style="{ padding: '0px' }"
              @row-click="showOrderSuperLossGy"
              @current-change="
                (row, oldRow) => {
                  currentRow = row;
                }
              "
            >
              <el-table-column
                type="selection"
                width="55"
              />
              <!-- 使用 v-for 循环渲染每一列 -->
              <el-table-column
                v-for="column in tableCols1"
                :key="column.prop"
                :prop="column.prop"
                :label="column.label"
                :width="column.width"
				:align='column.left'
				:fixed='column.fixed'
				:sortable="column.sortable"
                show-overflow-tooltip="true"
                sortable
              />
            </el-table>
          </div>

          <!-- 下方表格 -->
          <el-table
            style="width: 100%; height: 40vh"
            row-key="ID"
            highlight-current-row
            border
            :data="tableData2"
            :row-style="{ height: '20px' }"
            :cell-style="{ padding: '0px' }"
            :header-row-style="{ height: '20px' }"
            :header-cell-style="{ padding: '0px' }"
          >
            <el-table-column
              type="selection"
              width="55"
            />
            <!-- 使用 v-for 循环渲染每一列 -->
            <el-table-column
              v-for="column in tableCols2"
              :key="column.prop"
              :prop="column.prop"
              :label="column.label"
              :width="column.width"
              show-overflow-tooltip="true"
              sortable
            />
          </el-table>
        </layout-content>
      </layout>
    </layout>
  </div>
</template>

<script>
import service from '@/utils/request'
import { writeXLSX } from 'xlsx'
// 5.1流程单查询-工单工序生产进程菜单栏
export const getOrderProcessLeft = (params) => {
  return service({
    url: '/mes_server/work_order_verification/getOrderProcessLeft',
    method: 'get',
    params,
  })
}
// 5.2流程单查询-获取工单工序生产进程右侧
export const getOrderProcessRight = (params) => {
  return service({
    url: '/mes_server/work_order_verification/getOrderProcessRight',
    method: 'get',
    params,
  })
}
</script>
<script setup>
import {
  Layout,
  LayoutContent,
  LayoutHeader,
  LayoutSider,
} from '@arco-design/web-vue'
import { ref, watch } from 'vue'
import {
  getOrderSuperLossGy,
  getSide,
  EmployeeDataCollect,
  getTable,
} from '@/api/mes_api_gty/orderAccounting'
import Khsz from '@/view/performance/12-orderAccounting/componets/khsz.vue'
import {hiprint} from "vue-plugin-hiprint";
import Gdcjstj from '@/view/performance/12-orderAccounting/componets/gdcjstj.vue'
import Xzgdtl from '@/view/performance/12-orderAccounting/componets/xzgdtl.vue'
import Gxclhc from '@/view/performance/12-orderAccounting/componets/gxclhc.vue'
import Gongdanzhijianfeipintongji from '@/view/performance/09-workOrderVerification/componets/gongdanzhijianfeipintongji.vue'
import Detail from '@/view/performance/12-orderAccounting/componets/detail.vue'
import Hjfpfb from './componets/hjfpfb.vue'
import PrintPage from '@/view/yunyin/shengchanguanli/components/print.vue'
import { reactive } from 'vue'
import { exportExcelFile } from '@/utils/excel'
import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore()
const sys_id =
  '[' + userStore.userInfo.userName + '/' + userStore.userInfo.nickName + ']'

// 弹窗
const dialogGdcjstj = ref(false)
const dialogDetail = ref(false)
const dialogKhsz = ref(false)
const dialogXzgdtl = ref(false)
const dialogGxclhc = ref(false)
const dialogGdzjfptj = ref(false)
const dialogHjfpfb = ref(false)

// 侧边栏数据
const treeData = ref([])
const getSideData = async() => {
  const res = await getSide()
  if (res.code === 0) {
    const { data } = res
    const transformedData = []

    for (const [key, value] of Object.entries(data)) {
      const [date, total] = key.split('-') // 提取日期和数量
      const transformedItem = {
        label: `${date}(工单数:${total})`,
        date: date,
        children: value.map((item) => ({
          label: `${item['客户编号']}【${item['客户名称']}】(工单数:${item.total})`,
          date: date,
          code: item?.['客户编号'],
        })),
      }
      transformedData.push(transformedItem)
    }
    treeData.value = transformedData
  }
}
getSideData()

// 表格数据
const tableCols1 = [
  // { label: '超损工单', prop: 'csgd', width: '110' ,sortable:'sortable'},
  { label: '工单编号', prop: 'Gd_gdbh', width: '110',sortable:'sortable',fixed:'fixed',align:'left'},
  { label: '印件号', prop: 'jjcp_yjno', width: '95' ,sortable:'sortable'},
  { label: '联数', prop: 'yj_ls', width: '80' ,sortable:'sortable'},
  { label: '产品代号', prop: '成品编码', width: '120' ,sortable:'sortable'},
  { label: '产品名称', prop: '成品名称', width: '250' ,sortable:'sortable'},
  { label: '实际投料', prop: '实际投料', width: '115' ,sortable:'sortable'},
  { label: '计量单位', prop: '计量单位', width: '115' ,sortable:'sortable'},
  { label: '入仓日期', prop: 'warehousing_date', width: '110' ,sortable:'sortable'},
  { label: '入仓数量', prop: 'warehousing_num', width: '110' ,sortable:'sortable'},
  { label: '目标合格率', prop: 'target_rate', width: '120' ,sortable:'sortable'},
  { label: '实际合格率', prop: 'real_rate', width: '120' ,sortable:'sortable'},
  { label: '奖惩系数', prop: 'reward_rate', width: '110' ,sortable:'sortable'},
  { label: '奖罚金额合计', prop: 'reward_money', width: '140',sortable:'sortable' },
  { label: '废品合计', prop: '废品合计', width: '120' ,sortable:'sortable'},
  { label: '工单无形损', prop: '工单无形损', width: '120',sortable:'sortable' },
  { label: '材料废', prop: '材料废', width: '120' ,sortable:'sortable'},
  { label: '零头处理', prop: '零头处理', width: '120',sortable:'sortable' },
  { label: '处发废', prop: '外发废', width: '120',sortable:'sortable' },
  { label: '外摊废', prop: '分摊废', width: '120' ,sortable:'sortable'},
  { label: '工单计划损耗', prop: '工单计划损耗', width: '140',sortable:'sortable' },
  { label: '工单制程废', prop: 'zcfp', width: '120',sortable:'sortable' },
  { label: '工单检验废', prop: '工单质检废', width: '120',sortable:'sortable' },
  { label: '年月', prop: 'date', width: '120' ,sortable:'sortable'},
]
const tableCols2 = [
  { label: '工单编号', prop: 'Gy0_gdbh', width: '120' },
  { label: '印件及工序', prop: 'Gy0_yjno', width: '120' },
  { label: '工序名称', prop: 'Gy0_gxmc', width: '200' },
  { label: '联数', prop: 'Gy0_ls', width: '80' },
  { label: '基础损耗', prop: 'Gy0_Rate0', width: '120' },
  { label: '损耗率', prop: 'Gy0_Rate1', width: '120' },
  { label: '损耗系数', prop: '损耗系数', width: '120' },
  { label: '计损色数', prop: 'Gy0_ms', width: '120' },
  { label: '计划产量', prop: 'Gy0_计划接货数', width: '120' },
  { label: '计划损耗', prop: 'Gy0_计划损耗', width: '120' },
  { label: '上报产量', prop: 'total_cl', width: '120' },
  { label: '制程废', prop: 'total_fp', width: '120' },
]
const tableData1 = ref([])
const tableData2 = ref([])
const currentRow = ref({})
const gdbh = ref('')
const jjcp_yjno = ref('')
const date = ref('')
const yjno = ref ('')
const searchInfo = ref('')

watch(currentRow, (value, oldValue, onCleanup) => {
  gdbh.value = value?.['Gd_gdbh']
  date.value = value?.['date']
  yjno.value = value?.['yj_Yjno']
  jjcp_yjno.value = value?.['jjcp_yjno']
  pd_lcdformData['gdbh'] = value?.['Gd_gdbh']
})

const cjsriqi = ref ('')
// 显示上方表格
const handleNodeClick = async(node) => {
  // console.log(node.date)
  cjsriqi.value = node.date
  console.log(cjsriqi.value)
  if (!node.children) {
    const { date, code } = node
    const res = await getTable({ date, code, limit: 9999, page: 1 })
    tableData1.value = res.data.data.map((item) => ({
      ...item,
      csgd:
        parseFloat(item['target_rate']) - parseFloat(item['real_rate']) > 0
          ? '√'
          : '',
      date: date,
    }))
    // console.log(tableData1.value )
  } else {
    // console.log(node.date, node.code)
  }
}

// 显示下方表格
const showOrderSuperLossGy = async() => {
  jjcp_yjno.value  =  currentRow.value['jjcp_yjno']
  const { Gd_gdbh: order } = currentRow.value
  const yjno = jjcp_yjno.value
  console.log(yjno)
  const res = await getOrderSuperLossGy({ order,yjno })
  if (res.code === 0) {
    const { data } = res
    tableData2.value = data.map((item) => ({
      ...item,
      Gy0_yjno: `${item.Gy0_yjno}-${item.Gy0_gxh}`,
      Gy0_gxmc:
        item.Add_gxmc === ''
          ? item.Gy0_gxmc
          : `${item.Gy0_gxmc}〖${item.Add_gxmc}〗`,
    }))
  }
}
// 定位
const  handleSearch = async() => {
  console.log(searchInfo.value)
  //调用搜索接口
  const res = await getTable({ search:searchInfo.value,limit:999,page:1})
  console.log(res)
  tableData1.value = res.data.data.map((item) => ({
      ...item,
      csgd:
        parseFloat(item['target_rate']) - parseFloat(item['real_rate']) > 0
          ? '√'
          : '',
      date: date,
    }))




  // if (searchInfo.value) {
  //   tableData1.value = tableData1.value.filter((item) => {
  //     return item['Gd_gdbh'] === searchInfo.value ?? item
  //   })
  // }
}

/* const rowClassName = ({ row, rowIndex }) => {
  if (row['csgd'] === '√') {
    return 'yellow-row'
  }
  return ''
}*/

  function cellClassName({ row, column, rowIndex, columnIndex }) {
    if ([7, 11, 13, 21].includes(columnIndex)) {
      return 'red-cell'
    }
    return ''
  }

const printPageRef = ref()
function handleGddy() {
  printPageRef.value.open(gdbh.value)
}

const pd_lcdlist = ref(false)
const processList = ref([])

const pd_lcdformData = reactive({})
const pd_lcdProductValue = async() => {
  _getOrderProcessLeft_list()
}
const pd_lcd_treeData = ref([])
const _getOrderProcessLeft_list = async() => {
  const order = pd_lcdformData['gdbh']
  console.log(order)
  try {
    // 5.1流程单查询-工单工序生产进程菜单栏
    const getOrderProcessLeft_list = await getOrderProcessLeft({
      order: order,
    })
    console.log(getOrderProcessLeft_list)
    pd_lcdformData['code'] = getOrderProcessLeft_list.data.Gd_info['code']
    pd_lcdformData['name'] = getOrderProcessLeft_list.data.Gd_info['name']
    pd_lcd_treeData.value = [
      {
        label: order + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
        // label: order + '-' + getOrderProcessLeft_list.data.Gd_info['code'] + '-' + getOrderProcessLeft_list.data.Gd_info['name'],
        value: undefined,
        children: [],
      },
    ]
    const newData = []
    for (const key in getOrderProcessLeft_list.data.Gy_info) {
      const temp = getOrderProcessLeft_list.data.Gy_info[key]
      const concatenatedValue = `${temp.Gy0_yjno}-${temp.Gy0_gxh} ---> ${temp.Gy0_gxmc}`
      newData.push({ label: concatenatedValue, value: temp.Gy0_gxh })
    }
    pd_lcd_treeData.value[0].children = newData
    // 5.2流程单查询-获取工单工序生产进程右侧【进入页面默认显示第一个】
    const getOrderProcessRight_list = await getOrderProcessRight({
      order: order,
      gxNo: newData[0].value,
    })
    processList.value = getOrderProcessRight_list.data
  } catch (error) {
    console.error(error)
  }
}

const pd_lcd_handleNodeClick = async(node) => {
  if (node.value === undefined) return
  const order = pd_lcdformData['gdbh']
  // //5.2流程单查询-获取工单工序生产进程右侧
  const getOrderProcessRight_list = await getOrderProcessRight({
    order: order,
    gxNo: node.value,
  })
  console.log(getOrderProcessRight_list)
  processList.value = getOrderProcessRight_list.data
}
// 导出excel
const exportExcel = () => {
  const labels = tableCols1.map((item) => item.label)
  const props = tableCols1.map((item) => item.prop)

  const data = tableData1.value.map((item) => {
    const row = {}
    props.forEach((prop, index) => {
      row[labels[index]] = item?.[prop]
    })
    return row
  })
  if (data[0]?.[labels[0]] === undefined) {
    return
  }
  exportExcelFile(data)
}





// 员工打印
// false是弹窗默认关闭 
const dialogygdy = ref(false)
const ygdy_formData = reactive({
  ygriqi : '',
})
// 点击 超节损员工打印打开弹窗
const ygdy = () => {
  dialogygdy.value = true
}

// json
const jsondatas = {"panels":[{"index":0,"name":1,"paperType":"A4","height":210,"width":297,"paperHeader":76.5,"paperFooter":837,"printElements":[{"options":{"left":12,"top":9,"height":40,"width":40,"src":"https://shangbiaopic.11467.com/13/85/13855845.jpg","fit":"","coordinateSync":false,"widthHeightSync":false,"right":55,"bottom":45.989585876464844,"vCenter":35,"hCenter":25.989585876464844,"field":"minong"},"printElementType":{"title":"图片","type":"image"}},{"options":{"left":57,"top":15,"height":14,"width":180,"title":"浙江翌星包装科技有限公司","coordinateSync":false,"widthHeightSync":false,"fontSize":13.5,"textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":319.5,"top":15,"height":30,"width":168,"title":"员工超结损奖罚统计","right":393,"bottom":36,"vCenter":333,"hCenter":31.125,"coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"fontSize":16.5,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":46.5,"top":54,"height":16,"width":90,"title":"文本","field":"riqi","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":203.2474136352539,"bottom":92.23958587646484,"vCenter":154.4974136352539,"hCenter":71.98958587646484,"hideTitle":true},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":510,"top":52.5,"height":16,"width":48,"title":"打印时间","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":556.5,"top":52.5,"height":16,"width":141,"field":"dysj","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":15,"top":54,"height":16,"width":31.5,"title":"日期","right":90.74478149414062,"bottom":93.0000228881836,"vCenter":48.744781494140625,"hCenter":71.2500228881836,"coordinateSync":false,"widthHeightSync":false,"fontSize":12,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":19.5,"top":85.5,"height":61.5,"width":735,"field":"table","groupFieldsFormatter":"function(type,options,data){ return [\"name\"] }","qid":"table_1","right":755.2421951293945,"bottom":147.74480438232422,"vCenter":387.74219512939453,"hCenter":116.99480438232422,"coordinateSync":false,"widthHeightSync":false,"maxRows":25,"tableHeaderBorder":"border","columns":[[{"width":107.22811671087534,"title":"所在部门","field":"szbm","checked":true,"columnId":"szbm","fixed":false,"rowspan":1,"colspan":1},{"width":128.67374005305038,"title":"班组","field":"banzu","checked":true,"columnId":"banzu","fixed":false,"rowspan":1,"colspan":1,"align":"left"},{"width":128.67374005305038,"title":"员工编号","field":"ygbh","checked":true,"columnId":"ygbh","fixed":false,"rowspan":1,"colspan":1},{"width":128.67374005305038,"title":"员工姓名","field":"ygxm","checked":true,"columnId":"ygxm","fixed":false,"rowspan":1,"colspan":1},{"width":128.67374005305038,"title":"超节损金额","field":"cjsje","checked":true,"columnId":"cjsje","fixed":false,"rowspan":1,"colspan":1},{"width":113.07692307692307,"title":"备注说明","field":"beizhu","checked":true,"columnId":"beizhu","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}}],"paperNumberLeft":822,"paperNumberTop":501,"paperNumberDisabled":true,"paperNumberContinue":true,"rotate":true,"orient":2,"watermarkOptions":{},"panelLayoutOptions":{}}]}
const onclick_ygdy = async () => {
	// 获取用户选择的日期
	const selectedDate = new Date(ygdy_formData['ygriqi']);
	// 手动增加一个月
	selectedDate.setMonth(selectedDate.getMonth() + 1);
	// 格式化为 YYYY-MM
	const formattedDate = selectedDate.toISOString().slice(0, 7);
    // 引入打印初始化
    hiprint.init();
    const hiprintTemplate = new hiprint.PrintTemplate({ template: jsondatas });

    // 获取数据
	// console.log(formattedDate);
    const res = await EmployeeDataCollect({ date: formattedDate });
	console.log(res)
console.log(121212)
    const { data } = res;
	
	// if (res.data.印刷车间.A班.length === 0) {
	//     console.log("A班数据为空");
	// } else {
	//     console.log("A班数据不为空");
	// }
	// return false;

    // 将数据转换为目标格式
    const dataSource = { 'table': [] };

    // 处理“印刷车间”A班的数据
    let isFirstA班 = true;
    for (const [key, value] of Object.entries(data['印刷车间']['A班'])) {
        const [ygbh, ygxm] = key.split('(');
        dataSource.table.push({
            'szbm': isFirstA班 ? '印刷车间' : '',
            'banzu': isFirstA班 ? 'A班' : '',
            'ygbh': ygbh,
            'ygxm': ygxm.replace(')', ''),
            'cjsje': value
        });
        isFirstA班 = false;
    }
    // 添加“印刷车间”A班的合计行
    dataSource.table.push({
        'szbm': '',
        'banzu': '车间班组合计',
        'ygbh': '',
        'ygxm': '',
        'cjsje': data['yinshuaA']
    });

    // 处理“印刷车间”B班的数据
    let isFirstB班 = true;
    for (const [key, value] of Object.entries(data['印刷车间']['B班'])) {
        const [ygbh, ygxm] = key.split('(');
        dataSource.table.push({
            'szbm': isFirstB班 ? '印刷车间' : '',
            'banzu': isFirstB班 ? 'B班' : '',
            'ygbh': ygbh,
            'ygxm': ygxm.replace(')', ''),
            'cjsje': value
        });
        isFirstB班 = false;
    }
    // 添加“印刷车间”B班的合计行
    dataSource.table.push({
        'szbm': '',
        'banzu': '车间班组合计',
        'ygbh': '',
        'ygxm': '',
        'cjsje': data['yinshuaB']
    });

    // 处理“印后车间”A班的数据
    let isFirst印后A班 = true;
    for (const [key, value] of Object.entries(data['印后车间']['A班'])) {
        const [ygbh, ygxm] = key.split('(');
        dataSource.table.push({
            'szbm': isFirst印后A班 ? '印后车间' : '',
            'banzu': isFirst印后A班 ? 'A班' : '',
            'ygbh': ygbh,
            'ygxm': ygxm.replace(')', ''),
            'cjsje': value
        });
        isFirst印后A班 = false;
    }
    // 添加“印后车间”A班的合计行
    dataSource.table.push({
        'szbm': '',
        'banzu': '车间班组合计',
        'ygbh': '',
        'ygxm': '',
        'cjsje': data['yinhouA']
    });

    // 处理“印后车间”B班的数据
    let isFirst印后B班 = true;
    for (const [key, value] of Object.entries(data['印后车间']['B班'])) {
        const [ygbh, ygxm] = key.split('(');
        dataSource.table.push({
            'szbm': isFirst印后B班 ? '印后车间' : '',
            'banzu': isFirst印后B班 ? 'B班' : '',
            'ygbh': ygbh,
            'ygxm': ygxm.replace(')', ''),
            'cjsje': value
        });
        isFirst印后B班 = false;
    }
    // 添加“印后车间”B班的合计行
    dataSource.table.push({
        'szbm': '',
        'banzu': '车间班组合计',
        'ygbh': '',
        'ygxm': '',
        'cjsje': data['yinhouB']
    });

    // 获取当前日期
    const today = new Date();
    const year = today.getFullYear();
    const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要补零
    const day = String(today.getDate()).padStart(2, '0');
    const hours = String(today.getHours()).padStart(2, '0');
    const minutes = String(today.getMinutes()).padStart(2, '0');
    const seconds = String(today.getSeconds()).padStart(2, '0');
    const currentDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

    // 初始化数据结构
    const tableDataFormatted = {
        "minong": "/src/assets/logotx.png",
        "dysj": currentDate,
        "riqi": data['日期'],
        "table": dataSource['table'],
        "cjbzhj": data['total'] // 将total作为车间班组合计
    };

    // 输出结果，确保数据格式正确
    console.log(tableDataFormatted);

    // 打印结果
    hiprintTemplate.print(tableDataFormatted);
}























//关闭窗口
const exitXzgdtl = (data) => {
  dialogXzgdtl.value = data;
};
</script>

<style scoped>
:deep(.plan-usage-low div) {
  color: red !important;
}

.JKWTree-container {
  display: flex;
}

.JKWTree-tree {
  width: 100%;
  background-color: #fff;
  /*background-color: rgba(241, 224, 224, 0.99);*/
  padding: 10px;
  margin-right: 20px;
}

.JKWTree-tree h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 10px 0;
}

.JKWTree-content {
  flex: 1;
}

:deep(.el-table .yellow-row) {
  background: #ffff80;
}

:deep(.red-cell div) {
  color: #ff0000 !important;
}

/* 选中某行时的背景色 */
:deep(.el-table__body tr.current-row) > td {
  background: #ff80ff !important;
}
</style>
<style scoped>
:deep(.el-table td .cell) {
  line-height: 20px !important;
}

:deep(.el-tabs__header) {
  margin-bottom: 0;
}

.search {
  margin-left: 0px !important;
  margin-right: 10px !important;
}

.bt {
  margin-left: 2px !important;
  padding: 3px !important;
  font-size: 12px;
}

.el-tabs__header {
  margin: 0px !important;
}

.gva-table-box {
  padding: 0px !important;
}

.mab {
  margin-bottom: 5px;
}
</style>
