stationTable.vue 6.9 KB
Newer Older
neogcg's avatar
neogcg committed
1 2 3 4 5 6
<template>
  <div>
    <div class="leakage-top">
      <div style="color: #666666"></div>

      <div class="operate-btn">
neogcg's avatar
neogcg committed
7 8 9
        <delids :multipleSelection2="multipleSelection" @del="del()"
          >删除</delids
        >
neogcg's avatar
neogcg committed
10
        <el-button type="primary" @click="refresh">刷新</el-button>
neogcg's avatar
neogcg committed
11
        <el-button type="primary" @click="block = !block">查询</el-button>
neogcg's avatar
neogcg committed
12 13
        <el-button type="primary" @click="exportData">导出</el-button>
      </div>
neogcg's avatar
neogcg committed
14
    </div>
neogcg's avatar
neogcg committed
15 16 17 18 19 20 21 22
    <el-form
      class="search-div"
      v-if="block"
      :model="siteForm"
      :inline="true"
      size="mini"
    >
      <el-form-item label="站名:">
neogcg's avatar
neogcg committed
23 24
        <el-input
          placeholder="请输入站名"
neogcg's avatar
neogcg committed
25
          v-model="siteForm.siteName"
neogcg's avatar
neogcg committed
26 27 28
          clearable
        >
        </el-input>
neogcg's avatar
neogcg committed
29 30
      </el-form-item>
      <el-form-item label="站点编号:">
neogcg's avatar
neogcg committed
31 32
        <el-input
          placeholder="请输入起点编号"
neogcg's avatar
neogcg committed
33
          v-model="siteForm.siteCode"
neogcg's avatar
neogcg committed
34 35
          clearable
        >
neogcg's avatar
neogcg committed
36 37 38
        </el-input
      ></el-form-item>
      <el-form-item label="站点地址:">
neogcg's avatar
neogcg committed
39 40
        <el-input
          placeholder="请输入站点地址"
neogcg's avatar
neogcg committed
41
          v-model="siteForm.siteAddress"
neogcg's avatar
neogcg committed
42 43
          clearable
        >
neogcg's avatar
neogcg committed
44 45 46
        </el-input
      ></el-form-item>
      <el-form-item label="所在铁路线:">
neogcg's avatar
neogcg committed
47 48
        <el-select
          placeholder="请选择所在铁路线"
neogcg's avatar
neogcg committed
49
          v-model="siteForm.wayId"
neogcg's avatar
neogcg committed
50 51
          clearable
        >
neogcg's avatar
neogcg committed
52
          <el-option
neogcg's avatar
neogcg committed
53 54 55 56
            v-for="item in railWaySelect"
            :key="item.id"
            :label="item.name"
            :value="item.id"
neogcg's avatar
neogcg committed
57 58 59
          ></el-option> </el-select
      ></el-form-item>
      <el-form-item>
neogcg's avatar
neogcg committed
60 61
        <el-button type="success" @click="searchQuery()">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
neogcg's avatar
neogcg committed
62 63
      </el-form-item>
    </el-form>
neogcg's avatar
neogcg committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    <el-table
      ref="multipleTable"
      class="statistics-table"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      :row-class-name="tableRowClassName"
      :row-style="{ height: '50px' }"
      :header-cell-style="{
        background: '#eaf1fe',
        color: '#000',
        fontWeight: 700,
        height: '50px',
      }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
neogcg's avatar
neogcg committed
81
      <el-table-column prop="siteName" label="站名" align="center" />
neogcg's avatar
neogcg committed
82
      <el-table-column prop="siteCode" label="站点编号" align="center" />
neogcg's avatar
neogcg committed
83 84 85 86 87 88
      <el-table-column
        prop="siteAddress"
        label="站点地址"
        show-overflow-tooltip
        align="center"
      />
neogcg's avatar
neogcg committed
89
      <el-table-column prop="railWayName" label="所在铁路线" align="center" />
