index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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="fetchData">
  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 ref="tableSort" v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText"
  27. :height="height" @selection-change="setSelectRows">
  28. <el-table-column show-overflow-tooltip type="selection" width="40"></el-table-column>
  29. <el-table-column show-overflow-tooltip label="id" prop="id" 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="country" align="center" sortable></el-table-column>
  32. <el-table-column show-overflow-tooltip label="地址" prop="address" align="center" sortable>
  33. </el-table-column>
  34. <el-table-column show-overflow-tooltip label="电话" prop="telephone" align="center" sortable>
  35. </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. getMyExcelData(val) {
  95. val.forEach(item => {
  96. api.addManufacturer(item).then(res => {
  97. if (res.code == 200) {
  98. this.$message({
  99. type: 'success',
  100. message: '添加成功!'
  101. });
  102. this.fetchData()
  103. }
  104. })
  105. })
  106. },
  107. getStation() {
  108. stationApi.windpowerstationList({
  109. id: '',
  110. name: '',
  111. companyid: '',
  112. pageNum: 1,
  113. pageSize: 1000,
  114. }).then(res => {
  115. if (res.data) {
  116. this.listLoading = false
  117. this.stationList = res.data.records
  118. }
  119. })
  120. },
  121. fetchData() {
  122. api.manufacturer({
  123. name: this.fuzzyQuery_name,
  124. pageNum: this.queryForm.pageNo,
  125. pageSize: this.queryForm.pageSize,
  126. }).then(res => {
  127. if (res.data) {
  128. this.listLoading = false
  129. this.total = res.data.total
  130. this.list = res.data.records
  131. this.templateExcel = [
  132. {
  133. id: '',
  134. name: '',
  135. country: '',
  136. address: '',
  137. telephone: ''
  138. }
  139. ]
  140. // 导出
  141. let exportExcel = []
  142. res.data.records.forEach(item => {
  143. exportExcel.push({
  144. id: item.id,
  145. name: item.name,
  146. country: item.country,
  147. address: item.address,
  148. telephone: item.telephone
  149. })
  150. })
  151. this.exportExcel = exportExcel
  152. }
  153. })
  154. },
  155. handleSizeChange(val) {
  156. this.queryForm.pageSize = val
  157. this.fetchData()
  158. },
  159. handleCurrentChange(val) {
  160. this.queryForm.pageNo = val
  161. this.fetchData()
  162. },
  163. handleAdd() {
  164. this.$refs['edit'].showEdit()
  165. },
  166. handleEdit(row) {
  167. this.$refs['edit'].showEdit(row)
  168. },
  169. handleDelete(row) {
  170. if (row.id || this.selectRows.length > 0) {
  171. this.$baseConfirm('你确定要删除吗', null, async () => {
  172. let ids = ''
  173. if (this.selectRows.length > 0) {
  174. ids = this.selectRows.map((item) => item.id).join()
  175. }
  176. api.deleteManufacturer({
  177. id: row.id || ids
  178. }).then(res => {
  179. if (res.data) {
  180. this.$baseMessage('删除成功', 'success')
  181. this.fetchData()
  182. }
  183. })
  184. })
  185. } else {
  186. this.$baseMessage('未选中任何行', 'error')
  187. return false
  188. }
  189. },
  190. setSelectRows(val) {
  191. this.selectRows = val
  192. },
  193. },
  194. }
  195. </script>
  196. <style lang="less" scoped>
  197. .title {
  198. display: flex;
  199. flex-direction: row;
  200. align-items: center;
  201. justify-content: space-between;
  202. margin-bottom: 20px;
  203. }
  204. .left {
  205. display: flex;
  206. flex-direction: row;
  207. align-items: center;
  208. .left-item {
  209. display: flex;
  210. flex-direction: row;
  211. align-items: center;
  212. margin-right: 10px;
  213. }
  214. }
  215. </style>