<template>
  <!-- 修改物资信息 -->
  <div id="contractDetails">
    <page-title>编辑</page-title>
    <div class="main"></div>
    <div class="contractTitle">
      <div class="form-box">
        <div class="form-one">
          <dil-form :formId="314" v-model="form1"></dil-form>
        </div>
      </div>
    </div>
    <div class="form-box f1">
      <el-input v-model="materialTypeName" disabled> </el-input>
      <el-button type="primary" @click="openDrawer">物资种类</el-button>
    </div>
    <div class="eldrawer">
      <el-drawer
        :visible.sync="drawer"
        :before-close="handleClose"
        :direction="direction"
      >
        <el-input
          placeholder="请输入内容"
          v-model="inputText"
          clearable
          style="width:250px"
        >
        </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>
    <div class="button-box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
    </div>
  </div>
</template>

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

export default {
  components: { PageTitle },
  data() {
    return {
      inputText: null,
      materialTypeId: null,
      drawer: false,
      form1: {},
      mapList: {},
      materialTypeName: null,
      options: {
        requestUrl: "",
        selectionType: "radio"
      }
    };
  },

  mounted() {
    this.information();
  },
  methods: {
    openDrawer() {
      this.drawer = true;
      this.options.requestUrl =
        "/api/v1/rms/getMaterialTypeList?apiId=376&i=" + new Date();
      this.inputText = null;
    },
    currentRadioChange(selection) {
      this.mapList = selection;
      this.materialTypeId = this.mapList.materialTypeId;
      this.materialTypeName = this.mapList.materialTypeName;
    },
    information() {
      console.log("数据显示")
      console.log(this.$route.params.materialTypeName)
      console.log(this.$route.params.materialId)
      this.materialTypeName=this.$route.params.materialTypeName
      //编辑
      this.axios
        .post("/api/v1/rms/getMaterialById/" + this.$route.params.materialId)
        .then(res => {
          console.log(res);
          res.data.data.forEach(e => {
            this.form1 = e;
            console.log(this.form1);
            console.log(this.$route.params.materialId);
          });
        });
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    onclick() {
      this.options.requestUrl =
        "/api/v1/rms/getMaterialTypeList?apiId=376&con=" + this.inputText;
    },
    // 确认
    onClickConfirm() {
      console.log(this.form1);
      let RmsMaterial = {
        materialId: this.form1.materialId,
        materialCode: this.form1.materialCode,
        materialName: this.form1.materialName,
        materialSpecification: this.form1.materialSpecification,
        materialModel: this.form1.materialModel,
        materialTypeId: this.materialTypeId,
        unitOfMeasureId: this.form1.unitOfMeasureId,
        materialTheoreticalWeight: this.form1.materialTheoreticalWeight
      };
      this.axios.post("/api/v1/rms/updateMaterial", RmsMaterial).then(res => {
        if (res.data.code == "200") {
          this.$router.go(-1);
        }
      });
    }
  },
  // 取消
  cancel() {
    this.$router.go(-1);
  }
};
</script>
<style lang="scss" scoped>
.form-box,
.button-box {
  display: flex;
  justify-content: center;
  .el-button {
    width: 80px;
    margin-right: 10px;
  }
}
.f1 {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  .el-input {
    width: 250px;
  }
}
</style>
