TpmEquipmentTreeList.vue 13 KB

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