278f6d0bfd11bc5aa419ae012c53461a35352a5f.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. let i;
  346. for (i = 0; i < this.queryInfo.length; i++) {
  347. this.queryParam[this.queryInfo[i].field] = '*' + this.queryParam[this.queryInfo[i].field] + '*'
  348. }
  349. this.loadData();
  350. for (i = 0; i < this.queryInfo.length; i++) {
  351. this.queryParam[this.queryInfo[i].field] = this.queryParam[this.queryInfo[i].field].replace(/\*/g, '')
  352. }
  353. },
  354. handleCancel() {
  355. this.close()
  356. },
  357. handleSubmit() {
  358. if(!this.multi){
  359. if(this.table.selectionRows && this.table.selectionRows.length>1){
  360. this.$message.warning("请选择一条记录")
  361. return false
  362. }
  363. }
  364. if(!this.table.selectionRows || this.table.selectionRows.length==0){
  365. this.$message.warning("请选择一条记录")
  366. return false
  367. }
  368. this.$emit('ok', this.table.selectionRows);
  369. this.close()
  370. },
  371. close() {
  372. this.$emit('close');
  373. this.visible = false;
  374. this.onClearSelected()
  375. },
  376. show(){
  377. this.visible = true
  378. this.loadColumnsInfo()
  379. },
  380. handleToggleSearch(){
  381. this.toggleSearchStatus = !this.toggleSearchStatus;
  382. },
  383. searchByquery(){
  384. let i;
  385. for (i = 0; i < this.queryInfo.length; i++) {
  386. this.queryParam[this.queryInfo[i].field] = '*' + this.queryParam[this.queryInfo[i].field] + '*'
  387. }
  388. this.loadData(1);
  389. for (i = 0; i < this.queryInfo.length; i++) {
  390. this.queryParam[this.queryInfo[i].field] = this.queryParam[this.queryInfo[i].field].replace(/\*/g, '')
  391. }
  392. },
  393. onlyReload(){
  394. this.loadData();
  395. },
  396. searchReset(){
  397. Object.keys(this.queryParam).forEach(key=>{
  398. this.queryParam[key]=""
  399. })
  400. this.loadData(1);
  401. },
  402. onClearSelected(){
  403. this.table.selectedRowKeys = []
  404. this.table.selectionRows = []
  405. },
  406. combineRowKey(record){
  407. let res = ''
  408. Object.keys(record).forEach(key=>{
  409. //update-begin---author:liusq Date:20210203 for:pop选择器列主键问题 issues/I29P9Q------------
  410. if(key=='id'){
  411. res=record[key]+res
  412. }else{
  413. res+=record[key]
  414. }
  415. //update-end---author:liusq Date:20210203 for:pop选择器列主键问题 issues/I29P9Q------------
  416. })
  417. // update-begin---author:taoyan Date:20211025 for:jpopup 表格key重复BUG /issues/3121
  418. res = md5(res)
  419. /*if(res.length>50){
  420. res = res.substring(0,50)
  421. }*/
  422. // update-end---author:taoyan Date:20211025 for:jpopup 表格key重复BUG /issues/3121
  423. return res
  424. },
  425. clickThenCheck(record){
  426. return {
  427. on: {
  428. click: () => {
  429. let rowKey = this.combineRowKey(record)
  430. if(!this.table.selectedRowKeys || this.table.selectedRowKeys.length==0){
  431. let arr1=[],arr2=[]
  432. arr1.push(record)
  433. arr2.push(rowKey)
  434. this.table.selectedRowKeys=arr2
  435. this.table.selectionRows=arr1
  436. }else{
  437. if(this.table.selectedRowKeys.indexOf(rowKey)<0){
  438. this.table.selectedRowKeys.push(rowKey)
  439. this.table.selectionRows.push(record)
  440. }else{
  441. let rowKey_index = this.table.selectedRowKeys.indexOf(rowKey)
  442. this.table.selectedRowKeys.splice(rowKey_index,1);
  443. this.table.selectionRows.splice(rowKey_index,1);
  444. }
  445. }
  446. // 判断是否允许多选,如果不允许多选,就只存储最后一个选中的行
  447. if (!this.multi && this.table.selectedRowKeys.length > 1) {
  448. this.table.selectionRows = [this.table.selectionRows.pop()]
  449. this.table.selectedRowKeys = [this.table.selectedRowKeys.pop()]
  450. }
  451. }
  452. }
  453. }
  454. },
  455. //防止字典中有垃圾数据
  456. initDictOptionData(dictOptions){
  457. let obj = { }
  458. Object.keys(dictOptions).map(k=>{
  459. obj[k] = dictOptions[k].filter(item=>{
  460. return item!=null
  461. });
  462. });
  463. this.dictOptions = obj
  464. }
  465. }
  466. }
  467. </script>
  468. <style scoped>
  469. </style>