From 81d0d7721bb14a34b1eef99fd9506c3eda4bda99 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 18 十月 2023 17:17:47 +0800
Subject: [PATCH] 2023-10-18

---
 src/templates/zshare/modalform/index.jsx |  197 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 156 insertions(+), 41 deletions(-)

diff --git a/src/templates/zshare/modalform/index.jsx b/src/templates/zshare/modalform/index.jsx
index 6b480c0..0c6a6b7 100644
--- a/src/templates/zshare/modalform/index.jsx
+++ b/src/templates/zshare/modalform/index.jsx
@@ -1,9 +1,10 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { fromJS } from 'immutable'
-import { Form, Row, Col, Input, Select, Radio, notification, InputNumber, Tooltip, Checkbox, AutoComplete } from 'antd'
+import { Form, Row, Col, Input, Select, Radio, notification, InputNumber, Tooltip, Checkbox, AutoComplete, Modal } from 'antd'
 import { QuestionCircleOutlined } from '@ant-design/icons'
 
+import Api from '@/api'
 import { formRule } from '@/utils/option.js'
 import { dateOptions } from '@/utils/option.js'
 import Utils from '@/utils/utils.js'
@@ -14,18 +15,18 @@
 
 const { TextArea } = Input
 const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
-const FieldsTable = asyncComponent(() => import('./fieldtable'))
+const FieldsTable = asyncComponent(() => import('@/templates/zshare/editTable'))
 const MkEditIcon = asyncComponent(() => import('@/components/mkIcon'))
 
 const modalTypeOptions = {
   text: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'regular', 'interception', 'span', 'labelwidth', 'encryption', 'tooltip', 'extra', 'enter', 'cursor', 'scan', 'splitline', 'placeholder', 'place', 'marginTop', 'marginBottom', 'lenControl', 'inputType', 'constant'],
   number: ['initval', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'cursor', 'splitline', 'place', 'marginTop', 'marginBottom'],
-  select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'setAll', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'emptyText', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom', 'pickerMode'],
+  select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom', 'pickerMode'],
   checkbox: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
-  radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'setAll', 'emptyText', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
+  radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
   checkcard: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'span', 'labelwidth', 'display', 'tooltip', 'extra', 'place', 'width', 'multiple', 'splitline', 'marginTop', 'marginBottom'],
   multiselect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'marginTop', 'marginBottom', 'dropdown'],
-  link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'setAll', 'linkField', 'linkSubField', 'span', 'place', 'labelwidth', 'tooltip', 'extra', 'emptyText', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom', 'pickerMode'],
+  link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkField', 'linkSubField', 'span', 'place', 'labelwidth', 'tooltip', 'extra', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom', 'pickerMode'],
   fileupload: ['readonly', 'required', 'hidden', 'readin', 'fieldlength', 'maxfile', 'fileType', 'span', 'labelwidth', 'linkSubField', 'tooltip', 'extra', 'compress', 'miniSet', 'splitline', 'marginTop', 'marginBottom', 'maxSize'],
   switch: ['initval', 'openVal', 'closeVal', 'openText', 'closeText', 'readonly', 'hidden', 'readin', 'span', 'labelwidth', 'linkSubField', 'tooltip', 'extra', 'splitline', 'marginTop', 'marginBottom'],
   check: ['initval', 'openVal', 'closeVal', 'readonly', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'splitline', 'marginTop', 'marginBottom', 'checkTip'],
@@ -42,6 +43,7 @@
   brafteditor: ['required', 'hidelabel', 'hidden', 'readin', 'fieldlength', 'readonly', 'span', 'labelwidth', 'tooltip', 'extra', 'encryption', 'marginTop', 'marginBottom'],
   funcvar: ['span', 'labelwidth', 'splitline', 'marginTop', 'marginBottom'],
   linkMain: ['readonly', 'required', 'hidden','declare', 'span', 'labelwidth', 'tooltip', 'interception', 'extra', 'place', 'marginTop', 'marginBottom'],
+  popSelect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'enter', 'dataSource', 'columns', 'primaryKey', 'order', 'controlField', 'laypage', 'onload', 'searchKey', 'showField', 'popWidth'],
   vercode: ['label', 'field', 'type', 'blacklist', 'supField', 'readonly', 'required', 'hidden', 'span', 'labelwidth', 'tooltip', 'marginTop', 'marginBottom', 'placeholder', 'enter', 'smsId', 'phoneField', 'sendType']
 }
 
