index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="table-container">
  3. <vab-query-form>
  4. <vab-query-form-left-panel>
  5. <el-form ref="form" :model="queryForm" :inline="true" @submit.native.prevent>
  6. <el-form-item>
  7. <el-cascader class="cascaders" v-model="cascaderSel" :options="options"
  8. :props="{ checkStrictly: true, label: 'name', value: 'id' }" clearable>
  9. </el-cascader>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button icon="el-icon-search" type="primary" native-type="submit" @click="handleQuery">
  13. 查询
  14. </el-button>
  15. </el-form-item>
  16. </el-form>
  17. </vab-query-form-left-panel>
  18. <vab-query-form-right-panel>
  19. <el-button icon="el-icon-plus" type="primary" @click="handleAdd">
  20. 添加
  21. </el-button>
  22. <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
  23. 删除
  24. </el-button>
  25. </vab-query-form-right-panel>
  26. </vab-query-form>
  27. <el-table ref="tableSort" v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText"
  28. :height="height" @selection-change="setSelectRows" @sort-change="tableSortChange" show-summary
  29. :summary-method="getSummaries">
  30. <el-table-column show-overflow-tooltip type="selection" width="65"></el-table-column>
  31. <el-table-column show-overflow-tooltip label="风场编号" prop="windpower" width="200" align="center" sortable>
  32. </el-table-column>
  33. <el-table-column show-overflow-tooltip label="工程编号" prop="projectid" align="center" sortable></el-table-column>
  34. <el-table-column show-overflow-tooltip label="计划发电量" prop="generatingcapacity" align="center" sortable>
  35. </el-table-column>
  36. <el-table-column show-overflow-tooltip label="计划停运小时" prop="outagehours" align="center" sortable>
  37. </el-table-column>
  38. <el-table-column show-overflow-tooltip label="年份" prop="year" align="center" sortable></el-table-column>
  39. <el-table-column show-overflow-tooltip label="月份" prop="month" align="center" sortable></el-table-column>
  40. <el-table-column show-overflow-tooltip label="操作" width="180px">
  41. <template #default="{ row }">
  42. <el-button type="text" @click="handleEdit(row)">编辑</el-button>
  43. <el-button type="text" @click="handleDelete(row)">删除</el-button>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <el-pagination :background="background" :current-page="queryForm.pageNo" :layout="layout"
  48. :page-size="queryForm.pageSize" :total="total" @current-change="handleCurrentChange"
  49. @size-change="handleSizeChange"></el-pagination>
  50. <table-edit ref="edit" :options="options" @handleSuccess="fetchData"></table-edit>
  51. </div>
  52. </template>
  53. <script>
  54. import api from '@/api/table'
  55. import TableEdit from './components/TableEdit'
  56. export default {
  57. name: 'ComprehensiveTable',
  58. components: {
  59. TableEdit
  60. },
  61. filters: {
  62. statusFilter(status) {
  63. const statusMap = {
  64. published: 'success',
  65. draft: 'gray',
  66. deleted: 'danger',
  67. }
  68. return statusMap[status]
  69. },
  70. },
  71. data() {
  72. return {
  73. imgShow: true,
  74. list: [],
  75. cascaderSel: [],
  76. imageList: [],
  77. listLoading: true,
  78. layout: 'total, sizes, prev, pager, next, jumper',
  79. total: 0,
  80. background: true,
  81. selectRows: '',
  82. elementLoadingText: '正在加载...',
  83. queryForm: {
  84. pageNo: 1,
  85. pageSize: 20,
  86. title: '',
  87. },
  88. options: []
  89. }
  90. },
  91. computed: {
  92. height() {
  93. return this.$baseTableHeight() + 50
  94. },
  95. },
  96. created() {
  97. this.getStation()
  98. this.fetchData()
  99. },
  100. beforeDestroy() { },
  101. mounted() { },
  102. methods: {
  103. getStation() {
  104. api.wtls().then(res => {
  105. if (res.data) {
  106. this.options = res.data
  107. }
  108. })
  109. },
  110. tableSortChange() {
  111. const imageList = []
  112. this.$refs.tableSort.tableData.forEach((item, index) => {
  113. imageList.push(item.img)
  114. })
  115. this.imageList = imageList
  116. },
  117. setSelectRows(val) {
  118. this.selectRows = val
  119. },
  120. handleAdd() {
  121. this.$refs['edit'].showEdit()
  122. },
  123. handleEdit(row) {
  124. this.$refs['edit'].showEdit(row)
  125. },
  126. handleDelete(row) {
  127. if (row.id) {
  128. this.$baseConfirm('你确定要删除当前项吗', null, async () => {
  129. api.deleteProjectstudy({
  130. id: row.id
  131. }).then(res => {
  132. if (res.code == 200) {
  133. this.$baseMessage('删除成功', 'success')
  134. this.fetchData()
  135. }
  136. })
  137. })
  138. } else {
  139. if (this.selectRows.length > 0) {
  140. const ids = this.selectRows.map((item) => item.id).join()
  141. this.$baseConfirm('你确定要删除选中项吗', null, async () => {
  142. api.deleteProjectstudy({
  143. id: ids
  144. }).then(res => {
  145. if (res.code == 200) {
  146. this.$baseMessage('删除成功', 'success')
  147. this.fetchData()
  148. }
  149. })
  150. })
  151. } else {
  152. this.$baseMessage('未选中任何行', 'error')
  153. return false
  154. }
  155. }
  156. },
  157. handleSizeChange(val) {
  158. this.queryForm.pageSize = val
  159. this.fetchData()
  160. },
  161. handleCurrentChange(val) {
  162. this.queryForm.pageNo = val
  163. this.fetchData()
  164. },
  165. handleQuery() {
  166. this.queryForm.pageNo = 1
  167. this.fetchData()
  168. },
  169. async fetchData() {
  170. this.listLoading = true
  171. api.projectstudy({
  172. pagenum: this.queryForm.pageNo,
  173. pagesize: this.queryForm.pageSize,
  174. }).then(res => {
  175. if (res.data) {
  176. this.total = res.data.total
  177. this.list = res.data.records
  178. setTimeout(() => {
  179. this.listLoading = false
  180. }, 500)
  181. }
  182. })
  183. },
  184. testMessage() {
  185. this.$baseMessage('test1', 'success')
  186. },
  187. testALert() {
  188. this.$baseAlert('11')
  189. this.$baseAlert('11', '自定义标题', () => {
  190. /* 可以写回调; */
  191. })
  192. this.$baseAlert('11', null, () => {
  193. /* 可以写回调; */
  194. })
  195. },
  196. testConfirm() {
  197. this.$baseConfirm(
  198. '你确定要执行该操作?',
  199. null,
  200. () => {
  201. /* 可以写回调; */
  202. },
  203. () => {
  204. /* 可以写回调; */
  205. }
  206. )
  207. },
  208. testNotify() {
  209. this.$baseNotify('测试消息提示', 'test', 'success', 'bottom-right')
  210. },
  211. getSummaries(param) {
  212. console.log(11111);
  213. const { columns, data } = param;
  214. const sums = [];
  215. columns.forEach((column, index) => {
  216. if (index === 0) {
  217. sums[index] = '总计';
  218. return;
  219. }
  220. else if (index === 3) {
  221. let totle = 0
  222. data.forEach(item => {
  223. totle = totle + Number(item.generatingcapacity)
  224. })
  225. sums[index] = totle;
  226. }
  227. else if (index === 4) {
  228. let totle = 0
  229. data.forEach(item => {
  230. totle = totle + Number(item.outagehours)
  231. })
  232. sums[index] = totle;
  233. } else {
  234. sums[index] = '--';
  235. }
  236. });
  237. return sums;
  238. }
  239. },
  240. }
  241. </script>
  242. <style lang="less" scoped>
  243. .cascaders {
  244. width: 300px;
  245. }
  246. </style>