From 6b72e0d7751fba6af94a64020ac1fb1199612d05 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 14 五月 2023 20:56:03 +0800
Subject: [PATCH] 2023-05-14

---
 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx |  112 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 63 insertions(+), 49 deletions(-)

diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
index 2329e72..2a2e40f 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -221,12 +221,12 @@
     }, 50)
 
     let values = {}
-    if (col.editField) {
-      values[col.field] = label
-      values[col.editField] = val
-    } else {
+    // if (col.editField) {
+    //   values[col.field] = label
+    //   values[col.editField] = val
+    // } else {
       values[col.field] = val
-    }
+    // }
 
     MKEmitter.emit('changeRecord', col.tableId, {...record, ...values})
   }
@@ -244,12 +244,12 @@
         })
       }
 
-      if (col.editField) {
-        values[col.field] = _option.label
-        values[col.editField] = val
-      } else {
+      // if (col.editField) {
+      //   values[col.field] = _option.label
+      //   values[col.editField] = val
+      // } else {
         values[col.field] = val
-      }
+      // }
     }
 
     this.setState({editing: false})
@@ -292,6 +292,10 @@
         content = `${record[col.field]}`
       }
 
+      if (col.editType === 'select' && col.options.length > 0) {
+        content = col.map.get(content) || content
+      }
+
       if (content !== '') {
         if (col.textFormat === 'YYYY-MM-DD' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])/.test(content)) {
           content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
@@ -330,21 +334,21 @@
             </td>)
           } else if (col.editType === 'switch') {
             let _value = ''
-            if (col.editField) {
-              _value = record[col.editField] !== undefined ? record[col.editField] : ''
-            } else {
+            // if (col.editField) {
+            //   _value = record[col.editField] !== undefined ? record[col.editField] : ''
+            // } else {
               _value = record[col.field] !== undefined ? record[col.field] : ''
-            }
+            // }
             return (<td className="editing_table_cell">
               <CusSwitch config={col} defaultValue={_value} autoFocus={true} onChange={this.onSwitchChange} onBlur={this.switchBlur}/>
             </td>)
           } else {
             let _value = ''
-            if (col.editField) {
-              _value = record[col.editField] !== undefined ? record[col.editField] : ''
-            } else {
+            // if (col.editField) {
+            //   _value = record[col.editField] !== undefined ? record[col.editField] : ''
+            // } else {
               _value = record[col.field] !== undefined ? record[col.field] : ''
-            }
+            // }
             return (<td className="editing_table_cell">
               <Select
                 showSearch
@@ -637,12 +641,12 @@
     }, 50)
 
     let values = {}
-    if (col.editField) {
-      values[col.field] = label
-      values[col.editField] = val
-    } else {
+    // if (col.editField) {
+    //   values[col.field] = label
+    //   values[col.editField] = val
+    // } else {
       values[col.field] = val
-    }
+    // }
 
     MKEmitter.emit('changeRecord', col.tableId, {...record, ...values})
   }
@@ -660,12 +664,12 @@
         })
       }
 
-      if (col.editField) {
-        values[col.field] = _option.label
-        values[col.editField] = val
-      } else {
+      // if (col.editField) {
+      //   values[col.field] = _option.label
+      //   values[col.editField] = val
+      // } else {
         values[col.field] = val
-      }
+      // }
     }
 
     setTimeout(() => {
@@ -703,11 +707,11 @@
     if (col.type === 'text') {
       if (col.editable === 'true' && !disabled) {
         let _value = ''
-        if (col.editField) {
-          _value = record[col.editField] !== undefined ? record[col.editField] : ''
-        } else {
+        // if (col.editField) {
+        //   _value = record[col.editField] !== undefined ? record[col.editField] : ''
+        // } else {
           _value = record[col.field] !== undefined ? record[col.field] : ''
-        }
+        // }
         
         if (!col.editType || col.editType === 'text') {
           children = (<>
@@ -736,6 +740,10 @@
         let content = ''
         if (record[col.field] !== undefined) {
           content = `${record[col.field]}`
+        }
+
+        if (col.editType === 'select' && col.options.length > 0) {
+          content = col.map.get(content) || content
         }
 
         if (content !== '') {
@@ -967,17 +975,24 @@
               item.ctrlValue = item.ctrlValue.split(',')
             }
             
-            if (item.type === 'text' && item.editType === 'select' && item.resourceType === '1') {
-              let _option = Utils.getSelectQueryOptions(item)
-
-              if (/@BID@/ig.test(_option.sql)) {
-                hasBid = true
+            if (item.type === 'text' && item.editType === 'select') {
+              item.map = new Map()
+              if (item.resourceType === '1') {
+                let _option = Utils.getSelectQueryOptions(item)
+  
+                if (/@BID@/ig.test(_option.sql)) {
+                  hasBid = true
+                }
+        
+                item.base_sql = _option.sql
+                item.arr_field = _option.field
+        
+                deForms.push(item)
+              } else {
+                item.options.forEach(cell => {
+                  item.map.set(cell.value, cell.label)
+                })
               }
-      
-              item.base_sql = _option.sql
-              item.arr_field = _option.field
-      
-              deForms.push(item)
             }
           }
     
@@ -1234,7 +1249,7 @@
   }
 
   resetFormList = (result) => {
-    const { columns } = this.state
+    const { columns, edData } = this.state
 
     let _edColumns = []
 
@@ -1242,7 +1257,6 @@
     this.props.columns.forEach(item => {
       if (item.resourceType === '1' && result[item.uuid] && result[item.uuid].length > 0) {
         let options = []
-        let _map = new Map()
         let all = false
         result[item.uuid].forEach(cell => {
           let _cell = {key: Utils.getuuid()}
@@ -1259,8 +1273,8 @@
             }
           }
 
-          if (_map.has(_cell.value)) return
-          _map.set(_cell.value, 0)
+          if (item.map.has(_cell.value)) return
+          item.map.set(_cell.value, _cell.label)
 
           if (item.linkSubField) {
             item.linkSubField.forEach(m => {
@@ -1277,7 +1291,7 @@
 
         item.options = options
 
-        reCols[item.uuid] = item
+        reCols[item.uuid] = fromJS(item).toJS()
       }
     })
 
@@ -1292,8 +1306,8 @@
       return item
     })
 
-    this.setState({columns: []}, () => {
-      this.setState({columns: _edColumns})
+    this.setState({columns: [], edData: []}, () => {
+      this.setState({columns: _edColumns, edData: edData})
     })
   }
   

--
Gitblit v1.8.0