<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-col :span="2">
          <el-form-item>
            <el-select v-model="filters.value" placeholder="请选择">
              <el-option label="编号" value="0"></el-option>
              <el-option label="名称" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-form-item>
          <el-input v-model="filters.name" placeholder="请输入关键字进行搜索" style="width: 300px;" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getMoulds(filters.name)">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table
        :data="moulds"
        :height="tableHeight"
        highlight-current-row
        v-loading="listLoading"
        style="width: 100%;"
    >
        <el-table-column type="index" width="60"></el-table-column>
        <el-table-column prop="modelNo" label="模具编号" width="100" sortable></el-table-column>
        <el-table-column label="模具名称" width="200" sortable>
            <template slot-scope="scope">
                <a style="color: #409EFF; cursor: pointer" @click="toMaintenance(scope.row.id)">
                    {{scope.row.modelName}}
                </a>
            </template>
        </el-table-column>
        <el-table-column prop="equipmentNo" label="云模盒编号" width="120" sortable></el-table-column>
        <el-table-column prop="projectName" label="所属项目" width="200" sortable></el-table-column>
        <el-table-column prop="factoryName" label="制造工厂" width="200" sortable></el-table-column>
        <el-table-column prop="area" label="位置" width="200" sortable></el-table-column>
        <el-table-column prop="runTimes" label="运行次数" align="center" width="100" sortable></el-table-column>
        <el-table-column prop="ocCycle" label="每模平均周期" align="center" width="140" sortable></el-table-column>
        <el-table-column prop="hillNumber" label="电量" align="center" width="80" sortable></el-table-column>
        <el-table-column prop="state" label="当前状态" align="center" width="100" sortable></el-table-column>
        <el-table-column label="模具保养" align="center" fixed="right" width="100">
            <template slot-scope="scope">
                <span v-if="scope.row.runTimes > scope.row.initialModulus">需要</span>
                <span v-else>不需要</span>
            </template>
        </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[20 , 50 , 80 , 100 , 200]"
        :page-size="20"
        layout="total, sizes, prev, pager, next"
        :total="total"
        style="float:right;"
      ></el-pagination>
    </el-col>
  </section>
</template>

<script>
import util from "../../common/js/util";
export default {
  data() {
    return {
      moulds: [],
      filters: {
        name: "",
        value: "0"
      },
      listLoading: false,
      total: 0,
      tableHeight: 0,
      page: 1,
      size: 20
    };
  },
  methods: {
    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.getMoulds();
    },
    handleSizeChange(val) {
      this.size = val;
      this.getMoulds();
    },
    toMaintenance(id) {
      this.$router.push("/detection/" + id);
    },
    getMoulds(keyWord) {
      this.listLoading = true;
      if (keyWord == null) {
        var type = 0;
      } else {
        var type = this.filters.value;
      }
      var params = {
        pageNum: this.page,
        pageSize: this.size,
        projectId: -1,
        searchType: type,
        keyName: keyWord
      };
      this.http.post(
        this.port.mold.molds,
        params,
        res => {
          this.listLoading = false;
          if (res.code == "ok") {
            this.moulds = res.data.list;
            this.total = res.data.total;
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        },
        error => {
          this.listLoading = false;
          this.$message({
            message: error,
            type: "error"
          });
        }
      );
    }
  },
  created() {
    let height = window.innerHeight;
    this.tableHeight = height - 210;
  },
  mounted() {
    this.getMoulds();
  }
};
</script>

<style scoped>
</style>