From 4e570c993e66a47ead0f83de76b63b0a2f8c5446 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 05 六月 2023 17:28:16 +0800
Subject: [PATCH] 2023-06-05

---
 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx |  200 ++++++++++++++++++++++++-------------------------
 1 files changed, 97 insertions(+), 103 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 94d02eb..47fb9f2 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -8,15 +8,13 @@
 import Api from '@/api'
 import asyncComponent from '@/utils/asyncComponent'
 import Utils, { getEditTableSql, getMark } from '@/utils/utils.js'
-import MkIcon from '@/components/mk-icon'
 import MKEmitter from '@/utils/events.js'
-import zhCN from '@/locales/zh-CN/main.js'
-import enUS from '@/locales/en-US/main.js'
 import CusSwitch from './cusSwitch'
 import Encrypts from '@/components/encrypts'
 import './index.scss'
 
 const { Paragraph } = Typography
+const MkIcon = asyncComponent(() => import('@/components/mk-icon'))
 const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
 
 class BodyRow extends React.Component {
@@ -220,15 +218,7 @@
       }
     }, 50)
 
-    let values = {}
-    if (col.editField) {
-      values[col.field] = label
-      values[col.editField] = val
-    } else {
-      values[col.field] = val
-    }
-
-    MKEmitter.emit('changeRecord', col.tableId, {...record, ...values})
+    MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val})
   }
 
   onSelectChange = (val, option) => {
@@ -244,12 +234,7 @@
         })
       }
 
-      if (col.editField) {
-        values[col.field] = _option.label
-        values[col.editField] = val
-      } else {
-        values[col.field] = val
-      }
+      values[col.field] = val
     }
 
     this.setState({editing: false})
