From 5374fa10c854e2602e4a05e4475356c64d801114 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 08 一月 2020 18:00:24 +0800
Subject: [PATCH] 2020-01-08

---
 src/tabviews/subtable/subTable/index.jsx     |   39 ++++++++++++
 src/tabviews/commontable/mainTable/index.jsx |   25 ++++++++
 src/utils/utils.js                           |   57 ++++++++++++++-----
 src/tabviews/tableshare/actionList/index.jsx |   10 +-
 4 files changed, 109 insertions(+), 22 deletions(-)

diff --git a/src/tabviews/commontable/mainTable/index.jsx b/src/tabviews/commontable/mainTable/index.jsx
index 6a3c73c..b2223cd 100644
--- a/src/tabviews/commontable/mainTable/index.jsx
+++ b/src/tabviews/commontable/mainTable/index.jsx
@@ -1,8 +1,10 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Table, message, Affix, Button } from 'antd'
+import { Table, message, Affix, Button, Typography } from 'antd'
 import './index.scss'
+
+const { Paragraph } = Typography
 
 export default class MainTable extends Component {
   static propTpyes = {
@@ -141,6 +143,27 @@
           })}
         </div>
       )
+    } else if (item.type === 'textarea') {
+      let content = ''
+      let match = false
+      if (item.field && record.hasOwnProperty(item.field)) {
+        content = `${record[item.field]}`
+      }
+
+      if (content && item.matchVal && content.indexOf(item.matchVal) > 0) {
+        match = true
+      }
+
+      content = (item.prefix || '') + content + (item.postfix || '')
+
+      return (
+        <div className={match ? item.color : ''}>
+          <div className="background"></div>
+          <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}>
+            <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph>
+          </div>
+        </div>
+      )
     } else if (item.type === 'action') {
       return (
         <div className={item.style} style={{ minWidth: (item.Width || 120) + 'px' }}>
diff --git a/src/tabviews/subtable/subTable/index.jsx b/src/tabviews/subtable/subTable/index.jsx
index 093c555..f860604 100644
--- a/src/tabviews/subtable/subTable/index.jsx
+++ b/src/tabviews/subtable/subTable/index.jsx
@@ -1,7 +1,9 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Table, message, Button } from 'antd'
+import { Table, message, Button, Typography } from 'antd'
 import './index.scss'
+
+const { Paragraph } = Typography
 
 export default class MainTable extends Component {
   static propTpyes = {
@@ -109,6 +111,41 @@
           </div>
         </div>
       )
+    } else if (item.type === 'picture') {
+      let photos = ''
+      if (item.field && record.hasOwnProperty(item.field)) {
+        photos = record[item.field].split(',')
+      } else {
+        photos = ''
+      }
+      return (
+        <div className="picture-col" style={{ minWidth: (item.Width || 120) + 'px' }}>
+          {photos && photos.map((url, i) => {
+            return <img key={`${i}`} src={url} alt=""/>
+          })}
+        </div>
+      )
+    } else if (item.type === 'textarea') {
+      let content = ''
+      let match = false
+      if (item.field && record.hasOwnProperty(item.field)) {
+        content = `${record[item.field]}`
+      }
+
+      if (content && item.matchVal && content.indexOf(item.matchVal) > 0) {
+        match = true
+      }
+
+      content = (item.prefix || '') + content + (item.postfix || '')
+
+      return (
+        <div className={match ? item.color : ''}>
+          <div className="background"></div>
+          <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}>
+            <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph>
+          </div>
+        </div>
+      )
     } else if (item.type === 'action') {
       return (
         <div className={item.style} style={{ minWidth: (item.Width || 120) + 'px' }}>
diff --git a/src/tabviews/tableshare/actionList/index.jsx b/src/tabviews/tableshare/actionList/index.jsx
index 0c22ac1..f49ee91 100644
--- a/src/tabviews/tableshare/actionList/index.jsx
+++ b/src/tabviews/tableshare/actionList/index.jsx
@@ -177,7 +177,7 @@
           if (btn.innerFunc) { // 浣跨敤鑷畾涔夊嚱鏁�
             param.func = btn.innerFunc
           } else if (btn.sql) {
-            param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, '', param[setting.primaryKey], data[0])) // 鏁版嵁婧�
+            param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, '', param, data[0])) // 鏁版嵁婧�
             param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
             param.secretkey = Utils.encrypt(param.LText, param.timestamp)
           }
