//修改需求
<template>
  <div class="updateInwardRequirement">
    <page-title>修改需求</page-title>
    <div class="form-box f2">
        <el-form :inline="true"  class="demo-form-inline" label-width="80px">
  <el-form-item label="采购订单号">
    <el-input v-model="purchaseOrder" disabled>  
    </el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="ondrawer(1)">浏览</el-button>
  </el-form-item>
</el-form>
<el-form :inline="true"  class="demo-form-inline" label-width="80px">
  <el-form-item label="外轮船名">
    <el-input v-model="foreignShipName" disabled>  
    </el-input>
  </el-form-item>
</el-form>
<el-form :inline="true" class="demo-form-inline" :label-position="left" label-width="80px">
  <el-form-item label="发货单位">
    <el-input v-model="supplierName" disabled> </el-input>
  </el-form-item>
</el-form>
<el-form :inline="true" class="demo-form-inline" :label-position="left" label-width="80px">
  <el-form-item label="收货单位">
   <el-input v-model="shipperName" disabled> </el-input>
  </el-form-item>        
</el-form>
<el-form :inline="true"  class="demo-form-inline" label-width="80px">
  <el-form-item label="物资名称">
    <el-input v-model="materialName" disabled>  
    </el-input>
  </el-form-item>
</el-form>
<el-form :inline="true" class="demo-form-inline" :label-position="left" label-width="80px">
  <el-form-item label="装车点"> 
    <el-input v-model="truckPoint" placeholder="必填" disabled> </el-input>
  </el-form-item>
  <el-form-item>
      <el-button type="primary" @click="ondrawer(2)">浏览</el-button>
  </el-form-item>
  </el-form>
  <el-form :inline="true" class="demo-form-inline" :label-position="left" label-width="80px">
  <el-form-item label="卸车点">
    <el-input v-model="truckPoint1" placeholder="必填" disabled> </el-input>
  </el-form-item>
  <el-form-item>
      <el-button type="primary" @click="ondrawer(3)">浏览</el-button>
  </el-form-item>
  </el-form>
    </div>
    <div class="form-box">
    <dil-form :formId="300" v-model="form"></dil-form>
    </div>
      <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
      size="30%"
    >
      <el-input placeholder="请输入内容" v-model="input"  style="margin-top:10px;margin-left:20px" clearable> </el-input>
      <el-button type="primary" class="btn" @click="onclick(a)"  style="margin-bottom:15px">
        <i class="el-icon-search"></i>查询
      </el-button>
     <div v-show="a==1"><dilTable v-bind.sync="second" @radio-change="currentRadioChange1" ></dilTable></div>
      <div v-show="a==2"><dilTable v-bind.sync="second1" @radio-change="currentRadioChange2" ></dilTable></div>
    </el-drawer>
      <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 {
      requiremntUnitId:0,
      purchaseOrderId:0,
      purchaseOrder:'',
      foreignShipName:'',
      materialName:'',
      shipperName:null,
      supplierName:null,
      a:1,
      direction: "rtl",
      input:'',
      truckPoint:null,
      truckPoint1:null,
      drawer:false,
      form: {},
      second:{
        requestUrl:"/api/v1/ams/getPurchaseIdByBatch?apiId=252",
        selectionType: "radio",
        mapList1:[]
      },
      second1:{
          requestUrl:"/api/v1/ams/getWareHouse?apiId=251",
          selectionType: "radio",
          mapList2:[]
      },
    };
  },
  mounted(){
      this.information();
  },
  methods: {
       information() {
      //编辑
      this.axios
        .post("/api/v1/ams/selectRequirement/" + this.$route.params.requirementId)
        .then((res) => {
          console.log(res.data.data)
          const list = res.data.data;
          this.foreignShipName = list[0].resultForeignShipName,
          this.purchaseOrder = list[0].purchaseOrderNo,
          this.truckPoint = list[0].wareHouseName,
          this.materialName = list[0].materialName,
          this.purchaseOrderId = list[0].purchaseOrderId,
          this.requiremntUnitId = list[0].requiremntUnitId,
          this.truckPoint1 = list[0].unWarehouseName,
          this.shipperName = list[0].receiveUnitName,
          this.supplierName = list[0].sendUnitName,
          console.log('--------')
          console.log(this.foreignShipName,this.materialName,this.purchaseOrderId,this.requiremntUnitId)
          res.data.data.forEach((e) => {
            this.form= e;
            console.log(e);
            console.log(e);
            console.log(this.form1);
          });
        });
    },
     ondrawer(num){
      this.drawer = true;
      this.a = num;
    },
    handleClose(done){
      done();
    },
      onclick(a) {
      console.log(a)
      if(a==1){
        this.second.requestUrl =
        "/api/v1/ams/getPurchaseIdByBatch?apiId=252&con=" + this.input;
      }
      else{
        this.second1.requestUrl=
        "/api/v1/ams/getWareHouse?apiId=251&con=" + this.input;
      }
    },
     currentRadioChange1(selection){    
      this.mapList1=selection,
      console.log(this.mapList1);
      this.purchaseOrder=this.mapList1.purchaseOrderNo,
      this.purchaseOrderId = this.mapList1.purchaseOrderId,
      this.foreignShipName = this.mapList1.resultForeignShipName,
      this.materialName = this.mapList1.materialName
    },
    currentRadioChange2(selection){
      this.mapList2=selection,
      console.log(this.mapList2);
      this.truckPoint=this.mapList2.wareHouseName
    },
    // 修改
    makeSure() {
      console.log(this.form)
      let requiremnet = {
        requirementId:this.$route.params.requirementId,
        purchaseOrderId:this.purchaseOrderId,
        requiremntUnitId:this.requiremntUnitId,
        capacityTypeId: this.form.capacityTypeId,
        requirementEstimatedDuration: this.form.requirementEstimatedDuration,
        requirementOverlimit: this.form.requirementOverlimit,
        requirementShipperId: this.form.requirementShipperId,
        requirementTruckTime: sjTime(this.form.requirementTruckTime),
        requirementType:this.form.requirementType,
        requirementWorkContent:this.form.requirementWorkContent,
        requirementWorkEnvironment:this.form.requirementWorkEnvironment,
        requirementWorkType:this.form.requirementWorkType,
      };
      console.log(requiremnet)
      this.axios
        .post(
          "/api/v1/ams/updateTruckRequirement",
          requiremnet
        )
        .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" scoped>
.updateInwardRequirement{
.form-box {
  display: inline-block !important;
  margin-left: 38%;
  .el-input {
    width: 288px;
  }
  .el-form {
    padding: 10px;
  }
  .tx{
    margin-left: -75px;
  }
}
.box-form {
  display: inline-block !important;
  padding-left: 38%;
  .el-form-item {
    display: flex;
    padding: 10px;
    .el-form-item__label {
      width: 80px !important;
    }
    .el-input {
      width: 288px;
    }
  }
}
.button-box {
  margin-left: 25px !important;
}
}
</style>
