king
2024-04-22 fc8c8d714687a22f711d642d192bd4149f3b7e88
src/tabviews/custom/components/module/account/index.jsx
@@ -1,14 +1,17 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { notification, Select, Divider } from 'antd'
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 = {
@@ -22,6 +25,7 @@
  componentDidMount () {
    this.loadData()
    MKEmitter.addListener('reloadData', this.reloadData)
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -35,11 +39,27 @@
    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'
      func: 's_get_fcc_book_data',
      dataM: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
      mk_organization: sessionStorage.getItem('organization') || ''
    }
    Api.genericInterface(param).then(res => {
@@ -61,6 +81,9 @@
        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}))
          }
          activeItem = item
        }
        if (item.months) {
@@ -68,10 +91,6 @@
        }
        return true
      })
      if (!activeItem && books.length > 0) {
        activeItem = books[0]
      }
      this.setState({books, activeItem})
@@ -82,38 +101,83 @@
  }
  changeBook = (value) => {
    const { books } = this.state
    const { books, activeItem } = this.state
    let activeItem = books.filter(item => item.id === value)[0]
    let Item = books.filter(item => item.id === value)[0]
    this.setState({activeItem})
    if (activeItem) {
      MKEmitter.emit('resetSelectLine', this.props.config.uuid, activeItem.id, activeItem)
    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 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,
    let menu = {
      MenuID: config.wrap.MenuID,
      MenuName: config.wrap.MenuName,
      type: config.wrap.tabType,
      param: {}
    }
    MKEmitter.emit('modifyTabs', newtab, true)
    if (window.GLOB.mkThdMenus.has(config.wrap.MenuID)) {
      menu = {...window.GLOB.mkThdMenus.get(config.wrap.MenuID), param: {}}
    }
    MKEmitter.emit('modifyTabs', menu, true)
  }
  render() {
@@ -122,7 +186,7 @@
    return (
      <div className="menu-account-wrap" style={config.style}>
        {config.wrap.MenuID ? <Select value={activeItem ? activeItem.id : ''} placeholder="请选择账套" onChange={this.changeBook} dropdownRender={menu => (
        {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' }} />
@@ -132,11 +196,11 @@
          </div>
        )}>
          {books.map(item => (
            <Option key={item.id}>{item.account_name}</Option>
            <Option disabled={!item.months} title={item.account_name} key={item.id}>{item.account_name}</Option>
          ))}
        </Select> : <Select value={activeItem ? activeItem.id : ''} placeholder="请选择账套" onChange={this.changeBook}>
        </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 key={item.id}>{item.account_name}</Option>
            <Option disabled={!item.months} title={item.account_name} key={item.id}>{item.account_name}</Option>
          ))}
        </Select>}
        {activeItem ? <span className="date">{activeItem.date}</span> : null}