king
2023-02-09 79912db1a0f20a0bad10dd8afb63f8d73fbed5d8
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
import React, { useState } from 'react'
import { useDrop } from 'react-dnd'
import { is, fromJS } from 'immutable'
import update from 'immutability-helper'
import { Col, Button, Popover } from 'antd'
import { EditOutlined } from '@ant-design/icons'
 
import Utils from '@/utils/utils.js'
import Card from './card'
import './index.scss'
 
const Container = ({list, setting, handleList, handleMenu, deleteMenu, handleSetting }) => {
  const [cards, setCards] = useState(list)
  const moveCard = (id, atIndex) => {
    const { card, index } = findCard(id)
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    handleList(_cards)
  }
 
  if (!is(fromJS(cards), fromJS(list))) {
    setCards(list)
  }
  
  const findCard = id => {
    const card = cards.filter(c => `${c.uuid}` === id)[0]
    return {
      card,
      index: cards.indexOf(card),
    }
  }
 
  const editCard = id => {
    const { card } = findCard(id)
    handleMenu(card)
  }
  
 
  const delCard = id => {
    const { card } = findCard(id)
    deleteMenu(card)
  }
 
  const copyCard = id => {
    const { card } = findCard(id)
    let copycard = fromJS(card).toJS()
 
    copycard.uuid = Utils.getuuid()
    copycard.origin = false
    copycard.copyType = 'search'
    copycard.focus = true
 
    let _val = fromJS(copycard).toJS()
 
    try {
      delete _val.$srcId
 
      let srcid = localStorage.getItem(window.location.href.split('#')[0] + 'srcId')
      if (srcid) {
        _val.$srcId = srcid
      }
 
      _val.uuid = Utils.getuuid()
      _val = window.btoa(window.encodeURIComponent(JSON.stringify(_val)))
    } catch (e) {
      console.warn('Stringify Failure')
      _val = ''
    }
 
    if (_val) {
      let oInput = document.createElement('input')
      oInput.value = _val
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      document.body.removeChild(oInput)
    }
 
    const { index: overIndex } = findCard(id)
 
    const _cards = update(cards, { $splice: [[overIndex + 1, 0, copycard]] })
 
    handleList(_cards, copycard)
  }
 
  const [, drop] = useDrop({
    accept: 'search',
    drop(item) {
      if (item.hasOwnProperty('originalIndex')) {
        return
      }
 
      let newcard = {}
      newcard.uuid = Utils.getuuid()
      newcard.focus = true
 
      newcard.label = 'label'
      newcard.initval = ''
      newcard.type = item.subType
      newcard.resourceType = '0'
      newcard.options = []
      newcard.orderType = 'asc'
      
      let _match = 'like'
      if (item.subType === 'select' || item.subType === 'link' || item.subType === 'checkcard') {
        _match = '='
      } else if (item.subType === 'date' || item.subType === 'datemonth') {
        _match = '>='
      } else if (item.subType === 'dateweek' || item.subType === 'daterange') {
        _match = 'between'
      } else if (item.subType === 'group') {
        _match = 'between'
        newcard.items = ['day', 'week', 'month', 'quarter', 'year', 'customized']
      }
      
      newcard.match = _match
 
      let targetId = ''
 
      if (item.dropTargetId) {
        targetId = item.dropTargetId
        delete item.dropTargetId
      } else if (cards.length > 0) {
        targetId = cards[cards.length - 1].uuid
      }
 
      const { index: overIndex, card } = findCard(`${targetId}`)
 
      if (card) {
        newcard.ratio = card.ratio || 6
        newcard.labelwidth = card.labelwidth || 33.3
      }
 
      const _cards = update(cards, { $splice: [[overIndex + 1, 0, newcard]] })
 
      handleList(_cards, newcard)
    }
  })
 
  let radio = setting.searchRatio || 6
  let labelwidth = setting.searchLwidth !== undefined ? setting.searchLwidth : 33.3
  let advanceType = setting.advanceType || 'modal'
  let style = {}
  if (setting.borderRadius) {
    style.borderRadius = setting.borderRadius
  }
 
  return (
    <div ref={drop} className="ant-row">
      {cards.map(card => {
        let _ratio = card.ratio || 6
        if (card.advanced === 'true' && advanceType !== 'pulldown') {
          _ratio = 6
        }
        return (
          <Col className="mk-search-item-wrap" key={card.uuid} span={_ratio}>
            <Card
              id={`${card.uuid}`}
              card={card}
              moveCard={moveCard}
              copyCard={copyCard}
              editCard={editCard}
              delCard={delCard}
              findCard={findCard}
            />
          </Col>
        )
      })}
      {cards.length > 0 ? <Col className={'mk-search-item-wrap action ' + (setting.show === 'false' ? 'hide-button' : '')} key="action" span={radio}>
        <div className="ant-row ant-form-item" style={{whiteSpace: 'nowrap', lineHeight: '40px', height: '55px', marginBottom: 0}}>
          <div className="ant-col ant-form-item-label" style={{width: labelwidth + '%'}}></div>
          <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
            <div className="mk-popover-control">
              <EditOutlined className="edit" onClick={() => handleSetting()} />
            </div>
          } trigger="hover">
            <div className="ant-col ant-form-item-control-wrapper">
              <Button style={style} type="primary">搜索</Button>
              <Button style={{ marginLeft: 8, ...style }}>重置</Button>
              <div style={{position: 'absolute', top: 0, bottom: 0, left: 0, right: 0}}></div>
            </div>
          </Popover>
        </div>
      </Col> : null}
      {cards.length === 0 ?
        <div className="common-drawarea-placeholder">
          请添加搜索条件
        </div> : null
      }
    </div>
  )
}
export default Container