king
2023-02-02 6f817bf3ae4e6f51f982c07b0713adb3caf9fac2
src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
@@ -120,7 +120,10 @@
    editing: false,
    visible: false,
    counting: false,
    priceing: false
    priceing: false,
    curring: false,
    ratioing: false,
    origining: false,
  }
  componentDidMount () {
@@ -174,6 +177,14 @@
      }
    }
    if (line.foreign_currency_type === 'Y' && line.origin) {
      if (line.debtor) {
        line.unitratio = Math.round(line.debtor / line.origin * 100000) / 100000
      } else if (line.creditor) {
        line.unitratio = Math.round(line.creditor / line.origin * 100000) / 100000
      }
    }
    MKEmitter.emit('changeRecord', col.tableId, line)
    setTimeout(() => {
@@ -195,10 +206,8 @@
    if (col.field === 'subjectscode') {
      this.setState({editing: true}, () => {
        try {
          let node = document.getElementById(col.uuid + record.uuid)
          node.click()
        } catch(e) {}
        let node = document.getElementById(col.uuid + record.uuid)
        node && node.click()
      })
    } else {
      this.setState({editing: true, value: record[col.field]}, () => {
@@ -234,6 +243,14 @@
          line.price = Math.round(line.debtor / line.count * 10000) / 10000
        } else if (line.creditor) {
          line.price = Math.round(line.creditor / line.count * 10000) / 10000
        }
      }
      if (line.foreign_currency_type === 'Y' && line.origin) {
        if (line.debtor) {
          line.unitratio = Math.round(line.debtor / line.origin * 100000) / 100000
        } else if (line.creditor) {
          line.unitratio = Math.round(line.creditor / line.origin * 100000) / 100000
        }
      }
@@ -282,6 +299,16 @@
      })
    }
    if (line.foreign_currency_type === 'Y' && line.foreign_currency) {
      let msg = window.GLOB.CacheVoucher.get(col.tableId)
      let cur = msg ? msg.currency.filter(n => n.exratename === line.foreign_currency)[0] : null
      if (cur) {
        line = {...line, ...cur}
      }
      this.currencyChange(line)
    }
    MKEmitter.emit('changeRecord', col.tableId, line)
    if (line.sup_accounting) {
@@ -292,6 +319,11 @@
      this.setState({counting: true, value: line.count || 0}, () => {
        let node = document.getElementById(col.uuid + record.uuid + 'count')
        node && node.select()
      })
    } else if (line.foreign_currency_type === 'Y') {
      this.setState({curring: true}, () => {
        let node = document.getElementById(col.uuid + record.uuid + 'currency')
        node && node.click()
      })
    } else {
      this.setState({editing: false, visible: false, counting: false, priceing: false})
@@ -371,9 +403,7 @@
      line.count = 0
    }
    if (line.count && line.price) {
      line.debtor = Math.round(line.count * line.price * 100) / 100
    }
    this.countChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
@@ -396,9 +426,7 @@
      line.count = 0
    }
    if (line.count && line.price) {
      line.debtor = Math.round(line.count * line.price * 100) / 100
    }
    this.countChange(line)
    
    MKEmitter.emit('changeRecord', col.tableId, line)
  }
@@ -414,9 +442,7 @@
      line.price = 0
    }
    if (line.count && line.price) {
      line.debtor = Math.round(line.count * line.price * 100) / 100
    }
    this.countChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
