tableList.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="app-container">
  3. <div class="search-container">
  4. <el-form :inline="true" :model="searchForm" size="mini" class="demo-form-inline">
  5. <el-form-item label="充电站名称">
  6. <el-input v-model="searchForm.name" placeholder="充电站名称" clearable style="width: 160px;" />
  7. </el-form-item>
  8. <el-form-item label="状态">
  9. <el-select v-model="searchForm.status" clearable placeholder="状态" size="mini" style="width: 150px;">
  10. <el-option label="启用" value="ENABLED" />
  11. <el-option label="禁用" value="DISABLED" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleCurrentChange()">查询</el-button>
  16. <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-tooltip content="表格字段设置" effect="dark">
  20. <img
  21. class="table-cfg-icon"
  22. src="https://qiniu.bms16.com/menu_header_config.png"
  23. @click="loadFieldDialog"
  24. >
  25. </el-tooltip>
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. <el-table
  30. v-loading="loading"
  31. ref="multipleTable"
  32. :data="tableData"
  33. border
  34. style="width: 100%"
  35. @header-dragend="onHeaderDragend"
  36. >
  37. <el-table-column v-for="(item, index) in fieldDefsData" :key="index" v-bind="item" >
  38. <template slot-scope="scope">
  39. <div v-if="item.prop === 'status'">
  40. <el-tag v-if="scope.row.status === 'ENABLED'" type="success">启用</el-tag>
  41. <el-tag v-if="scope.row.status === 'DISABLED'" type="danger">禁用</el-tag>
  42. </div>
  43. <div v-else>{{ scope.row[item.prop] }}</div>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="操作" align="center">
  47. <template slot-scope="scope">
  48. <el-button type="text" size="mini" @click="showDetail(scope.row)">详情</el-button>
  49. <el-button type="text" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <el-pagination
  54. :current-page="searchForm.page"
  55. :page-size="searchForm.limit"
  56. :total="records"
  57. style="margin-top: 10px;"
  58. background
  59. layout="total, sizes, prev, pager, next, jumper"
  60. @current-change="handleCurrentChange"
  61. @size-change="handleSizeChange"
  62. />
  63. <TableFieldCfg
  64. ref="TableFieldCfg"
  65. :default-column-defs="fieldDefs"
  66. @success="getTableListFieldDefs"
  67. />
  68. </div>
  69. </template>
  70. <script>
  71. import { apiQueryChargerGroupList } from '@/api/deviceCfg'
  72. import TableFieldCfg from '@/common/components/TableFieldCfg'
  73. import tableFields from '@/common/components/TableFieldCfg/index.mixin.js'
  74. export default {
  75. components: {
  76. TableFieldCfg
  77. },
  78. mixins: [tableFields],
  79. data() {
  80. return {
  81. loading: false,
  82. records: 0,
  83. searchForm: {},
  84. tableData: [],
  85. fieldDefs: [
  86. { label: '充电站名称', prop: 'group_name', align: 'center' },
  87. { label: '所在城市', prop: 'cityname', align: 'center' },
  88. { label: '充电站地址', prop: 'address', align: 'center' },
  89. { label: '订单量', prop: 'order_count', align: 'center' },
  90. { label: '联系人', prop: 'contacts', align: 'center' },
  91. { label: '状态', prop: 'status', align: 'center' }
  92. ]
  93. }
  94. },
  95. created() {
  96. this.queryList()
  97. },
  98. methods: {
  99. handleAdd() {
  100. this.$router.push({ path: '/edit-chargingStation' })
  101. },
  102. handleUpdate(row) {
  103. const data = JSON.stringify(row)
  104. this.$router.push({ path: `/edit-chargingStation?data=${data}` })
  105. },
  106. handleCurrentChange(val = 1) {
  107. this.searchForm.page = val
  108. this.queryList()
  109. },
  110. handleSizeChange(val) {
  111. this.searchForm.limit = val
  112. this.queryList()
  113. },
  114. queryList() {
  115. this.loading = true
  116. apiQueryChargerGroupList(this.searchForm).then(res => {
  117. const { data, code } = res.data
  118. this.loading = false
  119. if (code === 200) {
  120. this.tableData = data.list
  121. this.records = +data.total
  122. }
  123. })
  124. },
  125. showDetail(row) {
  126. this.$router.push(`/chargingStationDetail?id=${row.group_id}`)
  127. }
  128. }
  129. }
  130. </script>