From 90fff0ec484bbb3a10248f389cb9c4bddeff93ed Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 31 一月 2023 18:10:44 +0800
Subject: [PATCH] 2023-01-31

---
 src/tabviews/custom/components/module/voucher/voucherTable/index.jsx |  246 +++++++++++++------------------------------------
 1 files changed, 66 insertions(+), 180 deletions(-)

diff --git a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
index 7ed2901..3cc17cb 100644
--- a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
+++ b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
@@ -1,14 +1,11 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Table, Modal, Form, Input, InputNumber, notification, message, AutoComplete, Select, Popover, Button } from 'antd'
+import { Table, Form, Input, InputNumber, notification, AutoComplete, Select, Popover, Button } from 'antd'
 import { PlusOutlined, CloseOutlined } from '@ant-design/icons'
 
-import Api from '@/api'
 import Utils from '@/utils/utils.js'
 import MKEmitter from '@/utils/events.js'
-import zhCN from '@/locales/zh-CN/main.js'
-import enUS from '@/locales/en-US/main.js'
 import './index.scss'
 
 class BodyRow extends React.Component {
@@ -155,24 +152,29 @@
     this.setState({editing: false})
 
     let line = {...record}
+    line[col.field] = value
 
-    if (value !== record[col.field]) {
-      line[col.field] = value
-
-      if (col.field === 'debtor') {
-        line.creditor = ''
-        if (isNaN(line.debtor)) {
-          line.debtor = ''
-        }
-      } else {
+    if (col.field === 'debtor') {
+      line.creditor = ''
+      if (isNaN(line.debtor)) {
         line.debtor = ''
-        if (isNaN(line.creditor)) {
-          line.creditor = ''
-        }
       }
-
-      MKEmitter.emit('changeRecord', col.tableId, line)
+    } else {
+      line.debtor = ''
+      if (isNaN(line.creditor)) {
+        line.creditor = ''
+      }
     }
+
+    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
+      }
+    }
+
+    MKEmitter.emit('changeRecord', col.tableId, line)
 
     setTimeout(() => {
       if (col.field === 'debtor' && (line.debtor || line.debtor === 0)) {
@@ -224,6 +226,14 @@
         line.debtor = ''
         if (isNaN(line.creditor)) {
           line.creditor = ''
+        }
+      }
+
+      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
         }
       }
 
@@ -361,6 +371,10 @@
       line.count = 0
     }
 
