<template>
  <!-- 门岗规则信息页面 -->
  <div class="homeworkPath">
    <page-title>门岗规则信息</page-title>
    <div>
      <el-form>
    <el-form-item>
    <div class="form1">
    <label class="el-form-item__label" style="width: 100px">门岗名称</label>

         <el-input
        placeholder=""
        v-model="gatepostName"
        :disabled="true">
      </el-input>
      </div>
      </el-form-item>
      </el-form>
    </div>
    <div class="form-box">
      <dil-form :formId="358" v-model="form"></dil-form>
    </div>
    <!-- 时间点 -->
    <div class="timeBox" >
        门岗开门时间
        <el-time-select
          v-model="rulesGatepostStartTime"
          :picker-options="{
            start: '06:00',
            step: '01:00',
            end: '20:00'
          }"
          placeholder="选择时间"
          >
        </el-time-select>
    </div>
    <div class="timeBox">
      门岗关门时间
      <el-time-select
      v-model="rulesGatepostEndTime"
      :picker-options="{
        start: '06:00',
        step: '01:00',
        end: '20:00'
      }"
      placeholder="选择门岗关门时间">
    </el-time-select>
    </div>
    <!-- 原料模态窗口显示 -->
    <div class="drawerBox">
      <el-form :inline="true"  class="demo-form-inline">
        
        <el-form-item>
          <el-button type="primary" @click="drawer = true">增加物资</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      >
      <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="options2" @selection-change="currentRadioChange" ></dilTable></div>
    </el-drawer>
    <div class="btn2">
      <el-button type="primary" @click="makeSure">新增规则</el-button>
    </div>
    <dilTable v-bind.sync="option">
      <el-table-column fixed="right" label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="deleteclick(scope)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </dilTable>
  </div>
</template>

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

export default {
  components: { PageTitle },
  data() {
    return {
      drawer:false,
      form: {},
      rulesGatepostStartTime:"",
      rulesGatepostEndTime:"",
      rulesGatepostEntityOutTypeList:{},
      materialNameList:{},
      direction: 'rtl',
      inputText:"",
      gatepostName:"",
      option: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/rms/getGatepostRulesById/"+this.$route.params.gatepostId+"?apiId=349",
      },
      options2:{
        // 获取原料
        requestUrl: "/api/v1/rms/getMaterialList?apiId=351",
        selectionType:"select",
        materialList:[]
      }
    };
  },
  mounted() {
    console.log(this.$route)
    this.information();
  },
  methods: {
    currentRadioChange(selection){
      this.materialNameList=selection
      console.log("materialNameList",this.materialNameList);
      // materialName=this.materialNameList.materialName
    },
    // 触发事件，渲染页面
    information(){
      //编辑
      this.axios
        .post(
          "/api/v1/rms/getGatepostName/" +
          this.$route.params.gatepostId
        )
        .then((res) => {
          this.gatepostName=res.data.data.gatepostName
        });
    },
    onclick(){
      this.option2.requestUrl="/api/v1/rms/getMaterialList?apiId=351&con=" +this.inputText;
    },
    // 新增
    makeSure() {
      let rmsGatepostRules = {
        gatepostId:this.$route.params.gatepostId,
        rulesGatepostStartTime:this.rulesGatepostStartTime,
        rulesGatepostEndTime:this.rulesGatepostEndTime,
        vehicleTypeId:this.form.vehicleTypeId,
      };
      var materialIds=[];
      this.materialNameList.forEach((item,index) => {
                  var materialId=item.materialId;
			            materialIds.push(materialId);
      });
			let  rulesGatepostEntityOutTypeList={
          rulesGatepostEntityOutTypeStr:this.form.rulesGatepostEntityOutTypeStr
      }  
      // = this.materialNameList;
      // console.log("materialIds",materialIds);
      let mapValue={
        rmsGatepostRules:rmsGatepostRules,
        materialIds:materialIds,
        rulesGatepostEntityOutTypeList:rulesGatepostEntityOutTypeList
      }  
      if (
        rmsGatepostRules.rulesGatepostStartTime == null ||
        rmsGatepostRules.rulesGatepostEndTime == null ||
        rmsGatepostRules.vehicleTypeId == null ||
        rulesGatepostEntityOutTypeList.rulesGatepostEntityOutTypeStr == null ||
        materialIds[0] == null 
      )
        this.$message.error("存在空值！"); 
      
      else
        this.axios
          .post(
            "/api/v1/rms/insertGatepostRule",
            mapValue
          )
          .then((res) => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
              // this.$refs.table.refreshData();
              this.$router.go(0);
            } else {
              this.$message.error("新增失败！");
            }
            this.$refs["table"].resetField();
          });
    },
    deleteclick(scope) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
      .then(() => {
          this.axios
            .post("/api/v1/rms/deleteGatepostRules/"+scope.row.rulesId)
            .then(() => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
  },
};
</script>
<style lang='scss'>
.homeworkPath {
  .shipName{
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 1.25rem;
    .text{
      width: 6.25rem;
      text-align: right;
      padding-right: 0.9375rem;
      font-size: 0.9375rem;
      font-weight: 600;
      color: #606266;
    }
  }
  .form1{
    display: flex;
    text-align: center;
    align-items: center;
    justify-content: center;
    margin-left: 34rem;
    width: 300px;
  }
  .form {
   display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
   margin-top: 4rem;
  margin-left: 35rem;
  width: 300px;
  }
}
.form-box{
  display: flex;
  justify-content: center;
   margin-top: 1rem;
  margin-left: -4rem;
  .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;
        }
      }
    }
  }
}
.timeBox{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  margin-left: -4rem;
}
.drawerBox{
  margin-top: 2.5rem;
  margin-left: 40rem;
}
.btn2{
  margin-top: 2.5rem;
  margin-left: 40rem;
}
</style>