<template>
  <!-- 添加货权转移实绩 -->
  <div class="shipTransport">
    <page-title>返回</page-title>
    <!-- 物资 -->
      <!-- <div class="mofrom">
        <span class="motext">物资</span>
        <el-input class="moinput" v-model="materialName" disabled> </el-input>
        <el-button class="mobutton" type="primary" @click="ondrawer(1)">浏览</el-button>
      </div> -->
      <div class="mofrom">
        <span class="motext">收货人</span>
        <el-input class="moinput" v-model="receiver" disabled> </el-input>
        <el-button class="mobutton" type="primary" @click="ondrawer(3)">浏览</el-button>
    </div>
    <div class="form">
      <div class="form_box">
          <dil-form :formId="137" v-model="form1"></dil-form>
      </div>        
    </div>
     <!-- 模态框 -->
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      size="50%"
    >
      <el-input
        placeholder="请输入内容"
        v-model="input"
        style="margin-top: 10px; margin-left: 20px; width:250px"
        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>
      <div v-show="a == 3">
        <dilTable
          v-bind.sync="second2"
          @radio-change="currentRadioChange3"
        ></dilTable>
      </div>
    </el-drawer>
    <!-- 确定和取消 -->
    <div class="button_box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
export default {
  components: { PageTitle },
    data(){
          return {
          form1: {},
          materialName:"",
          receiver:"",
          drawer: false,
          direction: "rtl",
          input: "",
          second: {
            requestUrl: "/api/v1/uc/queryMaterialByLike?apiId=244",
            selectionType: "radio",
            mapList1: [],
          },
          second1: {
            requestUrl: "/api/v1/tms/selectShippeByName?apiId=215",
            selectionType: "radio",
            mapList2: [],
          },
          second2: {
            requestUrl: "/api/v1/tms/getGroupList?apiId=217",
            selectionType: "radio",
            mapList3: [],
          },
        }
    },
  mounted() {
    this.information();
  },
  methods: {
    onclick(a) {
      console.log(a);
      if (a == 1) {
        this.second.requestUrl =
          "/api/v1/uc/queryMaterialByLike?apiId=244&index=" + this.input;
      } else if (a == 2) {
        this.second1.requestUrl =
          "/api/v1/tms/selectShippeByName?apiId=215&con=" + this.input;
      } else {
        this.second2.requestUrl =
          "/api/v1/tms/getGroupList?apiId=217&con=" + this.input;
      }
      
    },
    ondrawer(num) {
      this.drawer = true;
      this.a = num;
      // 清空当前输入框中的数据
      this.input = "";
    },
    currentRadioChange1(selection) {
      (this.second.mapList1 = selection),
        (this.materialName = selection.materialName);
    },
    currentRadioChange2(selection) {
      (this.second1.mapList2 = selection), (this.cargo = selection.portName);
    },
    currentRadioChange3(selection) {
      (this.second2.mapList3 = selection), (this.receiver = selection.pierName);
    },
    information() {
      //编辑货权转移
      this.axios
        .post("/api/v1/tms/selectByCargoTranferResultId/" + this.$route.params.cargoTransferResultId)
        .then((res) => {
          console.log("res",res)
          this.form1 = res.data.data
          this.materialName = res.data.data.materialName;
          this.receiver = res.data.data.receiver;
        });
    },
    // 确认
    onClickConfirm() {
      let AmsshipCargoTransferResult = {
        cargoTransferResultId: this.$route.params.cargoTransferResultId,
        carrierId: this.form1.carrierId,
        groupId: this.form1.groupId,     
        resultTelephoneFax: this.form1.resultTelephoneFax,
        resultContactPerson:this.form1.resultContactPerson,
        batchId:this.form1.batchId,
        resultNumberOfLoans: this.form1.resultNumberOfLoans,
        resultFreignForwardingInfo: this.form1.resultFreignForwardingInfo,
        resultMemo: this.form1.resultMemo,
        foreignShipName: this.form1.foreignShipName,
        materialId: this.second.mapList1.materialId,
      };
         //判断放货数量是否为数字
       function isNumber() {
        var value = AmsshipCargoTransferResult.resultNumberOfLoans;
        //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
          return false;
        } else {
          return true;
        }
      }
      //判断是否为电话号码
       function isTelePhone() {
        var value2 = AmsshipCargoTransferResult.resultTelephoneFax;
        //验证是否为数字
        var patrn  = /^1[3-9]\d{9}$/;
        // var patrn2 = /^(\d{3,4}-)?\d{7,8}$/;
        if (patrn.exec(value2) == null || value2 == "") {
          return false;
        } else {
          return true;
        }
      }
      //电话号码赋值
      var val2=this.value2;
      var val = this.value;
       if (
        AmsshipCargoTransferResult.foreignShipName == null ||
        AmsshipCargoTransferResult.resultNumberOfLoans == null ||
        AmsshipCargoTransferResult.resultContactPerson == null ||
        AmsshipCargoTransferResult.resultTelephoneFax == null
      )
        this.$message.error("存在空值！");
          else if (!isNumber(val)) this.$message.warning("放货数量必须为数字");
            else if (!isTelePhone(val2)) this.$message.warning("电话号码或传真格式不正确");  
      else this.axios
        .post("/api/v1/tms/editCargoTransferResult" ,
         AmsshipCargoTransferResult
        )
        .then(() => {
          this.$message({
            type: "success",  
            message: "修改成功!",
          });
          this.$router.go(-1);
        });
    },
      // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang="scss">
.shipTransport{
  .mofrom {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 5px;
    margin-bottom: 20px;
    .motext{
      width: 70px;
    }
    .moinput{
      width: 250px;
    }
    .mobutton{
      margin-left: 5px;
    }
  }
  .form{
    display: flex;
    .form_box{
      width: 320px;
      margin-left: 35%;
      margin-top: 30px;
      margin-right: 20px;
      .el-form{
        .preview-group{
          .el-form-item{
            .el-form-item__label{
              display: inline-block;
              width: 70px !important;
            }
            .el-form-item__content{
              .el-select{
                width: 250px;
              }
              .el-input{
                width: 250px;
              }
            }
          }
        }
      }
    }
  }
  .button_box{
    margin-left: 45%;
  }
}
</style>
