index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="table-container">
  3. <vab-query-form>
  4. <div class="title">
  5. <div class="left">
  6. <div class="left-item">
  7. <div style="width: 70px;">名称:</div>
  8. <el-input v-model="fuzzyQuery_name" placeholder="请输入" clearable />
  9. </div>
  10. <el-button icon="el-icon-search" type="primary" native-type="submit" @click="searchFetchData">
  11. 查询
  12. </el-button>
  13. </div>
  14. <div class="right">
  15. <el-button icon="el-icon-plus" type="primary" @click="handleAdd">
  16. 添加
  17. </el-button>
  18. <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
  19. 删除
  20. </el-button>
  21. <UploadExcel style="margin-left: 10px;" @getResult="getMyExcelData"></UploadExcel>
  22. <ExportExcel :exportList="exportExcel" :useType="'export'" partsName="气象站"></ExportExcel>
  23. <ExportExcel :exportList="templateExcel" :useType="'template'" partsName="气象站模板"></ExportExcel>
  24. </div>
  25. </div>
  26. <el-table header-cell-class-name="table_header_style" border ref="tableSort" v-loading="listLoading" :data="list"
  27. :element-loading-text="elementLoadingText" :height="height" @selection-change="setSelectRows">
  28. <el-table-column show-overflow-tooltip type="selection" align="center" width="40"></el-table-column>
  29. <el-table-column show-overflow-tooltip label="编码" prop="nemCode" align="center" sortable></el-table-column>
  30. <el-table-column show-overflow-tooltip label="名称" prop="name" align="center" sortable></el-table-column>
  31. <el-table-column show-overflow-tooltip label="别名" prop="aname" align="center" sortable></el-table-column>
  32. <el-table-column show-overflow-tooltip label="容量" prop="capacity" align="center" sortable></el-table-column>
  33. <el-table-column show-overflow-tooltip :formatter="windpowerstationIdFormatter" label="风场编号" prop="windpowerstationId" align="center" sortable></el-table-column>
  34. <el-table-column show-overflow-tooltip label="顺序" prop="orderNum" align="center" sortable></el-table-column>
  35. <el-table-column show-overflow-tooltip label="是否可用" prop="isAble" align="center" sortable></el-table-column>
  36. <el-table-column show-overflow-tooltip label="操作" width="100px" fixed="right">
  37. <template #default="{ row }">
  38. <el-button type="text" @click="handleEdit(row)">编辑</el-button>
  39. <el-button type="text" @click="handleDelete(row)">删除</el-button>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <el-pagination :background="background" :current-page="queryForm.pageNo" :layout="layout"
  44. :page-size="queryForm.pageSize" :total="total" @current-change="handleCurrentChange"
  45. @size-change="handleSizeChange"></el-pagination>
  46. <table-edit ref="edit" :options="options" :stationList="stationList" @save-success="fetchData"></table-edit>
  47. </vab-query-form>
  48. </div>
  49. </template>
  50. <script>
  51. import UploadExcel from '@/components/UploadExcel/index'
  52. import ExportExcel from '@/components/ExportExcel/index'
  53. import api from '@/api/realtimeDatabaseConfiguration'
  54. import stationApi from '@/api/station'
  55. import TableEdit from './components/TableEdit'
  56. export default {
  57. components: {
  58. UploadExcel,
  59. ExportExcel,
  60. TableEdit,
  61. },
  62. data() {
  63. return {
  64. fuzzyQuery_name: '',
  65. listLoading: true,
  66. list: [],
  67. options: [],
  68. exportExcel: [],
  69. templateExcel: [],
  70. elementLoadingText: '正在加载...',
  71. selectRows: '',
  72. layout: 'total, sizes, prev, pager, next, jumper',
  73. total: 0,
  74. background: true,
  75. exportList: [],
  76. queryForm: {
  77. pageNo: 1,
  78. pageSize: 20,
  79. },
  80. stationList: [],
  81. selectValue: ''
  82. };
  83. },
  84. computed: {
  85. height() {
  86. return this.$baseTableHeight() + 50
  87. },
  88. },
  89. created() {
  90. this.getStation()
  91. this.fetchData()
  92. },
  93. methods: {
  94. windpowerstationIdFormatter(row){
  95. for (const iterator of this.stationList) {
  96. if(row.windpowerstationId == iterator.id){
  97. return iterator.name
  98. }
  99. }
  100. },
  101. getMyExcelData(val) {
  102. val.forEach(item => {
  103. api.addWeatherStation(item).then(res => {
  104. if (res.code == 200) {
  105. this.$message({
  106. type: 'success',
  107. message: '添加成功!'
  108. });
  109. this.fetchData()
  110. }
  111. })
  112. })
  113. },
  114. getStation() {
  115. stationApi.windpowerstationList({
  116. id: '',
  117. name: '',
  118. companyId: '',
  119. groupId: '',
  120. pageNum: 1,
  121. pageSize: 1000,
  122. }).then(res => {
  123. if (res.data) {
  124. this.listLoading = false
  125. this.stationList = res.data.records
  126. }
  127. })
  128. },
  129. searchFetchData(){
  130. this.queryForm.pageNo = 1
  131. this.fetchData()
  132. },
  133. fetchData() {
  134. api.weatherStationList({
  135. name: this.fuzzyQuery_name,
  136. pageNum: this.queryForm.pageNo,
  137. pageSize: this.queryForm.pageSize,
  138. }).then(res => {
  139. if (res.data) {
  140. this.listLoading = false
  141. this.total = res.data.total
  142. this.list = res.data.records
  143. this.templateExcel = [
  144. {
  145. nemCode: "",
  146. name: "",
  147. aname: "",
  148. capacity: "",
  149. windpowerstationId: "",
  150. orderNum: "",
  151. isAble: "",
  152. }
  153. ]
  154. // 导出
  155. let exportExcel = []
  156. res.data.records.forEach(item => {
  157. exportExcel.push({
  158. nemCode: item.nemCode,
  159. name: item.name,
  160. aname: item.aname,
  161. capacity: item.capacity,
  162. windpowerstationId: item.windpowerstationId,
  163. orderNum: item.orderNum,
  164. isAble: item.isAble,
  165. })
  166. })
  167. this.exportExcel = exportExcel
  168. }
  169. })
  170. },
  171. handleSizeChange(val) {
  172. this.queryForm.pageSize = val
  173. this.fetchData()
  174. },
  175. handleCurrentChange(val) {
  176. this.queryForm.pageNo = val
  177. this.fetchData()
  178. },
  179. handleAdd() {
  180. this.$refs['edit'].showEdit()
  181. },
  182. handleEdit(row) {
  183. this.$refs['edit'].showEdit(row)
  184. },
  185. handleDelete(row) {
  186. if (row.id || this.selectRows.length > 0) {
  187. this.$baseConfirm('你确定要删除吗', null, async () => {
  188. let ids = ''
  189. if (this.selectRows.length > 0) {
  190. ids = this.selectRows.map((item) => item.id).join()
  191. }
  192. api.deleteWeatherStation({
  193. id: row.id || ids
  194. }).then(res => {
  195. if (res.data) {
  196. this.$baseMessage('删除成功', 'success')
  197. this.fetchData()
  198. }
  199. })
  200. })
  201. } else {
  202. this.$baseMessage('未选中任何行', 'error')
  203. return false
  204. }
  205. },
  206. setSelectRows(val) {
  207. this.selectRows = val
  208. },
  209. },
  210. }
  211. </script>
  212. <style lang="less" scoped>
  213. .title {
  214. display: flex;
  215. flex-direction: row;
  216. align-items: center;
  217. justify-content: space-between;
  218. margin-bottom: 20px;
  219. }
  220. .left {
  221. display: flex;
  222. flex-direction: row;
  223. align-items: center;
  224. .left-item {
  225. display: flex;
  226. flex-direction: row;
  227. align-items: center;
  228. margin-right: 10px;
  229. }
  230. }
  231. </style>