index.vue 7.6 KB

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