From 30c350ff93af3fcc7dcd9b78eb110212b2d44a49 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 11 二月 2020 08:53:53 +0800
Subject: [PATCH] 2020-02-11

---
 src/utils/utils.js |   90 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 76 insertions(+), 14 deletions(-)

diff --git a/src/utils/utils.js b/src/utils/utils.js
index 05da502..5bc7055 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -452,7 +452,8 @@
     let _formFieldValue = {}
     // 闇�瑕佸0鏄庣殑鍙橀噺闆�
     // let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName', 'ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey']
-    let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey']
+    // let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey']
+    let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname']
 
     // 涓婚敭瀛楁
     let primaryKey = setting.primaryKey || 'id'
@@ -462,7 +463,8 @@
       `
 
     // let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 宸茶祴鍊煎瓧娈甸泦
-    let _initvars = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] // 宸茶祴鍊煎瓧娈甸泦
+    // let _initvars = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] // 宸茶祴鍊煎瓧娈甸泦
+    let _initvars = [] // 宸茶祴鍊煎瓧娈甸泦
     let _initfields = []
     let _declarefields = []
 
@@ -474,7 +476,12 @@
 
         if (!_initvars.includes(_key)) {
           _initvars.push(_key)
-          _initfields.push(`@${_key}='${form.value}'`)
+
+          if (form.type === 'number' && typeof(form.value) === 'number') {
+            _initfields.push(`@${_key}=${form.value}`)
+          } else {
+            _initfields.push(`@${_key}='${form.value}'`)
+          }
         }
         
         if (!_vars.includes(_key)) {
@@ -505,7 +512,12 @@
             _initvars.push(_key)
 
             let _val = data.hasOwnProperty(col.field) ? data[col.field] : ''
-            _initfields.push(`@${_key}='${_val}'`)
+
+            if (col.type === 'number' && typeof(_val) === 'number') {
+              _initfields.push(`@${_key}=${_val}`)
+            } else {
+              _initfields.push(`@${_key}='${_val}'`)
+            }
           }
           
           if (!_vars.includes(_key)) {
@@ -514,7 +526,7 @@
             let _type = `nvarchar(${col.fieldlength || 50})`
 
             if (col.type === 'number') {
-              let _length = (col.decimal || col.decimal === 0) ? col.decimal : 18
+              let _length = col.decimal ? col.decimal : 0
               _type = `decimal(18,${_length})`
             } else if (col.type === 'picture' || col.type === 'textarea') {
               _type = `nvarchar(${col.fieldlength || 512})`
@@ -605,6 +617,12 @@
 
     // 鍞竴鎬ч獙璇侊紝蹇呴』瀛樺湪琛ㄥ崟锛堣〃鍗曞瓨鍦ㄦ椂锛屼富閿潎涓哄崟鍊硷級,蹇呴』濉啓鏁版嵁婧�
     if (formdata && verify.uniques && verify.uniques.length > 0) {
+      let hasBid = false // 妫�楠岃〃鍗曞強鍒楀瓧娈典腑鏄惁鏈塨id
+      let _keys_ = Object.keys(_formFieldValue).map(key => key.toLowerCase())
+      if (_keys_.includes('bid')) {
+        hasBid = true
+      }
+
       verify.uniques.forEach(item => {
         let _fieldValue = []                     // 琛ㄥ崟閿�煎field=value
         let _value = []                          // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず
@@ -612,8 +630,11 @@
 
         item.field.split(',').forEach((_field, index) => {
           let _fval = `'${_formFieldValue[_field]}'`
-          if (['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(_field.toLowerCase())) {
-            _fval = '@' + _field + '@'
+          // if (['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(_field.toLowerCase())) {
+          //   _fval = '@' + _field + '@'
+          // }
+          if (_field.toLowerCase() === 'bid' && !hasBid) { // 琛ㄥ崟涓病鏈塨id鍒欎娇鐢ㄧ郴缁焍id鍙橀噺
+            _fval = '@BID@'
           }
           _fieldValue.push(`${_field}=${_fval}`)
           _value.push(`${_labels[index] || ''}锛�${_formFieldValue[_field] || ''}`)
@@ -690,13 +711,13 @@
       })
     }
 
-    let _updateconfig = ''
+    let hasvoucher = false
 
     // 鍑瘉-鏄剧ず鍒椾腑閫夊彇,蹇呴』閫夎
     if (verify.voucher && verify.voucher.enabled && data) {
       let _voucher = verify.voucher
 
-      _updateconfig = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear'
+      hasvoucher = true
 
       _sql += `exec s_BVoucher_Create
           @Bill ='${data[_voucher.linkField]}',
@@ -724,26 +745,48 @@
     if (btn.OpenType === 'pop' && btn.sqlType === 'insert' && verify.default !== 'false') {
       let keys = []
       let values = []
+
       formdata.forEach(item => {
         if (item.type === 'funcvar') {
-          keys.push(item.key)
+          keys.push(item.key.toLowerCase())
           values.push('@' + item.key)
         } else if (item.type === 'number') {
-          keys.push(item.key)
+          keys.push(item.key.toLowerCase())
           values.push(item.value)
         } else {
-          keys.push(item.key)
+          keys.push(item.key.toLowerCase())
           values.push('\'' + item.value + '\'')
         }
       })
 
+      if (!keys.includes('createuserid')) {
+        keys.push('createuserid')
+        values.push('@userid@')
+      }
+      if (!keys.includes('createuser')) {
+        keys.push('createuser')
+        values.push('@username')
+      }
+      if (!keys.includes('createstaff')) {
+        keys.push('createstaff')
+        values.push('@fullname')
+      }
+      if (!keys.includes('bid')) {
+        keys.push('bid')
+        values.push('@BID@')
+      }
+
       keys = keys.join(',')
       values = values.join(',')
       _sql += _user
-      _sql += `insert into ${btn.sql} (${keys},createuserid,CreateUser,CreateStaff,BID) select ${values},@userid@,@username,@fullname,@BID@;`
+      _sql += `insert into ${btn.sql} (${keys}) select ${values};`
     } else if (btn.OpenType === 'pop' && btn.sqlType === 'update' && verify.default !== 'false') {
       let _form = []
+      let _arr = []
+
       formdata.forEach(item => {
+        _arr.push(item.key.toLowerCase())
+
         if (item.type === 'funcvar') {
           _form.push(item.key + '=@' + item.key)
         } else if (item.type === 'number') {
@@ -752,8 +795,27 @@
           _form.push(item.key + '=\'' + item.value + '\'')
         }
       })
+
+      if (!_arr.includes('modifydate')) {
+        _form.push('modifydate=getdate()')
+      }
+      if (!_arr.includes('modifyuserid')) {
+        _form.push('modifyuserid=@userid@')
+      }
+      if (hasvoucher) {
+        if (!_arr.includes('bvoucher')) {
+          _form.push('BVoucher=@BVoucher')
+        }
+        if (!_arr.includes('fibvoucherdate')) {
+          _form.push('FIBVoucherDate=@FIBVoucherDate')
+        }
+        if (!_arr.includes('fiyear')) {
+          _form.push('FiYear=@FiYear')
+        }
+      }
+
       _form = _form.join(',')
-      _sql += `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid@${_updateconfig} where ${primaryKey}=@${primaryKeyName};`
+      _sql += `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};`
     } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'LogicDelete' && verify.default !== 'false') { // 閫昏緫鍒犻櫎
       _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKeyName};`
     } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete' && verify.default !== 'false') {      // 鐗╃悊鍒犻櫎

--
Gitblit v1.8.0