railWayTable.vue 8.88 KB
Newer Older
neogcg's avatar
neogcg committed
1 2 3 4 5
<template>
  <div>
    <div class="leakage-top">
      <div style="color: #666666"></div>
      <div class="operate-btn">
neogcg's avatar
neogcg committed
6 7 8
        <delids :multipleSelection2="multipleSelection" @del="del()"
          >删除</delids
        >
neogcg's avatar
neogcg committed
9
        <el-button type="primary" @click="refresh()">刷新</el-button>
neogcg's avatar
neogcg committed
10
        <el-button type="primary" @click="block = !block">查询</el-button>
neogcg's avatar
neogcg committed
11
        <el-button type="primary" @click="exportData()">导出</el-button>
neogcg's avatar
neogcg committed
12 13
      </div>
    </div>
neogcg's avatar
neogcg committed
14 15 16 17 18 19 20 21
    <el-form
      class="search-div"
      v-if="block"
      :model="railData"
      :inline="true"
      size="mini"
    >
      <el-form-item label="铁路名称:">
neogcg's avatar
neogcg committed
22 23 24
        <el-input
          placeholder="请输入铁路名称"
          style="width: 180px"
neogcg's avatar
neogcg committed
25
          v-model="railData.name"
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="railData.startPointName"
neogcg's avatar
neogcg committed
34 35 36 37
          style="width: 180px"
          clearable
        >
        </el-input>
neogcg's avatar
neogcg committed
38 39 40
      </el-form-item>

      <el-form-item label="铁路终点站名:">
neogcg's avatar
neogcg committed
41 42
        <el-input
          placeholder="请输入终点站名"
neogcg's avatar
neogcg committed
43
          v-model="railData.endPointName"
neogcg's avatar
neogcg committed
44 45 46 47
          style="width: 180px"
          clearable
        >
        </el-input>
neogcg's avatar
neogcg committed
48 49
      </el-form-item>

yanzhongrong's avatar
yanzhongrong committed
50
      <el-form-item>
neogcg's avatar
neogcg committed
51 52
        <el-button type="success" @click="searchQuery()">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
neogcg's avatar
neogcg committed
53 54
      </el-form-item>
    </el-form>
neogcg's avatar
neogcg committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    <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" />
      <el-table-column prop="name" label="铁路名称" align="center" />
      <el-table-column
        prop="startPointName"
        label="铁路起点站名"
        align="center"
      />
      <el-table-column
        prop="endPointName"
        label="铁路终点站名"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="totalLong"
        label="铁路总长度(公里)"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="action"
yanzhongrong's avatar
yanzhongrong committed
92
        label="操作"
neogcg's avatar
neogcg committed
93 94 95 96
        show-overflow-tooltip
        align="center"
      >
        <template slot-scope="{ row }">
yanzhongrong's avatar
yanzhongrong committed
97 98 99 100 101 102
          <el-link type="primary" :underline="false" @click="handleView(row)"
            >查看</el-link
          >
          <el-link type="primary" :underline="false" @click="toEdit(row)"
            >编辑</el-link
          >
neogcg's avatar
neogcg committed
103 104 105
        </template>
      </el-table-column>
    </el-table>
neogcg's avatar
neogcg committed
106
    <Pagination
neogcg's avatar
neogcg committed
107 108
      :limit="railData.size"
      :page="railData.current"
neogcg's avatar
neogcg committed
109 110 111 112
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
yanzhongrong's avatar
yanzhongrong committed
113 114 115 116 117 118

    <el-dialog
      title="编辑-铁路线"
      :visible.sync="visible"
      width="30%"
      :close-on-click-modal="false"
yanzhongrong's avatar
yanzhongrong committed
119
    >
yanzhongrong's avatar
yanzhongrong committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
      <el-form
        ref="formData"
        :model="formData"
        :rules="rules"
        label-width="200px"
        class="form"
      >
        <el-form-item label="铁路名:" prop="name">
          <el-input v-model="formData.name" placeholder="请输入铁路名" />
        </el-form-item>
        <el-form-item label="铁路线起点站名:" prop="startPointName">
          <el-input
            v-model="formData.startPointName"
            placeholder="请输入铁路线起点站名"
          />
        </el-form-item>
        <el-form-item label="铁路线终点站名:" prop="endPointName">
          <el-input
            v-model="formData.endPointName"
            placeholder="请输入铁路线终点站名"
          />
        </el-form-item>
        <el-form-item label="铁路全长(公里):" prop="totalLong">
          <el-input
            v-model="formData.totalLong"
            placeholder="请输入铁路全长公里数"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
