//补录批次id
<template>
  <div class="recordBathch">
     <div class="purchaseOrder_table">
      <div class="search" style="display:flex">
      <el-input
        placeholder="物资名"
        v-model="materialName"
        style="margin-top: 10px; margin-left: 20px; width: 150px"
        clearable
      >
       </el-input>
       <el-input
        placeholder="外轮船名"
        v-model="resultForeignShipName"
        style="margin-top: 10px; margin-left: 20px; width: 150px"
        clearable
      >
       </el-input>
      <el-button
        type="primary"
        class="btn"
        @click="searchNotice()"
        style="margin: 10px;">
        <i class="el-icon-search"></i>查询
      </el-button>
      </div>
      <!-- 未绑定金蝶的发货通知及其批次 -->
      <dilTable
        v-bind.sync="noticeOption"
      >
      <el-table-column
      fixed="right"
      label="操作"
      width="70">
      <template slot-scope="scope">
          <el-button
            @click.native.prevent="ondrawer(scope.row)"
            type="text"
            size="small">
            关联订单
          </el-button>
        </template>
      </el-table-column>
      </dilTable>
      </div>
    
    <!-- 模态框 -->
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
      size="50%"
    >
      <el-input
        placeholder="物资名或外轮船名"
        v-model="inputText"
        style="margin-top: 10px; margin-left: 20px; width: 200px"
        clearable
      >
       </el-input>
      <el-button
        type="primary"
        class="btn"
        @click="onClick"
        style="margin-bottom: 15px">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button
        type="primary"
        class="btn"
        @click="makeSure"
        style="margin-bottom: 15px">
        确认绑定
      </el-button>
      <div v-show="drawer">
        <dilTable
        ref="ordertable"
          v-bind.sync="purchaseOption"
          @radio-change="orderChange"
        ></dilTable>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import {getCookie} from "@/utils/util.js";
export default {
  components: { PageTitle },
  data() {
    return {
      purchaseOption:{
        requestUrl: "/api/v1/tms/getBatchIdByForeign?apiId=489",
        selectionType: "radio"
      },
      noticeOption: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/tms/findBatchForBind?apiId=489"
      },
      //物资名称
      materialName:'',
      //外轮船名
      resultForeignShipName:'',
      //是否需要打开模态窗口
      drawer: false,
      a: 1,
      direction: "rtl",
      inputText: null,
      row:null,
      order:null,
    };
  },
  mounted(){
  },
  methods: {
    //确定
    makeSure() {
      if(this.row!=null && this.order!=null){
        let map = {
          batchInfactoryId:this.row.batchInfactoryId,
          batchIdOld:this.row.batchId,
          batchId:this.order.batchId,
          gmId:this.row.gmId,
          portId:this.row.portId,
          userId:getCookie("userId")
        }
        console.log(map);
        this.axios.post('/api/v1/tms/bindBatch',map).then((res)=>{
          console.log(res.data)
          if(res.data.code == "200"){
            this.$message({
              message: "绑定成功!",
              type: "success",
            });
            //刷新表格
            this.searchNotice();
            //关闭抽屉
            this.drawer=false;
          }
        })
      }else{
        this.$message.warning("请选择采购订单!");
      }
      
    },
    //采购订单表格选中
    orderChange(selection){
        console.log("order:",selection);
        this.order=selection;
    },

    currentRadioChange1(selection) {
      this.input = null;
      this.materialName = selection.materialName;
      this.materialId = selection.materialId;
    },
    ondrawer(row) {
      this.drawer = true;
      this.row=row;
      this.inputText=row.foreignShipName;
      console.log("row:",row);
      this.purchaseOption.requestUrl =
          "/api/v1/tms/getBatchIdByForeign?apiId=489&con=" + this.inputText;
    },
    searchNotice(){
      //查询发货通知
        this.noticeOption.requestUrl=
        "/api/v1/tms/findBatchForBind?apiId=489"+"&materialName="+this.materialName
        +"&foreignShipName="+this.resultForeignShipName
        +"&i="+new Date();
    },
    onClick() {
        this.purchaseOption.requestUrl =
          "/api/v1/tms/getBatchIdByForeign?apiId=489&con=" + this.inputText;
    },
    handleClose(done) {
        this.row=null;
        done();
    }
  },
};
</script>

<style lang="scss">

</style>