// 汽车发运水渣日计划
<template>
  <div class="steel_inbound">
    <div class="sache">
      <el-input placeholder="请输入内容" v-model="inputText" clearable>
      </el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" class="btn" @click="toInsert">
        <i class="el-icon-plus"></i>新增
      </el-button>
    </div>
    <div class="table">
      <el-tabs v-model="activeName">
        <el-tab-pane label="未下发" name="first">
          <dilTable v-bind.sync="options">
            <el-table-column fixed="right" label="操作" width="130">
              <template slot-scope="scope">
                <el-button type="text" size="mini" @click="xiafaClick(scope)">
                  下发
                </el-button>
                <el-button
                  type="text"
                  size="mini"
                  @click="updateRailPlan(scope)"
                >
                  修改
                </el-button>
                <el-button
                  type="text"
                  size="mini"
                  @click="delectRailPlan(scope)"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </dilTable>
        </el-tab-pane>
        <el-tab-pane label="已下发" name="second">
          <dilTable v-bind.sync="options1"></dilTable>
        </el-tab-pane>
      </el-tabs>

      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <span>承运商：</span>
        <el-select v-model="value" placeholder="请选择承运商">
          <el-option
            v-for="item in option1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="updataClick(scope)"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeName: "first",
      inputText: "",
      options: {
        // first请求数据的地址
        requestUrl: "/api/v1/ams/getSzTruckRailDayPlanList?apiId=236&status=2",
      },
      dialogVisible: false,
      value: "",
      // 承运商
      option1: [],
      dayplanId: 0,
      options1: {
        // first请求数据的地址
        requestUrl: "/api/v1/ams/getSzTruckRailDayPlanList?apiId=239&status=0",
      },
    };
  },
  methods: {
    xiafaClick(scope) {
      this.dialogVisible = true;
      this.initialization();
      this.dayplanId = scope.row.dayPlanId;
    },
    initialization() {
      this.axios.get("/api/v1/ams/getCarrierMes").then((res) => {
        if (res.data.code == "200") {
          this.option1 = res.data.data;
        }
      });
    },
    updataClick() {
      if (this.value) {
        this.axios
          .post("/api/v1/ams/updateDayPlan", {
            carrierId: this.value,
            dayplanId: this.dayplanId,
            dayplanReceiveStatus: 0,
          })
          .then((res) => {
            if (res.data.code == "200") {
              this.$message({
                type: "success",
                message: "下发成功!",
              });
              this.dialogVisible = false;
              this.$router.go(0);
            } else {
              this.$message({
                type: "warning",
                message: "下发失败!",
              });
            }
          });
      } else {
        this.$message({
          type: "warning",
          message: "请选择承运商!",
        });
        this.dialogVisible = false;
      }
    },
    toInsert() {
      this.$router.push("/addSlagRailPlan");
    },
    updateRailPlan(scope) {
      this.$router.push("/updateSlagRailPlan/" + scope.row.dayPlanId);
    },
    delectRailPlan(scope) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          // 接口不对
          this.axios
            .post("/api/v1/ams/updateDayPlan", {
              dayplanId: scope.row.dayPlanId,
              dayplanReceiveStatus: 3,
            })
            .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: "删除操作已取消!",
          });
        });
    },
    onclick() {
      console.log("点击事件");
    },
  },
};
</script>

<style lang="scss" scode>
.steel_inbound {
  .sache {
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>