//修改计划
<template>
  <div id="endMaintenance">
    <page-title>修改计划</page-title>

    <div class="form-box">
<el-form  class="demo-form-inline"  label-width="80px" label-position="left">
  <el-form-item label="承运商">
    <el-autocomplete
      class="inline-input"
      v-model="state2"
      :fetch-suggestions="querySearch"
      placeholder="请输入承运商名称"
      :trigger-on-focus="false"
      @select="handleSelect"
      @input="oninput"
    >
  <template slot-scope="{ item }">
    <div class="name">{{ item.value }}</div>
  </template>
    </el-autocomplete>
  </el-form-item>
  <el-form  class="demo-form-inline"  label-width="80px" label-position="left">
  <el-form-item label="车数">
    <el-input   v-model="planTruckNumber" placeholder="必填" class="input"></el-input>
  </el-form-item>
  </el-form>
</el-form>
</div>
    <template>
			<div>		
						<dilTable v-bind.sync="first" >
						</dilTable>
            </div>
		</template>
    <div class="button-box">
      <el-button type="primary" @click="makeSure">确认修改</el-button>
      <el-button type="primary" @click="cancel">返回</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { sjTime } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      form: {},
      restaurants: [],
      state2:null,
      planTruckNumber:null,
      carrierId:null,
      numberValidateForm: {
          planTruckNumber: null,
        },
      first:{
        requestUrl:"/api/v1/ams/getTruckPlanList?apiId=257&planStatus=0&planId=" + this.$route.params.planId,
      }
    };
  },
  mounted(){
      this.information();
  },
  methods: {
    handleSelect(item){
      this.carrierId = item.carrierId
      item.carrierName = this.state2
    },
    oninput(){
      this.axios.post('/api/v1/uc/getCarrierMesByLike?index='+this.state2).then((res)=>{
        if(res.data.code == "200"){
          console.log(res)
          this.restaurants = res.data.data
        }
      })
    },
    //搜索
    querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        console.log(this.restaurants,"this.restaurants");
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) :restaurants;
        // 调用 callback 返回建议列表的数据
        console.log(results,"results");
        cb(results);
      },
      createFilter(queryString) {
        return (restaurants) => {
          return (restaurants.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
    // 修改
    makeSure() {
      if(this.carrierId == null){
        this.$alert('请输入承运商！')
        return
      }else if(this.planTruckNumber == null){
        this.$alert('请输入车数！')
        return
      }
      let plan = {
        planId : this.$route.params.planId,
        planTruckNumber: this.planTruckNumber,
        carrierId: this.carrierId
      };
          
      this.axios
        .post(
          "/api/v1/ams/updateTruckPlan",
          plan
        )
        .then((res) => {
            console.log(res)
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "修改成功!",
            });            
            this.$router.go(-1);
          } else {
            this.$message.error("修改失败！");
          }
        });
    },
    // 返回
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="scss">
.form-box{
  display: inline-block;
  margin-left: 38%;
  .el-input{
    width:288px
  }
  .input{
    margin-left: -10px;
  }
  .el-form{
    padding: 10px;
    
  }
}
.button-box
{
  margin-left: 45%;
}
</style>
