king
2022-12-29 836722dd114fa35967a5e96be96ba4503ebf8e1d
src/tabviews/custom/components/module/account/index.jsx
@@ -1,12 +1,14 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
// import { Button, Select, Input, DatePicker } from 'antd'
// import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined } from '@ant-design/icons'
import { notification, Select, Divider } from 'antd'
import { PlusOutlined } from '@ant-design/icons'
import Api from '@/api'
// import MKEmitter from '@/utils/events.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const { Option } = Select
class AccountModule extends Component {
  static propTpyes = {
@@ -14,37 +16,12 @@
  }
  state = {
    BID: '',
    type: '',
    config: null
  }
  UNSAFE_componentWillMount () {
    const { config } = this.props
    let BID = ''
    let BData = ''
    if (config.wrap.supModule) {
      BData = window.GLOB.CacheData.get(config.wrap.supModule)
    } else {
      BData = window.GLOB.CacheData.get(config.$pageId)
    }
    if (BData) {
      BID = BData.$BID || ''
    }
    this.setState({
      config: fromJS(config).toJS(),
      BID: BID || '',
      type: config.wrap.type
    }, () => {
      this.loadData()
    })
    activeItem: null,
    books: []
  }
  componentDidMount () {
    this.loadData()
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -62,22 +39,107 @@
  loadData = () => {
    let param = {
      func: 's_get_fcc_account_data'
    }
    Api.genericInterface(param)
    let _param = {
      func: 's_get_fcc_book_data'
    }
    Api.genericInterface(_param)
    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) {
          activeItem = item
        }
        if (item.months) {
          item.date = item.months.replace('-', '年') + '月'
        }
        return true
      })
      if (!activeItem && books.length > 0) {
        activeItem = books[0]
      }
      this.setState({books, activeItem})
      if (activeItem) {
        MKEmitter.emit('resetSelectLine', this.props.config.uuid, activeItem.id, activeItem)
      }
    })
  }
  changeBook = (value) => {
    const { books } = this.state
    let activeItem = books.filter(item => item.id === value)[0]
    this.setState({activeItem})
    if (activeItem) {
      MKEmitter.emit('resetSelectLine', this.props.config.uuid, activeItem.id, activeItem)
    }
  }
  addBook = () => {
    const { config } = this.props
    let menuId = config.wrap.MenuID
    let menu = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0]
    if (!menu && config.wrap.MenuNo) {
      menu = {
        MenuID: menuId,
        MenuName: config.wrap.MenuName,
        MenuNo: config.wrap.MenuNo || '',
        type: config.wrap.tabType
      }
    }
    let newtab = {
      ...menu,
      param: {}
    }
    MKEmitter.emit('modifyTabs', newtab, true)
  }
  render() {
    const { config } = this.state
    const { config } = this.props
    const { activeItem, books } = this.state
    return (
      <div className="menu-account-wrap" style={config.style}>
        {config.wrap.MenuID ? <Select 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 key={item.id}>{item.account_name}</Option>
          ))}
        </Select> : <Select value={activeItem ? activeItem.id : ''} placeholder="请选择账套" onChange={this.changeBook}>
          {books.map(item => (
            <Option key={item.id}>{item.account_name}</Option>
          ))}
        </Select>}
        {activeItem ? <span className="date">{activeItem.date}</span> : null}
      </div>
    )
  }