<template>
  <div>
    <el-card class="el-card">
      <el-form :model="filterQuery" class="query-form" label-width="100px" >

        <el-row>
          <el-col :span="12">
            <el-form-item label="上级产品">
              <el-input v-model="filterQuery.upProduct " :disabled="isUp" style="width: 80%" placeholder="请输入多级产品" clearable></el-input>
              <el-button style="margin-left: 10px" :disabled="isUp" type="primary" @click="addUpProduct()">添加</el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="下级产品">
              <el-input v-model="filterQuery.lowProduct" style="width: 80%" placeholder="请输入下级产品" clearable></el-input>
              <el-button style="margin-left: 10px" :disabled="isLow" type="primary" @click="addLowProduct()">添加</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>


      <el-table v-loading="loading" :data="list" style="width: 100%"  border highlight-current-row>
        <el-table-column label="序号" type="index" width="60"></el-table-column>
        <el-table-column label="UDI码" prop="code"></el-table-column>
        <el-table-column label="产品编码" prop="nameCode"></el-table-column>
        <el-table-column label="产品名称" prop="cpmctymc"></el-table-column>
        <el-table-column label="规格型号" prop="ggxh"></el-table-column>
        <el-table-column label="序列号" prop="serialNo"></el-table-column>
        <el-table-column label="生产企业" prop="manufactory"></el-table-column>
        <el-table-column label="计量单位" prop="measname"></el-table-column>
        <el-table-column label="创建时间" prop="createTime"></el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="filterQuery.page"
        :limit.sync="filterQuery.limit"
        @pagination="handleCurrentChange"
      ></pagination>
    </el-card>
  </div>
</template>
<script>
import {checkLowProduct, checkUpProduct, getDelectList, getList} from "@/api/inout/ioCodeRel";
import ioCodeRelEdit from "@/views"

export default {
  props: {
    closeDialog: {
      type: Function,
      required: true,
    },
    idQuery: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      showSearch: true,
      newSpDistributionVisible: false,
      filterQuery: {
        upProduct:'',
        lowProduct:'',
        page: 1,
        limit: 10,
      },
      isLow:true,
      isUp:false,
      upCode:null,
      formName:null,
      loading:false,
      list:[],
      formData:null,
      total:0,
    };
  },

  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        page: 1,
        limit: 10,
      };
      this.getList();
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    getList() {
      if (this.filterQuery.upProduct!=null){
        this.filterQuery.parentCode=this.filterQuery.upProduct
      }
      getDelectList(this.filterQuery)
        .then((response) => {
          if (response.code == 20000) {
            this.list = response.data.list || [];
            this.total = response.data.total || 0;
          } else {
            this.$message.error(response.message);
          }
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
    addUpProduct(){
      checkUpProduct({code:this.filterQuery.upProduct}).then((res)=>{
        if(res.code==20000){
          this.isLow=false;
          this.isUp=true;
        }else{
          this.$message.error(res.message);
        }
      }).catch(()=>{
        this.$message.error("扫码错误！");
      })
    },
    addLowProduct(){
      checkLowProduct({lowCode:this.filterQuery.lowProduct,upCode:this.filterQuery.upProduct}).then((res)=>{
        if(res.code==20000){
            this.getList();
        }else{
          this.$message.error(res.message);
        }
      }).catch(()=>{
        this.$message.error("扫码错误！");
      })
    },
  },
  components: {},
  filters: {},
  mounted() {
  }
  ,
  created() {
    if(this.idQuery.id!=null){
      this.filterQuery.upProduct=this.idQuery.parentCode
      this.isLow=false;
      this.isUp=true;
      this.getList();
    }

  }
  ,
}
;
</script>
<style scoped>
</style>

