<template>
  <!-- 修改运力信息 -->
<div class="editCapacity">
  <div id="contractDetails">
    <page-title>编辑</page-title>
    <div class="contractimage">
      <el-image  class="imageStyle"
            :src="src" 
            :preview-src-list="srcList">
          </el-image>
    </div>
    <div class="contractTitle">
      <div class="form_box" style="margin-right: 10rem">
          <dil-form :formId="310" v-model="form1"></dil-form>
      </div>
    </div>
<div class="elForm">
  <el-form
        :inline="true"
        class="demo-form-inline"
        label-width="80px"
      >
        <el-form-item label="选择承运商">
         <el-autocomplete
          class="inline-input"
          v-model="state"
          :fetch-suggestions="querySearch"
          placeholder="请输入承运商名称"
          :trigger-on-focus="false"
          @select="handleSelect"
        >
        <template slot-scope="{ item }">
          <div class="name">{{ item.carrierName }}</div>
        </template>
        </el-autocomplete>
        </el-form-item>
    </el-form>
</div>
    
</div>
    <div class="button_box">
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
    </div>
  </div>

</template>

<script>
import PageTitle from "@/components/Page/Title";
import { getCookie } from "@/utils/util.js";
export default {
  components: { PageTitle },
  data() {
    return {
      srcList:[],
      src:"",
      state: "",
      userId:null,
      restaurants: [],
      accessToken:null,
      userCode:null,
      carrierUserId:null,
      carrierId:null,
      carrierIds:null,
      direction: 'rtl',
      inputText:"",
      form1: {},
      carrierUserId:null,
      carrierName:"",
      options:{
        requestUrl:"/api/v1/rms/getCarrierList?apiId=417",
        selectionType:"radio",
        mapList:[]
      }
    };
  },
  created(){
      this.carrierUserId = getCookie("userId");
      console.log(this.carrierUserId ,'carrierUserId')     
  },
  mounted() {
   this.information();
   this.axios.post(
       "/api/v1/rms/getCarrierNameBySSOId?carrierSSOId=" + this.carrierUserId
      )
      .then((res) => {
        if(res.data.code == "200"){
        console.log(res.data.data)
        this.state = res.data.data.carrierName
        this.carrierIds = res.data.data.carrierId
        }      
  })},
  methods: {
    //承运商弹出层
    handleSelect(item){    
      this.carrierIds = item.carrierId
      item.carrierName = this.state
    },
    //以下是承运商边输边查搜索
    querySearch(queryString, cb) {
        this.axios.post('/api/v1/uc/getCarrierMesByLike?index='+queryString).then((res)=>{
        if(res.data.code == "200"){
          console.log(res.data.data)
          var restaurants = res.data.data
          console.log(restaurants,"restaurants");
          var results = queryString ? restaurants.filter(this.createFilter(queryString)) :restaurants;
           // 调用 callback 返回建议列表的数据
          cb(results);
        }
        })     
      },
    createFilter(queryString) {
        return (restaurants)  =>  {
          return (restaurants.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
        };
      },
    //以上是承运商边输边查搜索
    currentRadioChange(selection){
      this.mapList=selection,
      console.log(this.mapList)
      this.carrierName=this.mapList.carrierName
    },
    onclick(){
      this.options.requestUrl="/api/v1/rms/getCarrierList?apiId=417&con=" +this.inputText;
    },
    information() {
      //编辑 
    console.log(this.$route.params)            
     
      this.axios
        .post(
          "/api/v1/rms/getCapacityById/" +
            this.$route.params.capacityId
        )
        .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.capacityId);
            this.srcList=[];
            this.isShow=true;
            this.src=e.driverLicenceUrl;
            this.srcList.push(e.driverLicenceUrl)
          }); 
        this.axios
        .post(
          "/api/v1/rms/getCarrierNameById/" +
          this.$route.params.capacityId
        )
        .then((res) => {
          this.state=res.data.data.carrierName
          console.log("carrierName",this.carrierName);
        }); 
        });
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    // 确认
    onClickConfirm() {
      console.log(this.form1)
       let RmsCapacity={
         capacityId:this.form1.capacityId,
         capacityTypeId:this.form1.capacityTypeId,
         capacityNumber:this.form1.capacityNumber.toUpperCase(),
         capacityCorlor:this.form1.capacityCorlor,
         capacityOwneris:this.form1.capacityOwneris,
         capacityVip:this.form1.capacityVip,
         capacityBlacklist:this.form1.capacityBlacklist,
         carrierId:this.carrierIds,
       };if(
         RmsCapacity.capacityNumber==null ||
         RmsCapacity.capacityCorlor==null ||
         RmsCapacity.capacityOwneris==null ||
         RmsCapacity.capacityVip==null ||
         RmsCapacity.capacityBlacklist==null 
         //RmsCapacity.carrierId==null
       )this.$message.error("存在空值！");  
        console.log( this.$route.params.capacityId);
        this.axios
          .post(
            "/api/v1/rms/updateCapacity",
           RmsCapacity
          )
          .then((res) => {
            if (res.data.code == "200") {
              this.$message.success("修改成功")
              this.$router.go(-1);           
            }
          });
    },
  },
};
</script>
<style lang='scss' scoped>
  .contractimage{
    text-align: center;
    position: relative;
    left: 35px;
  }
.editCapacity{
    .elForm{
      margin-left: 40%;
    }
    .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;
          }
      }
    }
 }
 .imageStyle{
    height:150px;
    text-align:center
 }
 .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;
}
}
 
</style>