king
2021-10-14 b5c96c82c04f57d1d0e1e04d96e99e6d7829881f
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
 
import Utils from '@/utils/utils.js'
import ColumnForm from './columnform'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
 
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
 
class CardMenus extends Component {
  static propTpyes = {
    appType: PropTypes.string,
    menulist: PropTypes.array,
    menus: PropTypes.array,
    update: PropTypes.func
  }
 
  state = {
    columns: [
      {
        title: '标识',
        dataIndex: 'sign',
        inputType: 'input',
        editable: true,
        unique: true,
        required: false,
        width: '30%'
      },
      {
        title: '菜单',
        dataIndex: 'menu',
        inputType: !this.props.appType ? 'cascader' : 'select',
        editable: true,
        required: true,
        width: '40%',
        render: (text, record) => record.label,
        options: this.props.menulist
      }
    ]
  }
 
  UNSAFE_componentWillMount() {
    const { menus } = this.props
 
    this.setState({
      menus: fromJS(menus).toJS()
    })
  }
 
  columnChange = (values) => {
    const { menus } = this.state
    values.uuid = Utils.getuuid()
    let _menus = [...menus, values]
 
    this.setState({menus: _menus})
    this.props.update(_menus)
  }
 
  changeColumns = (columns) => {
    const { appType, menulist } = this.props
    const { menus } = this.state
 
    let m = {}
    menus.forEach(item => {
      m[item.uuid] = item
    })
 
    columns = columns.map(col => {
      let ori = m[col.uuid]
      if (ori && is(fromJS({...col, $index: 1}), fromJS({...ori, $index: 1}))) return col
      if (!appType) {
        let fId = col.menu[0] || ''
        let sId = col.menu[1] || ''
        let tId = col.menu[2] || ''
        let label = ''
        
        menulist.forEach(f => {
          if (!fId || fId !== f.value) return
          label = f.label
 
          f.children.forEach(s => {
            if (!sId || sId !== s.value) return
            label += ' / ' + s.label
 
            s.children.forEach(t => {
              if (!tId || tId !== t.value) return
              label += ' / ' + t.label
 
              col.MenuID = t.MenuID
              col.MenuName = t.MenuName
              col.MenuNo = t.MenuNo
              col.tabType = t.type
              col.label = label
            })
          })
        })
      } else {
        menulist.forEach(f => {
          if (col.menu !== f.value) return
          col.label = f.label
        })
      }
      return col
    })
    
    this.setState({menus: columns})
    this.props.update(columns)
  }
 
  render() {
    const { appType, menulist } = this.props
    const { menus, columns } = this.state
 
    return (
      <div className="menus-box-wrap">
        <ColumnForm appType={appType} menus={menus} menulist={menulist} columnChange={this.columnChange}/>
        <EditTable actions={['edit', 'move', 'copy', 'del']} type={appType + 'cardmenus'} data={menus} columns={columns} onChange={this.changeColumns}/>
      </div>
    )
  }
}
 
export default CardMenus