<template>
    <div>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
            <el-form-item prop="startTime">
              <el-date-picker
                v-model="queryParams.startTime"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="开始日期"
                @change="() => queryParams.endTime = ''"
                style="width: 130px"
              />
            </el-form-item>
            <el-form-item>-</el-form-item>
            <el-form-item prop="endTime">
              <el-date-picker
                v-model="queryParams.endTime"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="结束日期"
                :picker-options="{ disabledDate: (t) => t.getTime() < new Date(queryParams.startTime).getTime() - 86400000}"
                style="width: 130px"
              />
            </el-form-item>
            <el-form-item prop="keyWord">
                <el-input maxlength="50" v-model="queryParams.keyWord" placeholder="请输入关键字" clearable style="width: 240px"/>
            </el-form-item>
            <el-form-item prop="repairStatus">
                <el-select v-model="queryParams.repairStatus" clearable filterable style="width: 240px" placeholder="请选择状态">
                    <el-option v-for="dict in dict.type.repair_task_status"
                        v-if="dict.value == 0 || dict.value == 1 || dict.value == 2 || dict.value == 4"
                        :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >查询</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <!-- <el-col :span="1.5">
                <el-button type="primary" plain size="mini" @click="handleAdd">新增</el-button>
            </el-col> -->
            <el-col :span="1.5">
                <el-button type="primary" plain size="mini"  @click="handleSend">提交审核</el-button>
            </el-col>
            <!-- <el-col :span="1.5">
                <el-button type="danger" plain size="mini" @click="handleReject">驳回退料</el-button>
            </el-col> -->
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
            </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleDetailsExport">导出明细</el-button>
          </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="tableList" border @selection-change="handleSelectionChange" :max-height="650">
            <el-table-column type="selection" align="center" :selectable="selectable"/>
            <el-table-column label="序号" align="center" type="index">
                <template slot-scope="scope">
                    <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
                </template>
            </el-table-column>
            <!-- <el-table-column align="center" label="序号" type="index"/> -->
          <el-table-column label="分公司" align="center" prop="impUnitName" width="140" />
            <el-table-column label="退料单位" align="center" width="180" prop="backUnit" />
            <el-table-column label="退料工程" align="center" width="180" prop="backPro" />
            <el-table-column label="退料单号" align="center" width="150" prop="backCode" :show-overflow-tooltip="true"/>
            <el-table-column label="维修单号" align="center" width="150" prop="repairCode" :show-overflow-tooltip="true" />
            <el-table-column label="物资名称" align="center" width="150" prop="type" :show-overflow-tooltip="true"/>
            <!-- <el-table-column label="维修班组" align="center" width="120" prop="repairer" :show-overflow-tooltip="true"/> -->
            <!-- <el-table-column label="退料人电话" align="center" prop="phone" :show-overflow-tooltip="true"/> -->
            <el-table-column label="创建人" align="center" prop="createName" :show-overflow-tooltip="true"/>
            <el-table-column label="创建时间" align="center" width="100" prop="createTime" />
            <el-table-column label="状态" align="center" width="100" :show-overflow-tooltip="true" prop="repairStatusCode">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.repair_task_status" :value="scope.row.repairStatusCode"/>
                </template>
            </el-table-column>
            <el-table-column label="提交时间" align="center" width="100" prop="submitTime" />
            <!-- <el-table-column label="备注" align="center" width="100" prop="remark" :show-overflow-tooltip="true"/> -->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" plain icon="el-icon-zoom-in" @click="handleSee(scope.row)" >查看</el-button>
                    <el-button size="mini" type="primary" plain icon="el-icon-edit" v-if="scope.row.repairStatusCode=='0' ||scope.row.repairStatusCode=='4'" @click="handleUpdate(scope.row)">维修</el-button>
                   <!-- 针对于驳回按钮，做特殊校验，维修拆分数据不可驳回 -->
                    <el-button size="mini" type="danger" icon="el-icon-delete" v-if="(scope.row.repairStatusCode =='0' && scope.row.level =='1')||scope.row.repairStatusCode=='12'" @click="handleReject(scope.row)">驳回</el-button>
                    <el-button size="mini" type="success"   @click="handlePrint(scope.row)">维修单</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination
            v-show="total > 0" :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />

    <!-- 维修任务单弹窗 -->
    <el-dialog :title="title" :visible.sync="openPrint" width="1090px" append-to-body>
      <div style="height: 600px; overflow-y: scroll">
        <!-- <vue-easy-print tableShow ref="remarksPrintRef" class="print"> -->
          <div id="checkId">
            <div class="title" style="text-align: center; font-weight: 600; font-size: 16px">
              机具设备维修任务单
            </div>
            <div class="info" style="margin-top: 10px; display: flex; flex-wrap: wrap">
              <div class="item" style="width: 60%;flex-shrink: 0;margin-bottom: 5px;font-size: 14px;">
                <span>日期：</span>
                {{ repairTicketlLevelOne.createTime }}
              </div>
              <div class="item" style="width: 40%;flex-shrink: 0;margin-bottom: 5px;font-size: 14px;">
                <span>单号：</span>
                {{ repairTicketlLevelOne.repairCode }}
              </div>
              <div class="item" style="width: 60%;flex-shrink: 0;margin-bottom: 5px;font-size: 14px;">
                <span>承修单位：</span>
                <!-- {{ repairTicketlLevelOne.backUnit }} -->
                <span>机具（物流）分公司</span>
              </div>
              <!-- <div class="item" style="width: 50%;flex-shrink: 0;margin-bottom: 5px;font-size: 14px;">
                <span>制单：</span>
                {{ repairTicketlLevelOne.repairer }}
              </div>  -->
              <div class="item" style="width: 40%;flex-shrink: 0;margin-bottom: 5px;font-size: 14px;">
                <span>项目名称：</span>
                  {{ repairTicketlLevelOne.backPro }}
              </div>
              <div class="item" style="width: 50%;flex-shrink: 0;margin-bottom: 5px;font-size: 14px;">
                <span>委托单位：</span>
                  {{ repairTicketlLevelOne.backUnit }}
              </div>
              <!-- <div class="item" style="width: 50%; flex-shrink: 0; margin-bottom: 5px; font-size: 14px;">
                <span>验收人：</span>
              </div> -->
            </div>
            <!-- <el-table :data="repairTicketDevice" class="table" style="margin-top: 20px; width: 1000px; " border>
              <el-table-column label="名称" align="center" prop="typeName" />
              <el-table-column label="型号" align="center" prop="type"/>
              <el-table-column label="编号" align="center" prop="code" >
                <template slot-scope="scope">
                    <div v-if="scope.row.manageType==1" >计数</div>
                    <div v-if="scope.row.manageType==0" style="color: blue;" @click="handleView(scope.row)">详见附件</div>
                </template>
              </el-table-column>
              <el-table-column label="单位" align="center" prop="unitName" />
              <el-table-column label="报修数量" align="center" prop="typeRepairNum" />
              <el-table-column label="修复数量" align="center" prop="typeRepairedNum" />
              <el-table-column label="报废数量" align="center" prop="typeScrapNum" />
              <el-table-column label="维修费小计" align="center" prop="typeCost" >
                <template slot-scope="scope">
                    <div >{{"¥"+" "+Number(scope.row.typeCost)}}</div>
                </template>
              </el-table-column>
              <el-table-column label="报废图片" align="center" >
                <template slot-scope="scope">
                    <div v-if="scope.row.fileList.length==0" ></div>
                    <div v-if="scope.row.fileList.length!=0" style="color: blue;" @click="picturesPreview(scope.row)">{{scope.row.fileList.length}}</div>
                </template>
              </el-table-column>
            </el-table>
            <div class="tabelAll">
              <div class="columnAllNum">总计</div>
              <div class="columnAll">{{ repairNum1 }}</div>
              <div class="columnAll">{{ repairNum2 }}</div>
              <div class="columnAll">{{ repairNum3 }}</div>
              <div class="columnAll">{{ "¥"+" "+repairNum4 }}</div>
              <div class="columnAll"></div>
            </div> -->

            <table
              class="table"
              style="
                margin-top: 20px;
                width: 1000px;
                border: 1px solid #333;
                border-collapse: collapse;
                text-align: center;
              "
            >
              <thead>
                <tr style="background-color: #f5f7fa;">
                  <th style="border: 1px solid #333; padding: 8px;">名称</th>
                  <th style="border: 1px solid #333; padding: 8px;">型号</th>
                  <th style="border: 1px solid #333; padding: 8px;">编号</th>
                  <th style="border: 1px solid #333; padding: 8px;">单位</th>
                  <th style="border: 1px solid #333; padding: 8px;">报修数量</th>
                  <th style="border: 1px solid #333; padding: 8px;">修复数量</th>
                  <th style="border: 1px solid #333; padding: 8px;">报废数量</th>
                  <th style="border: 1px solid #333; padding: 8px;">维修费小计</th>
                  <th style="border: 1px solid #333; padding: 8px;">报废图片</th>
                </tr>
              </thead>

              <tbody>
                <tr v-for="(row, index) in repairTicketDevice" :key="index">
                  <td style="border: 1px solid #333; padding: 8px;">{{ row.typeName }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ row.type }}</td>

                  <td style="border: 1px solid #333; padding: 8px;">
                    <div v-if="row.manageType == 1">计数</div>
                    <div
                      v-else-if="row.manageType == 0"
                      style="color: blue; cursor: pointer;"
                      @click="handleView(row)"
                    >
                      详见附件
                    </div>
                  </td>

                  <td style="border: 1px solid #333; padding: 8px;">{{ row.unitName }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ row.typeRepairNum }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ row.typeRepairedNum }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ row.typeScrapNum }}</td>

                  <td style="border: 1px solid #333; padding: 8px;">
                    ¥ {{ Number(row.typeCost) }}
                  </td>

                  <td style="border: 1px solid #333; padding: 8px;">
                    <div v-if="!row.fileList || row.fileList.length === 0"></div>
                    <div
                      v-else
                      style="color: blue; cursor: pointer;"
                      @click="picturesPreview(row)"
                    >
                      {{ row.fileList.length }}
                    </div>
                  </td>
                </tr>

                <!-- ✅ 总计行（内嵌在表格中） -->
                <tr style="font-weight: bold; background-color: #f5f5f5;">
                  <td style="border: 1px solid #333; padding: 8px;" colspan="4">总计</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ repairNum1 }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ repairNum2 }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">{{ repairNum3 }}</td>
                  <td style="border: 1px solid #333; padding: 8px;">¥ {{ repairNum4 }}</td>
                  <td style="border: 1px solid #333; padding: 8px;"></td>
                </tr>
              </tbody>
            </table>

            <div class="fillIn" style="margin-top: 20px;display: flex;justify-content: space-between;">
              <div class="item" style="text-align: center;width: 100% ;font-weight: 600; font-size: 14px" >
                <div><span>维修内容</span></div>
              </div>
            </div>
            <!-- <el-table :data="repairTicketPart" class="table" style="margin-top: 20px; width: 1000px; " border>
              <el-table-column label="修理项目" align="center" prop="repairName" >
                <template slot-scope="scope">
                  <div>{{ scope.row.maTypeName }}-{{ scope.row.typeName }}</div>
                </template>
              </el-table-column>
              <el-table-column  align="center" prop="specificationType" >
                <template #header>
                  <span>配件名称 * 数量 / 单价</span>
                  <span style="margin-left: 20px;">总价</span>
                </template>
                <template slot-scope="scope">
                          <div class="part-info">
                              {{ scope.row.partName + " " }}*{{ " "+scope.row.partNum + (scope.row.partPrice!== 0? " / ¥ " + scope.row.partPrice : " / 无") }}
                          <span class="total-price">{{ "¥"+" "+scope.row.partCost }}</span>
                        </div>
                </template>

              </el-table-column>
            </el-table>
            <div class="tabelAll">
              <div class="columnAllNumTwo">合计</div>
              <div class="columnAllNumThree">{{ "¥"+" "+acountAll }}</div>
            </div> -->

            <table
              class="table"
              style="
                margin-top: 20px;
                width: 1000px;
                border: 1px solid #333;
                border-collapse: collapse;
                text-align: center;
              "
            >
              <thead>
                <tr style="background-color: #f5f7fa;">
                  <th style="border: 1px solid #333; padding: 8px;">修理项目</th>
                  <th style="border: 1px solid #333; padding: 8px;">
                    配件名称 * 数量 / 单价
                    <span style="margin-left: 20px;">总价</span>
                  </th>
                </tr>
              </thead>

              <tbody>
                <tr v-for="(row, index) in repairTicketPart" :key="index">
                  <!-- 修理项目 -->
                  <td style="border: 1px solid #333; padding: 8px;">
                    {{ row.maTypeName }} - {{ row.typeName }}
                  </td>

                  <!-- 配件详情 -->
                  <td
                    style="border: 1px solid #333; padding: 8px; text-align: left;"
                  >
                    <div>
                      {{ row.partName }}
                      ×
                      {{ row.partNum }}
                      /
                      <span v-if="row.partPrice !== 0">¥ {{ row.partPrice }}</span>
                      <span v-else>无</span>
                      <span style="float: right;">¥ {{ row.partCost }}</span>
                    </div>
                  </td>
                </tr>

                <!-- ✅ 合计行 -->
                <tr style="font-weight: bold; background-color: #f5f5f5;">
                  <td
                    style="border: 1px solid #333; padding: 8px; text-align: center;"
                  >
                    合计
                  </td>
                  <td
                    style="border: 1px solid #333; padding: 8px; text-align: center;"
                  >
                    ¥ {{ acountAll }}
                  </td>
                </tr>
              </tbody>
            </table>

            <div class="fillIn" style="margin-top: 20px; display: flex; align-items: center; justify-content: space-between;">
              <!-- 负责人 + 签名 -->
              <div class="item" style="width: 50%; display: flex; align-items: center;">
                <div style="width: 30%; white-space: nowrap; display: flex; align-items: center;">
                  维修人员：
                </div>
                <div
                  v-if="repairTicketlLevelOne.signUrl"
                  style="width: 70%; display: flex; justify-content: flex-start;"
                >
                  <img
                    :src="repairTicketlLevelOne.signUrl"
                    style="width: 40px; height: 100px; object-fit: contain;"
                    :class="{ 'is-rotate': repairTicketlLevelOne.signType == 0 }"
                    alt=""
                  />
                </div>
              </div>

              <!-- 完成日期 -->
              <div class="item" style="width: 50%; display: flex; align-items: center;">
                <span>完成日期：</span>
                <span style="margin-left: 4px;">{{ repairTicketlLevelOne.repairTime }}</span>
              </div>
            </div>