@@ -439,16 +465,181 @@
      line.price = 0
    }
    if (line.count && line.price) {
      line.debtor = Math.round(line.count * line.price * 100) / 100
    }
    this.countChange(line)
    
    MKEmitter.emit('changeRecord', col.tableId, line)
  }
  editCurrency = (e) => {
    const { col, record } = this.props
    e.stopPropagation()
    this.setState({curring: true}, () => {
      let node = document.getElementById(col.uuid + record.uuid + 'currency')
      node && node.click()
    })
  }
  onCurrSelectChange = (val, option) => {
    const { col, record } = this.props
    let line = {...record, ...option.props.extra}
    this.currencyChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
    if (line.exratename === 'CNY') {
      this.setState({curring: false, origining: true, value: line.origin || 0}, () => {
        let node = document.getElementById(col.uuid + record.uuid + 'origin')
        node && node.select()
      })
    } else {
      this.setState({curring: false, ratioing: true, value: line.unitratio || 1}, () => {
        let node = document.getElementById(col.uuid + record.uuid + 'ratio')
        node && node.select()
      })
    }
  }
  editRatio = (e) => {
    const { col, record } = this.props
    e.stopPropagation()
    this.setState({ratioing: true, value: record.unitratio || 1}, () => {
      let node = document.getElementById(col.uuid + record.uuid + 'ratio')
      node && node.select()
    })
  }
  ratioPress = () => {
    const { col, record } = this.props
    const { value } = this.state
    let line = {...record}
    line.unitratio = value || 1
    if (isNaN(line.unitratio)) {
      line.unitratio = 1
    }
    this.currencyChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
    this.setState({ratioing: false, origining: true, value: line.origin || 0}, () => {
      let node = document.getElementById(col.uuid + record.uuid + 'origin')
        node && node.select()
    })
  }
  ratioBlur = () => {
    const { col, record } = this.props
    const { value } = this.state
    this.setState({ratioing: false})
    let line = {...record}
    line.unitratio = value || 1
    if (isNaN(line.unitratio)) {
      line.unitratio = 1
    }
    this.currencyChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
  }
  editOrigin = (e) => {
    const { col, record } = this.props
    e.stopPropagation()
    this.setState({origining: true, value: record.origin || 1}, () => {
      let node = document.getElementById(col.uuid + record.uuid + 'origin')
      node && node.select()
    })
  }
  originPress = () => {
    const { col, record } = this.props
    const { value } = this.state
    let line = {...record}
    line.origin = value || 0
    if (isNaN(line.origin)) {
      line.origin = 0
    }
    this.currencyChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
    this.setState({origining: false})
    setTimeout(() => {
      MKEmitter.emit('tdFocus', 'debtor' + record.uuid)
    }, 50)
  }
  originBlur = () => {
    const { col, record } = this.props
    const { value } = this.state
    this.setState({origining: false})
    let line = {...record}
    line.origin = value || 0
    if (isNaN(line.origin)) {
      line.origin = 0
    }
    this.currencyChange(line)
    MKEmitter.emit('changeRecord', col.tableId, line)
  }
  countChange = (line) => {
    if (line.count && line.price) {
      if (line.creditor) {
        line.creditor = Math.round(line.count * line.price * 100) / 100
      } else {
        line.debtor = Math.round(line.count * line.price * 100) / 100
      }
      if (line.foreign_currency_type === 'Y' && line.origin) {
        if (line.debtor) {
          line.unitratio = Math.round(line.debtor / line.origin * 100000) / 100000
        } else if (line.creditor) {
          line.unitratio = Math.round(line.creditor / line.origin * 100000) / 100000
        }
      }
    }
  }
  currencyChange = (line) => {
    if (line.unitratio && line.origin) {
      if (line.creditor) {
        line.creditor = Math.round(line.unitratio * line.origin * 100) / 100
      } else {
        line.debtor = Math.round(line.unitratio * line.origin * 100) / 100
      }
      if (line.count_type === 'Y' && line.count) {
        if (line.debtor) {
          line.price = Math.round(line.debtor / line.count * 10000) / 10000
        } else if (line.creditor) {
          line.price = Math.round(line.creditor / line.count * 10000) / 10000
        }
      }
    }
  }
  render() {
    let { col, record, className } = this.props
    const { editing, visible, counting, priceing } = this.state
    const { editing, visible, counting, priceing, curring, ratioing, origining } = this.state
    let children = null
    let colSpan = 1
@@ -501,7 +692,7 @@
            >
              {subjects.map((item, i) => (<Select.Option key={i} extra={item} value={item.subjectscode}>{item.subjectscode + ' ' + item.subjectsname}</Select.Option>))}
            </Select>
            <Popover overlayClassName="subject-pop-wrap" placement="bottom" title="辅助核算" visible={visible} content={<Accounting confirm={this.confirm} cancel={this.cancel} tableId={col.tableId} data={record}/>}>
            <Popover overlayClassName="subject-pop-wrap" placement="bottom" title="" visible={visible} content={<Accounting confirm={this.confirm} cancel={this.cancel} tableId={col.tableId} data={record}/>}>
              <span className="pop-anchor"></span>
            </Popover>
          </>
@@ -517,53 +708,129 @@
            })
          }
          let countNode = null
          let currencyNode = null
          if (record.count_type === 'Y') {
            if (counting) {
              children = <div className="content-wrap" onClick={this.focus}>
                <div>{val}</div>
                <div className="count-wrap">
                  <span style={{marginRight: '5px'}}>
                    <span>数量:</span>
                    <span><InputNumber className="inner-input" id={col.uuid + record.uuid + 'count'} defaultValue={record.count || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.countPress} onBlur={this.countBlur}/></span>
                  </span>
                  <span onClick={this.editPrice}>
                    <span>单价:</span>
                    <span>{record.price || 0}</span>
                  </span>
                </div>
              countNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={(e) => e.stopPropagation()}>
                  <span>数量:</span>
                  <span><InputNumber precision={4} className="inner-input" id={col.uuid + record.uuid + 'count'} defaultValue={record.count || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.countPress} onBlur={this.countBlur}/></span>
                </span>
                <span onClick={this.editPrice}>
                  <span>单价:</span>
                  <span>{record.price || 0}</span>
                </span>
              </div>
            } else if (priceing) {
              children = <div className="content-wrap" onClick={this.focus}>
                <div>{val}</div>
                <div className="count-wrap">
                  <span style={{marginRight: '5px'}} onClick={this.editCount}>
                    <span>数量:</span>
                    <span>{record.count || 0}</span>
                  </span>
                  <span>
                    <span>单价:</span>
                    <span><InputNumber className="inner-input" id={col.uuid + record.uuid + 'price'} defaultValue={record.price || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.pricePress} onBlur={this.priceBlur}/></span>
                  </span>
                </div>
              countNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={this.editCount}>
                  <span>数量:</span>
                  <span>{record.count || 0}</span>
                </span>
                <span onClick={(e) => e.stopPropagation()}>
                  <span>单价:</span>
                  <span><InputNumber precision={4} className="inner-input" id={col.uuid + record.uuid + 'price'} defaultValue={record.price || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.pricePress} onBlur={this.priceBlur}/></span>
                </span>
              </div>
            } else {
              children = <div className="content-wrap" onClick={this.focus}>
                <div>{val}</div>
                <div className="count-wrap">
                  <span style={{marginRight: '5px'}} onClick={this.editCount}>
                    <span>数量:</span>
                    <span>{record.count || 0}</span>
                  </span>
                  <span onClick={this.editPrice}>
                    <span>单价:</span>
                    <span>{record.price || 0}</span>
                  </span>
                </div>
              countNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={this.editCount}>
                  <span>数量:</span>
                  <span>{record.count || 0}</span>
                </span>
                <span onClick={this.editPrice}>
                  <span>单价:</span>
                  <span>{record.price || 0}</span>
                </span>
              </div>
            }
          } else {
            children = <div className="content-wrap" onClick={this.focus}>{val}</div>
          }
          if (record.foreign_currency_type === 'Y') {
            if (curring) {
              let msg = window.GLOB.CacheVoucher.get(col.tableId)
              let currency = msg ? msg.currency : []
              currencyNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={(e) => e.stopPropagation()}>
                  <span>货币:</span>
                  <span>
                    <Select
                      className="currency-select"
                      defaultValue={record.exratename || ''}
                      dropdownClassName="edit-table-dropdown"
                      id={col.uuid + record.uuid + 'currency'}
                      onBlur={() => this.setState({curring: false})}
                      onSelect={this.onCurrSelectChange}
                    >
                      {currency.map((item, i) => (<Select.Option key={i} extra={item} value={item.exratename}>{item.exratename}</Select.Option>))}
                    </Select>
                  </span>
                </span>
                <span style={{marginRight: '5px'}} onClick={this.editRatio}>
                  <span>汇率:</span>
                  <span>{record.unitratio || 1}</span>
                </span>
                <span onClick={this.editOrigin}>
                  <span>原币:</span>
                  <span>{record.origin || 0}</span>
                </span>
              </div>
            } else if (ratioing) {
              currencyNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={this.editCurrency}>
                  <span>货币:</span>
                  <span>{record.exratename || ''}</span>
                </span>
                <span style={{marginRight: '5px'}} onClick={(e) => e.stopPropagation()}>
                  <span>汇率:</span>
                  <span><InputNumber precision={5} className="inner-input" id={col.uuid + record.uuid + 'ratio'} defaultValue={record.unitratio || 1} onChange={(val) => this.onChange(val)} onPressEnter={this.ratioPress} onBlur={this.ratioBlur}/></span>
                </span>
                <span onClick={this.editOrigin}>
                  <span>原币:</span>
                  <span>{record.origin || 0}</span>
                </span>
              </div>
            } else if (origining) {
              currencyNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={this.editCurrency}>
                  <span>货币:</span>
                  <span>{record.exratename || ''}</span>
                </span>
                <span style={{marginRight: '5px'}} onClick={this.editRatio}>
                  <span>汇率:</span>
                  <span>{record.unitratio || 1}</span>
                </span>
                <span onClick={(e) => e.stopPropagation()}>
                  <span>原币:</span>
                  <span><InputNumber precision={2} className="inner-input" id={col.uuid + record.uuid + 'origin'} defaultValue={record.origin || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.originPress} onBlur={this.originBlur}/></span>
                </span>
              </div>
            } else {
              currencyNode = <div className="count-wrap">
                <span style={{marginRight: '5px'}} onClick={this.editCurrency}>
                  <span>货币:</span>
                  <span>{record.exratename || ''}</span>
                </span>
                <span style={{marginRight: '5px'}} onClick={this.editRatio}>
                  <span>汇率:</span>
                  <span>{record.unitratio || 1}</span>
                </span>
                <span onClick={this.editOrigin}>
                  <span>原币:</span>
                  <span>{record.origin || 0}</span>
                </span>
              </div>
            }
          }
          children = <div className="content-wrap" onClick={this.focus}>
            {val}
            {countNode}
            {currencyNode}
          </div>
        }
      }
    } else if (col.field === 'debtor') {
@@ -749,22 +1016,23 @@
  initData = (data) => {
    let _data = data.map((item, i) => {
      item.uuid = Utils.getuuid()
      // item.uuid = Utils.getguid()
      item.index = i
      item.$origin = true
      
      return item
    })
    if (_data.length < 4) {
      for (let i = _data.length - 1; i < 4; i++) {
        _data.push({uuid: Utils.getuuid(), index: i + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''})
        _data.push({uuid: Utils.getguid(), index: i + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''})
      }
    }
    return _data
  }
  getTotalLine = (data) => {
    let totalLine = {uuid: Utils.getuuid(), type: 'total'}
    let totalLine = {uuid: Utils.getguid(), type: 'total'}
    let debtor = ''
    let creditor = ''
@@ -886,7 +1154,7 @@
      MKEmitter.emit('tdFocus', 'remark' + edData[record.index + 1].uuid)
    } else {
      let _data = fromJS(edData).toJS()
      let line = {uuid: Utils.getuuid(), index: _data.length - 1, remark: record.remark || '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}
      let line = {uuid: Utils.getguid(), index: _data.length - 1, remark: record.remark || '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}
      _data.splice(_data.length - 1, 0, line)
@@ -903,7 +1171,7 @@
    if (tid !== tableId) return
    let _data = fromJS(edData).toJS()
    let line = {uuid: Utils.getuuid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}
    let line = {uuid: Utils.getguid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}
    _data.splice(record.index, 0, line)
    _data = _data.map((item, index) => {
@@ -926,7 +1194,7 @@
    if (_data.length < 4) {
      for (let i = _data.length; i < 4; i++) {
        _data.push({uuid: Utils.getuuid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''})
        _data.push({uuid: Utils.getguid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''})
      }
    }
@@ -938,7 +1206,7 @@
    _data.push(this.getTotalLine(_data))
    this.setState({edData: _data})
    this.props.onChange(_data)
    this.props.onChange(_data, record.$origin ? record : null)
  }
  changeRecord = (tableId, record) => {
@@ -955,7 +1223,7 @@
    _data.pop()
    if (record.index === _data.length - 1) {
      _data.push({uuid: Utils.getuuid(), index: record.index + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''})
      _data.push({uuid: Utils.getguid(), index: record.index + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''})
    }
    _data.push(this.getTotalLine(_data))