From 2ff464f30d94235b3ad04475593b75a74a354de9 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 09 四月 2020 19:04:01 +0800
Subject: [PATCH] 2020-04-09

---
 src/templates/zshare/verifycard/index.jsx |  154 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 135 insertions(+), 19 deletions(-)

diff --git a/src/templates/zshare/verifycard/index.jsx b/src/templates/zshare/verifycard/index.jsx
index 1d453bc..452686b 100644
--- a/src/templates/zshare/verifycard/index.jsx
+++ b/src/templates/zshare/verifycard/index.jsx
@@ -27,6 +27,8 @@
   }
 
   state = {
+    updateloading: false, // 淇敼涓�
+    initsql: '',          // sql楠岃瘉鏃跺彉閲忓0鏄庡強璧嬪��
     verify: {},
     fields: [],
     usefulfields: '',
@@ -268,13 +270,13 @@
       {
         title: this.props.dict['header.form.funcvar'],
         dataIndex: 'fieldName',
-        width: '13%',
+        width: '12%',
         render: (text, record) => (`${record.fieldName || ''}(${record.field})`)
       },
       {
         title: '绫诲瀷',
         dataIndex: 'billType',
-        width: '8%',
+        width: '6%',
       },
       {
         title: '鍑瘉绫诲瀷',
@@ -289,13 +291,13 @@
       {
         title: '鍏宠仈瀛楁',
         dataIndex: 'linkFieldName',
-        width: '12%',
+        width: '10%',
         render: (text, record) => (record.linkField ? `${record.linkFieldName || ''}(${record.linkField})` : '')
       },
       {
         title: '浣嶆暟',
         dataIndex: 'Type',
-        width: '8%'
+        width: '6%'
       },
       {
         title: '绀轰緥',
@@ -324,9 +326,14 @@
         }
       },
       {
+        title: '鏍囪瘑',
+        dataIndex: 'mark',
+        width: '8%'
+      },
+      {
         title: '鐘舵��',
         dataIndex: 'status',
-        width: '9%',
+        width: '8%',
         render: (text, record) => record.status === 'false' ?
           (
             <div>
@@ -373,6 +380,9 @@
 
     if (!_invalid) { // 閫夋嫨琛屾椂锛屽け鏁堥獙璇侀粯璁ゅ紑鍚�
       _invalid = card.Ot !== 'notRequired' ? 'true' : 'false'
+    }
+    if (card.sqlType === 'custom') { // 鑷畾涔夐獙璇佹椂锛屼笉浣跨敤榛樿sql
+      _verify.default = 'false'
     }
 
     _verify.default = _verify.default || 'true'
@@ -448,11 +458,39 @@
           }
 
           let _usefulfields = ['BID', 'ID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey', 'UserName', 'FullName']
+          let _declare = ['@UserName nvarchar(50)', '@FullName nvarchar(50)']
+          let _select = ['@UserName=\'\'', '@FullName=\'\'']
           let hasBid = false
+          let fieldArr = _usefulfields.map(_f => _f.toLowerCase())
 
           _fields.forEach(_f => {
             if (_f.field) {
+              if (fieldArr.includes(_f.field.toLowerCase())) return
+              fieldArr.push(_f.field.toLowerCase())
+
               _usefulfields.push(_f.field)
+
+              let _fieldlen = _f.fieldlength || 50
+
+              if (['textarea', 'fileupload', 'multiselect'].includes(_f.type)) {
+                _fieldlen = _f.fieldlength || 512
+              } else if (_f.type === 'number') {
+                _fieldlen = _f.decimal ? _f.decimal : 0
+              }
+
+              let _type = `nvarchar(${_fieldlen})`
+
+              if (_f.type.match(/date/ig)) {
+                _type = 'datetime'
+                _select.push(`@${_f.field}='1900-01-01'`)
+              } else if (_f.type === 'number') {
+                _type = `decimal(18,${_fieldlen})`
+                _select.push(`@${_f.field}=0`)
+              } else {
+                _select.push(`@${_f.field}=''`)
+              }
+
+              _declare.push(`@${_f.field} ${_type}`)
             }
             if (_f.field && _f.field.toLowerCase() === 'bid') {
               hasBid = true
@@ -470,18 +508,38 @@
 
           if (columns && columns.length > 0 && this.props.card.Ot !== 'notRequired') {
             columns.forEach(_f => {
-              if (_f.field) {
-                _usefulfields.push(_f.field)
+              if (!_f.field || fieldArr.includes(_f.field.toLowerCase())) return
+
+              fieldArr.push(_f.field.toLowerCase())
+
+              _usefulfields.push(_f.field)
+
+              let _type = `nvarchar(${_f.fieldlength || 50})`
+
+              if (_f.type === 'number') {
+                _type = `decimal(18,${_f.decimal ? _f.decimal : 0})`
+              } else if (_f.type === 'picture' || _f.type === 'textarea') {
+                _type = `nvarchar(${_f.fieldlength || 512})`
               }
+
+              if (_f.type === 'number') {
+                _select.push(`@${_f.field}=0`)
+              } else {
+                _select.push(`@${_f.field}=''`)
+              }
+    
+              _declare.push(`@${_f.field} ${_type}`)
             })
           }
 
-          _usefulfields = Array.from(new Set(_usefulfields))
           _usefulfields = _usefulfields.join(', ')
-
+          let _sql = `Declare ${_declare.join(', ')}
+            Select ${_select.join(', ')}
+          `
 
           this.setState({
             fields: _fields,
+            initsql: _sql,
             usefulfields: _usefulfields
           })
         } else {
@@ -494,20 +552,43 @@
       })
     } else {
       let _usefulfields = ['BID', 'ID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey', 'UserName', 'FullName']
+      let _declare = ['@UserName nvarchar(50)', '@FullName nvarchar(50)']
+      let _select = ['@UserName=\'\'', '@FullName=\'\'']
+      let fieldArr = _usefulfields.map(_f => _f.toLowerCase())
 
       if (columns && columns.length > 0 && this.props.card.Ot !== 'notRequired') {
         columns.forEach(_f => {
-          if (_f.field) {
-            _usefulfields.push(_f.field)
+          if (!_f.field || fieldArr.includes(_f.field.toLowerCase())) return
+
+          fieldArr.push(_f.field.toLowerCase())
+
+          _usefulfields.push(_f.field)
+
+          let _type = `nvarchar(${_f.fieldlength || 50})`
+
+          if (_f.type === 'number') {
+            _type = `decimal(18,${_f.decimal ? _f.decimal : 0})`
+          } else if (_f.type === 'picture' || _f.type === 'textarea') {
+            _type = `nvarchar(${_f.fieldlength || 512})`
           }
+
+          if (_f.type === 'number') {
+            _select.push(`@${_f.field}=0`)
+          } else {
+            _select.push(`@${_f.field}=''`)
+          }
+
+          _declare.push(`@${_f.field} ${_type}`)
         })
       }
 
-      _usefulfields = Array.from(new Set(_usefulfields))
       _usefulfields = _usefulfields.join(', ')
-
+      let _sql = `Declare ${_declare.join(', ')}
+        Select ${_select.join(', ')}
+      `
 
       this.setState({
+        initsql: _sql,
         usefulfields: _usefulfields
       })
     }
@@ -516,7 +597,7 @@
   componentDidMount() {
     // 鑾峰彇鐢熸垚鍗曞彿涓�绾ц彍鍗�
     let defer1 = new Promise(resolve => {
-      let _orderSql = 'select ID,ModularCode+ModularName+ModularNo as NameNO from sModular where deleted=0 order by ID asc'
+      let _orderSql = `select distinct ModularCode as ID,ModularCode+ModularName+ModularNo as NameNO from sModular where deleted=0 and Appkey=case when Appkey='' then '' else @Appkey@ end order by ID asc`
       _orderSql = Utils.formatOptions(_orderSql)
 
       let orderParam = {
@@ -544,7 +625,7 @@
 
     // 鑾峰彇鐢熸垚鍗曞彿浜岀骇鑿滃崟
     let defer2 = new Promise(resolve => {
-      let _orderDetailSql = 'select ModularDetailCode,ModularDetailCode+ModularDetailName as CodeName,BID,Type from sModularDetail where Deleted=0'
+      let _orderDetailSql = `select distinct ModularDetailCode,ModularDetailCode+ModularDetailName as CodeName,ModularCode as BID,Type from sModularDetail where Deleted=0 and Appkey=case when Appkey='' then '' else @Appkey@ end order by ModularDetailCode`
       _orderDetailSql = Utils.formatOptions(_orderDetailSql)
 
       let orderDetailParam = {
@@ -579,7 +660,7 @@
 
     // 鑾峰彇鍑瘉浜岀骇鑿滃崟
     let defer3 = new Promise(resolve => {
-      let _voucherSql = 'select ID,ModularCode+ModularName+ModularNo as NameNO,TypeCharOne from sModular where deleted=0'
+      let _voucherSql = 'select distinct ModularCode as ID,ModularCode+ModularName+ModularNo as NameNO,TypeCharOne from sModular where deleted=0  and Appkey=case when Appkey=\'\' then \'\' else @Appkey@ end  order by ModularCode'
       _voucherSql = Utils.formatOptions(_voucherSql)
 
       let voucherParam = {
@@ -607,7 +688,7 @@
 
     // 鑾峰彇鍑瘉涓夌骇鑿滃崟
     let defer4 = new Promise(resolve => {
-      let _voucherDetailSql = 'select ModularDetailCode,ModularDetailCode+ModularDetailName as CodeName,BID, VoucherTypeTwo, IDefine1 from sModularDetail where Deleted=0 and VoucherTypeTwo!=\'\''
+      let _voucherDetailSql = 'select distinct ModularDetailCode,ModularDetailCode+ModularDetailName as CodeName,ModularCode as BID, VoucherTypeTwo, IDefine1 from sModularDetail where Deleted=0 and VoucherTypeTwo!=\'\' and Appkey=case when Appkey=\'\' then \'\' else @Appkey@ end  order by ModularDetailCode'
       _voucherDetailSql = Utils.formatOptions(_voucherDetailSql)
 
       let voucherDetailParam = {
@@ -641,6 +722,25 @@
     })
   }
 
+  updateChange = () => {
+    let _loading = false
+    if (this.customForm && this.customForm.state.editItem) {
+      _loading = true
+    } else if (this.uniqueForm && this.uniqueForm.state.editItem) {
+      _loading = true
+    } else if (this.orderForm && this.orderForm.state.editItem) {
+      _loading = true
+    } else if (this.scriptsForm && this.scriptsForm.state.editItem) {
+      _loading = true
+    } else if (this.contrastForm && this.contrastForm.state.editItem) {
+      _loading = true
+    }
+
+    this.setState({
+      updateloading: _loading
+    })
+  }
+
   uniqueChange = (values) => {
     let verify = JSON.parse(JSON.stringify(this.state.verify))
 
@@ -659,6 +759,8 @@
 
     this.setState({
       verify: verify
+    }, () => {
+      this.updateChange()
     })
   }
 
@@ -680,6 +782,8 @@
 
     this.setState({
       verify: verify
+    }, () => {
+      this.updateChange()
     })
   }
 
@@ -701,6 +805,8 @@
 
     this.setState({
       verify: verify
+    }, () => {
+      this.updateChange()
     })
   }
 
@@ -722,6 +828,8 @@
 
     this.setState({
       verify: verify
+    }, () => {
+      this.updateChange()
     })
   }
 
@@ -743,6 +851,8 @@
 
     this.setState({
       verify: verify
+    }, () => {
+      this.updateChange()
     })
   }
 
@@ -800,6 +910,10 @@
         }
       }, 10)
     }
+
+    this.setState({
+      updateloading: true
+    })
   }
 
   handleStatus = (record, type) => {
@@ -1034,7 +1148,7 @@
           <TabPane tab="鍩虹楠岃瘉" key="1">
             <Form {...formItemLayout}>
               <Row gutter={24}>
-                <Col span={8}>
+                {this.props.card.sqlType !== 'custom' ? <Col span={8}>
                   <Form.Item label={
                     <Tooltip placement="bottomLeft" title={'榛樿sql鎵ц椤哄簭涓鸿嚜瀹氫箟鑴氭湰涔嬪墠'}>
                       <Icon type="question-circle" style={{color: '#c49f47', marginRight: '5px'}} />
@@ -1046,7 +1160,7 @@
                       <Radio value="false">涓嶆墽琛�</Radio>
                     </Radio.Group>
                   </Form.Item>
-                </Col>
+                </Col> : null}
                 <Col span={8}>
                   <Form.Item label={'璐︽湡楠岃瘉'}>
                     <Radio.Group value={verify.accountdate} onChange={(e) => {this.onOptionChange(e, 'accountdate')}}>
@@ -1100,6 +1214,7 @@
           <TabPane tab="鑷畾涔夐獙璇�" key="3">
             <CustomForm
               dict={this.props.dict}
+              initsql={this.state.initsql}
               usefulfields={this.state.usefulfields}
               customChange={this.customChange}
               wrappedComponentRef={(inst) => this.customForm = inst}
@@ -1148,6 +1263,7 @@
           <TabPane tab="鑷畾涔夎剼鏈�" key="6">
             <CustomScript
               usefulfields={this.state.usefulfields}
+              initsql={this.state.initsql}
               dict={this.props.dict}
               scriptsChange={this.scriptsChange}
               wrappedComponentRef={(inst) => this.scriptsForm = inst}

--
Gitblit v1.8.0