neogcg's avatar
neogcg committed
154 155 156
  </div>
</template>
<script>
yanzhongrong's avatar
yanzhongrong committed
157
import { railWaylist, updateRailWay, railWaybatchDelete } from "../../api";
neogcg's avatar
neogcg committed
158
import { exportRailWay } from "@/api/export";
neogcg's avatar
neogcg committed
159
import { successAlert, warningAlert } from "@/utils/alert";
neogcg's avatar
neogcg committed
160
import download from "@/utils/download";
yanzhongrong's avatar
yanzhongrong committed
161

neogcg's avatar
neogcg committed
162 163 164
export default {
  data() {
    return {
neogcg's avatar
neogcg committed
165
      railData: formInit(),
neogcg's avatar
neogcg committed
166
      visible: false,
neogcg's avatar
neogcg committed
167
      tableData: [],
neogcg's avatar
neogcg committed
168
      params: {
neogcg's avatar
neogcg committed
169 170
        current: 1,
        size: 10,
neogcg's avatar
neogcg committed
171 172 173 174
      },
      total: 10,
      multipleSelection: [],
      ids: [],
neogcg's avatar
neogcg committed
175
      block: 0,
neogcg's avatar
neogcg committed
176
      istrue: 0,
neogcg's avatar
neogcg committed
177
      exids: [],
yanzhongrong's avatar
yanzhongrong committed
178 179 180 181 182 183 184 185 186
      formData: {},
      rules: {
        name: [{ required: true, message: "请输入铁路名", trigger: "blur" }],
        startPointName: [
          { required: true, message: "请输入铁路线起点站名", trigger: "blur" },
        ],
        endPointName: [
          { required: true, message: "请输入铁路线终点站名", trigger: "blur" },
        ],
yanzhongrong's avatar
yanzhongrong committed
187 188
        totalLong: [
          { required: true, pattern: /^0\.([1-9]|\d[1-9])$|^[1-9]\d{0,7}\.\d{0,2}$|^[1-9]\d{0,7}$/, message: "最大输入8位整数(小数点后最多2位)", trigger: "blur" },
yanzhongrong's avatar
yanzhongrong committed
189 190
        ],
      },
neogcg's avatar
neogcg committed
191 192
    };
  },
yanzhongrong's avatar
yanzhongrong committed
193 194 195 196 197 198 199 200 201 202 203 204
  created() {
    var that = this;
    document.onkeydown = function (e) {
      var key = window.event.keyCode;
      if (key == 13) {
        that.searchQuery();
      }
    };
  },
  mounted() {
    this.getTableData();
  },
neogcg's avatar
neogcg committed
205 206 207 208
  methods: {
    tableRowClassName({ row, rowIndex }) {
      return rowIndex % 2 === 0 ? "" : "single-row";
    },
neogcg's avatar
neogcg committed
209
    del() {
neogcg's avatar
neogcg committed
210
      let ids = this.ids;
neogcg's avatar
neogcg committed
211
      railWaybatchDelete({ ids }).then((res) => {
neogcg's avatar
neogcg committed
212
        if (res.code == 200) {
neogcg's avatar
neogcg committed
213
          successAlert("删除成功");
neogcg's avatar
neogcg committed
214 215 216
          this.getTableData();
        } else {
          warningAlert("删除失败");
neogcg's avatar
neogcg committed
217 218
        }
      });
neogcg's avatar
neogcg committed
219
    },
neogcg's avatar
neogcg committed
220
    refresh() {
yanzhongrong's avatar
yanzhongrong committed
221
      this.reset();
neogcg's avatar
neogcg committed
222
    },
neogcg's avatar
neogcg committed
223
    searchQuery() {
neogcg's avatar
neogcg committed
224 225
      this.istrue = 1;
      this.getTableData();
neogcg's avatar
neogcg committed
226 227
    },
    reset() {
neogcg's avatar
neogcg committed
228
      this.railData = formInit();
yanzhongrong's avatar
yanzhongrong committed
229
      this.searchQuery();
neogcg's avatar
neogcg committed
230
    },
yanzhongrong's avatar
yanzhongrong committed
231 232 233 234
    toEdit(row) {
      this.visible = true
      this.formData = editForm(row)
    },
neogcg's avatar
neogcg committed
235
    exportData() {
yanzhongrong's avatar
yanzhongrong committed
236
      if (this.exids.length == 0) {
neogcg's avatar
neogcg committed
237 238 239
        this.$message.warning("暂无数据");
        return false;
      } else {
yanzhongrong's avatar
yanzhongrong committed
240 241 242
        exportRailWay({ ids: this.exids }).then((res) => {
          download(res, "vnd.ms-excel", `铁路线表.xls`);
        });
neogcg's avatar
neogcg committed
243
      }
neogcg's avatar
neogcg committed
244
    },
neogcg's avatar
neogcg committed
245 246 247 248 249
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = this.multipleSelection.map((i) => i.id);
    },
    handleView(row) {
neogcg's avatar
neogcg committed
250
      this.$router.push({
dupengyu's avatar
dupengyu committed
251
        path: "/setting/statistics/detail",
neogcg's avatar
neogcg committed
252 253
        query: {
          id: row.id,
neogcg's avatar
neogcg committed
254
          type: 1,
neogcg's avatar
neogcg committed
255 256
        },
      });
neogcg's avatar
neogcg committed
257 258
    },
    handlePageChange(pageData) {
neogcg's avatar
neogcg committed
259 260
      this.railData.size = pageData.size;
      this.railData.current = pageData.page;
neogcg's avatar
neogcg committed
261 262 263
      this.getTableData();
    },
    getTableData() {
neogcg's avatar
neogcg committed
264
      railWaylist(this.railData).then((res) => {
neogcg's avatar
neogcg committed
265 266 267
        let list = res.records || [];
        this.tableData = list;
        this.total = res.total;
neogcg's avatar
neogcg committed
268
        this.exids = list.map((i) => i.id);
neogcg's avatar
neogcg committed
269 270
        if (this.istrue == 1) {
          if (this.tableData.length) {
yanzhongrong's avatar
yanzhongrong committed
271
            successAlert("操作成功");
neogcg's avatar
neogcg committed
272 273 274 275 276
          } else {
            warningAlert("查询结果为空");
          }
          this.istrue = 0;
        }
neogcg's avatar
neogcg committed
277 278
      });
    },
yanzhongrong's avatar
yanzhongrong committed
279
    confirm() {
yanzhongrong's avatar
yanzhongrong committed
280 281
      updateRailWay({ ...this.formData }).then(res => {
        if (res.code == 200) {
yanzhongrong's avatar
yanzhongrong committed
282 283 284 285 286 287 288
          this.$message.success('保存成功!')
        }
        this.getTableData()
        this.visible = false
      })
    }

neogcg's avatar
neogcg committed
289 290
  },
};
yanzhongrong's avatar
yanzhongrong committed
291

neogcg's avatar
neogcg committed
292 293 294 295 296 297 298 299 300 301
function formInit(data = {}) {
  return {
    endPointName: "",
    name: "",
    startPointName: "",
    current: 1,
    size: 10,
    ...data,
  };
}
yanzhongrong's avatar
yanzhongrong committed
302 303

function editForm(data = {}) {
yanzhongrong's avatar
yanzhongrong committed
304
  return {
yanzhongrong's avatar
yanzhongrong committed
305 306 307 308 309 310 311
    endPointName: "",
    name: "",
    startPointName: "",
    totalLong: '',
    ...data,
  }
}
neogcg's avatar
neogcg committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
</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;
    }
  }
}
yanzhongrong's avatar
yanzhongrong committed
343 344 345
.el-link {
  margin-right: 20px;
}
neogcg's avatar
neogcg committed
346 347 348 349 350 351 352 353 354 355 356
</style>
<style lang="scss">
.statistics-table {
  .single-row {
    background: #f1f6ff;
  }
  td {
    padding: 5px !important;
  }
}
</style>