<template>
  <!-- 添加运力信息 -->
  <div class="addWagonLoad">
    <PageTitle>返回</PageTitle>
    <el-divider content-position="left">运力信息</el-divider>
     <div class="form_box" style="margin-right: 10rem">
        <dil-form :formId="309" v-model="form1" ref="from1"></dil-form>
      </div>
      <div class="inputBox">
    <span class="text">所属单位类型</span>
      <el-autocomplete
        v-model="state"
        @input="onInput"
        :fetch-suggestions="querySearch"
        placeholder="边输入边查询"
        :trigger-on-focus="false"
        @select="handleSelect"
      ></el-autocomplete>
      </div>
    <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: {},
      // value: undefined,
     carrierIds:"",
      state: "",
      restaurants: [],
    };
  },
  mounted() {},
  methods: {
     onInput() {
      this.axios.post(
        "/api/v1/rms/getCarrierName?state="+this.state,
      )
      .then((res) => {
        if(res.data.code == "200"){
          res.data.data.forEach(element => {
            this.restaurants.push({
              value:element.carrierName,
              carrierIds:element.carrierId
            })
          });
        }
        
      });
    },
    querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
    handleSelect(item){
      this.carrierIds=item.carrierIds;
      console.log(item)
    },
   
     makeSure() {
      //  console.log(this.form1)
       let RmsCapacity={
         capacityTypeId:this.form1.capacityTypeId,
         capacityNumber:this.form1.capacityNumber.toUpperCase(),
         number:this.capacityNumber,
         capacityCorlor:this.form1.capacityCorlor,
         capacityOwneris:this.form1.capacityOwneris,
         capacityVip:this.form1.capacityVip,
         capacityBlacklist:this.form1.capacityBlacklist,
        // carrierId:this.form1.carrierId,
        state:this.state,
        carrierName:this.state,
        carrierIds: this.carrierIds,
       };
      //  console.log("RmsCapacity",RmsCapacity)
       if(
         RmsCapacity.capacityNumber==null ||
         RmsCapacity.capacityCorlor==null ||
         RmsCapacity.capacityOwneris==null ||
         RmsCapacity.capacityVip==null ||
         RmsCapacity.capacityBlacklist==null ||
         RmsCapacity.carrierIds==null
       )this.$message.error("存在空值！");
       else
      this.axios
        .post(
          "/api/v1/rms/insertCapacity", RmsCapacity
        )
        .then((res) => {
          console.log("res.data.code",res.data.code);
          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);
    },
  },
};
</script>
<style lang='scss' >
.addWagonLoad {
  .form_box {
    width: 100%;
    margin-top: 30px;
    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-select{
            width: 250px;
          }
          .el-input{
            width: 250px;
          }
      }
    }
  }
  .inputBox{
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
    .text{
      text-align: right;
      display: flex;
      align-items: center;
      margin-right: 5px;
    }
    .input{
      width: 250px;
    }
  }
  .button_box{
    display: flex;
    justify-content: center;
    .el-button{
      width: 80px;
      margin-right: 10px;
    }
  }
}
</style>
