<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="354" v-model="form1"></dil-form>
        </div>
      </div>
        <div class="materialBox">
          <el-form :inline="true" :model="formInline" 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"
      :before-close="handleClose">
      <div class="inputBox">
        <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>
            <div><dilTable v-bind.sync="option2" @radio-change="currentRadioChange" ></dilTable></div>
              <div class="button-box">
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
</el-drawer>
      <dilTable v-bind.sync="option1">
      <el-table-column fixed="right" label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="deleteclick(scope)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </dilTable>
    <div class="button-box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
    </div>  
  </div>
  </div>
</template>

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

export default {
  components: { PageTitle },
  data() {
    return {
      materialName: {},
      form1: {},
      drawer: false,
      direction: 'rtl',
      inputText:"",
      option1:{
        // first请求数据的地址
        requestUrl: "/api/v1/rms/getCalculateOfMaterialList?apiId=379&truckCalculateId="+this.$route.params.truckCalculateId,
        
      },
      option2:{
        requestUrl:"/api/v1/rms/getMaterialList?apiId=351",
        selectionType:"radio",
        mapList:[]
      }
    };
  },
  mounted() {
      console.log(this.$route)
    this.information();
  },
  methods: {
   currentRadioChange(selection){
      this.mapList=selection,
      console.log(this.mapList)
      this.materialName=this.mapList.materialName
    },
    // onclick(){
    //   this.options.requestUrl="/api/v1/rms/getMaterialList?apiId=351&con=" +this.inputText;
    // },
    information() {
      //编辑 
   console.log("information")          
   console.log("truckCalculateId",this.$route.params.truckCalculateId);  
      this.axios
        .post(
          "/api/v1/rms/getTruckCalculateById/" +
            this.$route.params.truckCalculateId
        )

        .then((res) => {
            console.log(res.data.data)
          res.data.data.forEach((e) => {
            this.form1 = e;
            console.log(e);
            console.log(this.form1);
            console.log( this.$route.params.truckCalculateId);
          });
        });
    },
    onclick(){
      this.option2.requestUrl="/api/v1/rms/getMaterialList?apiId=351&con=" +this.inputText;
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    // 修改汽车衡
    onClickConfirm() {
      console.log(this.form1)
          let map={
         truckCalculateNumber:this.form1.truckCalculateNumber,
         truckCalculateId:this.form1.truckCalculateId,
         truckCalculateStatus:this.form1.truckCalculateStatus,
         truckCalculateLongitude:this.form1.truckCalculateLongitude,
         truckCalculateLatitude:this.form1.truckCalculateLatitude,
         calculateType:this.form1.calculateType,
       };
         if(
        rmsTruckCalculate.truckCalculateNumber == null ||
        rmsTruckCalculate.calculateType ==null
         )this.$message.error("存在空值！");
    
        this.axios
          .post(
            "/api/v1/rms/updateTruckCalculate",
          map
          )
          .then((res) => {
            if (res.data.code == "200") {
              this.$router.go(-1);
            }
          });
    },
//增加汽车衡的物资
makeSure() {
      let rmsTruckCalculateMaterial = {
        truckCalculateId:this.form1.truckCalculateId,
        materialId:this.mapList.materialId,
      }

      this.axios
        .post(
          "/api/v1/rms/insertTruckCalculateOfMaterial",
           rmsTruckCalculateMaterial
        )
        .then((res) => {
          if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "添加成功!",
                });     
                this.$router.go(0);
              }
        });
    },

     deleteclick(scope){
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios
            .post("/api/v1/rms/deleteTruckCalculateMaterial/" + scope.row.truckCalculateMaterialId)
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });     
                this.$router.go(0);
              } else {
                this.$message({
                  message: "删除失败",
                  type: "warning",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "删除操作已取消!",
          });
        });
    },
 // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss'>
.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;
        }
      }
    }
  }
}
.inputBox{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  width: 800px;
}

 .button-box{
    display: flex;
    justify-content: center;
    .el-button{
      width: 80px;
      margin-right: 10px;
    }
  }
.btn-left {
  margin-left: 470px;
}
.input {
  margin-left: 90px;
}
.label{
  margin-left: 445px;
  margin-bottom: -30px;
  font: bold;
  font-size: 1rem;
  padding-left: -30px;
  font-family:Arial, Helvetica, sans-serif;
  margin-bottom:20px;
} 
.label2{
  margin-left: 425px;
  margin-bottom: -30px;
  font: bold;
  font-size: 1rem;
  font-family:Arial, Helvetica, sans-serif
}
.label1{
  margin-left: 345px;
  margin-bottom: -30px;
  font: bold;
}
.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;
}
.materialBox{
   display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 0.3125rem;
  margin-bottom: 1.25rem;
}
</style>
