<template>
  <!-- 未轧规格 -->
  <div class="ModelUnrolled" style="width:100%;">
    <div style="height:100%;width:100%">
      <div class="search" style="display:flex;margin: 10px;">
        <el-input
          placeholder="请输入"
          v-model="map.input"
          style="margin: 10px; width:10%"
          clearable
        ></el-input>
        <!-- <el-date-picker style="margin: 10px;" v-model="map.startTime" type="datetime" placeholder="起始日期"></el-date-picker>
       <el-date-picker style="margin: 10px;" v-model="map.endTime" type="datetime" placeholder="结束日期"></el-date-picker> -->
        <el-button
          type="primary"
          class="btn"
          @click="search"
          style="margin: 10px;"
        >
          <i class="el-icon-search"></i>查询
        </el-button>
        <el-button
          type="primary"
          class="btn"
          @click="addclick()"
          style="margin: 10px;"
        >
          <i class="el-icon-plus"></i>新增
        </el-button>
      </div>

      <div  style="height:500px;float:left;margin-left:5px;width:100%">
        <div  style="height:500px;overflow:scroll;width:100%">
             <el-table
          highlight-current-row
          border
          fit
          :data="loadTable"
          :row-style="{height:'40px'}"
          style="width: 100%;font-size: 18px">
          <el-table-column
          align="center"
            prop="materialName"
            label="物资名称">
          </el-table-column>
          <el-table-column
          align="center"
            prop="spectionsModel"
            label="未轧规格">
          </el-table-column>
           <el-table-column fixed="right" label="操作" width="180">
              <template slot-scope="scope">
                <el-button type="text" size="mini" @click="updateclick(scope.row)">
                  修改
                </el-button>
                <el-button type="text" size="mini" @click="deleteclick(scope.row.resultId)">
                  删除
                </el-button>
              </template>
            </el-table-column>
        </el-table>
        </div >
      </div>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { sjTime } from "@/utils/sharedJsFile";
import {getCookie} from "@/utils/util.js";
import FileSaver from "file-saver";
export default {
  components: { PageTitle },
  data() {
    return {
        count:0,
        loadTable:[],
        unLoadTable:[],
        map:{
            input:"",
            startTime:null,
            endTime:null
        },
        spanArr: [], // 用于存放需要合并的行的个数
        spanIndex: 0, // 记录spanArr数组的下标
      
    };
  },
  mounted(){
    this.search();
  },
  methods: {
    //查询装车数据
    search(){
      //时间校验
    //   if(this.map.startTime && this.map.endTime){
    //     if(this.map.startTime>=this.map.endTime){
    //         this.$message({
    //             message:"结束日期必须大于起始日期!",
    //             type:"warning",
    //             duration:2000
    //         });
    //         return;
    //     }
    //     this.map.startTime=sjTime(this.map.startTime);
    //     this.map.endTime=sjTime(this.map.endTime);
    //   }else if((this.map.startTime && !this.map.endTime) || (!this.map.startTime && this.map.endTime)){
    //     this.$message({
    //         message:"起止日期错误!",
    //         type:"warning",
    //         duration:2000
    //     });
    //     return;
    //   }
      this.axios.get('/api/v1/qms/getAllModelUnrolled?index='+this.map.input).then((res)=>{
        if(res.data.code == "200"){
          this.loadTable=res.data.data;
        }else {
          this.$message({
              type: "error", 
              message: res.data.data,
          });
        }
      })
    },
    updateclick(row) {
      console.log(row);
      this.$router.push("/editModel/" + row.resultId+"/"+row.materialId);
    },
    addclick() {
      this.$router.push("/addModel");
    },
    deleteclick(resultId) {
        console.log(resultId);
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios.post("/api/v1/qms/deleteModel",{
            resultId:resultId
          }).then(() => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.search();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
  },
};
</script>
<style lang='scss'>

</style>