neogcg's avatar
neogcg committed
90 91 92 93 94 95 96 97 98 99 100 101 102
      <el-table-column
        prop="action"
        label="详细信息"
        show-overflow-tooltip
        align="center"
      >
        <template slot-scope="{ row }">
          <el-link type="primary" :underline="false" @click="handleView(row)"
            >查看</el-link
          >
        </template>
      </el-table-column>
    </el-table>
neogcg's avatar
neogcg committed
103

neogcg's avatar
neogcg committed
104
    <Pagination
neogcg's avatar
neogcg committed
105 106
      :limit="siteForm.size"
      :page="siteForm.current"
neogcg's avatar
neogcg committed
107 108 109 110 111 112 113
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
  </div>
</template>
<script>
neogcg's avatar
neogcg committed
114
import { sitelist, sitebatchDelete, sitedetail, railWaylist } from "../../api";
neogcg's avatar
neogcg committed
115
import { successAlert, warningAlert } from "@/utils/alert";
neogcg's avatar
neogcg committed
116 117
import download from "@/utils/download";
import { exportSite } from "@/api/export";
neogcg's avatar
neogcg committed
118 119
export default {
  props: [],
neogcg's avatar
neogcg committed
120
  components: {},
neogcg's avatar
neogcg committed
121 122
  data() {
    return {
neogcg's avatar
neogcg committed
123
      siteForm: formInit(),
neogcg's avatar
neogcg committed
124 125
      railWaySelect: [],
      visible: false,
neogcg's avatar
neogcg committed
126

neogcg's avatar
neogcg committed
127
      tableData: [],
neogcg's avatar
neogcg committed
128
      params: {
neogcg's avatar
neogcg committed
129 130
        current: 1,
        size: 10,
neogcg's avatar
neogcg committed
131 132 133 134
      },
      total: 10,
      multipleSelection: [],
      ids: [],
neogcg's avatar
neogcg committed
135
      block: 0,
neogcg's avatar
neogcg committed
136
      istrue: 0,
neogcg's avatar
neogcg committed
137
      exids: [],
neogcg's avatar
neogcg committed
138 139
    };
  },
neogcg's avatar
neogcg committed
140
  computed: {},
neogcg's avatar
neogcg committed
141 142 143 144 145 146 147
  methods: {
    tableRowClassName({ row, rowIndex }) {
      return rowIndex % 2 === 0 ? "" : "single-row";
    },
    changeType(item) {
      this.activeName = item.key;
    },
neogcg's avatar
neogcg committed
148
    del() {
neogcg's avatar
neogcg committed
149
      let ids = this.ids;
neogcg's avatar
neogcg committed
150
      sitebatchDelete({ ids }).then((res) => {
neogcg's avatar
neogcg committed
151
        if (res.code == 200) {
neogcg's avatar
neogcg committed
152
          successAlert("删除成功");
neogcg's avatar
neogcg committed
153

neogcg's avatar
neogcg committed
154 155 156
          this.getTableData();
        } else {
          warningAlert("删除失败");
neogcg's avatar
neogcg committed
157 158
        }
      });
neogcg's avatar
neogcg committed
159 160
    },
    refresh() {
neogcg's avatar
neogcg committed
161
      this.reset();
neogcg's avatar
neogcg committed
162
      
neogcg's avatar
neogcg committed
163
    },
neogcg's avatar
neogcg committed
164
    searchQuery() {
neogcg's avatar
neogcg committed
165
      this.istrue = 1;
neogcg's avatar
neogcg committed
166 167 168
      this.getTableData();
    },
    reset() {
neogcg's avatar
neogcg committed
169
      this.siteForm = formInit();
neogcg's avatar
neogcg committed
170
      this.searchQuery();
neogcg's avatar
neogcg committed
171
    },
neogcg's avatar
neogcg committed
172
    exportData() {
neogcg's avatar
neogcg committed
173 174 175 176
       if (this.exids.length == 0) {
        this.$message.warning("暂无数据");
        return false;
      } else {
neogcg's avatar
neogcg committed
177 178 179
      exportSite({ ids: this.exids }).then((res) => {
        download(res, "vnd.ms-excel", `站点表.xls`);
      });
neogcg's avatar
neogcg committed
180
      }
neogcg's avatar
neogcg committed
181
    },
neogcg's avatar
neogcg committed
182 183 184 185 186
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = this.multipleSelection.map((i) => i.id);
    },
    handleView(row) {
neogcg's avatar
neogcg committed
187
      this.$router.push({
neogcg's avatar
neogcg committed
188
        path: "/detail",
neogcg's avatar
neogcg committed
189 190
        query: {
          id: row.id,
neogcg's avatar
neogcg committed
191
          type: 2,
neogcg's avatar
neogcg committed
192
        },
neogcg's avatar
neogcg committed
193 194 195
      });
    },
    handlePageChange(pageData) {
neogcg's avatar
neogcg committed
196
      this.siteForm.size = pageData.size;
neogcg's avatar
neogcg committed
197
      this.siteForm.current = pageData.page;
neogcg's avatar
neogcg committed
198 199 200
      this.getTableData();
    },
    getTableData() {
neogcg's avatar
neogcg committed
201
      sitelist(this.siteForm).then((res) => {
neogcg's avatar
neogcg committed
202 203 204
        let list = res.records || [];
        this.tableData = list;
        this.total = res.total;
neogcg's avatar
neogcg committed
205
        this.exids = list.map((i) => i.id);
neogcg's avatar
neogcg committed
206
        if (this.istrue == 1) {
neogcg's avatar
neogcg committed
207
          if (this.tableData.length) {
yanzhongrong's avatar
yanzhongrong committed
208
            successAlert("操作成功");
neogcg's avatar
neogcg committed
209 210 211 212 213
          } else {
            warningAlert("查询结果为空");
          }
          this.istrue = 0;
        }
neogcg's avatar
neogcg committed
214 215
      });
    },
neogcg's avatar
neogcg committed
216 217 218 219 220 221 222 223 224
    getAllWay() {
      railWaylist(this.params).then((res) => {
        this.railWaySelect = res.records;
        if (res.total > this.params.size) {
          this.params.size = res.total;
          this.getAllWay();
        }
      });
    },
neogcg's avatar
neogcg committed
225
  },
