<template>
<div class="examination">
  <el-dialog
    @close="closeDialog"
    :visible.sync="dialogTableVisible"
    width="80%"
  >
    <div slot="title" class="titleBox">
      <i
        :class="tableType === 0 ? 'el-icon-document' : 'el-icon-edit-outline'"
        style="font-size: 20px"
      ></i>
      <span style="margin-left: 10px; font-size: 18px">{{
          tableTypeDsc
        }}</span>
    </div>
    <el-form
      ref="baseData"
      label-width="80px"
      :inline="true"
      :model="baseData"
    >
      <el-row>
        <el-col :span='8'>
          <el-form-item prop="matName" label="物料名称">
            <el-select
              v-model="baseData.matNo"
              filterable
              collapse-tags
              size="small"
              style="width: 120px"
            >
              <el-option
                v-for="item in matType"
                :key="item.matNo"
                :label="item.matName"
                :value="item.matNo"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span='8'>
          <el-form-item prop="gradeNo" label="牌号/等级">
            <el-select
              v-model="baseData.gradeNo"
              filterable
              collapse-tags
              size="small"
            >
              <el-option
                v-for="(item, index) in gradeType"
                :key="index"
                :label="item.gradeName"
                :value="item.gradeNo"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span='8'>
            <el-form-item prop="batchNo" label="批次号">
              <el-input v-model="baseData.batchNo" size="small" style="width: 100%;"></el-input>
            </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span='24'>
          <el-form-item prop="memo" label="备注">
            <el-input v-model="baseData.memo" size="small" placeholder="请输入" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button type="goon" icon="el-icon-check"size="mini" :loading='buttonLoading1' @click="changeJudge">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
  </el-dialog>
</div>
</template>

<script>
export default {
  name: 'changeJudgeComponents',
  props: ["showFlag", "Params"],
  data () {
    return {
      dialogTableVisible: false,
      tableTypeDsc: "更改判定信息",
      tableType: 0,
      tableData: [],
      buttonLoading1 :false,
      gradeType:null,
      height_top: 0,
      addLoading: false,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0,
      },
      dataLoading: false,
      baseData: {},
      matType:[],
      matAllList: []
    };
  },
  created () {
    this.height_top =
      window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
    this.baseData=this.Params;
    this.getMatType();
    this.getGradeType();
  },
  mounted () {
    this.getGradeType();
  },
  methods: {
    searchFollow (row) {
      this.saveRow = row;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.mainData();
    },
    getSummaries (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        if (index === 1) {
          sums[index] = data.length;
        }
      });
      return sums;
    },
    cancel () {
      this.buttonLoading1=false
      this.baseData = {}
      this.dialogTableVisible = false
      this.addLoading = false
      this.$emit('refresh')
    },
    closeDialog () {
      this.addLoading = false
      this.$emit('refresh')
    },
    tableHeaderCellStyle () {
      return "background-color: rgb(249,249,249) !important;color: rgb(73, 72, 72);border-bottom: 1px solid #DCDFE7;border-top:3px solid #3ac1ea;";
    },
    getGradeType() {
      let that = this;
      let obj = {
        object: {
          validFlag: "1",
        },
        pageIndex: 1,
        pageSize: 99999,
      };
      that.axios.post("pass/baseManagement/v1/limsbasegrades/queryLimsBaseGradePage", obj,{individualType: "json"}).then((res) => {
          if (res.succeed) {
            this.gradeType = res.data.list;
          }
        }).catch((e) => {});
    },
    getMatType(){
      this.axios.get('pass/baseManagement/v1/limsbasematerialss/like/?pageNum=1&pageSize=10000&matClassNo=S006&matName=').then(res => {
        if (res.code == 0 || res.code == 200){
          // this.matAllList = [...res.data.list]
          // this.matType = [...res.data.list].slice(0,200)
          this.matType = res.data.list
        }else {

        }
      }).catch(ex => {

      })

    },
    getMatterName (val){
      if(val){
        this.matType=this.matAllList.filter(item=>{
          if(item.matName.indexOf(val)!==-1){
            return true
          }
        }).slice(0,300)
      }else{
        this.matType=[...this.matAllList].slice(0,300)
      }
    },
    changeJudge(){
      if (this.baseData.batchNo == null || this.baseData.batchNo == ''){
        this.$message.warning('请填写批次号!');
        return
      }
      this.buttonLoading1=true
      let matItem = this.matType.find(item => {
        if (item.matNo == this.baseData.matNo){
          return item;
        }
      })
      this.baseData.matName = matItem.matName
      if (this.baseData.gradeNo){
        let gradeItem = this.gradeType.find(item => {
          if (item.gradeNo == this.baseData.gradeNo){
            return item;
          }
        })
        this.baseData.gradeName = gradeItem.gradeName
      }
      this.axios.post("pass/testManagement/v1/limssamplejudges/changeJudge",this.baseData,{individualType: "json"}).then(res=>{
        if (res.code == 0 || res.code == 200){
          this.$message.success(res.data);
          this.cancel();
        }else{
          this.$message.warning(res.message);
          this.cancel();
        }
      }).catch(ex => {
        this.cancel();
        this.$message.warning(ex.message)
      })
    }
  },
  watch: {
    showFlag (arg) {
      let _this = this;
      if (arg) {
        _this.dialogTableVisible = true;
        if (_this.Params !== null) {
          _this.baseData = Object.assign({ clearFlag: true }, this.Params);
          this.baseData.clearFlag = false;
          _this.tableType = 1;
          _this.tableTypeDsc = "更改判定信息";
        }
      }
    },
  },
};
</script>
<style lang="less">
.customWidth_anpr{
  width: 1100px !important
}
</style>