@@ -194,11 +194,11 @@
               param[setting.primaryKey] = Utils.getguid()
             }
 
-            param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, formdata, param[setting.primaryKey], data[0])) // 鏁版嵁婧�
+            param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, formdata, param, data[0])) // 鏁版嵁婧�
             param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
             param.secretkey = Utils.encrypt(param.LText, param.timestamp)
           } else if (btn.sql) {
-            param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, formdata, param[setting.primaryKey], data[0])) // 鏁版嵁婧�
+            param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, formdata, param, data[0])) // 鏁版嵁婧�
             param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
             param.secretkey = Utils.encrypt(param.LText, param.timestamp)
           }
@@ -229,7 +229,7 @@
             if (btn.innerFunc) {
               param.func = btn.innerFunc
             } else if (btn.sql) {
-              param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, '', param[setting.primaryKey], cell)) // 鏁版嵁婧�
+              param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, '', param, cell)) // 鏁版嵁婧�
               param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
               param.secretkey = Utils.encrypt(param.LText, param.timestamp)
             }
@@ -245,7 +245,7 @@
               if (setting.primaryKey) {
                 param[setting.primaryKey] = cell[setting.primaryKey]
               }
-              param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, formdata, param[setting.primaryKey], cell)) // 鏁版嵁婧�
+              param.LText = Utils.formatOptions(Utils.getSysDefaultSql(btn, setting, formdata, param, cell)) // 鏁版嵁婧�
               param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
               param.secretkey = Utils.encrypt(param.LText, param.timestamp)
             }
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 2a52009..4d2c968 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -448,7 +448,9 @@
    * @return {String} type   鎵ц绫诲瀷
    * @return {String} table  琛ㄥ悕
    */
