index.vue 8.6 KB

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