<!--            <div class="fillIn" style="margin-top: 20px; display: flex; justify-content: space-between;">-->
<!--              <div class="item" style="width: 33%">-->
<!--                <div>-->
<!--                  <span>维修人员：</span>-->
<!--                </div>-->
<!--              </div>-->

<!--              <div class="item" style="width: 33%">-->
<!--                <div>-->
<!--                  <span>试验人员：</span>-->
<!--                </div>-->
<!--              </div>-->

<!--              <div class="item" style="width: 33%">-->
<!--                <div>-->
<!--                  <span>检验人员：</span>-->
<!--                </div>-->
<!--              </div>-->
<!--            </div>-->
          </div>
        <!-- </vue-easy-print> -->
      </div>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="print">打 印</el-button>
        <el-button @click="openPrint = false">关 闭</el-button>
      </div>
    </el-dialog>

     <!-- 查看弹窗 -->
    <el-dialog :title="titleView" :visible.sync="showView" width="1000px" append-to-body>
      <div style="overflow-y: scroll">
        <!-- <vue-easy-print tableShow ref="remarksPrintRefView" class="print"> -->
          <div id="checkIdTwo">
            <div class="title" style="text-align: center; font-weight: 600; font-size: 16px; margin-bottom:20px">
                维修任务单编号明细
            </div>
            <!-- <el-table :data="getListViewInfo"  width="100%" border>
              <el-table-column align="center" label="序号" type="index" width="55" />
              <el-table-column label="类型名称" align="center" prop="typeName" :show-overflow-tooltip="true"/>
              <el-table-column label="规格型号" align="center" prop="type" :show-overflow-tooltip="true"/>
              <el-table-column label="设备编码" align="center" prop="code" :show-overflow-tooltip="true"/>
              <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <div v-if="scope.row.status=='1'" >已完成</div>
                  <div v-if="scope.row.status=='0'">未完成</div>
                </template>
              </el-table-column>
            </el-table> -->
            <table
              class="table"
              style="
                width: 100%;
                margin-top: 20px;
                border: 1px solid #333;
                border-collapse: collapse;
                text-align: center;
              "
            >
              <thead>
                <tr style="background-color: #f5f7fa;">
                  <th style="border: 1px solid #333; padding: 8px; width: 55px;">序号</th>
                  <th style="border: 1px solid #333; padding: 8px;">类型名称</th>
                  <th style="border: 1px solid #333; padding: 8px;">规格型号</th>
                  <th style="border: 1px solid #333; padding: 8px;">设备编码</th>
                  <th style="border: 1px solid #333; padding: 8px;">状态</th>
                </tr>
              </thead>

              <tbody>
                <tr v-for="(row, index) in getListViewInfo" :key="index">
                  <!-- 序号 -->
                  <td style="border: 1px solid #333; padding: 8px;">{{ index + 1 }}</td>

                  <!-- 类型名称 -->
                  <td style="border: 1px solid #333; padding: 8px;" :title="row.typeName">
                    {{ row.typeName }}
                  </td>

                  <!-- 规格型号 -->
                  <td style="border: 1px solid #333; padding: 8px;" :title="row.type">
                    {{ row.type }}
                  </td>

                  <!-- 设备编码 -->
                  <td style="border: 1px solid #333; padding: 8px;" :title="row.code">
                    {{ row.code }}
                  </td>

                  <!-- 状态 -->
                  <td style="border: 1px solid #333; padding: 8px;">
                    <span v-if="row.status == '1'">已完成</span>
                    <span v-else-if="row.status == '0'">未完成</span>
                    <span v-else>-</span>
                  </td>
                </tr>
              </tbody>
            </table>

          </div>
        <!-- </vue-easy-print> -->
      </div>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="printView">打 印</el-button>
        <el-button @click="showView = false">关 闭</el-button>
      </div>
    </el-dialog>

     <!--多图片查看弹窗 -->
    <el-dialog :visible.sync="dialogVisibles">
      <div style="width: 100%;height: 600px;display: flex;justify-content: space-between;align-items: center;">
        <div style="width: 5%;height: 100%;display: flex;align-items: center;justify-content: center;" >
          <i class="el-icon-caret-left" style="font-size: 32px;" @click="imgIndex=imgIndex-1" v-show="imgIndex>0"></i>
        </div>
        <div style="width: 90%;height: 100%;overflow: hidden;">
          <img v-for="(item,index) of dialogImageUrls" :key="index" v-show="imgIndex==index" width="100%" height="500px" :src="item.url.replaceAll('#','%23')" alt />
        </div>
        <div style="width: 5%;height: 100%;display: flex;align-items: center;" >
          <i class="el-icon-caret-right" style="font-size: 32px;" @click="imgIndex=imgIndex+1" v-show="(imgIndex+1)<(dialogImageUrls.length)"></i>
        </div>
      </div>
    </el-dialog>
    </div>
