<template>
  <!--  分派运输销售运输订单查看 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input placeholder="请输入内容" v-model="input" clearable> </el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" @click="btnClick">
        <i class="el-icon-plus"></i>新增
      </el-button>
    </div>
    <el-tabs v-model="activeName">
      <!-- 未下发 -->
      <el-tab-pane label="未分派" name="first">
        <dilTable v-bind.sync="option1" @radio-change="currentRadioChange">
          <!-- <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button
                @click="sendClick(scope.row.orderId)"
                type="text"
                size="small"
              >
                派单
              </el-button>
              <el-button
                @click="
                  updateClick(scope.row.orderId, scope.row.orderMaterialWeight)
                "
                type="text"
                size="small"
              >
                修改
              </el-button>
              <el-button
                @click="
                  deleteClick(
                    scope.row.orderId,
                    scope.row.orderMaterialWeight,
                    scope.row.capacityNumber
                  )
                "
                type="text"
                size="small"
              >
                删除
              </el-button>
            </template>
          </el-table-column> -->
        </dilTable>
      </el-tab-pane>
      <!-- 已下发 -->
      <el-tab-pane label="已分派" name="second">
        <dilTable v-bind.sync="option2"> </dilTable>
      </el-tab-pane>
    </el-tabs>
    <div v-if="activeName == 'first'" class="xhd">
      <div class="contractTitle">
        <div class="form-box">
          <div class="form-one">
            <dil-form :formId="280" v-model="form1"></dil-form>
          </div>
        </div>
      </div>
    </div>
    <div class="btnn">
      <el-button @click="onClickCancel(1)" class="btn1">取消</el-button>
      <el-button @click="onClickCancel(2)" type="primary" class="btn1"
        >下发</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: "wagonPlease",
  data() {
    return {
      activeName: "first",
      status: "",
      input: "",
      option1: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/oms/getCokeRailDayPlanForGenOrder/1?apiId=169&orderStatus=3&orderType=2&dayPlanId="   +this.$route.params.dayPlanId,
        // 控制显示当选列
        selectionType: "radio",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/oms/getCokeRailDayPlanForGenOrder/1?apiId=169&orderStatus=4&orderType=2&dayPlanId="   +this.$route.params.dayPlanId ,
      },
      form1: [],
      orderId: 0,
    };
  },
  methods: {
    currentRadioChange(row) {
      this.orderId = row.orderId;
      console.log(this.orderId);
    },
    // 查询
    onclick() {
      if (this.activeName == "first") {
        this.option1.requestUrl =
          "/api/v1/oms/getCokeRailDayPlanForGenOrder/1?apiId=169&orderStatus=3&orderType=2&dayPlanId=" +
          this.$route.params.dayPlanId +
          "&con=" +
          this.input;
      } else {
        this.option2.requestUrl =
          "/api/v1/oms/getCokeRailDayPlanForGenOrder/1?apiId=169&orderStatus=4&orderType=2&dayPlanId=" +
          this.$route.params.dayPlanId +
          "&con=" +
          this.input;
      }
    },
    // 返回
    onClickCancel(type) {
      if (type == 1) {
        this.$router.go(-1);
      } else if (type == 2) {
        if (
          this.orderId==null||
          this.form1.LoadId==null
      ){
        this.$message.error("存在空值！");
      }else{
        this.axios
          .post("/api/v1/oms/dispatchOrderForSale",{
            orderId: this.orderId,
            LoadId: this.form1.LoadId,
            orderType:2,
          })
          .then((res) => {
            if (res.data.code == "200") {
              this.$message({
                type: "success",
                message: "下发成功!",
              });
              this.$router.go(0);
            }
          });
      }
      }
    },
    // //修改
    // updateClick(orderId, weight) {
    //   this.$router.push(
    //     "/importedTruckOrder/breakdownPlanEdit/" +
    //       this.$route.params.dayPlanId +
    //       "?orderId=" +
    //       orderId +
    //       "&weight=" +
    //       weight
    //   );
    // },
    // deleteClick(orderId, weight, capacityNumber) {
    //   this.$confirm("是否删除", "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //     center: true,
    //   })
    //     .then(() => {
    //       this.$message({
    //         type: "success",
    //         message: "删除成功!",
    //       });
    //       this.axios
    //         .post(
    //           "/api/v1/oms/deleteOrder?planId=" + this.$route.params.planId,
    //           {
    //             orderId: orderId,
    //             orderMaterialWeight: weight,
    //             capacityNumber: capacityNumber,
    //           }
    //         )
    //         .then(() => {
    //           this.$router.go(0);
    //         });
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "取消删除!",
    //       });
    //     });
    // },

    btnClick() {
      this.$router.push(
        "/dispatchCokeRailPlanAdd/" + this.$route.params.dayPlanId
      );
    },
  },
};
</script>
<style lang='scss' scoped>
.form-box{
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 5px;
  margin-bottom: 20px;
}
.button-box{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 0.3125rem;
  margin-bottom: 1.25rem;
}
.homeworkPath {
  .top {
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
  .xhd {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 3.75rem;
  }
  .btnn {
    width: 100%;
    height: 6.25rem;
    position: absolute;
    bottom: 0rem;
    display: flex;
    align-items: center;
    justify-content: center;
    .btn1 {
      width: 6.25rem;
      height: 2.5rem;
    }
  }
}
</style>