-  static getSysDefaultSql (btn, setting, formdata, primaryId, data) {
+  static getSysDefaultSql (btn, setting, formdata, param, data) {
+    let primaryId = param[setting.primaryKey]
+    let BID = param.BID
     let verify = btn.verify
     let _formFieldValue = {}
 
@@ -461,7 +463,7 @@
     let primaryKey = setting.primaryKey || 'id' // 涓婚敭瀛楁
     // 绯荤粺鍙橀噺澹版槑涓庤缃垵濮嬪��
     let _sql = `Declare @tbid nvarchar(50), @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50)
-      Select @tbid='', @ErrorCode='',@retmsg='',@BVoucher='',@FIBVoucherDate='',@FiYear=''
+      Select @BVoucher='',@FIBVoucherDate='',@FiYear=''
       `
 
     if (verify && verify.accountdate === 'true') { // 鍚敤璐︽湡楠岃瘉
@@ -470,20 +472,27 @@
           GOTO aaa
         `
     }
-    if (btn.sqlType !== 'insert' && verify && verify.invalid === 'true') { // 澶辨晥楠岃瘉锛屾坊鍔犳暟鎹椂涓嶇敤
-      _sql += `Select @tbid=${primaryKey} from ${btn.sql} where ${primaryKey} ='${primaryId}'
+    if (btn.sqlType !== 'insert' && verify && verify.invalid === 'true' && setting.dataresource) { // 澶辨晥楠岃瘉锛屾坊鍔犳暟鎹椂涓嶇敤
+      let datasource = setting.dataresource
+      if (/\s/.test(datasource)) { // 鎷兼帴鍒悕
+        datasource = '(' + datasource + ') tb'
+      }
+
+      _sql += `Select @tbid='', @ErrorCode='',@retmsg=''
+        Select @tbid=${primaryKey} from ${datasource} where ${primaryKey} ='${primaryId}'
         If @tbid=''
         Begin
-          Setect @ErrorCode='E',@retmsg='鏁版嵁宸插け鏁�'
+          select @ErrorCode='E',@retmsg='鏁版嵁宸插け鏁�'
           goto aaa
         end
         `
     }
-    if (formdata && verify && verify.uniques.length > 0) { // 鍞竴鎬ч獙璇侊紝蹇呴』瀛樺湪琛ㄥ崟锛堣〃鍗曞瓨鍦ㄦ椂锛屼富閿潎涓哄崟鍊硷級
+    if (formdata && verify && verify.uniques.length > 0) { // 鍞竴鎬ч獙璇侊紝蹇呴』瀛樺湪琛ㄥ崟锛堣〃鍗曞瓨鍦ㄦ椂锛屼富閿潎涓哄崟鍊硷級,蹇呴』濉啓鏁版嵁婧�
       let _primaryId = primaryId
       if (btn.sqlType === 'insert') {
         _primaryId = ''
       }
+
       verify.uniques.forEach(item => {
         let _fieldValue = [] // 琛ㄥ崟閿�煎field=value
         let _value = []      // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず
@@ -497,7 +506,7 @@
           Select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${_primaryId}'
           If @tbid!=''
           Begin
-            Setect @ErrorCode='${item.errorCode}',@retmsg='${item.fieldlabel || ''}锛�${_value.join(' ')} 宸插瓨鍦�' 
+            select @ErrorCode='${item.errorCode}',@retmsg='${item.fieldlabel || ''}锛�${_value.join(' ')} 宸插瓨鍦�' 
             goto aaa
           end
           `
@@ -505,6 +514,11 @@
     }
     
     if (verify && verify.customverifys.length > 0) { // 鑷畾涔夐獙璇�
+      let _primaryId = primaryId
+      if (btn.sqlType === 'insert') {
+        _primaryId = ''
+      }
+
       verify.customverifys.forEach(item => {
         let _cuSql = item.sql
         if (data) {
@@ -514,15 +528,22 @@
         keys = keys.sort((a, b) => {
           return b.length - a.length
         })
+
         keys.forEach(key => {
-          _cuSql.replace('@' + key, _formFieldValue[key])
+          let reg = new RegExp('@' + key, 'ig')
+          _cuSql = _cuSql.replace(reg, `'${_formFieldValue[key]}'`)
         })
+        let idreg = new RegExp('@ID', 'ig')
+        _cuSql = _cuSql.replace(idreg, `'${_primaryId}'`)
+
+        let bidreg = new RegExp('@BID', 'ig')
+        _cuSql = _cuSql.replace(bidreg, `'${BID}'`)
 
         _sql += `Select @tbid='', @ErrorCode='',@retmsg=''
           Select top 1 @tbid='X' from (${_cuSql}) a
-          If @tbid ${item.result === 'true' ? '=' : '!='}''
+          If @tbid ${item.result === 'true' ? '!=' : '='}''
           Begin
-            Setect @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}'
+            select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}'
             goto aaa
           end
           `
@@ -554,8 +575,12 @@
       })
     }
 
+    let _updateconfig = ''
+
     if (verify && verify.voucher && verify.voucher.enabled) { // 鍑瘉-鏄剧ず鍒椾腑閫夊彇,蹇呴』閫夎
       let _voucher = verify.voucher
+
+      _updateconfig = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear'
 
       _sql += `exec s_BVoucher_Create
           @Bill ='${data[_voucher.linkField]}',
@@ -587,8 +612,10 @@
       })
       keys = keys.join(',')
       values = values.join(',')
-
-      _sql += `insert into ${btn.sql} (${keys}, createuserid, BID) select ${values},@BID,@userid`
+      _sql += `declare @UserName  nvarchar(50),@FullName nvarchar(50)
+        select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID 
+        `
+      _sql += `insert into ${btn.sql} (${keys},createuserid,CreateUser,CreateStaff,BID) select ${values},@BID,@userid,@username,@fullname`
     } else if (btn.OpenType === 'pop' && btn.sqlType === 'update') {
       let _form = []
       formdata.forEach(item => {
@@ -599,15 +626,15 @@
         }
       })
       _form = _form.join(',')
-      _sql += `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid,BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear where ${primaryKey}=@${primaryKey}`
+      _sql += `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid${_updateconfig} where ${primaryKey}=@${primaryKey}`
     } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'LogicDelete') { // 閫昏緫鍒犻櫎
       _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid where ${primaryKey}=@${primaryKey}`
-    } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') {
+    } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') {      // 鐗╃悊鍒犻櫎
       _sql += `insert into snote (remark,createuserid) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${primaryKey}='+@${primaryKey},@userid delete ${btn.sql} where ${primaryKey}=@${primaryKey}`
     }
     _sql += `
       aaa:
-      select @ErrorCode= as ErrorCode,@retmsg as ErrorCode
+      select @ErrorCode as ErrorCode,@retmsg as retmsg
       `
     console.log(_sql)
     return _sql

--
Gitblit v1.8.0