</template>

<script>

import {
    getRepairTaskList,
    getRepaiDocumentInfo,
    rejectRepair,
    sendList,
    getRepairDocumentInfo,
} from '@/api/repair/repair.js'

 import { getInfo, h } from '@/api/login'

import vueEasyPrint from "vue-easy-print";
import { formatTime } from '@/utils/bonus'
export default {
    name: '',
    dicts: ['repair_task_status'],
    data() {
        return {
            type: '',
            isShowOneFlag: false,
            priKey: '',
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            tableList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                keyWord: '', //关键字
                unitId: '', //单位id
                proId: '', //工程id
                repairStatus: '', //状态
                typeId: '', //工机具类型
                time: [],// 日期范围
                agreementCode: '', //协议
                startTime: '',
                endTime: '',
            },
            companyId: '',
            unitList: [],
            proList: [],
            //维修单显示
            openPrint:false,
            printData: {},
            // //选择的taskId数组
            // ids:[],
            taskList:[],
            //维修任务单上部分数据
            repairTicketlLevelOne:{},
            //中间维修设备
            repairTicketDevice:[],
            //下方维修内容
            repairTicketPart:[],
            //报修数量计和
            repairNum1:0,
            //修复数量计和
            repairNum2:0,
            //报废数量计和
            repairNum3:0,
            //维修费小计计和
            repairNum4:0,
            //维修任务单详见附件
            showView:false,
            //维修任务单详见附件标题
            titleView:'',
            //维修任务单详见附件列表
            getListViewInfo:[],
            //维修内容列表合计金额
            acountAll:0,
            //多图片查看弹窗
            dialogImageUrls: [],
            dialogVisibles: false,
            imgIndex:0,
        }
    },
    created() {
      if(this.$route.query.code){
        this.queryParams.keyWord=this.$route.query.code
      }
      const end = new Date()
      let start = new Date()
      start.setMonth(start.getMonth() - 1)
      this.queryParams.startTime = this.format(start)
      this.queryParams.endTime = this.format(end)
      // 不在这里直接调用getList，等字典数据加载完成后再调用
        // this.initSelectData()
        // this.InitIGetInfo()
    },
    components: { vueEasyPrint },
    methods: {
        // 字典数据加载完成后的回调
        onDictReady(dict) {
            // 获取repair_task_status的所有选项，并过滤出有效的选项（值为0、1、2、4）
            const allOptions = dict.type.repair_task_status || []
            const validOptions = allOptions.filter(item =>
                item.value == 0 || item.value == 1 || item.value == 2 || item.value == 4
            )

            // 如果有有效选项，设置第一个为默认值
            if (validOptions.length > 0) {
                this.queryParams.repairStatus = validOptions[0].value
            }
            if (validOptions.length > 1) {
                this.queryParams.repairStatus = validOptions[1].value
            }

            // 执行查询
            this.getList()
        },
        format(date) {
          const y = date.getFullYear()
          const m = String(date.getMonth() + 1).padStart(2, '0')
          const day = String(date.getDate()).padStart(2, '0')
          return `${y}-${m}-${day}`
        },
        //人员信息
        InitIGetInfo() {
            getInfo().then((res) => {
                this.companyId = res.user.companyId
                this.getList()
            })
        },
        /** 查询列表 startTime,结束日期endTime  */
        async getList() {
            this.loading = true
            // this.queryParams.startTime = this.queryParams.time ? this.queryParams.time[0] : ''
            // this.queryParams.endTime = this.queryParams.time ? this.queryParams.time[1] : ''
            try {
                let params = {
                    companyId: this.companyId,
                    ...this.queryParams,
                }
                const res = await getRepairTaskList(params)
                this.tableList = res.data.rows
                this.total = res.data.total
                this.loading = false
            } catch (error) {}
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            const end = new Date()
            let start = new Date()
            start.setMonth(start.getMonth() - 1)
            this.queryParams.startTime = this.format(start)
            this.queryParams.endTime = this.format(end)
            // this.resetForm("queryForm");
            this.$refs.queryForm.resetFields()
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.$emit('handelAdd')
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.$emit("handelEdit",row);
        },
         /** 查看按钮操作 */
        handleSee(row) {
            this.$emit("handelView",row);
        },
        /** 删除按钮操作 */
        handleReject(row) {
            const taskIds = row.taskId || this.ids;
            this.$modal.confirm('是否确认驳回该退料？').then(function() {
                return rejectRepair(taskIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("驳回成功");
            }).catch(() => {});
        },
        /** 导出按钮操作 */
        handleExport() {
          const currentTime = formatTime(new Date());
            this.download(
                'material/repair/export',
                {
                    ...this.queryParams,
                    // startTime:this.queryParams.time[0],
                    // endTime:this.queryParams.time[1]
                },
                `维修任务单_${currentTime}.xlsx`,
            )
        },
      handleDetailsExport() {
        const currentTime = formatTime(new Date());
        this.download(
          'material/repair/exportDetails',
          {
            ...this.queryParams,
            // startTime:this.queryParams.time[0],
            // endTime:this.queryParams.time[1]
          },
          `维修任务详情单_${currentTime}.xlsx`,
        )
      },
        //查看维修任务单
       async handlePrint(row) {
            const res = await getRepairDocumentInfo(row.taskId);
            this.repairTicketlLevelOne = res.data.repairTaskInfo;
            this.repairTicketDevice = res.data.repairDeviceSummaryList;
            //维修设备列表计算
            if(this.repairTicketDevice.length>0){
              let num1 = 0;  //报废数量
              let num2 = 0;  //修复数量
              let num3 = 0;  //报废数量
              let num4 = 0.0;  //维修费小计
            this.repairTicketDevice.forEach(item=>{
              num1 = num1 + Number(item.typeRepairNum)
              num2 = num2 + Number(item.typeRepairedNum)
              num3 = num3 + Number(item.typeScrapNum)
              num4 = num4 + item.typeCost
            })
            this.repairNum1 = num1
            this.repairNum2 = num2
            this.repairNum3 = num3
            this.repairNum4 = num4
            }

            //维修内容列表
            this.repairTicketPart = res.data.repairPartArray;

            //维修费小计 计算
            if(this.repairTicketPart.length>0){
              let acount = 0 //维修费用
              this.repairTicketPart.forEach(item=>{
                acount = acount + item.partCost
              })
              this.acountAll = acount;
            }

            this.openPrint = true;
            this.title = "机具设备维修任务单";
        },
        //提交
        handleSend(row){
        if (this.ids.length == 0) {
          this.$alert("请至少勾选一条要提交的数据", "提示", {
            type: "warning",
            confirmButtonText: "确定",
          });
          return;
        } else {
          sendList(this.taskList).then((response) => {
            if (response.code == 200) {
              this.$modal.msgSuccess("通过成功");
            }
            this.getList()
          });
          }
        },

        // 多选框选中数据
        handleSelectionChange(selection) {
          this.taskList = [];
          this.ids = selection.map((item) => item.taskId);
          selection.forEach((item) => {
            this.taskList.push({ taskId: item.taskId });
          });
          this.single = selection.length != 1;
          this.multiple = !selection.length;
          },

        //维修任务单打印
        print() {
          // this.$refs.remarksPrintRef.print();
          printJS({
            printable: 'checkId',
            type: 'html',
            targetStyles: ['*'],
            maxWidth:'1400'
            // 其他配置选项
          });
        },

        //详见附件打印
        printView() {
          // this.$refs.remarksPrintRefView.print();
          printJS({
            printable: 'checkIdTwo',
            type: 'html',
            targetStyles: ['*'],
            maxWidth:'1400'
            // 其他配置选项
          });
        },

        handleView(row){
          this.getListViewInfo = row.repairDeviceList
          console.log('this.getListViewInfo',this.getListViewInfo)
          this.titleView = "查看"
          this.showView = true;
        },

        //多图片查看
        picturesPreview(row) {
          this.dialogImageUrls = [];
            row.fileList.forEach(item => {
                this.dialogImageUrls.push({
                  name: item.name,
                  url: item.url
                })
            });
            this.imgIndex=0
            this.dialogVisibles = true;
        },

        //是否可用勾选框
        selectable(row) {
          if (row.repairStatusCode == "1" || row.repairStatusCode == "2") {
            return false;
          } else {
            return true;
          }
        },
        },
}
</script>
<style lang="scss" scoped>
.submit_box {
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .submit_box_title {
        display: flex;
        flex-direction: column;
        margin-left: 15px;

        :first-child {
            font-size: 14px;
            font-weight: 600;
        }

        :last-child {
            margin-top: 6px;
            font-size: 12px;
        }
    }
}

