5ea10244d449885d9b5f23219511922290362099.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="modalWidth"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. switchFullscreen
  8. wrapClassName="j-popup-modal"
  9. @ok="handleSubmit"
  10. @cancel="handleCancel"
  11. cancelText="关闭">
  12. <div class="table-page-search-wrapper">
  13. <a-form layout="inline" @keyup.enter.native="searchByquery">
  14. <a-row :gutter="24" v-if="showSearchFlag">
  15. <template v-for="(item,index) in queryInfo">
  16. <template v-if=" item.hidden==='1' ">
  17. <a-col :md="8" :sm="24" :key=" 'query'+index " v-show="toggleSearchStatus">
  18. <online-query-form-item :queryParam="queryParam" :item="item" :dictOptions="dictOptions"></online-query-form-item>
  19. </a-col>
  20. </template>
  21. <template v-else>
  22. <a-col :md="8" :sm="24" :key=" 'query'+index ">
  23. <online-query-form-item :queryParam="queryParam" :item="item" :dictOptions="dictOptions"></online-query-form-item>
  24. </a-col>
  25. </template>
  26. </template>
  27. <a-col :md="8" :sm="8">
  28. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  29. <a-button type="primary" @click="searchByquery" icon="search">查询</a-button>
  30. <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
  31. <a @click="handleToggleSearch" style="margin-left: 8px">
  32. {{ toggleSearchStatus ? '收起' : '展开' }}
  33. <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
  34. </a>
  35. </span>
  36. </a-col>
  37. </a-row>
  38. </a-form>
  39. </div>
  40. <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  41. <i class="anticon anticon-info-circle ant-alert-icon"></i>
  42. 已选择&nbsp;<a style="font-weight: 600">{{ table.selectedRowKeys.length }}</a>项&nbsp;&nbsp;
  43. <a style="margin-left: 24px" @click="onClearSelected">清空</a>
  44. <a v-if="!showSearchFlag" style="margin-left: 24px" @click="onlyReload">刷新</a>
  45. </div>
  46. <a-table
  47. ref="table"
  48. size="middle"
  49. bordered
  50. :rowKey="combineRowKey"
  51. :columns="table.columns"
  52. :dataSource="table.dataSource"
  53. :pagination="table.pagination"
  54. :loading="table.loading"
  55. :rowSelection="{type:rowSelectionType,fixed:true,selectedRowKeys: table.selectedRowKeys, onChange: handleChangeInTableSelect}"
  56. @change="handleChangeInTable"
  57. style="min-height: 300px"
  58. :scroll="tableScroll"
  59. :customRow="clickThenCheck">
  60. </a-table>
  61. </j-modal>
  62. </template>
  63. <script>
  64. import { getAction } from '@/api/manage'
  65. import {filterObj} from '@/utils/util'
  66. import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
  67. import { httpGroupRequest } from '@/api/GroupRequest.js'
  68. import md5 from 'md5'
  69. import OnlineQueryFormItem from '@/components/online/autoform/OnlineQueryFormItem.vue'
  70. const MODAL_WIDTH = 1200;
  71. export default {
  72. name: 'JPopupOnlReport',
  73. props: ['multi', 'code', 'sorter', 'groupId', 'param'],
  74. components:{
  75. OnlineQueryFormItem
  76. },
  77. data(){
  78. return {
  79. visible:false,
  80. title:"",
  81. confirmLoading:false,
  82. queryInfo:[],
  83. toggleSearchStatus:false,
  84. queryParam:{
  85. },
  86. dictOptions:[],
  87. dictOptions1: {
  88. spzt:[{
  89. text:'已审批',
  90. title: "已审批",
  91. value: "ysp",
  92. }]
  93. },
  94. url: {
  95. getColumns: '/online/cgreport/api/getRpColumns/',
  96. getData: '/online/cgreport/api/getData/',
  97. getQueryInfo: '/online/cgreport/api/getQueryInfo/'
  98. },
  99. table: {
  100. loading: true,
  101. // 表头
  102. columns: [],
  103. //数据集
  104. dataSource: [],
  105. // 选择器
  106. selectedRowKeys: [],
  107. selectionRows: [],
  108. // 分页参数
  109. pagination: {
  110. current: 1,
  111. pageSize: 10,
  112. pageSizeOptions: ['10', '20', '30'],
  113. showTotal: (total, range) => {
  114. return range[0] + '-' + range[1] + ' 共' + total + '条'
  115. },
  116. showQuickJumper: true,
  117. showSizeChanger: true,
  118. total: 0
  119. }
  120. },
  121. cgRpConfigId:"",
  122. modalWidth:MODAL_WIDTH,
  123. tableScroll:{x:true},
  124. dynamicParam:{},
  125. // 排序字段,默认无排序
  126. iSorter: null,
  127. }
  128. },
  129. mounted() {
  130. this.loadColumnsInfo()
  131. },
  132. watch: {
  133. code() {
  134. this.loadColumnsInfo()
  135. },
  136. param:{
  137. deep:true,
  138. handler(){
  139. // update--begin--autor:liusq-----date:20210706------for:JPopup组件在modal中使用报错#2729------
  140. if(this.visible){
  141. this.dynamicParamHandler()
  142. this.loadData();
  143. }
  144. // update--begin--autor:liusq-----date:20210706------for:JPopup组件在modal中使用报错#2729------
  145. },
  146. },
  147. sorter: {
  148. immediate: true,
  149. handler() {
  150. if (this.sorter) {
  151. let arr = this.sorter.split('=')
  152. if (arr.length === 2 && ['asc', 'desc'].includes(arr[1].toLowerCase())) {
  153. this.iSorter = {column: arr[0], order: arr[1].toLowerCase()}
  154. // 排序字段受控
  155. this.table.columns.forEach(col => {
  156. if (col.dataIndex === this.iSorter.column) {
  157. this.$set(col, 'sortOrder', this.iSorter.order === 'asc' ? 'ascend' : 'descend')
  158. } else {
  159. this.$set(col, 'sortOrder', false)
  160. }
  161. })
  162. } else {
  163. console.warn('【JPopup】sorter参数不合法')
  164. }
  165. }
  166. },
  167. },
  168. },
  169. computed:{
  170. showSearchFlag(){
  171. return this.queryInfo && this.queryInfo.length>0
  172. },
  173. // 行选择框类型,根据是否多选来控制显示为单选框还是多选框
  174. rowSelectionType() {
  175. return this.multi ? 'checkbox' : 'radio'
  176. },
  177. },
  178. methods:{
  179. loadColumnsInfo(){
  180. let url = `${this.url.getColumns}${this.code}`
  181. //缓存key
  182. let groupIdKey
  183. if (this.groupId) {
  184. groupIdKey = this.groupId + url
  185. }
  186. httpGroupRequest(() => getAction(url), groupIdKey).then(res => {
  187. if(res.success){
  188. this.initDictOptionData(res.result.dictOptions);
  189. this.cgRpConfigId = res.result.cgRpConfigId
  190. this.title = res.result.cgRpConfigName
  191. let currColumns = res.result.columns
  192. for(let a=0;a<currColumns.length;a++){
  193. if(currColumns[a].customRender){
  194. let dictCode = currColumns[a].customRender;
  195. currColumns[a].customRender=(text)=>{
  196. return filterMultiDictText(this.dictOptions[dictCode], text+"");
  197. }
  198. }
  199. // 排序字段受控
  200. if (this.iSorter && currColumns[a].dataIndex === this.iSorter.column) {
  201. currColumns[a].sortOrder = this.iSorter.order === 'asc' ? 'ascend' : 'descend'
  202. }
  203. }
  204. this.table.columns = [...currColumns]
  205. this.initQueryInfo()
  206. } else {
  207. this.$error({
  208. title: '出错了',
  209. content: (<p>Popup初始化失败,请检查你的配置或稍后重试!<br/>错误信息如下:{res.message}</p>),
  210. onOk: () => this.close(),
  211. })
  212. }
  213. })
  214. },
  215. initQueryInfo() {
  216. let url = `${this.url.getQueryInfo}${this.cgRpConfigId}`
  217. //缓存key
  218. let groupIdKey
  219. if (this.groupId) {
  220. groupIdKey = this.groupId + url
  221. }
  222. httpGroupRequest(() => getAction(url), groupIdKey).then((res) => {
  223. // console.log("获取查询条件", res);
  224. if (res.success) {
  225. this.dynamicParamHandler(res.result)
  226. this.queryInfo = res.result
  227. console.log(this.queryInfo)
  228. //查询条件加载后再请求数据
  229. this.loadData(1)
  230. } else {
  231. this.$message.warning(res.message)
  232. }
  233. })
  234. },
  235. //处理动态参数
  236. dynamicParamHandler(arr){
  237. if(arr && arr.length>0){
  238. //第一次加载查询条件前 初始化queryParam为空对象
  239. let queryTemp = {}
  240. for(let item of arr){
  241. if(item.mode==='single'){
  242. queryTemp[item.field] = ''
  243. }
  244. }
  245. this.queryParam = {...queryTemp}
  246. }
  247. let dynamicTemp = {}
  248. if(this.param){
  249. Object.keys(this.param).map(key=>{
  250. let str = this.param[key]
  251. if(key in this.queryParam){
  252. if(str && str.startsWith("'") && str.endsWith("'")){
  253. str = str.substring(1,str.length-1)
  254. }
  255. //如果查询条件包含参数 设置值
  256. this.queryParam[key]=str
  257. }
  258. dynamicTemp[key] = this.param[key]
  259. })
  260. }
  261. this.dynamicParam = {...dynamicTemp}
  262. },
  263. loadData(arg) {
  264. if (arg == 1) {
  265. this.table.pagination.current = 1
  266. }
  267. let params = this.getQueryParams();//查询条件
  268. this.table.loading = true
  269. let url = `${this.url.getData}${this.cgRpConfigId}`
  270. //缓存key
  271. let groupIdKey
  272. if (this.groupId) {
  273. groupIdKey = this.groupId + url + JSON.stringify(params)
  274. }
  275. httpGroupRequest(() => getAction(url, params), groupIdKey).then(res => {
  276. this.table.loading = false
  277. // console.log("daa",res)
  278. let data = res.result
  279. if (data) {
  280. this.table.pagination.total = Number(data.total)
  281. this.table.dataSource = data.records
  282. } else {
  283. this.table.pagination.total = 0
  284. this.table.dataSource = []
  285. }
  286. })
  287. },
  288. getQueryParams() {
  289. let paramTarget = {}
  290. if(this.dynamicParam){
  291. //处理自定义参数
  292. Object.keys(this.dynamicParam).map(key=>{
  293. paramTarget['self_'+key] = this.dynamicParam[key]
  294. })
  295. }
  296. let param = Object.assign(paramTarget, this.queryParam, this.iSorter);
  297. param.pageNo = this.table.pagination.current;
  298. param.pageSize = this.table.pagination.pageSize;
  299. return filterObj(param);
  300. },
  301. handleChangeInTableSelect(selectedRowKeys, selectionRows) {
  302. //update-begin-author:taoyan date:2020902 for:【issue】开源online的几个问题 LOWCOD-844
  303. if(!selectedRowKeys || selectedRowKeys.length==0){
  304. this.table.selectionRows = []
  305. }else if(selectedRowKeys.length == selectionRows.length){
  306. this.table.selectionRows = selectionRows
  307. }else{
  308. //当两者长度不一的时候 需要判断
  309. let keys = this.table.selectedRowKeys
  310. let rows = this.table.selectionRows;
  311. //这个循环 添加新的记录
  312. for(let i=0;i<selectionRows.length;i++){
  313. let combineKey = this.combineRowKey(selectionRows[i])
  314. if(keys.indexOf(combineKey)<0){
  315. //如果 原来的key 不包含当前记录 push
  316. rows.push(selectionRows[i])
  317. }
  318. }
  319. //这个循环 移除取消选中的数据
  320. this.table.selectionRows = rows.filter(item=>{
  321. let combineKey = this.combineRowKey(item)
  322. return selectedRowKeys.indexOf(combineKey)>=0
  323. })
  324. }
  325. //update-end-author:taoyan date:2020902 for:【issue】开源online的几个问题 LOWCOD-844
  326. this.table.selectedRowKeys = selectedRowKeys
  327. },
  328. handleChangeInTable(pagination, filters, sorter) {
  329. //分页、排序、筛选变化时触发
  330. if (Object.keys(sorter).length > 0) {
  331. this.iSorter = {
  332. column: sorter.field,
  333. order: 'ascend' === sorter.order ? 'asc' : 'desc'
  334. }
  335. // 排序字段受控
  336. this.table.columns.forEach(col => {
  337. if (col.dataIndex === sorter.field) {
  338. this.$set(col, 'sortOrder',sorter.order)
  339. } else {
  340. this.$set(col, 'sortOrder', false)
  341. }
  342. })
  343. }
  344. this.table.pagination = pagination
  345. this.loadData()
  346. },
  347. handleCancel() {
  348. this.close()
  349. },
  350. handleSubmit() {
  351. if(!this.multi){
  352. if(this.table.selectionRows && this.table.selectionRows.length>1){
  353. this.$message.warning("请选择一条记录")
  354. return false
  355. }
  356. }
  357. if(!this.table.selectionRows || this.table.selectionRows.length==0){
  358. this.$message.warning("请选择一条记录")
  359. return false
  360. }
  361. this.$emit('ok', this.table.selectionRows);
  362. this.close()
  363. },
  364. close() {
  365. this.$emit('close');
  366. this.visible = false;
  367. this.onClearSelected()
  368. },
  369. show(){
  370. this.visible = true
  371. this.loadColumnsInfo()
  372. },
  373. handleToggleSearch(){
  374. this.toggleSearchStatus = !this.toggleSearchStatus;
  375. },
  376. searchByquery(){
  377. this.loadData(1);
  378. },
  379. onlyReload(){
  380. this.loadData();
  381. },
  382. searchReset(){
  383. Object.keys(this.queryParam).forEach(key=>{
  384. this.queryParam[key]=""
  385. })
  386. this.loadData(1);
  387. },
  388. onClearSelected(){
  389. this.table.selectedRowKeys = []
  390. this.table.selectionRows = []
  391. },
  392. combineRowKey(record){
  393. let res = ''
  394. Object.keys(record).forEach(key=>{
  395. //update-begin---author:liusq Date:20210203 for:pop选择器列主键问题 issues/I29P9Q------------
  396. if(key=='id'){
  397. res=record[key]+res
  398. }else{
  399. res+=record[key]
  400. }
  401. //update-end---author:liusq Date:20210203 for:pop选择器列主键问题 issues/I29P9Q------------
  402. })
  403. // update-begin---author:taoyan Date:20211025 for:jpopup 表格key重复BUG /issues/3121
  404. res = md5(res)
  405. /*if(res.length>50){
  406. res = res.substring(0,50)
  407. }*/
  408. // update-end---author:taoyan Date:20211025 for:jpopup 表格key重复BUG /issues/3121
  409. return res
  410. },
  411. clickThenCheck(record){
  412. return {
  413. on: {
  414. click: () => {
  415. let rowKey = this.combineRowKey(record)
  416. if(!this.table.selectedRowKeys || this.table.selectedRowKeys.length==0){
  417. let arr1=[],arr2=[]
  418. arr1.push(record)
  419. arr2.push(rowKey)
  420. this.table.selectedRowKeys=arr2
  421. this.table.selectionRows=arr1
  422. }else{
  423. if(this.table.selectedRowKeys.indexOf(rowKey)<0){
  424. this.table.selectedRowKeys.push(rowKey)
  425. this.table.selectionRows.push(record)
  426. }else{
  427. let rowKey_index = this.table.selectedRowKeys.indexOf(rowKey)
  428. this.table.selectedRowKeys.splice(rowKey_index,1);
  429. this.table.selectionRows.splice(rowKey_index,1);
  430. }
  431. }
  432. // 判断是否允许多选,如果不允许多选,就只存储最后一个选中的行
  433. if (!this.multi && this.table.selectedRowKeys.length > 1) {
  434. this.table.selectionRows = [this.table.selectionRows.pop()]
  435. this.table.selectedRowKeys = [this.table.selectedRowKeys.pop()]
  436. }
  437. }
  438. }
  439. }
  440. },
  441. //防止字典中有垃圾数据
  442. initDictOptionData(dictOptions){
  443. let obj = { }
  444. Object.keys(dictOptions).map(k=>{
  445. obj[k] = dictOptions[k].filter(item=>{
  446. return item!=null
  447. });
  448. });
  449. this.dictOptions = obj
  450. }
  451. }
  452. }
  453. </script>
  454. <style scoped>
  455. </style>