index.vue 7.7 KB

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