From 6dd965723be9dc245105296198c25a80cfe51b54 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 27 四月 2023 10:51:50 +0800
Subject: [PATCH] 2023-04-27

---
 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx |  173 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 104 insertions(+), 69 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 bcf4ee3..2efbd4e 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -126,6 +126,9 @@
     const { col, record } = this.props
 
     if (id !== col.uuid + record.$$uuid) return
+
+    if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField])) return
+
     this.focus()
   }
 
@@ -288,6 +291,11 @@
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
 
+    let disabled = false
+    if (col.ctrlField) {
+      disabled = col.ctrlValue.includes(record[col.ctrlField])
+    }
+
     let children = null
     if (col.type === 'text') {
       let content = ''
@@ -325,7 +333,7 @@
         }
       }
 
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         if (editing) {
           if (!col.editType || col.editType === 'text') {
             return (<td className="editing_table_cell">
@@ -421,7 +429,7 @@
         }
       }
 
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         if (editing) {
           return (<td className="editing_table_cell">
             <InputNumber id={col.uuid + record.$$uuid} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
@@ -685,9 +693,14 @@
     let { col, config, record, style, className } = this.props
     const { err } = this.state
 
+    let disabled = false
+    if (col.ctrlField) {
+      disabled = col.ctrlValue.includes(record[col.ctrlField])
+    }
+
     let children = null
     if (col.type === 'text') {
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         let _value = ''
         if (col.editField) {
           _value = record[col.editField] !== undefined ? record[col.editField] : ''
@@ -757,7 +770,7 @@
         children = content
       }
     } else if (col.type === 'number') {
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         let _value = record[col.field] !== undefined ? record[col.field] : ''
         children = (<>
           <InputNumber id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress}/>
@@ -916,7 +929,7 @@
     pageIndex: 1,         // 鍒濆椤甸潰绱㈠紩
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
     columns: null,        // 鏄剧ず鍒�
-    fields: [],
+    forms: [],
     pickup: false,        // 鏀惰捣鏈�夋嫨椤�
     orderfields: {},      // 鎺掑簭id涓巉ield杞崲
     loading: false,
@@ -932,51 +945,85 @@
 
     let _columns = []
     let deForms = []
-    columns.forEach(item => {
-      if (!initEditLine && item.editable === 'true') {
-        initEditLine = item
-      }
+    let _forms = {}
 
-      if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') {
-        let _option = Utils.getSelectQueryOptions(item)
+    let getColumns = (cols) => {
+      return cols.map(item => {
+        let cell = null
+  
+        if (item.type === 'colspan') {
+          cell = { title: item.label, align: item.Align }
+          cell.children = getColumns(item.subcols)
+        } else {
+          if (item.editable === 'true') {
+            _forms[item.field] = item
+            if (!initEditLine) {
+              initEditLine = item
+            }
 
-        if (window.GLOB.debugger === true || window.debugger === true) {
-          console.info(_option.sql)
+            if (item.ctrlField) {
+              item.ctrlValue = item.ctrlValue.split(',')
+            }
+          }
+    
+          if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') {
+            let _option = Utils.getSelectQueryOptions(item)
+    
+            if (window.GLOB.debugger === true || window.debugger === true) {
+              console.info(_option.sql)
+            }
+    
+            item.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
+            item.arr_field = _option.field
+    
+            deForms.push(item)
+          }
+    
+          if (item.field) {
+            orderfields[item.uuid] = item.field
+          }
+
+          cell = {
+            align: item.Align,
+            dataIndex: item.uuid,
+            title: item.label,
+            sorter: !!(item.field && item.IsSort === 'true'),
+            width: item.Width || 120,
+            $type: item.type,
+            onCell: record => ({
+              record,
+              col: item,
+              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
+            })
+          }
         }
+  
+        return cell
+      })
+    }
+    _columns = getColumns(columns)
 
-        item.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
-        item.arr_field = _option.field
+    let forms = []
+    fields.forEach(item => {
+      if (item.field === setting.primaryKey) return
 
-        deForms.push(item)
+      if (_forms[item.field]) {
+        forms.push({..._forms[item.field], datatype: item.datatype})
+      } else {
+        forms.push(item)
       }
+    })
 
-      if (item.field) {
-        orderfields[item.uuid] = item.field
+    _columns.forEach(item => {
+      if (item.$type === 'action') return
+
+      let _copy = fromJS(item).toJS()
+      _copy.sorter = false
+
+      if (item.editable === 'true') {
+        _copy.title = <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span>
       }
-
-      let _item = {
-        align: item.Align,
-        dataIndex: item.uuid,
-        title: item.label,
-        sorter: item.field && item.IsSort === 'true',
-        width: item.Width || 120,
-        onCell: record => ({
-          record,
-          col: item,
-          config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
-        })
-      }
-
-      if (item.type !== 'action') {
-        let _copy = fromJS(_item).toJS()
-        _copy.sorter = false
-
-        if (item.editable === 'true') {
-          _copy.title = <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span>
-        }
-        edColumns.push(_copy)
-      }
-      _columns.push(_item)
+      edColumns.push(_copy)
     })
 
     if (setting.delable !== 'false' && setting.operType !== 'buoyMode') {
@@ -993,13 +1040,6 @@
       })
     }
 
-    // if (setting.borderColor) { // 杈规棰滆壊
-    //   let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}`
-    //   let ele = document.createElement('style')
-    //   ele.innerHTML = style
-    //   document.getElementsByTagName('head')[0].appendChild(ele)
-    // }
-
     let size = (setting.pageSize || 10) + ''
     let pageOptions = ['10', '25', '50', '100', '500', '1000']
 
@@ -1009,6 +1049,7 @@
     }
 
     this.setState({
+      forms,
       pageSize: setting.pageSize || 10,
       pageOptions,
       columns: _columns,
@@ -1035,12 +1076,6 @@
   }
 
   componentDidMount () {
-    const { fields, setting } = this.props
-
-    this.setState({
-      fields: fields.filter(item => item.field !== setting.primaryKey),
-    })
-
     MKEmitter.addListener('subLine', this.subLine)
     MKEmitter.addListener('nextLine', this.nextLine)
     MKEmitter.addListener('addRecord', this.addLine)
@@ -1286,7 +1321,7 @@
   }
 
   subLine = (col, record) => {
-    const { tableId, fields, edData } = this.state
+    const { tableId, forms, edData } = this.state
 
     if (col && col.tableId !== tableId) return
 
@@ -1300,7 +1335,7 @@
     setTimeout(() => {
       let item = fromJS(record).toJS()
       let line = []
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.editable !== 'true' || item.$deleted) {
           if (col.type === 'number') {
             item[col.field] = +item[col.field]
@@ -1357,7 +1392,7 @@
   }
 
   plusLine = () => {
-    const { edData, fields, initEditLine } = this.state
+    const { edData, forms, initEditLine } = this.state
 
     let item = {...edData[edData.length - 1]}
 
@@ -1365,7 +1400,7 @@
     item.$type = 'add'
     item.$Index = ''
 
-    fields.forEach(col => {
+    forms.forEach(col => {
       if (col.initval !== '$copy') {
         item[col.field] = col.initval
       }
@@ -1434,7 +1469,7 @@
 
   addLine = (id, record) => {
     const { BID } = this.props
-    const { edData, fields, tableId } = this.state
+    const { edData, forms, tableId } = this.state
 
     if (id) {
       if (id !== tableId) return
@@ -1448,7 +1483,7 @@
       item.$Index = ''
       item.$$BID = BID || ''
   
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.initval !== '$copy') {
           item[col.field] = col.initval
         }
@@ -1481,7 +1516,7 @@
         item.$$BID = BID || ''
       }
   
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.initval !== '$copy') {
           item[col.field] = col.initval
         }
@@ -1502,7 +1537,7 @@
   }
 
   checkData = () => {
-    const { edData, fields } = this.state
+    const { edData, forms } = this.state
 
     if (edData.length === 0) {
       notification.warning({
@@ -1516,7 +1551,7 @@
     let Index = 1
     let data = fromJS(edData).toJS().map(item => {
       let line = []
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.editable !== 'true' || item.$deleted) {
           if (col.type === 'number') {
             item[col.field] = +item[col.field]
@@ -1581,7 +1616,7 @@
 
   submit = (data, type) => {
     const { submit, BID, setting } = this.props
-    const { fields } = this.state
+    const { forms } = this.state
 
     if (type !== 'simple' && (setting.commit === 'change' || setting.commit === 'simple')) {
       data = data.filter(item => !item.$origin)
@@ -1596,7 +1631,7 @@
       return
     }
 
-    let result = getEditTableSql(submit, data, fields)
+    let result = getEditTableSql(submit, data, forms)
 
     let param = {
       excel_in: result.lines,
@@ -1977,7 +2012,7 @@
         pageSizeOptions: pageOptions,
         showSizeChanger: true,
         total: this.props.total || 0,
-        showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}`
+        showTotal: (total, range) => `${range[0]}-${range[1]} 鍏� ${total} 鏉
       }
     }
 
@@ -1996,9 +2031,9 @@
         </div> : null}
         <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}>
           {!submit.hasAction && pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> : null}
-          <Switch title="缂栬緫" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} />
+          {setting.switchable !== 'false' ? <Switch title="缂栬緫" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} /> : null}
         </div>
-        <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''}`} id={tableId}>
+        <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} id={tableId}>
           <Table
             rowKey="$$uuid"
             components={components}

--
Gitblit v1.8.0