+    if (line.count && line.price) {
+      line.debtor = Math.round(line.count * line.price * 100) / 100
+    }
+
     MKEmitter.emit('changeRecord', col.tableId, line)
 
     this.setState({counting: false, priceing: true, value: line.price || 0}, () => {
@@ -381,6 +395,10 @@
     if (isNaN(line.count)) {
       line.count = 0
     }
+
+    if (line.count && line.price) {
+      line.debtor = Math.round(line.count * line.price * 100) / 100
+    }
     
     MKEmitter.emit('changeRecord', col.tableId, line)
   }
@@ -394,6 +412,10 @@
 
     if (isNaN(line.price)) {
       line.price = 0
+    }
+
+    if (line.count && line.price) {
+      line.debtor = Math.round(line.count * line.price * 100) / 100
     }
 
     MKEmitter.emit('changeRecord', col.tableId, line)
@@ -415,6 +437,10 @@
 
     if (isNaN(line.price)) {
       line.price = 0
+    }
+
+    if (line.count && line.price) {
+      line.debtor = Math.round(line.count * line.price * 100) / 100
     }
     
     MKEmitter.emit('changeRecord', col.tableId, line)
@@ -542,7 +568,7 @@
       }
     } else if (col.field === 'debtor') {
       if (editing) {
-        children = <InputNumber id={col.uuid + record.uuid} defaultValue={record.debtor} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
+        children = <InputNumber id={col.uuid + record.uuid} precision={2} defaultValue={record.debtor} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
       } else {
         let val = record.debtor
         let down = false
@@ -563,7 +589,7 @@
       extra = <CloseOutlined onClick={this.delRecord}/>
 
       if (editing) {
-        children = <InputNumber id={col.uuid + record.uuid} defaultValue={record.creditor} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
+        children = <InputNumber id={col.uuid + record.uuid} precision={2} defaultValue={record.creditor} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
       } else {
         let val = record.creditor
         let down = false
@@ -591,22 +617,16 @@
 class VoucherTable extends Component {
   static propTpyes = {
     config: PropTypes.object,        // 鑿滃崟Id
-    BID: PropTypes.any,              // 涓昏〃ID
     data: PropTypes.any,             // 琛ㄦ牸鏁版嵁
-    total: PropTypes.any,            // 鎬绘暟
     loading: PropTypes.bool,         // 琛ㄦ牸鍔犺浇涓�
-    refreshdata: PropTypes.func,     // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂�
+    onChange: PropTypes.func,        // 琛ㄦ牸鍙樺姩
   }
 
   state = {
-    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     data: [],
     edData: [],
-    edColumns: [],
     tableId: '',          // 琛ㄦ牸ID
-    pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
     columns: null,        // 鏄剧ず鍒�
-    loading: false,
   }
 
   UNSAFE_componentWillMount () {
@@ -682,6 +702,7 @@
     MKEmitter.addListener('nextLine', this.nextLine)
     MKEmitter.addListener('plusLine', this.plusLine)
     MKEmitter.addListener('delRecord', this.delRecord)
+    MKEmitter.addListener('cleartable', this.cleartable)
     MKEmitter.addListener('changeRecord', this.changeRecord)
   }
 
@@ -695,6 +716,7 @@
     MKEmitter.removeListener('nextLine', this.nextLine)
     MKEmitter.removeListener('plusLine', this.plusLine)
     MKEmitter.removeListener('delRecord', this.delRecord)
+    MKEmitter.removeListener('cleartable', this.cleartable)
     MKEmitter.removeListener('changeRecord', this.changeRecord)
   }
 
@@ -702,6 +724,14 @@
     if (!is(fromJS(this.props.data), fromJS(nextProps.data))) {
       this.resetData(fromJS(nextProps.data).toJS())
     }
+  }
+
+  cleartable = (tbid) => {
+    const { tableId } = this.state
+
+    if (tbid !== tableId) return
+
+    this.resetData([])
   }
 
   resetData = (data) => {
@@ -863,6 +893,7 @@
       this.setState({edData: _data}, () => {
         MKEmitter.emit('tdFocus', 'remark' + line.uuid)
       })
+      this.props.onChange(_data)
     }
   }
 
@@ -875,11 +906,13 @@
     let line = {uuid: Utils.getuuid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}
 
     _data.splice(record.index, 0, line)
-
-    this.setState({edData: _data.map((item, index) => {
+    _data = _data.map((item, index) => {
       item.index = index
       return item
-    })})
+    })
+
+    this.setState({edData: _data})
+    this.props.onChange(_data)
   }
 
   delRecord = (id, record) => {
@@ -905,6 +938,7 @@
     _data.push(this.getTotalLine(_data))
 
     this.setState({edData: _data})
+    this.props.onChange(_data)
   }
 
   changeRecord = (tableId, record) => {
@@ -927,155 +961,7 @@
     _data.push(this.getTotalLine(_data))
 
     this.setState({edData: _data})
-  }
-
-  checkData = () => {
-    const { edData } = this.state
-
-    let err = ''
-    let data = fromJS(edData).toJS().map(item => {
-      // let line = []
-      // fields.forEach(col => {
-      //   if (col.editable !== 'true' || item.$deleted) {
-      //     if (col.type === 'number') {
-      //       item[col.field] = +item[col.field]
-      //       if (isNaN(item[col.field])) {
-      //         item[col.field] = 0
-      //       }
-      //     } else {
-      //       item[col.field] = item[col.field] !== undefined ? (item[col.field] + '') : ''
-      //     }
-      //     return
-      //   }
-      //   if (col.type === 'text') {
-      //     let val = item[col.field] !== undefined ? (item[col.field] + '') : ''
-      //     if (col.required === 'true' && !val) {
-      //       line.push(`${col.label}涓嶅彲涓虹┖`)
-      //     }
-      //     item[col.field] = val
-      //   } else if (col.type === 'number') {
-      //     let val = item[col.field]
-      //     if (!val && val !== 0) {
-      //       line.push(`${col.label}涓嶅彲涓虹┖`)
-      //       return
-      //     }
-      //     val = +val
-      //     if (isNaN(val)) {
-      //       line.push(`${col.label}鏁版嵁鏍煎紡閿欒`)
-      //       return
-      //     }
-
-      //     val = +val.toFixed(col.decimal || 0)
-          
-      //     if (typeof(col.max) === 'number' && val > col.max) {
-      //       line.push(`${col.label}涓嶅彲澶т簬${col.max}`)
-      //     } else if (typeof(col.min) === 'number' && val < col.min) {
-      //       line.push(`${col.label}涓嶅彲灏忎簬${col.min}`)
-      //     }
-
-      //     item[col.field] = val
-      //   }
-      // })
-
-      return item
-    })
-
-    if (err) {
-      notification.warning({
-        top: 92,
-        message: err,
-        duration: 5
-      })
-    } else {
-      this.submit(data)
-    }
-  }
-
-  submit = (data) => {
-    const { BID } = this.props
-
-    let param = {
-      // excel_in: result.lines,
-      BID: BID || ''
-    }
-
-    this.setState({
-      loading: true
-    })
-
-    param.func = 'submit.innerFunc'
-
-    Api.genericInterface(param).then((res) => {
-      if (res.status) {
-        this.execSuccess(res)
-      } else {
-        this.execError(res)
-      }
-    }, () => {
-      this.execError({})
-    })
-  }
-
-  execSuccess = (res) => {
-    const { submit } = this.props
-
-    if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛
-      notification.success({
-        top: 92,
-        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
-        duration: submit.stime ? submit.stime : 2
-      })
-    } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛
-      Modal.success({
-        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
-      })
-    } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
-
-    }
-
-    this.setState({
-      loading: false
-    })
-
-    if (submit.closetab === 'true') {
-      MKEmitter.emit('popclose')
-    }
-    if (submit.execSuccess !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
-    }
-  }
-
-  execError = (res) => {
-    const { submit } = this.props
-
-    if (res.ErrCode === 'E') {
-      Modal.error({
-        title: res.message || res.ErrMesg,
-      })
-    } else if (res.ErrCode === 'N') {
-      notification.error({
-        top: 92,
-        message: res.message || res.ErrMesg,
-        duration: submit.ntime ? submit.ntime : 10
-      })
-    } else if (res.ErrCode === 'F') {
-      notification.error({
-        className: 'notification-custom-error',
-        top: 92,
-        message: res.message || res.ErrMesg,
-        duration: submit.ftime ? submit.ftime : 10
-      })
-    } else if (res.ErrCode === 'NM') {
-      message.error(res.message || res.ErrMesg)
-    }
-    
-    this.setState({
-      loading: false
-    })
-
-    if (submit.execError !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit)
-    }
+    this.props.onChange(_data)
   }
 
   render() {
@@ -1096,7 +982,7 @@
           columns={columns}
           dataSource={edData}
           bordered={true}
-          // loading={this.props.loading}
+          loading={this.props.loading}
           onRow={(record, index) => {
             return {
               data: record

--
Gitblit v1.8.0