@@ -292,6 +277,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)}`
@@ -329,22 +318,14 @@
               <Input className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
             </td>)
           } else if (col.editType === 'switch') {
-            let _value = ''
-            if (col.editField) {
-              _value = record[col.editField] !== undefined ? record[col.editField] : ''
-            } else {
-              _value = record[col.field] !== undefined ? record[col.field] : ''
-            }
+            let _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 {
-              _value = record[col.field] !== undefined ? record[col.field] : ''
-            }
+            let _value = record[col.field] !== undefined ? record[col.field] : ''
+
             return (<td className="editing_table_cell">
               <Select
                 showSearch
@@ -425,7 +406,7 @@
             val = ''
           }
           return (<td className="editing_table_cell">
-            <InputNumber className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
+            <InputNumber className={err ? 'has-error' : ''} precision={col.decimal || 0} title={err} id={col.uuid + record.$$uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
           </td>)
         } else {
           return (<td className={className + ' pointer'} style={style}>
@@ -462,6 +443,10 @@
           // eslint-disable-next-line
           content = eval(content)
         } catch (e) {
+          if (window.debugger) {
+            console.info(content)
+            console.warn(e)
+          }
           content = ''
         }
       }
@@ -470,6 +455,11 @@
 
       if (col.noValue === 'hide' && content === 0) {
         content = ''
+      }
+
+      if (col.round && typeof(content) === 'number') {
+        content = Math.round(content * col.round) / col.round
+        content = content.toFixed(col.decimal)
       }
 
       if (content !== '') {
@@ -501,14 +491,6 @@
         style = {...style, ...col.style}
       }
 
-      children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements}/>
-      )
-    } else if (col.type === 'action') {
-      style.padding = '0px'
-      if (col.style) {
-        style = {...style, ...col.style}
-      }
       children = (
         <CardCellComponent data={record} cards={config} elements={col.elements}/>
       )
@@ -636,15 +618,7 @@
       }
     }, 50)
 
-    let values = {}
-    if (col.editField) {
-      values[col.field] = label
-      values[col.editField] = val
-    } else {
-      values[col.field] = val
-    }
-
-    MKEmitter.emit('changeRecord', col.tableId, {...record, ...values})
+    MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val})
   }
 
   onSelectChange = (val, option) => {
@@ -660,12 +634,7 @@
         })
       }
 
-      if (col.editField) {
-        values[col.field] = _option.label
-        values[col.editField] = val
-      } else {
-        values[col.field] = val
-      }
+      values[col.field] = val
     }
 
     setTimeout(() => {
@@ -702,12 +671,7 @@
     let children = null
     if (col.type === 'text') {
       if (col.editable === 'true' && !disabled) {
-        let _value = ''
-        if (col.editField) {
-          _value = record[col.editField] !== undefined ? record[col.editField] : ''
-        } else {
-          _value = record[col.field] !== undefined ? record[col.field] : ''
-        }
+        let _value = record[col.field] !== undefined ? record[col.field] : ''
         
         if (!col.editType || col.editType === 'text') {
           children = (<>
@@ -736,6 +700,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 !== '') {
@@ -767,6 +735,11 @@
             content = <span style={mark.innerStyle}>{content}</span>
           }
         }
+
+        if (col.editable === 'true' && disabled) {
+          content = <span style={{display: 'inline-block', padding: '0 6px'}}>{content}</span>
+        }
+
         children = content
       }
     } else if (col.type === 'number') {
@@ -778,7 +751,7 @@
         }
 
         children = (<>
-          <InputNumber className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
+          <InputNumber className={err ? 'has-error' : ''} title={err} precision={col.decimal || 0} id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
         </>)
       } else {
         let content = ''
@@ -829,6 +802,11 @@
             content = <span style={mark.innerStyle}>{content}</span>
           }
         }
+
+        if (col.editable === 'true' && disabled) {
+          content = <span style={{display: 'inline-block', padding: '0 6px'}}>{content}</span>
+        }
+
         children = content
       }
     } else if (col.type === 'textarea') {
@@ -858,6 +836,10 @@
           // eslint-disable-next-line
           content = eval(content)
         } catch (e) {
+          if (window.debugger) {
+            console.info(content)
+            console.warn(e)
+          }
           content = ''
         }
       }
@@ -866,6 +848,11 @@
 
       if (col.noValue === 'hide' && content === 0) {
         content = ''
+      }
+
+      if (col.round && typeof(content) === 'number') {
+        content = Math.round(content * col.round) / col.round
+        content = content.toFixed(col.decimal)
       }
 
       if (content !== '') {
@@ -900,14 +887,6 @@
       children = (
         <CardCellComponent data={record} cards={config} elements={col.elements}/>
       )
-    } else if (col.type === 'action') {
-      style.padding = '0px'
-      if (col.style) {
-        style = {...style, ...col.style}
-      }
-      children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements}/>
-      )
     }
 
     return (<td className={'editing_all_table_cell ' + className} style={style}>{children}</td>)
@@ -929,7 +908,6 @@
   }
 
   state = {
-    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     edData: [],
     selectedRowKeys: [],  // 琛ㄦ牸涓�変腑琛�
     tableId: '',          // 琛ㄦ牸ID
@@ -967,17 +945,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)
             }
           }
     
@@ -995,7 +980,7 @@
             onCell: record => ({
               record,
               col: item,
-              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
+              config: item.type === 'custom' ? {setting, columns: fields} : null,
             })
           }
         }
@@ -1094,7 +1079,13 @@
     if (menuid !== MenuID) return
 
     if (type !== 'line') {
-      this.setState({edData: data})
+      if (setting.editType === 'multi' && data.length > 0) {
+        this.setState({edData: []}, () => {
+          this.setState({edData: data})
+        })
+      } else {
+        this.setState({edData: data})
+      }
 
       if (setting.addable && data.length === 0) {
         setTimeout(() => {
@@ -1135,6 +1126,9 @@
         if (debug) {
           console.info(sql)
         }
+
+        sql = sql.replace(/%/ig, ' mpercent ')
+
         mainItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`)
       } else {
         let sql = _sql + item.base_sql
@@ -1145,6 +1139,9 @@
         if (debug) {
           console.info(sql)
         }
+
+        sql = sql.replace(/%/ig, ' mpercent ')
+        
         localItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`)
       }
     })
@@ -1228,7 +1225,7 @@
   }
 
   resetFormList = (result) => {
-    const { columns } = this.state
+    const { columns, edData } = this.state
 
     let _edColumns = []
 
@@ -1236,7 +1233,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()}
@@ -1253,8 +1249,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 => {
@@ -1271,7 +1267,7 @@
 
         item.options = options
 
-        reCols[item.uuid] = item
+        reCols[item.uuid] = fromJS(item).toJS()
       }
     })
 
@@ -1286,8 +1282,8 @@
       return item
     })
 
-    this.setState({columns: []}, () => {
-      this.setState({columns: _edColumns})
+    this.setState({columns: [], edData: []}, () => {
+      this.setState({columns: _edColumns, edData: edData})
     })
   }
   
@@ -1393,19 +1389,18 @@
       let _data = edData.filter(item => item.$$uuid !== record.$$uuid)
       this.setState({edData: _data})
     } else {
-      let _data = edData.map(item => {
+      let _data = fromJS(edData).toJS().map(item => {
         if (item.$$uuid === record.$$uuid) {
-          record.$deleted = true
-          record.$origin = false
-          record.$type = 'del'
-          return record
-        } else {
-          return item
+          item.$deleted = true
+          item.$origin = false
+          item.$type = 'del'
         }
+
+        return item
       })
 
       this.setState({edData: _data}, () => {
-        if (setting.commit === 'simple' && record.$deleted) {
+        if (setting.commit === 'simple') {
           this.submit()
         }
       })
@@ -1688,7 +1683,7 @@
 
       this.setState({edData: _data})
     }
-    MKEmitter.emit('reloadData', this.props.MenuID, item.$$uuid, item)
+    MKEmitter.emit('reloadData', this.props.MenuID, item.$$uuid)
   }
 
   execSuccess = (res) => {
@@ -1697,12 +1692,12 @@
     if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛
       notification.success({
         top: 92,
-        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
+        message: res.ErrMesg || '鎵ц鎴愬姛',
         duration: submit.stime ? submit.stime : 2
       })
     } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛
       Modal.success({
-        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
+        title: res.ErrMesg || '鎵ц鎴愬姛'
       })
     } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
 
@@ -1719,6 +1714,8 @@
     if (submit.execSuccess !== 'never') {
       MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
     }
+
+    submit.syncComponentId && MKEmitter.emit('reloadData', submit.syncComponentId)
   }
 
   execError = (res) => {
@@ -1890,8 +1887,6 @@
       }
     }
 
-    let _footer = ''
-
     let height = setting.height || false
     if (height && height <= 100) {
       height = height + 'vh'
@@ -1924,7 +1919,6 @@
             onChange={this.changeTable}
             pagination={_pagination}
           />
-          {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
           {_data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">鎻愪氦</Button> : null}
         </div>
       </>

--
Gitblit v1.8.0