From a1e9b18a4dbfd21e1bf4d5cb60974ac2f0115efd Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 30 五月 2025 15:18:44 +0800
Subject: [PATCH] 2025-05-30

---
 src/tabviews/zshare/mutilform/mkPopSelect/index.jsx |  206 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 149 insertions(+), 57 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/mkPopSelect/index.jsx b/src/tabviews/zshare/mutilform/mkPopSelect/index.jsx
index a0d02c5..3aca1c8 100644
--- a/src/tabviews/zshare/mutilform/mkPopSelect/index.jsx
+++ b/src/tabviews/zshare/mutilform/mkPopSelect/index.jsx
@@ -39,6 +39,7 @@
     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 || ''}'`)
+    config.dataSource = config.dataSource.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
 
     if (/\s/.test(config.dataSource)) { // 鎷兼帴鍒悕
       config.dataSource = '(' + config.dataSource + ') tb'
@@ -60,6 +61,7 @@
     })
 
     let placeholder = ''
+    let searchKey = ''
     if (!config.searchKey) {
       config.onload = 'true'
     } else {
@@ -73,6 +75,11 @@
       })
 
       placeholder = placeholder ? placeholder.join('銆�') : ''
+
+      if (value && !config.showValue) {
+        searchKey = value
+        config.onload = 'true'
+      }
     }
 
     this.state = {
@@ -80,9 +87,10 @@
       options: [],
       columns,
       value,
+      showValue: config.showValue,
       placeholder,
       arr_field: arrfield.join(','),
-      searchKey: '',
+      searchKey: searchKey,
       pageIndex: 1,
       pageSize: 10,
       orderBy: '',
@@ -119,61 +127,128 @@
       loading: true
     })
 
-    let param = {
-      func: 'sPC_Get_TableData',
-      obj_name: 'data',
-      exec_type: window.GLOB.execType || '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.formSqlId)) {
+      let ex = window.GLOB.CacheData.get('sql_' + config.formSqlId)
+      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,
+        $type: 's_Get_TableData',
+        data: [{
+          id: ex.id,
+          menuname: config.label || '',
+          exps: exps,
+          md5_id: ''
+        }]
+      }
+    } else {
+      param = {
+        func: 'sPC_Get_TableData',
+        obj_name: 'data',
+        exec_type: window.GLOB.execType || 'y',
+        arr_field: 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} ${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') || ''
+      
+      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.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') || ''
 
     Api.genericInterface(param).then(result => {
       if (result.status) {
@@ -188,8 +263,17 @@
 
           return item
         })
+
+        let showValue = this.state.showValue
+
+        if (showValue) {
+          if (options.findIndex(item => this.state.value === item.$$uuid) > -1) {
+            showValue = ''
+          }
+        }
   
         this.setState({
+          showValue,
           options: options,
           total: result.total || 0,
           loading: false
@@ -260,18 +344,26 @@
       })
     }
 
+    if (config.linkFields) {
+      config.linkFields.forEach((m, i) => {
+        setTimeout(() => {
+          MKEmitter.emit('mkFP', m.uuid, val, 0)
+        }, (i + 1) * 100)
+      })
+    }
+
     this.props.onChange(val, other)
-    this.setState({value: val}, () => {
+    this.setState({value: val, showValue: ''}, () => {
       if (config.enter === 'tab') {
         MKEmitter.emit('mkFC', 'focus', config.tabUuid)
       } else if (config.enter === 'sub') {
         config.tabUuid && MKEmitter.emit('mkFC', 'focus', config.tabUuid)
         if (config.subFields) {
           setTimeout(() => {
-            this.props.onSubmit(config.tabUuid)
+            this.props.onSubmit(config.tabUuid, config.errTabUuid)
           }, 1000)
         } else {
-          this.props.onSubmit(config.tabUuid)
+          this.props.onSubmit(config.tabUuid, config.errTabUuid)
         }
       }
     })
@@ -312,14 +404,14 @@
   }
 
   render() {
-    const { value, config, options, visible, loading, total, pageIndex, pageSize, columns, placeholder } = this.state
+    const { value, showValue, config, options, visible, loading, total, pageIndex, pageSize, columns, placeholder, searchKey } = this.state
     
     return <>
       <Select
         className="mk-pop-select"
         showSearch={!!config.searchKey}
         allowClear
-        value={value}
+        value={showValue || value}
         onSearch={(val) => val && this.searchOption(val)}
         filterOption={false}
         onChange={(val) => this.selectChange(val === undefined ? '' : val)}
@@ -342,7 +434,7 @@
         onCancel={() => this.setState({visible: false})}
         destroyOnClose
       >
-        {config.searchKey ? <Search placeholder={placeholder} onSearch={this.searchOption} enterButton /> : null}
+        {config.searchKey ? <Search placeholder={placeholder} defaultValue={searchKey} onSearch={this.searchOption} enterButton /> : null}
         <Table
           rowKey="$$uuid"
           bordered={true}

--
Gitblit v1.8.0