TpmEquipmentTreeList.vue 13 KB

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