<template>
  <!-- 模板部分保持不变 -->
  <div>
    <el-card>
      <div class="search-container"> 
        <span class="show-text">任务ID:</span>
        <el-input v-model="taskid" placeholder="请输入任务ID" clearable style="width: 130px; margin-right: 10px" />
        <span class="show-text">生产订单:</span>
        <el-input v-model="taskorder" placeholder="请输入生产订单" clearable style="width: 150px; margin-right: 10px"/>
        <span class="show-text">操作人:</span>
        <el-select
          v-model="checker"
          placeholder="请选择操作人"
          clearable
          style="width: 150px; margin-right: 10px"
          filterable
        >
          <el-option
            v-for="item in checkerList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <span class="show-text">开始时间:</span>
        <el-date-picker 
          v-model="timeRange" 
          type="date"
          placeholder="开始时间" 
          />
        <span class="show-text">校验状态:</span>
        <el-select v-model="checkStatus" style="width: 120px; margin-right: 10px">
          <el-option label="全部" value="2" />
          <el-option label="已校验" value="1" />
          <el-option label="未校验" value="0" />
        </el-select>
        <span class="show-text">异常:</span>
        <el-select v-model="abnormalstatus" style="width: 120px; margin-right: 10px">
          <el-option label="全部" value="0" />
          <el-option label="异常" value="1" />
          <el-option label="正常" value="2" />
          <el-option label="大于550" value="3" />
          <el-option label="超时未校验" value="4" />
        </el-select>
        <span class="show-text">性质:</span>
        <el-select v-model="natureStatus"  style="width: 120px; margin-right: 10px">
          <el-option label="装配" value="2" />
          <el-option label="机加" value="1" />
          <el-option label="全部" value="0" />
        </el-select>
        <span class="show-text">加班:</span>
        <el-select v-model="addwork" style="width: 120px; margin-right: 10px">
          <el-option label="全部" value="0" />
          <el-option label="加班" value="1" />
          <el-option label="正常" value="2" />
        </el-select>
        <el-button :disabled="!!loading" icon="el-icon-search" plain type="primary" @click="searchTable()">查询</el-button>
        <el-button :disabled="!!loading" icon="el-icon-plus" plain type="warning" style="width: 130px;" @click="addWorkTimeRecord">新增工时记录</el-button>
      </div>
      
      <el-tabs v-model="activeTab" type="card" class="custom-tabs">
        <el-table 
          v-loading="loading" 
          :data="tableData" 
          :height="'67vh'" 
          border
          element-loading-background="rgba(0, 0, 0, 0.2)" 
          element-loading-spinner="el-icon-loading"
          highlight-current-row 
          size="mini" 
          style="width: 100%;margin-top: 20px;" 
          tooltip-effect="dark"
          :row-class-name="tableRowClassName"  
          @row-click="handleRowClick"
          @selection-change="handleSelectionChange">
          
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column align="center" label="序号" type="index" width="50" fixed />
          <el-table-column align="center" label="工时ID" prop="AID" width="100" fixed />
          <el-table-column align="center" prop="操作人" label="人员" width="120" fixed />
          <el-table-column align="center" prop="订单编号" label="生产订单" width="100" fixed />
          <el-table-column align="center" prop="产品编码" label="物料编码" width="220" />
          <el-table-column align="center" prop="产品名称" label="物料名称" width="190" />
          <el-table-column align="center" prop="工序名称" label="工序名称" width="120" />
          <el-table-column align="center" prop="工位名称" label="工位名称" width="120" />
          <el-table-column align="center" prop="操作类别" label="报工类型" width="120" />
          <el-table-column align="center" prop="操作数值" label="数量" width="120" />
          <el-table-column align="center" label="开始时间" width="160">
            <template slot-scope="scope">
              {{ formatDateTime(scope.row.开始时间) }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="结束时间" width="160">
            <template slot-scope="scope">
              {{ formatDateTime(scope.row.结束时间) }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="设备工时" width="100">
            <template slot-scope="scope">
              {{ scope.row.加工工时 || 0 }}秒
            </template>
          </el-table-column>
          <el-table-column align="center" label="人员工时" width="100">
            <template slot-scope="scope">
              {{ scope.row.总时长 || 0 }}秒
            </template>
          </el-table-column>
          <el-table-column align="center" label="校验状态" width="80">
            <template slot-scope="scope">
              <el-tag :type="scope.row.已校验 ? 'success' : 'info'" size="mini">
                {{ scope.row.已校验 ? '已校验' : '未校验' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="最后编辑人" label="最后编辑人" width="100" />
          <el-table-column align="center" label="最后编辑时间" width="160">
            <template slot-scope="scope">
              {{ formatDateTime(scope.row.最后编辑时间) }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" width="200" fixed="right">
            <template slot-scope="scope">
              <el-button 
                type="text" 
                size="mini" 
                :disabled="!!scope.row.已校验"
                @click="editTask(scope.row)">
                {{ scope.row.已校验 ? '已校验' : '修改' }}
              </el-button>
              <el-button 
                type="text" 
                size="mini" 
                @click="seetime(scope.row)">
                设备工时
              </el-button>
            </template>
          </el-table-column>

        </el-table>
        
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            :current-page="pageCurrent"
            :page-sizes="[20, 50, 100]"
            :page-size="pageSize"
            :total="total1"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChanges"
            @current-change="handleCurrentChanges" />
        </div>
      </el-tabs>
    </el-card>

    <!-- 编辑时间弹窗 -->
    <el-dialog 
      :visible.sync="editDialogVisible" 
      :title="currentTask.已校验 ? '查看任务信息' : '编辑任务信息'" 
      width="700px" 
      center
      :close-on-click-modal="false">
      <el-form ref="editForm" :model="editForm" label-width="120px" size="mini" :disabled="!!currentTask.已校验">
        <el-form-item label="生产订单">
          <el-input v-model="editForm.订单编号" readonly />
        </el-form-item>
        <el-form-item label="物料编码">
          <el-input v-model="editForm.产品编码" readonly />
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input v-model="editForm.产品名称" readonly />
        </el-form-item>
        <el-form-item label="工序名称">
          <el-input v-model="editForm.工序名称" readonly />
        </el-form-item>
        <el-form-item label="工位名称">
          <el-input v-model="editForm.工位名称" readonly />
        </el-form-item>
        <el-form-item label="操作人">
          <el-input v-model="editForm.操作人" readonly />
        </el-form-item>
        <el-form-item label="操作类别">
          <el-input v-model="editForm.操作类别" readonly />
        </el-form-item>
        <el-form-item label="操作数值">
          <el-input v-model="editForm.操作数值" readonly />
        </el-form-item>
        
        <el-form-item label="开始时间" required>
          <el-date-picker
            v-model="editForm.开始时间"
            type="datetime"
            placeholder="选择开始时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%"
            @change="calculateWorkTime" />
        </el-form-item>
        
        <el-form-item label="结束时间" required>
          <el-date-picker
            v-model="editForm.结束时间"
            type="datetime"
            placeholder="选择结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%"
            @change="calculateWorkTime" />
        </el-form-item>
        
        <!-- <el-form-item label="加工工时">
          <el-input v-model="editForm.加工工时" readonly>
            <template slot="append">秒</template>
          </el-input>
        </el-form-item> -->
        <el-form-item label="人员工时">
          <el-input v-model="editForm.总时长" readonly>
            <template slot="append">秒</template>
          </el-input>
        </el-form-item>
        <el-form-item label="班次标准工时">
          <el-input v-model="editForm.当日班次最小标准工时"  />
        </el-form-item>
        <!-- <el-form-item label="工序顺序">
          <el-input v-model="editForm.工艺顺序" readonly />
        </el-form-item> -->
      </el-form>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">关闭</el-button>
        <el-button 
          v-if="!currentTask.已校验"
          :loading="editSubmitLoading" 
          type="primary" 
          @click="submitEditForm"
          :disabled="!editForm.开始时间 || !editForm.结束时间">
          确 定
        </el-button>
      </div>
    </el-dialog>
    <!-- 查看工时弹窗 -->
    <el-dialog 
      :visible.sync="seeDialogVisible" 
      title="设备工时" 
      width="1200px" 
      center
      :close-on-click-modal="false">

        <el-table 
          :data="seeForm" 
          :height="'67vh'" 
          border
          element-loading-background="rgba(0, 0, 0, 0.2)" 
          element-loading-spinner="el-icon-loading"
          highlight-current-row 
          size="mini" 
          style="width: 100%;margin-top: 20px;" 
          tooltip-effect="dark">
          
          <el-table-column align="center" prop="工位名称" label="工位名称" width="120" />
          <el-table-column align="center" prop="累计分钟" label="累计分钟" width="120" />
          <el-table-column align="center" prop="设备状态" label="设备状态" width="150" />
          <el-table-column align="center" prop="累计秒数" label="累计秒数" width="120" />
          
        </el-table>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="seeDialogVisible = false">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 新增工时记录弹窗 -->
    <el-dialog 
      :visible.sync="addRecordDialogVisible" 
      title="新增工时记录" 
      width="700px" 
      center
      :close-on-click-modal="false">
      <el-form ref="addRecordForm" :model="addRecordForm" label-width="120px" size="mini" :rules="addRecordRules">
        <el-form-item label="操作类别" prop="操作类别">
          <el-select v-model="addRecordForm.操作类别" placeholder="请选择操作类别" style="width: 100%">
            <el-option label="辅助结束" value="辅助结束" />
            <el-option label="报工" value="报工" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="生产订单" prop="订单编号">
          <el-select 
            v-model="addRecordForm.订单编号" 
            placeholder="请选择订单编号" 
            style="width: 100%"
            @change="handleOrderChange"
            filterable
            remote
            :remote-method="loadOrderList">
            <el-option 
              v-for="order in orderList" 
              :key="order.订单编号" 
              :label="order.订单编号" 
              :value="order.订单编号" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="物料编码">
          <el-input v-model="addRecordForm.产品编码" readonly />
        </el-form-item>
        
        <el-form-item label="物料名称">
          <el-input v-model="addRecordForm.产品名称" readonly />
        </el-form-item>
        
        <el-form-item label="工序名称" prop="工序名称">
          <el-select 
            v-model="addRecordForm.工序名称" 
            placeholder="请选择工序名称" 
            style="width: 100%" 
            @change="handleProcessChange">
            <el-option 
              v-for="process in processList" 
              :key="process.TaskAID" 
              :label="process.工序名称" 
              :value="process.TaskAID" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="工位名称">
          <el-input v-model="addRecordForm.工位名称" readonly />
        </el-form-item>
        
        <el-form-item label="操作人" prop="操作人">
          <el-select 
            v-model="addRecordForm.操作人" 
            placeholder="请选择操作人" 
            style="width: 100%">
            <el-option 
              v-for="personne in personnelList" 
              :key="personne.key" 
              :label="personne.label" 
              :value="personne.label" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="开始时间" prop="开始时间">
          <el-date-picker
            v-model="addRecordForm.开始时间"
            type="datetime"
            placeholder="选择开始时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%" />
        </el-form-item>
        
        <el-form-item label="结束时间" prop="结束时间">
          <el-date-picker
            v-model="addRecordForm.结束时间"
            type="datetime"
            placeholder="选择结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%" />
        </el-form-item>
        
        <!-- <el-form-item label="操作数值">
          <el-input v-model="addRecordForm.操作数值" placeholder="请输入数量" />
        </el-form-item> -->
        
        <el-form-item label="工作内容">
          <el-input v-model="addRecordForm.操作内容" :rows="2" type="textarea" placeholder="请输入工作内容" />
        </el-form-item>
        
        <el-form-item label="备注说明">
          <el-input v-model="addRecordForm.操作描述" :rows="3" type="textarea" placeholder="请输入备注说明" />
        </el-form-item>
      </el-form>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="addRecordDialogVisible = false">取消</el-button>
        <el-button :loading="addRecordLoading" type="primary" @click="submitAddRecord">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'WorkTimeValidation',
  data() {
    return {
      // 分页
      pageCurrent: 1,
      pageSize: 20,
      total1: 0,
      
      // 搜索条件
      timeRange: '',
      checkStatus: '0',
      natureStatus: '1',
      addwork:'0',
      abnormalstatus: '2',
      
      // 表格数据
      loading: false,
      activeTab: 'first',
      tableData: [],
      multipleSelection: [],
      // 查看工时弹窗
      seeDialogVisible: false,
      // 编辑弹窗
      editDialogVisible: false,
      editSubmitLoading: false,
      currentTask: {},
      editForm: {
        订单编号: '',
        产品编码: '',
        产品名称: '',
        工位名称: '',
        工序名称: '',
        操作人: '',
        操作类别: '',
        操作数值: 0,
        开始时间: '',
        结束时间: '',
        加工工时: 0,
        总时长: 0,
        工艺顺序: 0,
        当日班次最小标准工时:8,
      },
      seeForm: [],
      // 新增相关数据
      orderList: [],
      processList: [],
      personnelList: [],
      
      // 新增工时记录
      addRecordDialogVisible: false,
      addRecordLoading: false,
      addRecordForm: {
        操作类别: '',
        订单编号: '',
        产品编码: '',
        产品名称: '',
        工序名称: '',
        工位名称: '',
        操作人: '',
        操作数值: '',
        开始时间: '',
        结束时间: '',
        操作内容: '',
        操作描述: '',
        工位ID: '',
        工序ID: ''
      },
      addRecordRules: {
        操作类别: [{ required: true, message: '请选择操作类别', trigger: 'change' }],
        订单编号: [{ required: true, message: '请选择订单编号', trigger: 'change' }],
        工序名称: [{ required: true, message: '请选择工序名称', trigger: 'change' }],
        操作人: [{ required: true, message: '请选择操作人员', trigger: 'change' }],
        开始时间: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
        结束时间: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
      },
      
      currentTime: '',
      currentdate: '',
      checkerList: [],
      checker: "",
      taskorder: '',
      taskid: '',
    }
  },
  
  mounted() {
    this.searchTable()
    this.loadOrderList('') 
    this.loadPersonnelList()
    this.getCheckerList()
  },
  
  methods: {
    getCheckerList() {
      this.checkerList = [];
      var Data = this.CreateData("11", "人员管理_人员信息查询_质检部门_查询");
      this.ExecDatabase(Data).then((response) => {
        for (let i = 0; i < response.data.length; i++) {
          this.checkerList.push({
            label: response.data[i].Personnel_Name,
            value: response.data[i].Personnel_Number,
          });
        }
      });
    },
    // ============ 表格相关方法 ============
    tableRowClassName({ row, rowIndex }) {
      if (!row.结束时间 || row.结束时间 === '') {
        return 'row-without-endtime'
      }
      return ''
    },
    
    handleRowClick(row) {
      this.currentTask = row
    },
    
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    
    // ============ 数据加载方法 ============
    loadPersonnelList() {
      var param = []
      var Data = this.CreateData('11', '系统管理_人员管理_所有有效人员查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data && response.data.length > 0) {
          this.personnelList = response.data.map(person => ({
            key: person.人员编号,
            label: person.人员姓名,
            disabled: false
          }))
        }
      })
    },
    
    loadOrderList(orderId) {
      var param = []
      param.push(['订单编号', orderId])
      var Data = this.CreateData('11', '工时校验_获取订单列表', param)
      this.ExecDatabase(Data).then(response => {
        this.orderList = response.data || []
      }).catch(error => {
        console.error('加载订单列表失败:', error)
        this.orderList = []
      })
    },
    
    handleOrderChange(orderId) {
      if (orderId) {
        // 自动填充零件信息
        const selectedOrder = this.orderList.find(order => order.订单编号 == orderId)
        if (selectedOrder) {
          this.addRecordForm.产品编码 = selectedOrder.零件编码
          this.addRecordForm.产品名称 = selectedOrder.零件名称
        }
        
        // 加载该订单的工序列表
        this.loadProcessList(orderId)
      } else {
        this.addRecordForm.产品编码 = ''
        this.addRecordForm.产品名称 = ''
        this.processList = []
      }
    },
    
    loadProcessList(orderId) {
      var param = [['订单编号', orderId]]
      var Data = this.CreateData('11', '工时校验_获取订单工序', param)
      this.ExecDatabase(Data).then(response => {
        this.processList = response.data || []
      }).catch(error => {
        console.error('加载工序列表失败:', error)
        this.processList = []
      })
    },
    
    handleProcessChange(taskAID) {
      const selectedProcess = this.processList.find(process => process.TaskAID == taskAID)
      if (selectedProcess) {
        this.addRecordForm.工序名称 = selectedProcess.工序名称
        this.addRecordForm.工位名称 = selectedProcess.工位名称
        this.addRecordForm.工位ID = selectedProcess.工位ID
        this.addRecordForm.工序ID = taskAID
      }
    },
    
    // ============ 分页方法 ============
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    
    searchTable() {
      this.loading = true
      
      var param = []
      // if (this.timeRange && this.timeRange.length === 2) {
      //   param[0] = ['开始时间', this.timeRange[0]]
      //   param[1] = ['结束时间', this.timeRange[1]]
      // }
      param[0] = ['开始时间', this.timeRange]
      param[param.length] = ['校验状态', this.checkStatus || 0]
      param[param.length] = ['过滤性质', this.natureStatus || 0]
      param[param.length] = ['异常', this.abnormalstatus || 0]
      param[param.length] = ['PageCurrent', this.pageCurrent]
      param[param.length] = ['PageSize', this.pageSize]
      param[param.length] = ['PageCount', '1111', 'int', '1']
      param[param.length] = ['ItemCount', '1111', 'int', '1']
      param[param.length] = ['任务ID', this.taskid || 0]
      param[param.length] = ['生产订单', this.taskorder || 0]
      param[param.length] = ['加班', this.addwork || 0]
      const selectedChecker = this.checkerList.find(
        (item) => item.value === this.checker
      );
      param.push(['人员', selectedChecker ? selectedChecker.label : 0])
      
      var Data = this.CreateData('11', '工时校验_获取操作记录列表', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData = response.data.result || []
        this.total1 = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      }).catch(error => {
        this.$message.error('查询失败：' + error.message)
        this.loading = false
      })
    },
    
    // ============ 工具方法 ============
    getCurrentTime() {
      const now = new Date()
      const year = now.getFullYear()
      const month = String(now.getMonth() + 1).padStart(2, "0")
      const day = String(now.getDate()).padStart(2, "0")
      const hours = String(now.getHours()).padStart(2, "0")
      const minutes = String(now.getMinutes()).padStart(2, "0")
      const seconds = String(now.getSeconds()).padStart(2, "0")
      this.currentTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
      this.currentdate = `${year}-${month}-${day}`
    },
    
    getCurrentUser() {
      return this.$store.state.user.name
    },
    
    formatDateTime(dateTime) {
      if (!dateTime) return ''
      const date = new Date(dateTime)
      return date.toLocaleString('zh-CN', { 
        year: 'numeric', 
        month: '2-digit', 
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        hour12: false
      }).replace(/\//g, '-')
    },
    // 获取工序数据（异步）
    async getProcessDataAsync(orderId) {
      try {
        var params = [['订单编号', orderId]]
        var processlist = this.CreateData('11', '工时校验_获取订单工序', params)
        const response = await this.ExecDatabase(processlist)
        return response.data || []
      } catch (error) {
        console.error('获取工序数据失败:', error)
        return []
      }
    },
    // ============ 查看工时相关 ============
    async seetime(row){
      this.currentTask = row
      this.seeDialogVisible = true
      var queryParam = [
        ['工位名称', row.工位名称],
      ]
      var queryData = this.CreateData('11', '工时校验_获取设备数据', queryParam)
      const response = await this.ExecDatabase(queryData)
      this.seeForm = response.data
      
    },
    
    // ============ 编辑任务相关 ============
    editTask(row) {
      this.currentTask = row
      this.editForm = {
        订单编号: row.订单编号,
        产品编码: row.产品编码,
        产品名称: row.产品名称,
        工序名称: row.工序名称,
        工位名称: row.工位名称,
        操作人: row.操作人,
        操作类别: row.操作类别,
        操作数值: row.操作数值 || 0,
        开始时间: row.开始时间,
        结束时间: row.结束时间,
        加工工时: row.加工工时 || 0,
        总时长: row.总时长 || 0,
        工艺顺序: row.订单行号 || 0,
        当日班次最小标准工时 : row.当日班次最小标准工时 || 8
      }
      this.editDialogVisible = true
    },
    
    calculateWorkTime() {
      if (this.editForm.开始时间 && this.editForm.结束时间) {
        const start = new Date(this.editForm.开始时间)
        const end = new Date(this.editForm.结束时间)
        const diff = end.getTime() - start.getTime()
        const seconds = Math.round(diff / 1000)
        this.editForm.加工工时 = seconds
        this.editForm.总时长 = seconds
      } else {
        this.editForm.加工工时 = 0
        this.editForm.总时长 = 0
      }
    },
    
    // 提交编辑表单
    async submitEditForm() {
      this.editSubmitLoading = true
      try {
        await this.updateValidationStatus(this.editForm)
        this.$message.success('校验成功')
        this.editDialogVisible = false
        this.searchTable()
      } catch (error) {
        this.$message.error('校验失败：' + error.message)
      } finally {
        this.editSubmitLoading = false
      }
    },
    // 更新数据库校验状态
    
    async updateValidationStatus(data) {
      var 加工工时 = this.editForm.加工工时
      var 总时长 = this.editForm.总时长
      var 工时 = 0
      if(加工工时 == 0){
          工时 = 总时长
      }else{
          工时 = 加工工时
      }
      console.log(加工工时,总时长)
      var param = [
        ['orderAID', this.currentTask.AID],
        ['开始时间', this.editForm.开始时间],
        ['结束时间', this.editForm.结束时间],
        ['总时长', 总时长],
        ['操作人', this.getCurrentUser()],
        ['最后编辑人', this.getCurrentUser()],
        ['当日班次最小标准工时', this.editForm.当日班次最小标准工时]
      ];
      var Data = this.CreateData('11', '工时校验_保存校验记录', param)
      await this.ExecDatabase(Data)
    },
    
    // ============ 新增工时记录 ============
    addWorkTimeRecord() {
      this.addRecordForm = {
        操作类别: '',
        订单编号: '',
        产品编码: '',
        产品名称: '',
        工序名称: '',
        工位名称: '',
        操作人: '',
        操作数值: '',
        开始时间: '',
        结束时间: '',
        操作内容: '',
        操作描述: '',
        工位ID: '',
        工序ID: ''
      }
      this.processList = []
      this.addRecordDialogVisible = true
      this.$nextTick(() => {
        this.$refs.addRecordForm.clearValidate()
      })
    },
    
    // 提交新增记录
    submitAddRecord() {
      this.$refs.addRecordForm.validate((valid) => {
        if (valid) {
          this.addRecordLoading = true
          
          // 计算工时（秒）
          let workTime = 0
          if (this.addRecordForm.开始时间 && this.addRecordForm.结束时间) {
            const start = new Date(this.addRecordForm.开始时间)
            const end = new Date(this.addRecordForm.结束时间)
            const diff = end.getTime() - start.getTime()
            workTime = Math.round(diff / 1000)
          }
          
          const param = [
            ['操作类别', this.addRecordForm.操作类别],
            ['订单编号', this.addRecordForm.订单编号],
            ['物料编号', this.addRecordForm.产品编码],
            ['物料描述', this.addRecordForm.产品名称],
            ['工序名称', this.addRecordForm.工序名称],
            ['工位名称', this.addRecordForm.工位名称],
            ['操作人', this.addRecordForm.操作人],
            ['开始时间', this.addRecordForm.开始时间],
            ['结束时间', this.addRecordForm.结束时间],
            ['操作内容', this.addRecordForm.操作内容],
            ['操作描述', this.addRecordForm.操作描述],
            ['TaskAID', this.addRecordForm.工序ID]
          ]
          
          var Data = this.CreateData('11', '工时校验_新增操作记录', param)
          this.ExecDatabase(Data).then(response => {
            this.$message.success('新增成功')
            this.addRecordDialogVisible = false
            this.searchTable()
          }).catch(error => {
            this.$message.error('新增失败：' + error.message)
          }).finally(() => {
            this.addRecordLoading = false
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.search-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.show-text {
  white-space: nowrap;
}

.custom-tabs {
  margin-top: 10px;
}

.dialog-footer {
  text-align: center;
}

::v-deep .row-without-endtime {
  background-color: #f56c6c !important;
  color: #000000 !important;
}
</style>