From e469a34f26637e177854b960bbd35c900ce0daff Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 30 一月 2023 15:50:34 +0800
Subject: [PATCH] 2023-01-30

---
 src/tabviews/custom/components/module/voucher/voucherTable/index.jsx |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 163 insertions(+), 7 deletions(-)

diff --git a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
index 2a636f1..7ed2901 100644
--- a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
+++ b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx
@@ -122,6 +122,8 @@
   state = {
     editing: false,
     visible: false,
+    counting: false,
+    priceing: false
   }
 
   componentDidMount () {
@@ -276,8 +278,13 @@
       setTimeout(() => {
         this.setState({visible: true})
       }, 100)
+    } else if (line.count_type === 'Y') {
+      this.setState({counting: true, value: line.count || 0}, () => {
+        let node = document.getElementById(col.uuid + record.uuid + 'count')
+        node && node.select()
+      })
     } else {
-      this.setState({editing: false})
+      this.setState({editing: false, visible: false, counting: false, priceing: false})
       setTimeout(() => {
         MKEmitter.emit('tdFocus', 'debtor' + record.uuid)
       }, 50)
@@ -290,9 +297,17 @@
     MKEmitter.emit('changeRecord', col.tableId, fromJS(res).toJS())
 
     this.setState({editing: false, visible: false})
-    setTimeout(() => {
-      MKEmitter.emit('tdFocus', 'debtor' + res.uuid)
-    }, 50)
+
+    if (res.count_type === 'Y') {
+      this.setState({counting: true, value: res.count || 0}, () => {
+        let node = document.getElementById(col.uuid + res.uuid + 'count')
+        node && node.select()
+      })
+    } else {
+      setTimeout(() => {
+        MKEmitter.emit('tdFocus', 'debtor' + res.uuid)
+      }, 50)
+    }
   }
 
   cancel = () => {
@@ -315,9 +330,99 @@
     this.setState({editing: false, visible: false})
   }
 
+  editCount = (e) => {
+    const { col, record } = this.props
+    e.stopPropagation()
+
+    this.setState({counting: true, value: record.count || 0}, () => {
+      let node = document.getElementById(col.uuid + record.uuid + 'count')
+      node && node.select()
+    })
+  }
+
+  editPrice = (e) => {
+    const { col, record } = this.props
+    e.stopPropagation()
+
+    this.setState({priceing: true, value: record.price || 0}, () => {
+      let node = document.getElementById(col.uuid + record.uuid + 'price')
+      node && node.select()
+    })
+  }
+
+  countPress = () => {
+    const { col, record } = this.props
+    const { value } = this.state
+
+    let line = {...record}
+    line.count = value || 0
+
+    if (isNaN(line.count)) {
+      line.count = 0
+    }
+
+    MKEmitter.emit('changeRecord', col.tableId, line)
+
+    this.setState({counting: false, priceing: true, value: line.price || 0}, () => {
+      let node = document.getElementById(col.uuid + record.uuid + 'price')
+      node && node.select()
+    })
+  }
+
+  countBlur = () => {
+    const { col, record } = this.props
+    const { value } = this.state
+
+    this.setState({counting: false})
+
+    let line = {...record}
+    line.count = value || 0
+
+    if (isNaN(line.count)) {
+      line.count = 0
+    }
+    
+    MKEmitter.emit('changeRecord', col.tableId, line)
+  }
+
+  pricePress = () => {
+    const { col, record } = this.props
+    const { value } = this.state
+
+    let line = {...record}
+    line.price = value || 0
+
+    if (isNaN(line.price)) {
+      line.price = 0
+    }
+
+    MKEmitter.emit('changeRecord', col.tableId, line)
+
+    this.setState({priceing: false})
+    setTimeout(() => {
+      MKEmitter.emit('tdFocus', 'debtor' + record.uuid)
+    }, 50)
+  }
+
+  priceBlur = () => {
+    const { col, record } = this.props
+    const { value } = this.state
+
+    this.setState({priceing: false})
+
+    let line = {...record}
+    line.price = value || 0
+
+    if (isNaN(line.price)) {
+      line.price = 0
+    }
+    
+    MKEmitter.emit('changeRecord', col.tableId, line)
+  }
+
   render() {
     let { col, record, className } = this.props
-    const { editing, visible } = this.state
+    const { editing, visible, counting, priceing } = this.state
 
     let children = null
     let colSpan = 1
@@ -385,7 +490,54 @@
               }
             })
           }
-          children = <div className="content-wrap" onClick={this.focus}>{val}</div>
+
+          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>
+              </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>
+              </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>
+              </div>
+            }
+          } else {
+            children = <div className="content-wrap" onClick={this.focus}>{val}</div>
+          }
         }
       }
     } else if (col.field === 'debtor') {
@@ -557,7 +709,11 @@
     data.push(this.getTotalLine(data))
 
     this.setState({
-      edData: data
+      edData: []
+    }, () => {
+      this.setState({
+        edData: data
+      })
     })
   }
 

--
Gitblit v1.8.0