index.vue 6.38 KB
<template>
  <div>
    <el-form :inline="true" :model="queryParams" class="form-header" size="medium" label-position="right"
      label-width="auto">
      <el-form-item label="航班号">
        <el-input v-model.trim="purposeOfFlightNo" placeholder="航班号" @keyup.enter.native="getList" clearable></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="状态" clearable>
          <el-option label="有效" value="1"></el-option>
          <el-option label="停用" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getList" size="mini">查询</el-button>
      </el-form-item>
      <div>
        <el-button style="margin-bottom: 20px" type="primary" icon="el-icon-plus" size="mini"
          v-hasPermi="['allocation:alloc:add']" @click="
            $router.push({
              name: 'FlightAllocConfigAdd',
              params: { handle: 'add' },
            })
          ">添加</el-button>
      </div>
    </el-form>

    <el-table :data="flyList" v-loading="loading" size="small" highlight-current-row border stripe>
      <el-table-column prop="purposeOfFlightNo" label="航班号" align="center"></el-table-column>

      <el-table-column prop="status" label="状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'">无效</span>
          <span v-if="scope.row.status === '1'">有效</span>
          <span v-if="scope.row.status === '2'">配置中</span>
          <span v-if="scope.row.status === '3'">停用</span>
        </template>
      </el-table-column>

      <el-table-column prop="createUserName" label="操作人" align="center">
      </el-table-column>

      <el-table-column prop="createTime" label="更新时间" align="center">
      </el-table-column>

      <el-table-column label="操作" prop="id" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="mini" icon="el-icon-view" @click="handleClick(scope.row.id, 'detail')">查看
          </el-button>
          <el-button type="text" size="mini" icon="el-icon-edit" v-hasPermi="['allocation:alloc:update']"
            @click="handleClick(scope.row.id, 'update')">修改</el-button>
          <el-button type="text" size="mini" icon="el-icon-delete" v-hasPermi="['allocation:alloc:delete']"
            @click="del(scope.row.id, scope.row.status)" style="color:#ff4949">删除</el-button>
          <el-button type="text" size="mini" icon="el-icon-video-pause" v-hasPermi="['allocation:alloc:openClose']"
            @click="changeStatus(scope.row.id, 3)" v-if="scope.row.status == '1'">停用</el-button>
          <el-button type="text" size="mini" icon="el-icon-video-play" v-hasPermi="['allocation:alloc:openClose']"
            @click="changeStatus(scope.row.id, 1)" v-else>启用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="getList" @current-change="getList" :current-page.sync="curPage"
      :page-sizes="[10, 20, 30, 40]" :page-size.sync="limit" layout="prev, pager, next, jumper, sizes, total"
      :total="total" background :hide-on-single-page="true" style="margin-top: 40px; text-align: right">
    </el-pagination>
  </div>
</template>

<script>
import {
  findFlightNo,
  delFlightId,
  enableOrDisable,
} from "@/api/destinationFlight";

export default {
  name: "FlightAllocConfig",
  data() {
    return {
      queryParams: {
        purposeOfFlightNo: "",
        status: "1",
        start: 0,
        limit: 10,
      },
      flyList: [],
      curPage: 1,
      limit: 10,
      total: 0,
      loading: false,
    };
  },
  created() {
    if (this.$store.state.tagsView.cachedViews.length == 0) {
      this.getList();
    }
  },
  activated() {
    this.getList()
  },
  deactivated() {
    this.flyList = []
  },
  methods: {
    getList() {
      this.queryParams.limit = this.limit;
      if (this.curPage > 1) {
        this.queryParams.start = (this.curPage - 1) * this.queryParams.limit;
      } else {
        this.queryParams.start = 0;
      }
      this.loading = true;
      findFlightNo(this.queryParams).then((response) => {
        if (response.code != 200) {
          this.$message({
            showClose: true,
            message: response.msg,
            type: "error",
          });
          return;
        }
        this.flyList = response.data.list;
        this.total = response.data.totalCount;
        this.loading = false;
      });
    },
    //跳转到查看,修改页面
    handleClick(flightiId, handle) {
      this.$router.push({
        name: "FlightAllocConfigInfo",
        params: { handle: handle, id: flightiId },
      });
    },
    //删除规则
    del(id, status) {
      if (status == "1") {
        this.$confirm("航班规则生效中,无法删除,请停用后再操作", "警告", {
          confirmButtonText: "确定",
          showCancelButton: false,
          type: "warning",
        });
      } else {
        this.$confirm("是否确认删除此航班规则?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          showCancelButton: true,
          type: "warning",
        }).then(() => {
          delFlightId(id)
            .then((res) => {
              this.$message({
                message: res.msg,
                type: res.code === 200 ? "success" : "warning",
              });
              this.getList();
            })
            .catch(() => { });
        });
      }
    },
    //启用,停用
    changeStatus(id, status) {
      let tip = status === 1 ? "启用" : "停用";
      this.$confirm("是否确认" + tip + "此航班规则?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        enableOrDisable(id, status)
          .then((res) => {
            if (res.code != 200) {
              this.msgError(res.msg);
            } else {
              this.getList();
              this.msgSuccess(tip + "成功");
            }
          })
          .catch(() => { });
      });
    },
  },
  computed: {
    purposeOfFlightNo: {
      get: function () {
        return this.queryParams.purposeOfFlightNo;
      },
      set: function (val) {
        this.queryParams.purposeOfFlightNo = val.toUpperCase();
      },
    },
  },
};
</script>