king
2024-02-03 131bc212f0cfe964c9a38bbe6178aca4f4a16677
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Modal, notification, Popconfirm } from 'antd'
import { ApartmentOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons'
 
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import MarkForm from './markform'
import './index.scss'
 
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
const { confirm } = Modal
 
class ColsControl extends Component {
  static propTpyes = {
    config: PropTypes.object,
    onSubmit: PropTypes.func
  }
 
  state = {
    searches: [],
    visible: false,
    colsCtrls: [],
    cols: [],
    svalues: {},
    cvalues: {},
    columns: [
      {
        title: '字段',
        dataIndex: 'field',
        width: '18%'
      },
      {
        title: '对比方式',
        dataIndex: 'match',
        width: '18%',
      },
      {
        title: '对比值',
        dataIndex: 'contrastValue',
        width: '18%',
      },
      {
        title: '显示列',
        dataIndex: 'cols',
        width: '24%',
        render: text => {
          return text.length
        }
      },
      {
        title: '操作',
        align: 'center',
        width: '18%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div style={{textAlign: 'center', cursor: 'default'}}>
            <span title="编辑" onClick={() => this.handleEdit(record)} style={{color: '#1890ff', marginRight: '15px', cursor: 'pointer'}}><EditOutlined /></span>
            <Popconfirm
              overlayClassName="popover-confirm"
              title="确定删除吗?"
              onConfirm={() => this.handleDelete(record)
            }>
              <span style={{color: '#ff4d4f', cursor: 'pointer'}}><DeleteOutlined /></span>
            </Popconfirm>
          </div>)
      }
    ]
  }
 
  handleEdit = (record) => {
    this.customForm.edit(record)
  }
 
  markChange = (values) => {
    let colsCtrls = fromJS(this.state.colsCtrls).toJS()
 
    let has = false
 
    if (!values.uuid) {
      colsCtrls.forEach(item => {
        if (item.field.join('') === values.field.join('') && item.match === values.match && item.contrastValue === values.contrastValue) {
          has = true
        }
      })
 
      values.uuid = Utils.getuuid()
      colsCtrls.push(values)
    } else {
      colsCtrls = colsCtrls.map(item => {
        if (values.uuid === item.uuid) {
          return values
        }
 
        if (item.field.join('') === values.field.join('') && item.match === values.match && item.contrastValue === values.contrastValue) {
          has = true
        }
        
        return item
      })
    }
 
    if (has) {
      notification.warning({
        top: 92,
        message: '此设置已存在!',
        duration: 5
      })
      return
    }
 
    this.setState({
      colsCtrls: colsCtrls
    })
  }
 
  handleDelete = (record) => {
    const { colsCtrls } = this.state
 
    this.setState({ colsCtrls: colsCtrls.filter(item => item.uuid !== record.uuid) })
  }
 
  resetMark = () => {
    const { config } = this.props
    const { columns } = this.state
 
    let search = config.search || []
    
    if (config.setting.useMSearch === 'true') { // 使用主搜索条件
      let menu = fromJS(window.GLOB.customMenu).toJS()
      
      let filterComponent = (box, mainSearch) => {
        box.components.forEach(item => {
          if (item.type !== 'search') return
          mainSearch = item.search
        })
        let has = false
        box.components.forEach(item => {
          if (item.uuid === config.uuid) {
            has = true
          } else if (item.type === 'group') {
            item.components.forEach(m => {
              if (m.uuid !== config.uuid) return
              has = true
            })
          }
        })
  
        if (has) {
          search = [...search, ...(mainSearch || [])]
        } else {
          box.components.forEach(item => {
            if (item.type !== 'tabs') return
  
            item.subtabs.forEach(tab => {
              filterComponent(tab, mainSearch)
            })
          })
        }
      }
      filterComponent(menu, null)
    }
 
    let cvalues = {}
    let cols = config.cols.map(item => {
      let types = {custom: '自定义列', colspan: '合并列'}
      let label = types[item.type] ? `${item.label}(${types[item.type]})` : item.label
 
      cvalues[item.uuid] = label
 
      return {
        key: item.uuid,
        title: label
      }
    })
 
    let searches = [{value: 'BID', label: 'BID'}]
    let svalues = {BID: 'BID'}
    search.forEach(item => {
      if (!item.field || item.type === 'group') return
 
      svalues[item.field] = item.label
      searches.push({value: item.field, label: item.label})
    })
 
    let colsCtrls = fromJS(config.colsCtrls || []).toJS()
    colsCtrls = colsCtrls.map(col => {
      col.cols = col.cols.filter(f => !!cvalues[f])
      return col
    })
 
    this.setState({
      cols,
      svalues,
      columns: columns.map(col => {
        if (col.dataIndex === 'field') {
          col.render = (text) => {
            return text.map(cell => svalues[cell] || cell).join('、')
          }
        } else if (col.dataIndex === 'cols') {
          col.render = (text) => {
            return text.map(cell => cvalues[cell] || cell).join('、')
          }
        }
 
        return col
      }),
      visible: true,
      searches: searches,
      colsCtrls: colsCtrls
    })
  }
 
  markSubmit = () => {
    const { config } = this.props
    const { colsCtrls, svalues } = this.state
 
    let _config = fromJS(config).toJS()
    let s = []
    let c = []
 
    colsCtrls.forEach((col, index) => {
      if (col.field.findIndex(f => !svalues[f]) > -1) {
        s.push(index + 1)
      }
      if (col.cols.length === 0) {
        c.push(index + 1)
      }
    })
 
    if (c.length > 0) {
      Modal.warning({
        title: `第 ${c.join('、')} 行中显示列不可为空。`,
        okText: '知道了'
      })
      return
    }
    
    _config.colsCtrls = colsCtrls
 
    if (this.customForm && this.customForm.state.editItem) {
      const _this = this
      let title = '存在未保存项,确定忽略吗?'
      if (s.length > 0) {
        title = `存在未保存项,且第 ${s.join('、')} 行中字段在搜索条件中不存在,确定忽略吗?`
      }
      confirm({
        title: title,
        onOk() {
          _this.setState({ visible: false })
          _this.props.onSubmit(_config)
        },
        onCancel() {}
      })
    } else if (s.length > 0) {
      const _this = this
      confirm({
        title: `第 ${s.join('、')} 行中字段在搜索条件中不存在,确定忽略吗?`,
        onOk() {
          _this.setState({ visible: false })
          _this.props.onSubmit(_config)
        },
        onCancel() {}
      })
    } else {
      this.setState({
        visible: false
      })
      this.props.onSubmit(_config)
    }
  }
 
  render() {
    const { config } = this.props
    const { colsCtrls, columns, visible, cols, searches } = this.state
 
    let className = ''
    if (config.colsCtrls && config.colsCtrls.length) {
      className = 'cols-ctrls'
    }
 
    return (
      <div style={{display: 'inline-block'}} className={className}>
        <ApartmentOutlined style={{color: '#13c2c2'}} title="显示列控制" onClick={this.resetMark} />
        <Modal
          wrapClassName="column-control-modal-wrap"
          title="显示列控制"
          visible={visible}
          width={'75vw'}
          maskClosable={false}
          okText="提交"
          onOk={this.markSubmit}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          <MarkForm columns={cols} searches={searches} markChange={this.markChange} wrappedComponentRef={(inst) => this.customForm = inst}/>
          <EditTable actions={['edit', 'move', 'del']} data={colsCtrls} columns={columns} onChange={(colsCtrls) => this.setState({colsCtrls})}/>
        </Modal>
      </div>
    )
  }
}
 
export default ColsControl