<template>
  <div class="app-container" v-loading="loading">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="90px">
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker v-model="queryParams.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择开始时间" />
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker v-model="queryParams.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择结束时间" />
      </el-form-item>
      <el-form-item label="目标炉" prop="targetFurnaceId">
        <el-select v-model="queryParams.targetFurnaceId" placeholder="请选择" clearable filterable>
          <el-option v-for="item in furnaceOptions" :key="item.furnaceId" :label="item.furnaceName" :value="item.furnaceId" />
        </el-select>
      </el-form-item>
      <el-form-item label="计划号" prop="planNo">
        <el-input v-model="queryParams.planNo" placeholder="请输入计划号" clearable />
      </el-form-item>
      <el-form-item label="入场钢卷号" prop="enterCoilNo">
        <el-input v-model="queryParams.enterCoilNo" placeholder="请输入入场钢卷号" clearable />
      </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-descriptions title="统计信息" :column="3" class="summary-block" border>
      <el-descriptions-item label="计划数量">{{ summary.planCount || 0 }}</el-descriptions-item>
      <el-descriptions-item label="钢卷数量">{{ summary.coilCount || 0 }}</el-descriptions-item>
      <el-descriptions-item label="总重量">{{ summary.totalWeight || 0 }} t</el-descriptions-item>
    </el-descriptions>

    <el-table :data="detailList" border height="calc(100vh - 330px)">
      <el-table-column label="计划号" prop="planNo" align="center" />
      <el-table-column label="目标炉" prop="targetFurnaceName" align="center" />
      <el-table-column label="开始时间" prop="actualStartTime" align="center" width="160">
        <template slot-scope="scope">
          {{ parseTime(scope.row.actualStartTime, '{y}-{m}-{d} {h}:{i}') }}
        </template>
      </el-table-column>
      <el-table-column label="结束时间" prop="endTime" align="center" width="160">
        <template slot-scope="scope">
          {{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}') }}
        </template>
      </el-table-column>
      <el-table-column label="入场钢卷号" prop="enterCoilNo" align="center" />
      <el-table-column label="当前钢卷号" prop="currentCoilNo" align="center" />
      <el-table-column label="重量(t)" prop="netWeight" align="center" />
    </el-table>
  </div>
</template>

<script>
import { getAnnealPerformance } from "@/api/wms/annealPerformance";
import { listAnnealFurnace } from "@/api/wms/annealFurnace";

export default {
  name: "AnnealPerformance",
  data() {
    return {
      loading: false,
      queryParams: {
        startTime: undefined,
        endTime: undefined,
        targetFurnaceId: undefined,
        planNo: undefined,
        enterCoilNo: undefined,
      },
      summary: {},
      detailList: [],
      furnaceOptions: [],
    };
  },
  created() {
    this.loadFurnaces();
  },
  methods: {
    loadFurnaces() {
      listAnnealFurnace({ pageNum: 1, pageSize: 999, status: 1 }).then(response => {
        this.furnaceOptions = response.rows || [];
      });
    },
    handleQuery() {
      this.loading = true;
      getAnnealPerformance(this.queryParams).then(response => {
        const data = response.data || {};
        this.summary = data.summary || {};
        this.detailList = data.details || [];
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>

<style scoped>
.summary-block {
  margin: 12px 0 16px;
}
</style>