@@ -428,28 +430,32 @@
         this.record.readonly = 'false'
       }
 
-      if (this.record.options.length > 0) {
-        if (value === 'checkcard') {
+      if (value === 'checkcard') {
+        if (this.record.options.length > 0) {
           this.record.options = this.record.options.map(cell => {
             cell.$value = cell.Value || ''
             delete cell.Value
             return cell
           })
+        }
   
-          if (this.record.options[0].Text) {
-            let key = Utils.getuuid()
-    
-            this.record.fields = [{
-              $index: 1,
-              align: 'left',
-              color: 'rgba(0, 0, 0, 0.85)',
-              field: 'Text',
-              fontSize: 14,
-              key: key,
-              uuid: key
-            }]
-          }
-        } else if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(value)) {
+        if (this.record.options[0] && this.record.options[0].Text) {
+          let key = Utils.getuuid()
+  
+          this.record.fields = [{
+            $index: 1,
+            align: 'left',
+            color: 'rgba(0, 0, 0, 0.85)',
+            field: 'Text',
+            fontSize: 14,
+            key: key,
+            uuid: key
+          }]
+        } else {
+          this.record.fields = []
+        }
+      } else if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(value)) {
+        if (this.record.options.length > 0) {
           if (!this.record.options[0].Text && this.record.fields.length > 0) {
             let field = this.record.fields[0].field
     
@@ -513,12 +519,8 @@
     this.record[key] = value
   }
 
-  changeField = (data) => {
-    this.record.fields = data || []
-  }
-
-  changeOptions = (data) => {
-    this.record.options = data || []
+  changeOptions = (data, key) => {
+    this.record[key] = data || []
   }
 
   changeVal = (val, type) => {
@@ -635,18 +637,15 @@
             message: '涓嶅彲浣跨敤鑻辨枃鐘舵�佺殑鍗曞紩鍙凤紒'
           }
         ]
-        if (item.key === 'field') {
+        if (item.rules) {
+          rules.push(...item.rules)
+        } else if (item.key === 'field') {
           rules.push({
             pattern: formRule.field.pattern,
             message: formRule.field.message
           }, {
             max: formRule.field.max,
             message: formRule.field.maxMessage
-          })
-        } else if (item.key === 'regularExtra') {
-          rules.push({
-            pattern: /^[~!@#$%^&*()_+:;{}<>,.-]*$/,
-            message: '鎵╁睍绗﹀寘鎷瑍!@#$%^&*()_+:;{}<>,.-'
           })
         } else if (item.max) {
           rules.push({
@@ -672,7 +671,7 @@
             <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />
           </AutoComplete>
         } else {
-          content = <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />
+          content = <Input placeholder={item.placeholder || ''} autoComplete="off" onPressEnter={this.handleSubmit} />
         }
       } else if (item.type === 'number') {
         rules = [
@@ -689,6 +688,12 @@
         rules = [
           { required: item.required, message: '璇烽�夋嫨' + item.label + '!' }
         ]
+
+        let options = item.options
+        if (typeof(item.options) === 'string') {
+          options = this.record[item.options] || []
+        }
+
         content = <Select
           showSearch
           allowClear={item.allowClear === true}
@@ -696,7 +701,7 @@
           onChange={(value) => {this.optionChange(item.key, value)}}
           getPopupContainer={() => document.getElementById('modal-fields-form-box')}
         >
-          {item.options.map((option, i) =>
+          {options.map((option, i) =>
             <Select.Option key={`${i}`} value={option.value || option.field || ''}>
               {option.text || option.label}
             </Select.Option>
@@ -791,7 +796,7 @@
             columns.push({ title: transfield[field] || field, key: field })
           })
 
-          content = <EditTable columns={columns} module="form" onChange={this.changeOptions}/>
+          content = <EditTable columns={columns} module="form" onChange={(data) => this.changeOptions(data, item.key)}/>
         } else {
           if (this.record.multiple === 'true') {
             linkSubFields = []
@@ -826,7 +831,7 @@
             columns.push({ title: transfield[m] || m, key: m })
           })
 
-          content = <EditTable columns={columns} onChange={this.changeOptions}/>
+          content = <EditTable columns={columns} onChange={(data) => this.changeOptions(data, item.key)}/>
         }
       } else if (item.type === 'fields') {
         span = 24
@@ -835,7 +840,7 @@
           { required: item.required, message: '璇锋坊鍔�' + item.label + '!' }
         ]
 
-        content = <FieldsTable onChange={this.changeField}/>
+        content = <FieldsTable indexShow={false} actions={['edit', 'move', 'del', 'add']} columns={item.columns} data={this.record[item.key] || []} onChange={(data) => this.changeOptions(data, item.key)}/>
       } else if (item.type === 'color') {
         className = 'color-form-item'
         rules = [
@@ -917,12 +922,36 @@
     }
   }
 
-  handleConfirm = () => {
+  handleConfirm = (fields) => {
+    const { card } = this.props
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     return new Promise((resolve, reject) => {
       this.props.form.validateFieldsAndScroll((err, values) => {
         if (!err) {
-          values.uuid = this.props.card.uuid
+          values.uuid = card.uuid
+
+          if (card.style) {
+            values.style = card.style
+          }
+
+          let fieldrepet = false // 瀛楁閲嶅
+
+          fields.forEach(item => {
+            if (item.uuid === card.uuid || !values.field || !item.field) return
+            if (item.field.toLowerCase() === values.field.toLowerCase()) {
+              fieldrepet = true
+            }
+          })
+
+          if (fieldrepet) {
+            notification.warning({
+              top: 92,
+              message: '瀛楁宸插瓨鍦紒',
+              duration: 10
+            })
+            return
+          }
+
           // 涓嬫媺鑿滃崟鎴栬仈鍔ㄨ彍鍗�
           if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(values.type)) {
             if (values.resourceType === '0') {
@@ -1060,7 +1089,93 @@
             return
           }
 
-          resolve(values)
+          window.GLOB.formId = card.uuid
+
+          if (['select', 'multiselect', 'link', 'checkbox', 'radio', 'checkcard'].includes(values.type) && values.resourceType === '1' && values.dataSource) {
+            let _option = Utils.getSelectQueryOptions(values)
+
+            let sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
+            ${_option.sql}`
+    
+            // LoginUID|SessionUid|UserID|Appkey 宸叉浛鎹�
+            sql = sql.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|time_id)@/ig, `'1949-10-01 15:00:00'`)
+    
+            let rduri = ''
+            if (window.GLOB.mainSystemApi && values.database === 'sso') {
+              rduri = window.GLOB.mainSystemApi
+            }
+            
+            resolve({values, loading: true, promise: () => new Promise((resolve, reject) => {
+              Api.sDebug(sql, rduri).then(result => {
+                if (result.status || result.ErrCode === '-2') {
+                  resolve()
+                } else {
+                  Modal.error({
+                    title: result.message
+                  })
+                  reject()
+                }
+              })
+            })})
+          } else if (values.type === 'popSelect') {
+            let arrfield = values.columns.map(f => f.field)
+  
+            if (values.linkSubField && values.linkSubField.length > 0) {
+              values.linkSubField.forEach(n => {
+                if (!arrfield.includes(n)) {
+                  arrfield.push(n)
+                }
+              })
+            }
+  
+            let _datasource = values.dataSource
+            let sql = ''
+  
+            if (/\s/.test(_datasource)) { // 鎷兼帴鍒悕
+              _datasource = '(' + _datasource + ') tb'
+            }
+  
+            arrfield = arrfield.join(',')
+  
+            let _search = ''
+
+            if (values.searchKey) {
+              let fields = values.searchKey.split(',').map(field => field + ' like \'%mk%\'')
+              _search = 'where ' + fields.join(' OR ')
+            }
+  
+            if (values.laypage === 'true') {
+              sql = `/*system_query*/select top 10 ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by ${values.order}) as rows from ${_datasource} ${_search}) tmptable where rows > 0 order by tmptable.rows `
+            } else if (values.order) {
+              sql = `/*system_query*/select ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by ${values.order}) as rows from ${_datasource} ${_search}) tmptable order by tmptable.rows `
+            } else {
+              sql = `/*system_query*/select ${arrfield} from ${_datasource} ${_search}  `
+            }
+  
+            sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
+              ${sql}`
+  
+            sql = sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
+            sql = sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+            sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+            sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+            sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+  
+            resolve({values, loading: true, promise: () => new Promise((resolve, reject) => {
+              Api.sDebug(sql).then(result => {
+                if (result.status || result.ErrCode === '-2') {
+                  resolve()
+                } else {
+                  Modal.error({
+                    title: result.message
+                  })
+                  reject()
+                }
+              })
+            })})
+          } else {
+            resolve({values})
+          }
         } else {
           reject(err)
         }

--
Gitblit v1.8.0