<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="main">
      <span class="text">请选择运力排班</span>
      <span class="a"></span>
    </div>
    <div>
      <dilTable
        v-bind.sync="option2"
        v-model="table2"
        @change="handleCheckedCitiesChange"
        ref="table"
        @radio-change="currentRadioChange2"
      >
      </dilTable>
    </div>
    <!-- <div class="contractTitle">
      <div class="form-box">
        <div class="form-one">
          <dil-form :formId="169" 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/getSaleOrderForCarrierList/1?apiId=168",
        // 控制显示当选列
        selectionType: "radio",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/oms/getCapacityForLeisure/1?apiId=186",
        // 控制显示当选列
        selectionType: "radio",
      },
      // 表单
      form1: {},
      // 表格
      table1: {},
      table2:{},
      contractId: "",
      inf: {},
      inf2: {}
    };
  },
  mounted() {
    // this.unit();
  },
  methods: {
    handleCheckedCitiesChange(value) {
      console.log(value);
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    currentRadioChange(row) {
      this.inf = row;
    },
    currentRadioChange2(row) {
      this.inf2 = row;
    },
    // 确认
    onClickConfirm() {
      let saleOrder = {
        //车序号订单物资id
        saleOrderMaterialId: this.inf.saleOrderMaterialId,
        // purchaseOrderId: this.inf.purchaseOrderId,
        // materialId: this.inf.materialId,
        driverCapacityId: this.inf2.driverCapacityId,
        // orderMaterialWeight: this.form1.orderMaterialWeight,
        orderType: 1
      };
      function isNumber() {
        var value = saleOrder.orderMaterialWeight;
        //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
          return false;
        } else {
          return true;
        }
      }
      var val = this.value;
      if (
        saleOrder.saleOrderMaterialId==null||
        saleOrder.driverCapacityId==null
      ){
        this.$message.error("存在空值！");
      }

      else{
            this.axios.post("/api/v1/oms/addPurOrder", saleOrder)
              .then(() => {
              this.$message({
                type: "success",  
                message: "新增成功!",
              });
              this.$router.go(0);
          });
        }
      }
    
  },
};
</script>
<style lang="scss" scoped>
.button-box{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 0.3125rem;
  margin-bottom: 1.25rem;
}
</style>