<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="年度" prop="reportMonth">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy"
          type="monthrange"
          range-separator="-"
          start-placeholder="开始年度"
          end-placeholder="结束年度"
        ></el-date-picker>
      </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="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['mes:pro:yearReport:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" type="index" width="80" align="center" :index="indexMethod"/>
      <el-table-column label="年度" prop="reportYear" align="center" width="150"/>
      <el-table-column label="原料（吨）" prop="itemQuantity" align="center"/>
      <el-table-column label="成品（吨）" prop="productQuantity" align="center"/>
      <el-table-column label="损耗（吨）" prop="loss" align="center"/>
      <el-table-column label="比例/%" prop="lossRate" align="center"/>
      <el-table-column label="天然气（立方）" prop="gas" align="center"/>
      <el-table-column label="吨/天然气" prop="gasProduce" align="center"/>
      <el-table-column label="电" prop="power" align="center"/>
      <el-table-column label="吨/度" prop="powerProduce" align="center"/>
      <el-table-column label="锌销量（吨）" prop="xsale" align="center"/>
      <el-table-column label="锌锭销量（吨）" prop="xdSale" align="center"/>
    </el-table>

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

  </div>
</template>

<script>
import {list} from "@/api/mes/pro/yearReport";

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      list(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.jobId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum
      let pageSize = this.queryParams.pageSize
      return (index + 1) + (pageNum - 1) * pageSize
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mes/pro/yearReport/exportExcel', {
        ...this.queryParams
      }, `生产年报表.xlsx`)
    }
  }
};
</script>
