king
2022-07-26 1e3e316b0d64a04fade0a006bec78475dddc06bd
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Modal, notification, Spin } from 'antd'
import { UnlockOutlined } from '@ant-design/icons'
 
import Api from '@/api'
import MKEmitter from '@/utils/events.js'
import TransferForm from '@/templates/zshare/basetransferform'
 
class ThawMenu extends Component {
  static propTpyes = {
    ParentId: PropTypes.string,
    Type: PropTypes.string
  }
 
  state = {
    visible: false,
    targetKeys: [],
    menulist: null,
    loading: false
  }
 
  trigger = () => {
    this.setState({
      visible: true,
      targetKeys: [],
      menulist: null,
      loading: false
    })
 
    Api.getSystemConfig({
      func: 'sPC_Get_FrozenMenu',
      ParentID: this.props.ParentId,
      TYPE: +this.props.Type
    }).then(res => {
      if (res.status) {
        this.setState({
          menulist: res.data.map(menu => {
            return {
              key: menu.MenuID,
              title: menu.MenuName
            }
          })
        })
      } else {
        this.setState({
          menulist: []
        })
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      }
    })
    this.setState({visible: true})
  }
 
  submit = () => {
    const { targetKeys } = this.state
    // 三级菜单解除冻结
    if (targetKeys.length === 0) {
      notification.warning({
        top: 92,
        message: this.state.dict['form.required.select'] + this.state.dict['model.menu'],
        duration: 5
      })
      return
    }
 
    this.setState({
      loading: true
    })
    let defers = targetKeys.map(item => {
      return new Promise((resolve) => {
        Api.getSystemConfig({
          func: 'sPC_MainMenu_ReDel',
          MenuID: item
        }).then(res => {
          if (res.status) {
            resolve('')
          } else {
            resolve(res.message)
          }
        })
      })
    })
    Promise.all(defers).then(res => {
      let msg = res.filter(Boolean)[0]
      if (msg) {
        notification.error({
          top: 92,
          message: msg,
          duration: 10
        })
      } else {
        this.setState({
          loading: false,
          visible: false,
          targetKeys: [],
          thawmenulist: null
        })
 
        MKEmitter.emit('mkUpdateMenuList')
      }
    })
  }
 
  render() {
    const { visible, menulist, loading } = this.state
 
    return (
      <>
        <UnlockOutlined onClick={this.trigger} style={{color: 'orange'}}/>
        <Modal
          title="解冻菜单"
          visible={visible}
          width={600}
          onOk={this.submit}
          confirmLoading={loading}
          onCancel={() => this.setState({visible: false})}
          destroyOnClose
        >
          {!menulist ?
            <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" /> :
            <TransferForm onChange={(vals) => this.setState({targetKeys: vals})} menulist={menulist}/>
          }
        </Modal>
      </>
    )
  }
}
 
export default ThawMenu