neogcg's avatar
neogcg committed
226
  created() {
neogcg's avatar
neogcg committed
227 228 229
    var that = this;
    document.onkeydown = function (e) {
      var key = window.event.keyCode;
neogcg's avatar
neogcg committed
230
      if (key == 13) {
neogcg's avatar
neogcg committed
231 232 233
        that.searchQuery();
      }
    };
neogcg's avatar
neogcg committed
234 235 236
  },
  mounted() {
    this.getTableData();
neogcg's avatar
neogcg committed
237
    this.getAllWay();
neogcg's avatar
neogcg committed
238 239
  },
};
neogcg's avatar
neogcg committed
240 241 242
function formInit(data = {}) {
  return {
    wayId: "",
neogcg's avatar
neogcg committed
243 244 245 246 247 248
    siteCode: "",
    siteName: "",
    siteAddress: "",
    siteId: "",
    current: 1,
    size: 10,
neogcg's avatar
neogcg committed
249 250 251
    ...data,
  };
}
neogcg's avatar
neogcg committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
</script>
<style lang="scss" scoped>
.leakage-cable {
  .leakage-top {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
  }
  & ::v-deep .cell {
    color: #333333;
  }
  & ::v-deep .stripe {
    background-color: #eaf1fe;
  }
  & ::v-deep .red {
    background-color: #f00;
  }
  & ::v-deep .green {
    background-color: green;
  }
  .page {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    .pageNum {
      margin: 0 20px;
    }
  }
}
</style>
<style lang="scss">
.statistics-table {
  .single-row {
    background: #f1f6ff;
  }
  td {
    padding: 5px !important;
  }
}
</style>