From 4d6b9f8a2d7b316633e43b489eae9ada949c07b5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 10 九月 2024 10:18:08 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx |  547 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 311 insertions(+), 236 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 651bc6f..7c1cc56 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
@@ -1,184 +1,173 @@
 import React, {Component} from 'react'
 import { is, fromJS } from 'immutable'
-import { notification, Modal, Table, Input } from 'antd'
+import { notification, Modal, Table, Input, Tabs } from 'antd'
 import moment from 'moment'
 import { TableOutlined, CloseCircleFilled } from '@ant-design/icons'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 const { Search } = Input
+const { TabPane } = Tabs
 
-class MKPopSelect extends Component {
-  constructor(props) {
-    super(props)
-    
-    let config = fromJS(props.config).toJS()
-    let value = props.defaultValue
-
-    let arrfield = config.columns.map(f => f.field)
-  
-    if (config.subFields && config.subFields.length > 0) {
-      config.subFields.forEach(n => {
-        if (!arrfield.includes(n.field)) {
-          arrfield.push(n.field)
-        }
-      })
-    }
-
-    if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
-      config.dataSource = config.dataSource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
-    } else {
-      config.dataSource = config.dataSource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
-    }
-
-    config.dataSource = config.dataSource.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
-    config.dataSource = config.dataSource.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
-    config.dataSource = config.dataSource.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
-    config.dataSource = config.dataSource.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
-
-    if (/\s/.test(config.dataSource)) { // 鎷兼帴鍒悕
-      config.dataSource = '(' + config.dataSource + ') tb'
-    }
-
-    let columns = []
-    let labels = {}
-    config.columns.forEach(col => {
-      labels[col.field] = col.label
-
-      if (col.Hide === 'true') return
-
-      columns.push({
-        dataIndex: col.field,
-        title: col.label,
-        sorter: col.IsSort === 'true',
-        width: col.Width || 120
-      })
-    })
-
-    let placeholder = ''
-    if (!config.searchKey) {
-      config.onload = 'true'
-    } else {
-      placeholder = []
-      config.searchKey.split(',').forEach(key => {
-        if (!labels[key]) {
-          placeholder = ''
-        } else if (placeholder) {
-          placeholder.push(labels[key])
-        }
-      })
-
-      placeholder = placeholder ? placeholder.join('銆�') : ''
-    }
-
-    this.state = {
-      config: config,
-      options: [],
-      columns,
-      value,
-      placeholder,
-      arr_field: arrfield.join(','),
-      searchKey: '',
-      pageIndex: 1,
-      pageSize: 10,
-      orderBy: '',
-      visible: false,
-      loading: false
-    }
-
-    this.timer = null
+class PopTable extends Component {
+  state = {
+    options: [],
+    searchKey: '',
+    pageIndex: 1,
+    pageSize: 10,
+    orderBy: '',
+    loading: false
   }
+
+  timer = null
 
   componentDidMount () {
-    const { mask } = this.props
+    const { config } = this.props
+    const { options } = this.state
 
-    if (mask) {
-      this.trigger()
-    }
-  }
-
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.state), fromJS(nextState))
-  }
-
-  componentWillUnmount () {
-    this.setState = () => {
-      return
+    if (config.onload === 'true' && options.length === 0) {
+      this.loadData()
     }
   }
 
   loadData () {
-    const { BID, ID } = this.props
-    const { config, pageIndex, pageSize, arr_field, searchKey, orderBy } = this.state
+    const { BID, ID, config } = this.props
+    const { pageIndex, pageSize, searchKey, orderBy } = this.state
 
     this.setState({
       loading: true
     })
 
-    let param = {
-      func: 'sPC_Get_TableData',
-      obj_name: 'data',
-      exec_type: 'y',
-      arr_field: arr_field,
-      default_sql: 'true',
-      custom_script: '',
-      menuname: config.label
-    }
+    let param = null
+    if (window.backend && window.GLOB.CacheData.has('sql_' + config.uuid)) {
+      let ex = window.GLOB.CacheData.get('sql_' + config.uuid)
+      let sysvals = {
+        time_id: Utils.getguid(),
+        mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
+        mk_organization: sessionStorage.getItem('organization') || '',
+        mk_user_type: sessionStorage.getItem('mk_user_type') || '',
+        id: ID || '',
+        bid: BID || '',
+        datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        orderby: orderBy || config.order || '',
+        pagesize: config.laypage === 'true' ? pageSize : '9999',
+        pageindex: pageIndex
+      }
+      if (window.GLOB.externalDatabase !== null) {
+        sysvals.db = window.GLOB.externalDatabase
+      }
 
-    let sql = ''
-    let DateCount = ''
-    let _search = ''
-    let _orderBy = orderBy || config.order || ''
-    let _datasource = config.dataSource
+      let exps = []
 
-    if (config.searchKey && searchKey) {
-      let fields = config.searchKey.split(',').map(field => field + ` like '%${searchKey}%'`)
-      _search = 'where ' + fields.join(' OR ')
-    }
+      if (config.searchKey) {
+        if (!searchKey) {
+          exps.push({
+            key: 'mk_search',
+            value: []
+          })
+        } else {
+          exps.push({
+            key: 'mk_search',
+            value: [{
+              key: config.searchKey,
+              match: '01',
+              type: /,/.test(config.searchKey) ? 'text_or' : 'text',
+              value: searchKey
+            }]
+          })
+        }
+        config.searchKey.split(',').forEach(key => {
+          sysvals[key.toLowerCase()] = searchKey || ''
+        })
+      }
 
-    _datasource = _datasource.replace(/@BID@/ig, `'${BID || ''}'`)
-    _datasource = _datasource.replace(/@ID@/ig, `'${ID || ''}'`)
-
-    if (config.laypage === 'true') {
-      sql = `/*system_query*/select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_datasource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
-      DateCount = `/*system_query*/select count(1) as total from ${_datasource} ${_search}`
-    } else if (_orderBy) {
-      sql = `/*system_query*/select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_datasource} ${_search}) tmptable order by tmptable.rows `
-    } else {
-      sql = `/*system_query*/select ${arr_field} from ${_datasource} ${_search}  `
-    }
-
-    let departmentcode = sessionStorage.getItem('departmentcode') || ''
-    let organization = sessionStorage.getItem('organization') || ''
-    let mk_user_type = sessionStorage.getItem('mk_user_type') || ''
+      ex.reps.forEach(n => {
+        let key = n.toLowerCase()
+        if (sysvals.hasOwnProperty(key)) {
+          exps.push({
+            key: n,
+            value: sysvals[key]
+          })
+        }
+      })
     
-    sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
-      Select @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}'
-      ${sql}`
-
-    // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
-    if (window.GLOB.debugger === true) {
-      console.info(`/*${config.label} 鏁版嵁婧�*/\n` + sql.replace(/\n\s{6}/ig, '\n'))
-      DateCount && console.info(`/*${config.label} 鎬绘暟鏌ヨ*/\n` + DateCount.replace(/\n\s{6}/ig, '\n'))
+      param = {
+        $backend: true,
+        data: [{
+          id: ex.id,
+          exps: exps,
+          menuname: '',
+          md5_id: ''
+        }]
+      }
+    } else {
+      param = {
+        func: 'sPC_Get_TableData',
+        obj_name: 'data',
+        exec_type: window.GLOB.execType || 'y',
+        arr_field: config.arr_field,
+        default_sql: 'true',
+        custom_script: '',
+        menuname: config.label
+      }
+  
+      let sql = ''
+      let DateCount = ''
+      let _search = ''
+      let _orderBy = orderBy || config.order || ''
+      let _datasource = config.dataSource
+  
+      if (config.searchKey && searchKey) {
+        let fields = config.searchKey.split(',').map(field => field + ` like '%${searchKey}%'`)
+        _search = 'where ' + fields.join(' OR ')
+      }
+  
+      _datasource = _datasource.replace(/@BID@/ig, `'${BID || ''}'`)
+      _datasource = _datasource.replace(/@ID@/ig, `'${ID || ''}'`)
+  
+      if (config.laypage === 'true') {
+        sql = `/*system_query*/select top ${pageSize} ${config.arr_field} from (select ${config.arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_datasource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
+        DateCount = `/*system_query*/select count(1) as total from ${_datasource} ${_search}`
+      } else if (_orderBy) {
+        sql = `/*system_query*/select ${config.arr_field} from (select ${config.arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_datasource} ${_search}) tmptable order by tmptable.rows `
+      } else {
+        sql = `/*system_query*/select ${config.arr_field} from ${_datasource} ${_search}  `
+      }
+  
+      let departmentcode = sessionStorage.getItem('departmentcode') || ''
+      let organization = sessionStorage.getItem('organization') || ''
+      let mk_user_type = sessionStorage.getItem('mk_user_type') || ''
+      
+      sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
+        Select @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}'
+        ${sql}`
+  
+      // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
+      if (window.GLOB.debugger === true) {
+        window.mkInfo(`/*${config.label} 鏁版嵁婧�*/\n` + sql.replace(/\n\s{6}/ig, '\n'))
+        DateCount && window.mkInfo(`/*${config.label} 鎬绘暟鏌ヨ*/\n` + DateCount.replace(/\n\s{6}/ig, '\n'))
+      }
+  
+      param.LText = Utils.formatOptions(sql, param.exec_type)
+      param.DateCount = Utils.formatOptions(DateCount, param.exec_type)
+  
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt('', param.timestamp)
+  
+      param.username = sessionStorage.getItem('User_Name') || ''
+      param.fullname = sessionStorage.getItem('Full_Name') || ''
     }
 
-    param.LText = Utils.formatOptions(sql)
-    param.DateCount = Utils.formatOptions(DateCount)
-
-    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-    param.secretkey = Utils.encrypt('', param.timestamp)
-
-    param.username = sessionStorage.getItem('User_Name') || ''
-    param.fullname = sessionStorage.getItem('Full_Name') || ''
-
-    Api.genericInterface(param).then(result => {
+    Api.getSystemCacheConfig(param, config.cache === 'true').then(result => {
       if (result.status) {
         let options = result.data.map((item, index) => {
           item.key = index
           item.$$uuid = item[config.primaryKey] || ''
-          item.$label = item[config.showField]
 
           if (config.controlField && item[config.controlField] === 'true') {
             item.$disabled = true
@@ -239,56 +228,10 @@
     }, 500)
   }
 
-  selectChange = (val, record) => {
-    const { config } = this.state
-
-    let values = {[config.field]: val}
-
-    if (config.linkSubField) {
-      config.linkSubField.forEach(m => {
-        values[m] = record[m] === undefined ? '' : record[m]
-      })
-    }
-
-    this.props.onChange(values)
-    this.setState({value: val})
-  }
-
-  trigger = (e) => {
-    const { config, options } = this.state
-    
-    e && e.stopPropagation()
-
-    this.setState({visible: true}, () => {
-      if (config.onload === 'true' && options.length === 0) {
-        this.loadData()
-      }
-    })
-  }
-
   changeRow = (record) => {
-
     if (record.$disabled) return
 
-    this.selectChange(record.$$uuid, record)
-    this.setState({visible: false})
-  }
-
-  clear = (e) => {
-    const { config } = this.state
-
-    e.stopPropagation()
-    
-    let values = {[config.field]: ''}
-
-    if (config.linkSubField) {
-      config.linkSubField.forEach(m => {
-        values[m] = ''
-      })
-    }
-
-    this.props.onChange(values)
-    this.setState({value: ''})
+    this.props.onChange(record)
   }
 
   changeTable = (pagination, filters, sorter) => {
@@ -311,29 +254,184 @@
     })
   }
 
-  cancel = () => {
-    const { mask } = this.props
+  render() {
+    const { config, value } = this.props
+    const { options, loading, total, pageIndex, pageSize } = this.state
+    
+    return <>
+      {config.searchKey ? <Search placeholder={config.placeholder} onSearch={this.searchOption} enterButton /> : null}
+      <Table
+        rowKey="$$uuid"
+        bordered={true}
+        rowSelection={null}
+        columns={config.cols}
+        dataSource={options}
+        loading={loading}
+        onRow={(record) => {
+          let className = ''
 
-    this.setState({visible: false})
+          if (record.$disabled) {
+            className = ' mk-disable-line '
+          } else if (value === record.$$uuid) {
+            className = ' ant-table-row-selected '
+          }
+          
+          return {
+            className: className,
+            onClick: () => {this.changeRow(record)},
+          }
+        }}
+        onChange={this.changeTable}
+        pagination={config.laypage === 'true' ? {
+          current: pageIndex,
+          pageSize: pageSize,
+          showSizeChanger: true,
+          total: total || 0,
+          showTotal: (total, range) => `${range[0]}-${range[1]} 鍏� ${total} 鏉
+        } : false}
+      />
+    </>
+  }
+}
 
-    if (mask) {
-      this.props.blur()
+class MKPopSelect extends Component {
+  constructor(props) {
+    super(props)
+    
+    this.state = {
+      value: props.defaultValue,
+      showValue: props.showValue,
+      visible: false
     }
   }
 
+  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))
+  }
+
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus)
+  }
+
+  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}
+    let showValue = ''
+    if (config.showField) {
+      showValue = record[config.showField] || ''
+    }
+
+    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, value: record.$$uuid, showValue})
+
+    if (config.$ctrl) {
+      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
+    }
+
+    this.props.onBlur && this.props.onBlur()
+
+    if (/\$noAct/.test(config.enter)) return
+
+    setTimeout(() => {
+      if (/\$next/.test(config.enter)) {
+        MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', ''))
+      } else {
+        MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter)
+      }
+    }, 10)
+  }
+
+  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, lineId } = this.props
+
+    e.stopPropagation()
+    
+    let values = {[config.field]: ''}
+
+    if (config.linkSubField) {
+      config.linkSubField.forEach((m, i) => {
+        values[m] = ''
+      })
+    }
+
+    this.props.onChange(values, '')
+    this.setState({value: '', showValue: ''})
+
+    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 } = this.props
-    const { value, config, options, visible, loading, total, pageIndex, pageSize, columns, placeholder } = this.state
+    const { autoFocus, BID, lineId, config } = this.props
+    const { showValue, 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}
+        {showValue || value}
+        {value && !autoFocus ? <CloseCircleFilled onClick={this.clear} /> : null}
         <TableOutlined onClick={this.trigger}/>
       </div>
       <Modal
-        wrapClassName='mk-pop-select-modal'
+        wrapClassName='mk-table-pop-select-modal'
         title={config.label}
         visible={visible}
         closable={true}
@@ -344,37 +442,14 @@
         onCancel={this.cancel}
         destroyOnClose
       >
-        {config.searchKey ? <Search placeholder={placeholder} onSearch={this.searchOption} enterButton /> : null}
-        <Table
-          rowKey="$$uuid"
-          bordered={true}
-          rowSelection={null}
-          columns={columns}
-          dataSource={options}
-          loading={loading}
-          onRow={(record) => {
-            let className = ''
-
-            if (record.$disabled) {
-              className = ' mk-disable-line '
-            } else if (value === record.$$uuid) {
-              className = ' ant-table-row-selected '
-            }
-            
-            return {
-              className: className,
-              onClick: () => {this.changeRow(record)},
-            }
-          }}
-          onChange={this.changeTable}
-          pagination={config.laypage === 'true' ? {
-            current: pageIndex,
-            pageSize: pageSize,
-            showSizeChanger: true,
-            total: total || 0,
-            showTotal: (total, range) => `${range[0]}-${range[1]} 鍏� ${total} 鏉
-          } : false}
-        />
+        {config.pops ? <Tabs>
+          {config.pops.map(tab => (
+            <TabPane tab={tab.tabName} key={tab.uuid}>
+              <PopTable config={tab} BID={BID} ID={lineId} value={value} onChange={this.selectChange}/>
+            </TabPane>
+          ))}
+        </Tabs> :
+        <PopTable config={config} BID={BID} ID={lineId} value={value} onChange={this.selectChange}/>}
       </Modal>
     </>
   }

--
Gitblit v1.8.0