// 分解计划
<template>
  <div class="inwardDisPlan">
    <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>
    </div>
    <template>
      <div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="待分解" name="second">
            <dilTable v-bind.sync="second" ref="table1">
              <el-table-column fixed="right" label="操作" width="100">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="mini"
                    @click="desponsePlan(scope)"
                  >
                    分解
                  </el-button>
                </template>
              </el-table-column>
            </dilTable>
          </el-tab-pane>
          <el-tab-pane label="已分解" name="third">
            <dilTable v-bind.sync="third" ref="table2">
              <el-table-column fixed="right" label="操作" width="180">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="mini"
                    @click="desponsePlan(scope)"
                  >
                    继续分解
                  </el-button>
                  <el-button
                    type="text"
                    size="mini"
                    @click="getPlanOrder(scope)"
                  >
                    运单
                  </el-button>
                  <el-button
                    type="text"
                    size="mini"
                    @click="closePlanOrder(scope)"
                  >
                    关闭计划
                  </el-button>
                </template>
              </el-table-column>
              <!-- 物资详情抽屉 -->
              <el-table-column type="expand" width="1">
                <template slot-scope="props">
                  <el-form
                    label-position="center"
                    inline
                    class="demo-table-expand"
                  >
                    <div v-if="false">{{ props }}</div>
                    <div>
                      <el-table :data="tableData" border>
                        <el-table-column
                          v-for="(item, i) in tableHead"
                          :key="i"
                          :prop="item.prop"
                          :label="item.label"
                          :width="item.width"
                        ></el-table-column>
                      </el-table>
                    </div>
                  </el-form>
                </template>
              </el-table-column>
            </dilTable>
          </el-tab-pane>

          <el-tab-pane label="已完成" name="four">
            <dilTable v-bind.sync="four" ref="table3"> </dilTable>
          </el-tab-pane>
        </el-tabs>
      </div>
    </template>
  </div>
</template>
<script>
import { getCookie } from "@/utils/util.js";
export default {
  data() {
    return {
      inputText: "",
      carrierId: 40,
      first: {
        // first请求数据的地址
        requestUrl: ""
      },
      second: {
        // second请求数据的地址
        requestUrl: ""
      },
      third: {
        // second请求数据的地址
        requestUrl: ""
      },
      four: {
        requestUrl: ""
      },
      activeName: "second",
      tableData: []
    };
  },
  created() {
    if (getCookie("orgCode") == "chengyunshang") {
      this.first.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=1&carrierId=" +
        getCookie("userId");
      this.second.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=2&carrierId=" +
        getCookie("userId");
      this.third.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=3&carrierId=" +
        getCookie("userId");
      this.four.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=4&carrierId=" +
        getCookie("userId");
    } else {
      this.first.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=1";
      this.second.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=2";
      this.third.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=3";
      this.four.requestUrl =
        "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=4";
    }
  },
  methods: {
    handleClick(tab, event) {
      console.log("zhix");
      this.getRequestUrl();
      this.getRequirementMaterial();
    },
    getRequestUrl() {
      if (getCookie("orgCode") == "chengyunshang") {
        this.first.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=1&carrierId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
        this.second.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=2&carrierId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
        this.third.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=3&carrierId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
        this.four.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=4&carrierId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
      } else {
        this.first.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=1" +
          "&i=" +
          new Date();
        this.second.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=2" +
          "&i=" +
          new Date();
        this.third.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=3" +
          "&i=" +
          new Date();
        this.four.requestUrl =
          "/api/v1/ams/getTruckPlanList?apiId=258&planStatus=4" +
          "&i=" +
          new Date();
      }
    },
    closePlanOrder(scope) {
      console.log(scope.row.planId);
      this.$confirm(
        "确定关闭该计划吗?该操作会将计划下未接收订单全部关闭",
        "是否继续?",
        {
          center: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        }
      ).then(() => {
        this.axios
          .post("/api/v1/oms/closeInwardOrderByPlan?planId=" + scope.row.planId)
          .then(res => {
            if (res.data.code == "200") {
              this.$message.success("关闭成功");
              this.getRequestUrl();
            } else {
              this.$message.error("关闭失败");
            }
          })
          .catch(() => {
            this.$message.error("关闭失败");
          });
      });
    },
    receiver(scope) {
      this.$confirm("是否接收", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.axios
            .post("/api/v1/ams/receiveInwardPlan/" + scope.row.planId)
            .then(res => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "接收成功!"
                });
                this.getRequestUrl();
              } else {
                this.$message({
                  message: "接收失败",
                  type: "warning"
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "接收操作已取消!"
          });
        });
    },
    selectionChange(selection) {
      this.second.mapList = selection;
    },
    desponsePlan(scope) {
      this.$router.push("/decomposePlan/" + scope.row.planId);
    },
    getPlanOrder(scope) {
      this.$router.push("/getPlanOrder/" + scope.row.planId);
    },
    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.getRequestUrl();
              } else {
                this.$message({
                  message: "删除失败",
                  type: "warning"
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "删除操作已取消!"
          });
        });
    },
    Issue() {
      console.log(this.first.mapList);
      this.$confirm("是否下发", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.axios
            .post(
              "/api/v1/ams/addFixedAmsDispatchSaleOrder",
              this.first.mapList
            )
            .then(res => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "下发成功!"
                });
                this.getRequestUrl();
              } else {
                this.$message({
                  message: "下发失败",
                  type: "warning"
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消下发!"
          });
        });
    }
  }
};
</script>
<style lang="scss">
.inwardDisPlan {
  margin-top: 20px;
  margin-left: 20px;
  .sache {
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>
