// 分派计划
<template>
  <div class="steel_inbound">
    <div class="sache">
      <el-input placeholder="请输入内容" v-model="inputText" clearable>
      </el-input>
      <el-button type="primary" class="btn">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button
        type="primary"
        class="btn"
        @click="dispatch"
        v-if="activeName == 'first'"
      >
        <i class="el-icon-download"></i>分派</el-button
      >
    </div>
    <template>
      <div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="未分派" name="first">
            <dilTable v-bind.sync="first" @selection-change="selectionChange">
            </dilTable>
          </el-tab-pane>
          <el-tab-pane label="已分派" name="second">
            <dilTable v-bind.sync="second"> </dilTable>
          </el-tab-pane>
        </el-tabs>
      </div>
    </template>
  </div>
</template>
<script>
export default {
  data() {
    return {
      inputText: "",
      first: {
        // first请求数据的地址
        requestUrl:
          "/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=3&carrierId=40",
        selectionType: "select",
        mapList: [],
      },
      second: {
        // second请求数据的地址
        requestUrl:
          "/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4&carrierId=40",
      },
      activeName: "first",
    };
  },
  methods: {
    selectionChange(selection) { 
      this.first.mapList = selection
    },
    dispatch() {
      if(this.first.mapList.length == 0){
          this.$alert('请选择订单')
          return
      }
      this.$confirm("是否分派", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios
            .post("/api/v1/oms/apportionInwardOrder", this.first.mapList)
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "分派成功!",
                });
                this.first.requestUrl = "/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=3&carrierId=40&test=1"
                this.second.requestUrl = "/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4&carrierId=40&test=1"
                this.activeName = 'second'
                this.first.mapList = []
              } else {
                this.$message({
                  message: "分派失败",
                  type: "warning",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "分派操作已取消!",
          });
        });
    },
    deletePlan(scope) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios
            .post(
              "/api/v1/bms/deleteTrainSettlement/" + scope.row.requirementId
            )
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.$router.go(0);
              } else {
                this.$message({
                  message: "删除失败",
                  type: "warning",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "删除操作已取消!",
          });
        });
    },
  },
};
</script>
<style lang="scss">
.steel_inbound{
  .sache{
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
  }
</style>
