ItdmSampleClassificationList.vue 12 KB

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