<template>
  <!-- 添加物资信息 -->
  <div class="addWagonLoad">
    <PageTitle>返回</PageTitle>
     <div class="form-box" style="margin-right: 10rem">
        <dil-form :formId="326" v-model="form1" ref="from1"></dil-form>
      </div>
        <div class="form-box f1">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
  <div class="disableBox">
  <el-form-item>
    <el-input v-model="materialTypeName" disabled>  
    </el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="drawer = true">物资种类</el-button>
  </el-form-item>
  </div>
    </el-form>
    </div>
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose">
        <el-input
            placeholder="请输入内容"
            v-model="inputText"
            clearable>
          </el-input>
          <el-button type="primary" class="btn" @click="onclick">
            <i class="el-icon-search"></i>查询
          </el-button>
            <div><dilTable v-bind.sync="options" @radio-change="currentRadioChange" ></dilTable></div>
</el-drawer>
    <div class="button-box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";

export default {
  components: { PageTitle },
  data() {
    return {
      form1: {},
      drawer: false,
      direction: 'rtl',
      inputText:"",
      options:{
        requestUrl:"/api/v1/rms/getMaterialTypeList?apiId=376",
        selectionType:"radio",
        mapList:[]
      }
    };
  },
  mounted() {},
  methods: {
      currentRadioChange(selection){
      this.mapList=selection,
      console.log(this.mapList)
      this.materialTypeName=this.mapList.materialTypeName
    },
    onclick(){
      this.options.requestUrl="/api/v1/rms/getMaterialTypeList?apiId=376&con=" +this.inputText;
    },
     makeSure() {
      let RmsMaterial = {
        materialCode:this.form1.materialCode,
        materialName:this.form1.materialName,
        materialSpecification:this.form1.materialSpecification,
        materialModel:this.form1.materialModel,
        materialTypeId:this.mapList.materialTypeId,
        unitOfMeasureId:this.form1.unitOfMeasureId,
        materialTheoreticalWeight:this.form1.materialTheoreticalWeight,
      };
      if(
        RmsMaterial.materialCode==null ||
        RmsMaterial.materialName==null ||
        RmsMaterial.materialSpecification==null ||
        RmsMaterial.materialModel==null ||
        RmsMaterial.materialTypeId==null ||
        RmsMaterial.unitOfMeasureId==null ||
        RmsMaterial.materialTheoreticalWeight==null 
      )this.$message.error("存在空值！");
      else
      this.axios
        .post(
          "/api/v1/rms/insertMaterial",
           RmsMaterial
        )
        .then((res) => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "新增成功!",
            });
            // this.$refs.table.refreshData();
            this.$router.go(-1);
          } else {
            this.$message.error("新增失败,可能存在重复！");
          }
          this.$refs['table'].resetField();
        });
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
   handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      }
};
</script>
<style lang='scss' >
 .button-box{
    display: flex;
    justify-content: center;
    .el-button{
      width: 80px;
      margin-right: 10px;
    }
  }
.disableBox{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 1.5rem;
  margin-bottom: 1.25rem;
}
.btn-left {
  margin-left: 470px;
}
.input {
  margin-left: 90px;
}
.common{
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-size: 1rem;
  cursor: default;
  color: #2c3e50;
}
.f1{
  margin-top: -2.5rem;
  margin-left: 22.3rem;
}
.f11{
  margin-top: -3rem;
  // margin-left: 29rem;
}
.f2{
  margin-top: -2.5rem;
  margin-left: 20.7rem;
}
.f3{
  margin-top: -2.5rem;
  margin-left: 25rem;
}
.form-box{
  display: flex;
  justify-content: center;
  .el-form-item{
    display: flex;
    justify-content: center;
    .el-form-item__label{
      display: flex;
      align-items: center;
    }
    .el-form-item__content{
      .el-input{
        .el-input__inner{
          width: 250px;
        }
      }
    }
  }
}
</style>