.submit_box_two {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    margin-left: 30%;

    .submit_box_title {
        display: flex;
        flex-direction: column;
        margin-left: 10px;
        font-size: 18px;
        font-weight: 600;
    }
}

::v-deep.el-table .fixed-width .el-button--mini {
    width: 60px !important;
    margin-bottom: 10px;
}
.dialog-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}
.tabelAll {
  display: flex;
  border: 1px solid #dfe6ec;
  margin-bottom: 1px;
  width:1000px;
  border-bottom: 1px solid #dfe6ec;
  border-top: none;
}
.columnAll {
  flex: 1;
  padding: 5px;
  border-left: 1px solid #dfe6ec;
  text-align: center;
  width:11.1%;
}
.columnAllNum {
  padding: 5px;
  text-align: center;
  width:44.4%;
  border-left: none;
}
.columnAllNumTwo {
  flex: 1;
  padding: 5px;
  border-left: 1px solid #dfe6ec;
  text-align: center;
  width:50%;
  border-left: none;
}
.columnAllNumThree {
  flex: 1;
  padding: 5px;
  border-left: 1px solid #dfe6ec;
  text-align: center;
  width:50%;
}
/* 最后一列无右边框 */
.tabelAll .column:last-child {
  border-right: none;
}
.part-info .total-price {
    margin-left: 20px; /* 调整间距大小 */
}
.is-rotate {
  transform: rotate(-90deg);
  transform-origin: center center;
}
</style>
