From eb0482b3fc2e91a626baa6ac73e75e0b0038f552 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 03 十一月 2023 01:25:59 +0800
Subject: [PATCH] 2023-11-03

---
 src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx |  111 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 81 insertions(+), 30 deletions(-)

diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx
index f2444ec..e99578c 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx
@@ -6,6 +6,7 @@
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 const { Search } = Input
@@ -162,19 +163,9 @@
   }
 
   changeRow = (record) => {
-    const { config } = this.props
-
     if (record.$disabled) return
 
-    let values = {[config.field]: record.$$uuid}
-
-    if (config.linkSubField) {
-      config.linkSubField.forEach(m => {
-        values[m] = record[m] === undefined ? '' : record[m]
-      })
-    }
-
-    this.props.onChange(values, record.$$uuid)
+    this.props.onChange(record)
   }
 
   changeTable = (pagination, filters, sorter) => {
@@ -247,6 +238,16 @@
     }
   }
 
+  componentDidMount() {
+    const { autoFocus, config } = this.props
+
+    MKEmitter.addListener('setFocus' + config.tableId, this.setFocus)
+
+    if (autoFocus) {
+      this.trigger()
+    }
+  }
+
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.state), fromJS(nextState))
   }
@@ -255,55 +256,105 @@
     this.setState = () => {
       return
     }
+    MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus)
   }
 
-  selectChange = (values, val) => {
-    this.props.onChange(values)
-    this.setState({value: val, visible: false})
+  setFocus = (lId, colId) => {
+    const { config, lineId } = this.props
+
+    if (lId !== lineId || config.uuid !== colId) return
+
+    if (config.$ctrl) {
+      MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid)
+    }
+
+    this.setState({visible: true})
+  }
+
+  selectChange = (record) => {
+    const { config, lineId } = this.props
+
+    let values = {[config.field]: record.$$uuid}
+
+    if (config.linkSubField) {
+      config.linkSubField.forEach((m, i) => {
+        values[m] = record[m] !== undefined ? record[m] : ''
+      })
+    }
+
+    this.props.onChange(values, record.$$uuid)
+
+    this.setState({visible: false})
+
+    if (config.$ctrl) {
+      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
+    }
+
+    this.props.onBlur && this.props.onBlur()
+
+    if (config.enter === '$noAct') return
+
+    if (/\$next/.test(config.enter)) {
+      MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', ''))
+    } else {
+      MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter)
+    }
   }
 
   trigger = (e) => {
+    const { config, lineId } = this.props
+
     e && e.stopPropagation()
+
+    if (config.$ctrl) {
+      MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid)
+    }
 
     this.setState({visible: true})
   }
 
   clear = (e) => {
-    const { config } = this.props
+    const { config, lineId } = this.props
 
     e.stopPropagation()
     
     let values = {[config.field]: ''}
 
     if (config.linkSubField) {
-      config.linkSubField.forEach(m => {
+      config.linkSubField.forEach((m, i) => {
         values[m] = ''
       })
     }
 
-    this.props.onChange(values)
+    this.props.onChange(values, '')
     this.setState({value: ''})
-  }
 
-  cancel = () => {
-    const { mask } = this.props
-
-    this.setState({visible: false})
-
-    if (mask) {
-      this.props.blur()
+    if (config.$ctrl) {
+      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
     }
   }
 
+  cancel = () => {
+    const { config, lineId } = this.props
+
+    this.setState({visible: false})
+
+    if (config.$ctrl) {
+      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
+    }
+
+    this.props.onBlur && this.props.onBlur()
+  }
+
   render() {
-    const { mask, BID, ID, config } = this.props
+    const { autoFocus, BID, lineId, config } = this.props
     const { value, visible } = this.state
     
     return <>
-      {mask ? <div className="mk-pop-select-mask" onClick={this.trigger}></div> : null}
+      {autoFocus ? <div className="mk-pop-select-mask" onClick={this.trigger}></div> : null}
       <div className="mk-pop-select-wrap" onClick={this.trigger}>
         {value}
-        {value && !mask ? <CloseCircleFilled onClick={this.clear} /> : null}
+        {value && !autoFocus ? <CloseCircleFilled onClick={this.clear} /> : null}
         <TableOutlined onClick={this.trigger}/>
       </div>
       <Modal
@@ -321,11 +372,11 @@
         {config.pops ? <Tabs>
           {config.pops.map(tab => (
             <TabPane tab={tab.tabName} key={tab.uuid}>
-              <PopTable config={tab} BID={BID} ID={ID} value={value} onChange={this.selectChange}/>
+              <PopTable config={tab} BID={BID} ID={lineId} value={value} onChange={this.selectChange}/>
             </TabPane>
           ))}
         </Tabs> :
-        <PopTable config={config} BID={BID} ID={ID} value={value} onChange={this.selectChange}/>}
+        <PopTable config={config} BID={BID} ID={lineId} value={value} onChange={this.selectChange}/>}
       </Modal>
     </>
   }

--
Gitblit v1.8.0