index.vue 9.7 KB

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