<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="Issue">
        <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" @selection-change="selectionChange">
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">

              <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>
</template>


<script>
export default {
  name: "wagonPlease",
  data() {
    return {
      activeName: "first",
      status: "",
      input: "",
      option1: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/oms/getAllTruckOrder?apiId=89&orderStatus=3&orderType=8" ,
          mapList: [],
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/oms/getAllTruckOrder?apiId=86&orderStatus=8&orderType=8",
      },
      form1: [],
      orderId: 0,
    };
  },
  methods: {
    currentRadioChange(row) {
      this.orderId = row.orderId;
      console.log(this.orderId);
    },
      selectionChange(selection) {
      console.log("-----");
      this.option1.mapList = selection;
      console.log(this.option1.mapList);
      console.log("------");
    },

    // 查询
    onclick() {
      if (this.activeName == "first") {
        this.option1.requestUrl =
          "/api/v1/oms/selectAllOrderForSale?apiId=168/1&orderStatus=3&orderType=1&con=" +this.input;
      } else {
        this.option2.requestUrl =
          "/api/v1/oms/selectAllOrderForSale?apiId=168/1&orderStatus=8&orderType=1&con=" +this.input;
      }
    },
     
    // 返回
    onClickCancel(type) {

    let map = {
        mapList:this.option1.mapList
    }

      if (type == 1) {
        this.$router.go(-1);
      } else if (type == 2) {
        if (
        this.orderId==null||
        this.form1.unloadPointId==null
      ){
        this.$message.error("存在空值！");
      }else{
        this.axios
          .post("/api/v1/oms/dispatchOrder",map)
          .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.planId +
          "?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(
        "/breakdownPlanAdd/" + this.$route.params.planId
      );
    },
  },
};
</script>
<style lang='scss' scoped>
.homeworkPath {
  .top {
    padding: 1.25rem 1.875rem;
  }
  .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>
