king
2024-05-21 8a6ce370f1aa1c061b76fa3e9d2d4d1df53ca4c5
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { notification, Select, Divider, Modal } from 'antd'
import { PlusOutlined } from '@ant-design/icons'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const { Option } = Select
const { confirm } = Modal
 
class AccountModule extends Component {
  static propTpyes = {
    config: PropTypes.object
  }
 
  state = {
    activeItem: null,
    books: []
  }
 
  componentDidMount () {
    this.loadData()
    MKEmitter.addListener('reloadData', this.reloadData)
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
  }
 
  reloadData = (menuId) => {
    const { config } = this.props
    const { activeItem } = this.state
    
    if (config.uuid !== menuId) return
 
    if (activeItem) {
      MKEmitter.emit('resetSelectLine', config.uuid, activeItem.id, activeItem)
    } else {
      this.loadData()
    }
  }
 
  loadData = () => {
    let param = {
      func: 's_get_fcc_book_data',
      dataM: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
      mk_organization: sessionStorage.getItem('organization') || ''
    }
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
 
      let books = res.book || []
      let activeItem = null
      let map = new Map()
      books = books.filter(item => {
        if (!item.id) return false
        if (map.has(item.id)) return false
        map.set(item.id, true)
 
        if (item.selected === 'true' && !activeItem) {
          if (res.invoice_type) {
            item.invoice_type = res.invoice_type.map(cell => ({value: cell.invoice_type_code, label: cell.invoice_type_name}))
          }
          item.$$uuid = item.id
          activeItem = item
        }
        if (item.months) {
          item.date = item.months.replace('-', '年') + '月'
        }
        return true
      })
 
      this.setState({books, activeItem})
 
      if (activeItem) {
        MKEmitter.emit('resetSelectLine', this.props.config.uuid, activeItem.id, activeItem)
      }
    })
  }
 
  changeBook = (value) => {
    const { books, activeItem } = this.state
 
    let Item = books.filter(item => item.id === value)[0]
 
    if (!activeItem && Item) {
      this.setBook(Item)
    } else if (Item) {
      const that = this
      confirm({
        title: '确定切换账套吗?',
        content: '切换账套时系统需要刷新。',
        onOk() {
          return new Promise(resolve => {
            that.setBook(Item, resolve)
          })
        },
        onCancel() {}
      })
    }
  }
 
  setBook = (item, resolve) => {
    const { config } = this.props
 
    if (!resolve) {
      this.setState({activeItem: item})
  
      MKEmitter.emit('resetSelectLine', config.uuid, item.id, item)
    }
    
    let userid = sessionStorage.getItem('UserID') || ''
    let sid = localStorage.getItem('SessionUid') || ''
    let param = {
      func: 'sPC_TableData_InUpDe',
      LText: `delete  tmp_session_show_key where createuserid='${userid}' and key_type='fcc_years'
        insert into tmp_session_show_key ( key_id,key_type,createuserid,CreateUser,CreateStaff) 
        select '${item.id}','fcc_years','${userid}','${sid}','${sessionStorage.getItem('Full_Name') || ''}'`,
      exec_type:  window.GLOB.execType || 'y'
    }
 
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
    param.LText = Utils.formatOptions(param.LText, param.exec_type)
 
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        resolve && resolve()
        return
      }
 
      if (resolve) {
        sessionStorage.setItem('ThirdMenu', config.$pageId)
        window.location.reload()
      }
    })
  }
 
  addBook = () => {
    const { config } = this.props
 
    let menu = {
      MenuID: config.wrap.MenuID,
      MenuName: config.wrap.MenuName,
      type: config.wrap.tabType,
      param: {}
    }
 
    if (window.GLOB.mkThdMenus.has(config.wrap.MenuID)) {
      menu = {...window.GLOB.mkThdMenus.get(config.wrap.MenuID), param: {}}
    }
 
    MKEmitter.emit('modifyTabs', menu, true)
  }
 
  render() {
    const { config } = this.props
    const { activeItem, books } = this.state
 
    return (
      <div className="menu-account-wrap" style={config.style}>
        {config.wrap.MenuID ? <Select dropdownMatchSelectWidth={false} showSearch filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} value={activeItem ? activeItem.id : ''} placeholder="请选择账套" onChange={this.changeBook} dropdownRender={menu => (
          <div>
            {menu}
            <Divider style={{ margin: '4px 0' }} />
            <div className="mk-add-book" onMouseDown={this.addBook}>
              <PlusOutlined /> 点击新增账套
            </div>
          </div>
        )}>
          {books.map(item => (
            <Option disabled={!item.months} title={item.account_name} key={item.id}>{item.account_name}</Option>
          ))}
        </Select> : <Select dropdownMatchSelectWidth={false} showSearch filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} value={activeItem ? activeItem.id : ''} disabled={config.wrap.readonly === 'true'} placeholder="请选择账套" onChange={this.changeBook}>
          {books.map(item => (
            <Option disabled={!item.months} title={item.account_name} key={item.id}>{item.account_name}</Option>
          ))}
        </Select>}
        {activeItem ? <span className="date">{activeItem.date}</span> : null}
      </div>
    )
  }
}
 
export default AccountModule