<template>
  <!-- 新增装车作业页面 -->
  <div id="contractDetails">
    <page-title>装车作业</page-title>

    <div class="main">
      <span class="text">选择运输订单</span>
      <span class="a"></span>
    </div>

    <div>
      <dilTable
        v-bind.sync="option"
        v-model="table1"
        @change="handleCheckedCitiesChange"
        ref="table"
        @radio-change="currentRadioChange">
      </dilTable>
    </div>
    <div class="contractTitle">
      <div class="form-box">
        <div class="form-one">
          <dil-form :formId="172" v-model="form1"></dil-form>
        </div>
      </div>
    </div>   
    <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 {
      option: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/oms/getAllTruckOrder?apiId=86&orderStatus=5&orderType=8",
        // 控制显示当选列
        selectionType: "radio",
      },
      // 表单
      form1: {},
      // 表格
      table1: {},
      contractId: "",
      inf: {},
    };
  },
  mounted() {
    // this.unit();
  },
  methods: {
    handleCheckedCitiesChange(value) {
      console.log(value);
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    currentRadioChange(row) {
      this.inf = row;
    },
    // 确认
    onClickConfirm() {
      console.log('----')
      let LR = {
        orderId: this.inf.orderId,
        resultLoadStartTime: sjTime(this.form1.resultLoadStartTime),
        insertUpdateRemark: this.form1.insertUpdateRemark,
        resultIsclear: this.form1.resultIsclear,
        resultMeasuredTonnage: this.form1.resultMeasuredTonnage,
        portId: 1
      };
    
      var val = this.value;
      function isNumber() {
        var value = LR.resultMeasuredTonnage;
        //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
          return false;
        } else {
          return true;
        }
      }
      if (
        LR.resultIsclear==null||
        LR.resultLoadStartTime==null||
        LR.orderId == null||
        LR.resultMeasuredTonnage == null
        // LR.loadingId == null
      ) {
        this.$message.error("存在空值！");
      }else{
        if(!isNumber(val)) {
          this.$message.error("计量吨位必须是数字！");
        }else{
              this.axios.post("/api/v1/tms/addCGLoadResult", LR)
                .then(() => {
                this.$message({
                  type: "success",
                  message: "新增成功!",
                });
                this.$router.push("/truckLoadResult")
            });
          }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
//@import "@/styles/appoint/contract/ContractInsert.scss";
</style>