SpaceList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <a-card :bordered="false">
  3. <!-- 查询区域 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="searchQuery">
  6. <a-row :gutter="24">
  7. <a-col :xl="6" :lg="7" :md="8" :sm="24">
  8. <a-form-item label="区域名称">
  9. <a-input placeholder="请输入设备区域名称" v-model="queryParam.name"></a-input>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :xl="6" :lg="7" :md="8" :sm="24">
  13. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  14. <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
  15. <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
  16. </span>
  17. </a-col>
  18. </a-row>
  19. </a-form>
  20. </div>
  21. <!-- 查询区域-END -->
  22. <!-- 操作按钮区域 -->
  23. <div class="table-operator">
  24. <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
  25. <!-- <a-button @click="expandClose" type="primary" :icon="tableTreeStatus == 1 ? 'down-circle' : 'up-circle'">{{tableTreeStatus == 1 ? '一键展开':'一键折叠'}}</a-button> -->
  26. <a-button @click="expandClose" type="primary">{{tableTreeStatus == 1 ? '一键展开':'一键折叠'}}</a-button>
  27. <!-- <a-button type="primary" icon="download" @click="handleExportXls('空间管理')">导出</a-button>
  28. <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
  29. <a-button type="primary" icon="import">导入</a-button>
  30. </a-upload> -->
  31. <!-- 高级查询区域 -->
  32. <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
  33. <a-dropdown v-if="selectedRowKeys.length > 0">
  34. <a-menu slot="overlay">
  35. <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
  36. </a-menu>
  37. <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
  38. </a-dropdown>
  39. </div>
  40. <!-- table区域-begin -->
  41. <div>
  42. <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  43. <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
  44. <a style="margin-left: 24px" @click="onClearSelected">清空</a>
  45. </div>
  46. <a-table
  47. ref="table"
  48. size="middle"
  49. rowKey="id"
  50. class="j-table-force-nowrap"
  51. :scroll="{x:true}"
  52. :columns="columns"
  53. :dataSource="dataSource"
  54. :pagination="false"
  55. :loading="loading"
  56. :expandedRowKeys="expandedRowKeys"
  57. @change="handleTableChange"
  58. @expand="handleExpand"
  59. v-bind="tableProps">
  60. <template slot="imgSlot" slot-scope="text,record">
  61. <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
  62. <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
  63. </template>
  64. <template slot="fileSlot" slot-scope="text">
  65. <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
  66. <a-button
  67. v-else
  68. :ghost="true"
  69. type="primary"
  70. icon="download"
  71. size="small"
  72. @click="downloadFile(text)">
  73. 下载
  74. </a-button>
  75. </template>
  76. <span slot="action" slot-scope="text, record">
  77. <a @click="handleEdit(record)">编辑</a>
  78. <a-divider type="vertical" />
  79. <a-dropdown>
  80. <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
  81. <a-menu slot="overlay">
  82. <a-menu-item>
  83. <a @click="handleAddChild(record)">添加下级</a>
  84. </a-menu-item>
  85. <a-menu-item>
  86. <a-popconfirm title="确定删除吗?" @confirm="() => handleDeleteNode(record.id)" placement="topLeft">
  87. <a>删除</a>
  88. </a-popconfirm>
  89. </a-menu-item>
  90. </a-menu>
  91. </a-dropdown>
  92. </span>
  93. </a-table>
  94. </div>
  95. <space-modal ref="modalForm" @ok="modalFormOk"></space-modal>
  96. </a-card>
  97. </template>
  98. <script>
  99. import { getAction, deleteAction } from '@/api/manage'
  100. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  101. import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  102. import { filterObj } from '@/utils/util';
  103. import SpaceModal from './modules/SpaceModal.vue'
  104. export default {
  105. name: "SpaceList",
  106. mixins:[JeecgListMixin],
  107. components: {
  108. SpaceModal
  109. },
  110. data () {
  111. return {
  112. description: '空间管理管理页面',
  113. // 表头
  114. columns: [
  115. {
  116. title:'区域名称',
  117. align:"left",
  118. dataIndex: 'name'
  119. },
  120. // {
  121. // title:'编号',
  122. // align:"left",
  123. // dataIndex: 'serialnum'
  124. // },
  125. // {
  126. // title:'类型',
  127. // align:"left",
  128. // dataIndex: 'spacetype'
  129. // },
  130. // {
  131. // title:'管理单位/部门',
  132. // align:"left",
  133. // dataIndex: 'deptid'
  134. // },
  135. // {
  136. // title:'建筑面积(平方米)',
  137. // align:"left",
  138. // dataIndex: 'builtarea'
  139. // },
  140. // {
  141. // title:'空调系统',
  142. // align:"left",
  143. // dataIndex: 'aircondsys'
  144. // },
  145. // {
  146. // title:'采暖系统',
  147. // align:"left",
  148. // dataIndex: 'heatsys'
  149. // },
  150. // {
  151. // title:'空调面积',
  152. // align:"left",
  153. // dataIndex: 'aircondarea'
  154. // },
  155. // {
  156. // title:'采暖面积',
  157. // align:"left",
  158. // dataIndex: 'heatarea'
  159. // },
  160. {
  161. title: '操作',
  162. dataIndex: 'action',
  163. align:"center",
  164. fixed:"right",
  165. width:147,
  166. scopedSlots: { customRender: 'action' },
  167. }
  168. ],
  169. url: {
  170. // list: "/space/space/rootList",
  171. list: "/space/space/treeList",
  172. childList: "/space/space/childList",
  173. getChildListBatch: "/space/space/getChildListBatch",
  174. delete: "/space/space/delete",
  175. deleteBatch: "/space/space/deleteBatch",
  176. exportXlsUrl: "/space/space/exportXls",
  177. importExcelUrl: "space/space/importExcel",
  178. },
  179. expandedRowKeys:[],
  180. hasChildrenField:"hasChild",
  181. pidField:"parentid",
  182. dictOptions: {},
  183. loadParent: false,
  184. superFieldList:[],
  185. // 展开/折叠
  186. tableTreeStatus: 1,
  187. }
  188. },
  189. created() {
  190. this.getSuperFieldList();
  191. },
  192. computed: {
  193. importExcelUrl(){
  194. return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
  195. },
  196. tableProps() {
  197. let _this = this
  198. return {
  199. // 列表项是否可选择
  200. rowSelection: {
  201. selectedRowKeys: _this.selectedRowKeys,
  202. onChange: (selectedRowKeys) => _this.selectedRowKeys = selectedRowKeys
  203. }
  204. }
  205. }
  206. },
  207. methods: {
  208. loadData(arg){
  209. if(arg==1){
  210. this.ipagination.current=1
  211. }
  212. this.loading = true
  213. let params = this.getQueryParams()
  214. params.hasQuery = 'true'
  215. getAction(this.url.list,params).then(res=>{
  216. if(res.success){
  217. this.dataSource = res.result;
  218. // let result = res.result
  219. // if(Number(result.total)>0){
  220. // this.ipagination.total = Number(result.total)
  221. // this.dataSource = this.getDataByResult(res.result.records)
  222. // return this.loadDataByExpandedRows(this.dataSource)
  223. // }else{
  224. // this.ipagination.total=0
  225. // this.dataSource=[]
  226. // }
  227. }else{
  228. this.$message.warning(res.message)
  229. }
  230. }).finally(()=>{
  231. this.loading = false
  232. })
  233. },
  234. // 根据已展开的行查询数据(用于保存后刷新时异步加载子级的数据)
  235. loadDataByExpandedRows(dataList) {
  236. if (this.expandedRowKeys.length > 0) {
  237. return getAction(this.url.getChildListBatch,{ parentIds: this.expandedRowKeys.join(',') }).then(res=>{
  238. if (res.success && res.result.records.length>0) {
  239. //已展开的数据批量子节点
  240. let records = res.result.records
  241. const listMap = new Map();
  242. for (let item of records) {
  243. let pid = item[this.pidField];
  244. if (this.expandedRowKeys.join(',').includes(pid)) {
  245. let mapList = listMap.get(pid);
  246. if (mapList == null) {
  247. mapList = [];
  248. }
  249. mapList.push(item);
  250. listMap.set(pid, mapList);
  251. }
  252. }
  253. let childrenMap = listMap;
  254. let fn = (list) => {
  255. if(list) {
  256. list.forEach(data => {
  257. if (this.expandedRowKeys.includes(data.id)) {
  258. data.children = this.getDataByResult(childrenMap.get(data.id))
  259. fn(data.children)
  260. }
  261. })
  262. }
  263. }
  264. fn(dataList)
  265. }
  266. })
  267. } else {
  268. return Promise.resolve()
  269. }
  270. },
  271. getQueryParams(arg) {
  272. //获取查询条件
  273. let sqp = {}
  274. let param = {}
  275. if(this.superQueryParams){
  276. sqp['superQueryParams']=encodeURI(this.superQueryParams)
  277. sqp['superQueryMatchType'] = this.superQueryMatchType
  278. }
  279. if(arg){
  280. param = Object.assign(sqp, this.isorter ,this.filters);
  281. }else{
  282. param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
  283. }
  284. if(JSON.stringify(this.queryParam) === "{}" || arg){
  285. param.hasQuery = 'false'
  286. }else{
  287. param.hasQuery = 'true'
  288. }
  289. param.field = this.getQueryField();
  290. param.pageNo = this.ipagination.current;
  291. param.pageSize = this.ipagination.pageSize;
  292. return filterObj(param);
  293. },
  294. searchReset() {
  295. //重置
  296. this.expandedRowKeys = []
  297. this.queryParam = {}
  298. this.loadData(1);
  299. },
  300. getDataByResult(result){
  301. if(result){
  302. return result.map(item=>{
  303. //判断是否标记了带有子节点
  304. if(item[this.hasChildrenField]=='1'){
  305. let loadChild = { id: item.id+'_loadChild', name: 'loading...', isLoading: true }
  306. item.children = [loadChild]
  307. }
  308. return item
  309. })
  310. }
  311. },
  312. handleExpand(expanded, record){
  313. // 判断是否是展开状态
  314. if (expanded) {
  315. this.expandedRowKeys.push(record.id)
  316. if (record.children.length>0 && record.children[0].isLoading === true) {
  317. let params = this.getQueryParams(1);//查询条件
  318. params[this.pidField] = record.id
  319. params.hasQuery = 'false'
  320. params.superQueryParams=""
  321. getAction(this.url.childList,params).then((res)=>{
  322. if(res.success){
  323. if(res.result.records){
  324. record.children = this.getDataByResult(res.result.records)
  325. this.dataSource = [...this.dataSource]
  326. }else{
  327. record.children=''
  328. record.hasChildrenField='0'
  329. }
  330. }else{
  331. this.$message.warning(res.message)
  332. }
  333. })
  334. }
  335. }else{
  336. let keyIndex = this.expandedRowKeys.indexOf(record.id)
  337. if(keyIndex>=0){
  338. this.expandedRowKeys.splice(keyIndex, 1);
  339. }
  340. }
  341. },
  342. handleAddChild(record){
  343. this.loadParent = true
  344. let obj = {}
  345. obj[this.pidField] = record['id']
  346. this.$refs.modalForm.add(obj);
  347. },
  348. handleDeleteNode(id) {
  349. if(!this.url.delete){
  350. this.$message.error("请设置url.delete属性!")
  351. return
  352. }
  353. var that = this;
  354. deleteAction(that.url.delete, {id: id}).then((res) => {
  355. if (res.success) {
  356. that.loadData(1)
  357. } else {
  358. that.$message.warning(res.message);
  359. }
  360. });
  361. },
  362. batchDel(){
  363. if(this.selectedRowKeys.length<=0){
  364. this.$message.warning('请选择一条记录!');
  365. return false;
  366. }else{
  367. let ids = "";
  368. let that = this;
  369. that.selectedRowKeys.forEach(function(val) {
  370. ids+=val+",";
  371. });
  372. that.$confirm({
  373. title:"确认删除",
  374. content:"是否删除选中数据?",
  375. onOk: function(){
  376. that.handleDeleteNode(ids)
  377. that.onClearSelected();
  378. }
  379. });
  380. }
  381. },
  382. getSuperFieldList(){
  383. let fieldList=[];
  384. fieldList.push({type:'string',value:'parentid',text:'上级id',dictCode:''})
  385. fieldList.push({type:'string',value:'name',text:'名称',dictCode:''})
  386. fieldList.push({type:'string',value:'serialnum',text:'编号',dictCode:''})
  387. fieldList.push({type:'string',value:'spacetype',text:'类型',dictCode:''})
  388. fieldList.push({type:'string',value:'deptid',text:'管理单位/部门',dictCode:''})
  389. fieldList.push({type:'int',value:'builtarea',text:'建筑面积(平方米)',dictCode:''})
  390. fieldList.push({type:'string',value:'aircondsys',text:'空调系统',dictCode:''})
  391. fieldList.push({type:'string',value:'heatsys',text:'采暖系统',dictCode:''})
  392. fieldList.push({type:'int',value:'aircondarea',text:'空调面积',dictCode:''})
  393. fieldList.push({type:'int',value:'heatarea',text:'采暖面积',dictCode:''})
  394. this.superFieldList = fieldList
  395. },
  396. expandClose(){
  397. this.tableTreeStatus = - this.tableTreeStatus
  398. if (this.tableTreeStatus == 1) {
  399. this.expandedRowKeys = []
  400. } else {
  401. this.expandedRowKeys = this.dataSource.map(item =>{
  402. return item.id
  403. })
  404. }
  405. }
  406. }
  407. }
  408. </script>
  409. <style scoped>
  410. @import '~@assets/less/common.less';
  411. </style>