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

---
 src/tabviews/commontable/index.scss                          |    3 
 src/tabviews/subtable/index.scss                             |    3 
 src/templates/zshare/createinterface/index.jsx               |   18 +
 src/templates/zshare/verifycardexcelin/uniqueform/index.scss |    0 
 src/templates/formtabconfig/index.jsx                        |    1 
 src/templates/zshare/verifycardexcelin/uniqueform/index.jsx  |  148 ++++++++++++++++++
 src/templates/comtableconfig/index.jsx                       |    9 +
 src/templates/subtableconfig/index.jsx                       |   48 ++++-
 src/templates/zshare/verifycardexcelin/index.jsx             |  141 ++++++++++++++++
 src/utils/utils.js                                           |  102 ++++++++++++
 10 files changed, 446 insertions(+), 27 deletions(-)

diff --git a/src/tabviews/commontable/index.scss b/src/tabviews/commontable/index.scss
index b5d768b..a79c63f 100644
--- a/src/tabviews/commontable/index.scss
+++ b/src/tabviews/commontable/index.scss
@@ -85,6 +85,9 @@
     width: 40px;
     height: 40px;
   }
+  .ant-table-fixed-left, .ant-table-fixed-right {
+    z-index: 1;
+  }
 }
 .commontable.pick-control {
   .button-list {
diff --git a/src/tabviews/subtable/index.scss b/src/tabviews/subtable/index.scss
index 7203900..43b4b66 100644
--- a/src/tabviews/subtable/index.scss
+++ b/src/tabviews/subtable/index.scss
@@ -44,4 +44,7 @@
       z-index: 10;
     }
   }
+  .ant-table-fixed-left, .ant-table-fixed-right {
+    z-index: 1;
+  }
 }
diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx
index 14c3833..65c1575 100644
--- a/src/templates/comtableconfig/index.jsx
+++ b/src/templates/comtableconfig/index.jsx
@@ -1086,6 +1086,15 @@
 
     this.menuformRef.handleConfirm().then(res => {
       this.actionFormRef.handleConfirm().then(result => {
+        if (!['pop', 'exec', 'prompt'].includes(result) || result.funcType || result.intertype !== 'inner' || result.innerFunc ) {
+          notification.warning({
+            top: 92,
+            message: '鎵撳紑鏂瑰紡涓� 寮圭獥锛堣〃鍗曪級銆佹彁绀烘鎴栫洿鎺ユ墽琛岋紝涓斾娇鐢ㄧ郴缁熷嚱鏁版椂锛屾墠鍙互鍒涘缓鎺ュ彛锛�',
+            duration: 10
+          })
+          return
+        }
+
         let _menu = {
           type: 'main',
           MenuID: menu.MenuID,
diff --git a/src/templates/formtabconfig/index.jsx b/src/templates/formtabconfig/index.jsx
index 5206745..d3cb943 100644
--- a/src/templates/formtabconfig/index.jsx
+++ b/src/templates/formtabconfig/index.jsx
@@ -119,7 +119,6 @@
         })
       })
     }
-    console.log(_config)
 
     if (menu && menu.LongParam && menu.LongParam.columns) {
       columns = menu.LongParam.columns
diff --git a/src/templates/subtableconfig/index.jsx b/src/templates/subtableconfig/index.jsx
index 824c78e..48fb0fa 100644
--- a/src/templates/subtableconfig/index.jsx
+++ b/src/templates/subtableconfig/index.jsx
@@ -2015,6 +2015,35 @@
   }
 
   /**
+   * @description 鍒涘缓鎸夐挳鎺ュ彛锛堝啓鍏ワ級
+   */
+  btnCreatInterface = () => {
+    const { config } = this.state
+
+    this.menuformRef.handleConfirm().then(res => {
+      this.actionFormRef.handleConfirm().then(result => {
+        if (!['pop', 'exec', 'prompt'].includes(result) || result.funcType || result.intertype !== 'inner' || result.innerFunc ) {
+          notification.warning({
+            top: 92,
+            message: '鎵撳紑鏂瑰紡涓� 寮圭獥锛堣〃鍗曪級銆佹彁绀烘鎴栫洿鎺ユ墽琛岋紝涓斾娇鐢ㄧ郴缁熷嚱鏁版椂锛屾墠鍙互鍒涘缓鎺ュ彛锛�',
+            duration: 10
+          })
+          return
+        }
+        
+        let _menu = {
+          type: 'subtable',
+          MenuID: config.uuid,
+          menuName: res.tabName,
+          menuNo: res.tabNo
+        }
+        
+        this.refs.btnCreatInterface.triggerInInterface(result, config, _menu)
+      })
+    })
+  }
+
+  /**
    * @description 鍒涘缓琛ㄦ牸鎺ュ彛
    */
   tableCreatInterface = () => {
@@ -2039,13 +2068,7 @@
           menuNo: res.tabNo
         }
   
-        this.refs.tableCreatInterface.exec(_menu, _config).then(result => {
-          if (result === 'success') {
-            this.setState({
-              config: _config
-            })
-          }
-        })
+        this.refs.tableCreatInterface.triggerOutInterface(_menu, _config)
       })
     })
   }
@@ -2077,10 +2100,16 @@
   }
 
   render () {
-    const { modaltype, activeKey } = this.state
-    const configAction = this.state.config.action.filter(_action =>
+    const { modaltype, activeKey, config } = this.state
+
+    const configAction = config.action.filter(_action =>
       !_action.origin && (_action.OpenType === 'pop' || _action.OpenType === 'popview' || _action.OpenType === 'blank' || _action.OpenType === 'tab')
     )
+
+    let hasbtncrtinter = false
+    if (modaltype === 'actionEdit' && config.setting.interType === 'inner' && !config.setting.innerFunc && config.setting.dataresource) {
+      hasbtncrtinter = true
+    }
 
     return (
       <div className="common-table-board">
@@ -2282,6 +2311,7 @@
           maskClosable={false}
           onCancel={this.editModalCancel}
           footer={[
+            hasbtncrtinter ? <CreateInterface key="interface" dict={this.state.dict} ref="btnCreatInterface" trigger={this.btnCreatInterface}/> : null,
             modaltype === 'actionEdit' ? <CreateFunc key="create" dict={this.state.dict} ref="btnCreatFunc" trigger={this.creatFunc}/> : null,
             <Button key="cancel" onClick={this.editModalCancel}>{this.state.dict['header.cancel']}</Button>,
             <Button key="confirm" type="primary" onClick={this.handleSubmit}>{this.state.dict['header.confirm']}</Button>
diff --git a/src/templates/zshare/createinterface/index.jsx b/src/templates/zshare/createinterface/index.jsx
index 5d0e55b..83fc27c 100644
--- a/src/templates/zshare/createinterface/index.jsx
+++ b/src/templates/zshare/createinterface/index.jsx
@@ -704,10 +704,12 @@
         let _fieldValue = []                     // 琛ㄥ崟閿�煎field=value
         let _value = []                          // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず
         let _labels = item.fieldlabel.split(',') // 琛ㄥ崟鎻愮ず鏂囧瓧
+        let arr = [] // 楠岃瘉涓婚敭
 
         item.field.split(',').forEach((_field, index) => {
           _fieldValue.push(`${_field}=@${_field}@`)
           _value.push(`${_labels[index] || ''}锛�'+@${_field}@+'`)
+          arr.push(_field.toLowerCase())
         })
 
         let _verifyType = ''
@@ -715,8 +717,12 @@
           _verifyType = ' and deleted=0'
         }
 
+        if (!arr.includes(primaryKey.toLowerCase())) {
+          _fieldValue.push(`${primaryKey} !=@${primaryKey}@`)
+        }
+
         _sql += `select @tbid='', @ErrorCode='',@retmsg=''
-          select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !=@${primaryKey}@${_verifyType}
+          select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')}${_verifyType}
           If @tbid!=''
           Begin
             select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�'
@@ -820,8 +826,8 @@
       receiptKeys.push(item.key.toLowerCase())
     })
 
-    if (!receiptKeys.includes(primaryKey)) {
-      receiptKeys.push(primaryKey)
+    if (!receiptKeys.includes(primaryKey.toLowerCase())) {
+      receiptKeys.push(primaryKey.toLowerCase())
     }
 
     if (!receiptKeys.includes('bid') && BID) {
@@ -842,8 +848,8 @@
         values.push('@' + item.key + '@')
       })
 
-      if (!keys.includes(primaryKey)) {
-        keys.push(primaryKey)
+      if (!keys.includes(primaryKey.toLowerCase())) {
+        keys.push(primaryKey.toLowerCase())
         values.push(`@${primaryKey}@`)
       }
 
@@ -947,7 +953,7 @@
 
     _sql += `
       aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg,'${_ltext}' as Ltext`
-    console.log(_sql)
+
     return _sql
   }
 
diff --git a/src/templates/zshare/verifycardexcelin/index.jsx b/src/templates/zshare/verifycardexcelin/index.jsx
index 0cc7084..3113e4e 100644
--- a/src/templates/zshare/verifycardexcelin/index.jsx
+++ b/src/templates/zshare/verifycardexcelin/index.jsx
@@ -4,6 +4,7 @@
 
 import Utils from '@/utils/utils.js'
 
+import UniqueForm from './uniqueform'
 import ColumnForm from './columnform'
 import CustomScript from './customscript'
 import './index.scss'
@@ -73,10 +74,67 @@
                 cancelText={this.props.dict['header.cancel']}
                 onConfirm={() => this.handleDelete(record, 'columns')
               }>
-                <span style={{color: '#1890ff', cursor: 'pointer'}}><Icon type="delete" /></span>
+                <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
               </Popconfirm>
             </div>
           )
+      }
+    ],
+    uniqueColumns: [
+      {
+        title: '瀛楁鍚�',
+        dataIndex: 'field',
+        width: '35%'
+      },
+      {
+        title: '鎶ラ敊缂栫爜',
+        dataIndex: 'errorCode',
+        width: '12%'
+      },
+      {
+        title: '楠岃瘉绫诲瀷',
+        dataIndex: 'verifyType',
+        width: '13%',
+        render: (text, record) => record.verifyType === 'logic' ? '閫昏緫楠岃瘉' : '鐗╃悊楠岃瘉'
+      },
+      {
+        title: '鐘舵��',
+        dataIndex: 'status',
+        width: '15%',
+        render: (text, record) => record.status === 'false' ?
+          (
+            <div>
+              {this.props.dict['header.form.status.forbidden']}
+              <Icon style={{marginLeft: '5px'}} type="stop" theme="twoTone" twoToneColor="#ff4d4f" />
+            </div>
+          ) :
+          (
+            <div>
+              {this.props.dict['header.form.status.open']}
+              <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
+            </div>
+          )
+      },
+      {
+        title: '鎿嶄綔',
+        align: 'center',
+        width: '25%',
+        dataIndex: 'operation',
+        render: (text, record) =>
+          (<div>
+            <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
+            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'unique', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
+            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'unique', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
+            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record, 'unique')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
+            <Popconfirm
+              title={this.props.dict['header.form.query.delete']}
+              okText={this.props.dict['header.confirm']}
+              cancelText={this.props.dict['header.cancel']}
+              onConfirm={() => this.handleDelete(record, 'unique')
+            }>
+              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
+            </Popconfirm>
+          </div>)
       }
     ],
     scriptsColumns: [
@@ -153,7 +211,8 @@
         sheet: _verify.sheet || 'Sheet1',
         range: _verify.range || 0,
         columns: _columns,
-        scripts: _verify.scripts || []
+        scripts: _verify.scripts || [],
+        uniques: _verify.uniques || []
       }
     })
   }
@@ -225,6 +284,27 @@
     })
   }
 
+  uniqueChange = (values) => {
+    let verify = JSON.parse(JSON.stringify(this.state.verify))
+
+    if (values.uuid) {
+      verify.uniques = verify.uniques.map(item => {
+        if (item.uuid === values.uuid) {
+          return values
+        } else {
+          return item
+        }
+      })
+    } else {
+      values.uuid = Utils.getuuid()
+      verify.uniques.push(values)
+    }
+
+    this.setState({
+      verify: verify
+    })
+  }
+
   scriptsChange = (values) => {
     let verify = JSON.parse(JSON.stringify(this.state.verify))
 
@@ -253,7 +333,10 @@
       verify.columns = verify.columns.filter(item => item.uuid !== record.uuid)
     } else if (type === 'scripts') {
       verify.scripts = verify.scripts.filter(item => item.uuid !== record.uuid)
+    } else if (type === 'unique') {
+      verify.uniques = verify.uniques.filter(item => item.uuid !== record.uuid)
     }
+
     this.setState({ verify: verify })
   }
 
@@ -262,6 +345,8 @@
       this.columnForm.edit(record)
     } else if (type === 'scripts') {
       this.scriptsForm.edit(record)
+    } else if (type === 'unique') {
+      this.uniqueForm.edit(record)
     }
 
     let node = document.getElementById('verify-excel-box-tab').parentNode
@@ -286,6 +371,14 @@
 
     if (type === 'scripts') {
       verify.scripts = verify.scripts.map(item => {
+        if (item.uuid === record.uuid) {
+          return record
+        } else {
+          return item
+        }
+      })
+    } else if (type === 'unique') {
+      verify.uniques = verify.uniques.map(item => {
         if (item.uuid === record.uuid) {
           return record
         } else {
@@ -319,6 +412,23 @@
         verify.columns.splice(index - 1, 0, record)
       } else {
         verify.columns.splice(index + 1, 0, record)
+      }
+    } else if (type === 'unique') {
+      verify.uniques = verify.uniques.filter((item, i) => {
+        if (item.uuid === record.uuid) {
+          index = i
+        }
+
+        return item.uuid !== record.uuid
+      })
+      if ((index === 0 && direction === 'up') || (index === verify.uniques.length && direction === 'down')) {
+        return
+      }
+
+      if (direction === 'up') {
+        verify.uniques.splice(index - 1, 0, record)
+      } else {
+        verify.uniques.splice(index + 1, 0, record)
       }
     } else if (type === 'scripts') {
       verify.scripts = verify.scripts.filter((item, i) => {
@@ -444,8 +554,9 @@
   }
 
   render() {
+    const { card } = this.props
     const { getFieldDecorator } = this.props.form
-    const { verify, excelColumns, scriptsColumns } = this.state
+    const { verify, excelColumns, scriptsColumns, uniqueColumns } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -483,14 +594,14 @@
                     })(<InputNumber min={0} max={100} precision={0} />)}
                   </Form.Item>
                 </Col>
-                <Col span={8}>
+                {card.intertype === 'inner' && !card.innerFunc ? <Col span={8}>
                   <Form.Item label={'榛樿sql'}>
                     <Radio.Group value={verify.default} onChange={this.onOptionChange}>
                       <Radio value="true">鎵ц</Radio>
                       <Radio value="false">涓嶆墽琛�</Radio>
                     </Radio.Group>
                   </Form.Item>
-                </Col>
+                </Col> : null}
               </Row>
             </Form>
           </TabPane>
@@ -513,7 +624,23 @@
               pagination={false}
             />
           </TabPane>
-          <TabPane tab="鑷畾涔夎剼鏈�" key="6">
+          {card.intertype === 'inner' && !card.innerFunc ? <TabPane tab="鍞竴鎬ч獙璇�" key="3">
+            <UniqueForm
+              fields={verify.columns}
+              dict={this.props.dict}
+              uniqueChange={this.uniqueChange}
+              wrappedComponentRef={(inst) => this.uniqueForm = inst}
+            />
+            <Table
+              bordered
+              rowKey="uuid"
+              className="custom-table"
+              dataSource={verify.uniques}
+              columns={uniqueColumns}
+              pagination={false}
+            />
+          </TabPane> : null}
+          {card.intertype === 'inner' && !card.innerFunc ? <TabPane tab="鑷畾涔夎剼鏈�" key="6">
             <CustomScript
               dict={this.props.dict}
               btn={this.props.card}
@@ -531,7 +658,7 @@
               columns={scriptsColumns}
               pagination={false}
             />
-          </TabPane>
+          </TabPane> : null}
           <TabPane tab="淇℃伅鎻愮ず" key="7">
             <Form {...formItemLayout}>
               <Row gutter={24}>
diff --git a/src/templates/zshare/verifycardexcelin/uniqueform/index.jsx b/src/templates/zshare/verifycardexcelin/uniqueform/index.jsx
new file mode 100644
index 0000000..2f0827f
--- /dev/null
+++ b/src/templates/zshare/verifycardexcelin/uniqueform/index.jsx
@@ -0,0 +1,148 @@
+import React, {Component} from 'react'
+import PropTypes from 'prop-types'
+import { Form, Row, Col, Select, Button } from 'antd'
+import './index.scss'
+
+
+class UniqueForm extends Component {
+  static propTpyes = {
+    dict: PropTypes.object,       // 瀛楀吀椤�
+    fields: PropTypes.array,      // 琛ㄥ崟瀛楁
+    uniqueChange: PropTypes.func  // 淇敼鍑芥暟
+  }
+
+  state = {
+    editItem: null // 缂栬緫鍏冪礌
+  }
+
+  edit = (record) => {
+    this.setState({
+      editItem: record
+    })
+
+    this.props.form.setFieldsValue({
+      field: record.field.split(','),
+      errorCode: record.errorCode,
+      verifyType: record.verifyType || 'physical'
+    })
+  }
+
+
+  handleConfirm = () => {
+    const { fields } = this.props
+    // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
+    this.props.form.validateFieldsAndScroll((err, values) => {
+      if (!err) {
+        values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
+        values.fieldlabel = values.field.map(field => {
+          let item = fields.filter(cell => cell.Column === field)[0]
+          let label = ''
+          if (item) {
+            label = item.Text
+          }
+          return label
+        })
+
+        values.fieldlabel = values.fieldlabel.join(',')
+        values.field = values.field.join(',')
+
+        this.props.uniqueChange(values)
+        this.setState({
+          editItem: null
+        })
+        this.props.form.setFieldsValue({
+          field: [],
+        })
+      }
+    })
+  }
+
+  render() {
+    const { getFieldDecorator } = this.props.form
+    const { fields } = this.props
+
+    const formItemLayout = {
+      labelCol: {
+        xs: { span: 24 },
+        sm: { span: 8 }
+      },
+      wrapperCol: {
+        xs: { span: 24 },
+        sm: { span: 16 }
+      }
+    }
+
+    return (
+      <Form {...formItemLayout} className="verify-form" id="verifycard1">
+        <Row gutter={24}>
+          <Col span={10}>
+            <Form.Item label={'鍒楀悕'}>
+              {getFieldDecorator('field', {
+                initialValue: [],
+                rules: [
+                  {
+                    required: true,
+                    message: this.props.dict['form.required.select'] + '鍒楀悕!'
+                  }
+                ]
+              })(
+                <Select
+                  mode="multiple"
+                >
+                  {fields.map(item => (
+                    <Select.Option key={item.uuid} value={item.Column}>{item.Text}</Select.Option>
+                  ))}
+                </Select>
+              )}
+            </Form.Item>
+          </Col>
+          <Col span={6}>
+            <Form.Item label={'鎶ラ敊缂栫爜'}>
+              {getFieldDecorator('errorCode', {
+                initialValue: 'E',
+                rules: [
+                  {
+                    required: true,
+                    message: this.props.dict['form.required.select'] + '鎶ラ敊缂栫爜!'
+                  }
+                ]
+              })(
+                <Select>
+                  <Select.Option value="E"> E </Select.Option>
+                  <Select.Option value="N"> N </Select.Option>
+                  <Select.Option value="F"> F </Select.Option>
+                  <Select.Option value="NM"> NM </Select.Option>
+                </Select>
+              )}
+            </Form.Item>
+          </Col>
+          <Col span={6}>
+            <Form.Item label={'楠岃瘉绫诲瀷'}>
+              {getFieldDecorator('verifyType', {
+                initialValue: 'physical',
+                rules: [
+                  {
+                    required: true,
+                    message: this.props.dict['form.required.select'] + '楠岃瘉绫诲瀷!'
+                  }
+                ]
+              })(
+                <Select>
+                  <Select.Option value="physical"> 鐗╃悊楠岃瘉 </Select.Option>
+                  <Select.Option value="logic"> 閫昏緫楠岃瘉 </Select.Option>
+                </Select>
+              )}
+            </Form.Item>
+          </Col>
+          <Col span={2} className="add">
+            <Button onClick={this.handleConfirm} type="primary" className="add-row">
+              纭畾
+            </Button>
+          </Col>
+        </Row>
+      </Form>
+    )
+  }
+}
+
+export default Form.create()(UniqueForm)
\ No newline at end of file
diff --git a/src/templates/zshare/verifycardexcelin/uniqueform/index.scss b/src/templates/zshare/verifycardexcelin/uniqueform/index.scss
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/templates/zshare/verifycardexcelin/uniqueform/index.scss
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 6a5c97a..901b4fe 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -565,6 +565,48 @@
     let _sql = ''
 
     if (item.intertype === 'inner' && !item.innerFunc) {
+      let _uniquesql = ''
+      if (btn.uniques && btn.uniques.length > 0) {
+        btn.uniques.forEach(unique => {
+          if (unique.status === 'false') return
+
+          let _fields = unique.field.split(',')
+          let _fields_ = _fields.map(_field => {
+            return `a.${_field}=b.${_field}`
+          })
+          _fields_ = _fields_.join(' and ')
+
+          if (unique.verifyType !== 'physical') {
+            _fields_ += ' and b.deleted=0'
+          }
+
+          _uniquesql += `
+          Set @tbid=''
+          Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${unique.field} from @${item.sheet} ) a group by ${unique.field} having sum(n)>1
+
+          If @tbid!=''
+          Begin
+            select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 閲嶅'
+            goto aaa
+          end
+
+          Set @tbid=''
+          Select top 1 @tbid=${_fields.join('+\' \'+')} from  @${item.sheet} a
+          Inner join ${item.sheet} b on ${_fields_}
+
+          If @tbid!=''
+          Begin
+            select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 涓庡凡鏈夋暟鎹噸澶�'
+            goto aaa
+          end
+          `
+        })
+
+        if (_uniquesql) {
+          _uniquesql = 'Declare @tbid Nvarchar(512)' + _uniquesql
+        }
+      }
+
       let declarefields = []
       let fields = []
 
@@ -603,6 +645,7 @@
       
       Insert into  @${item.sheet} (${fields},jskey)
       ${_Ltext}
+      ${_uniquesql}
       ${_insert}
       Delete @${item.sheet}
 
@@ -807,6 +850,7 @@
         let _fieldValue = []                     // 琛ㄥ崟閿�煎field=value
         let _value = []                          // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず
         let _labels = item.fieldlabel.split(',') // 琛ㄥ崟鎻愮ず鏂囧瓧
+        let arr = [] // 楠岃瘉涓婚敭
 
         item.field.split(',').forEach((_field, index) => {
           let _fval = `'${_formFieldValue[_field]}'`
@@ -816,6 +860,8 @@
           if (_field.toLowerCase() === 'bid' && !hasBid) { // 琛ㄥ崟涓病鏈塨id鍒欎娇鐢ㄧ郴缁焍id鍙橀噺
             _fval = '@BID@'
           }
+          arr.push(_field.toLowerCase())
+
           _fieldValue.push(`${_field}=${_fval}`)
           _value.push(`${_labels[index] || ''}锛�${_formFieldValue[_field] || ''}`)
         })
@@ -825,8 +871,12 @@
           _verifyType = ' and deleted=0'
         }
 
+        if (!arr.includes(primaryKey.toLowerCase())) {
+          _fieldValue.push(`${primaryKey} !='${primaryId}'`)
+        }
+
         _sql += `select @tbid='', @ErrorCode='',@retmsg=''
-          select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${primaryId}'${_verifyType}
+          select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')}${_verifyType}
           If @tbid!=''
           Begin
             select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�'
@@ -950,8 +1000,8 @@
         }
       })
 
-      if (!keys.includes(primaryKey)) {
-        keys.push(primaryKey)
+      if (!keys.includes(primaryKey.toLowerCase())) {
+        keys.push(primaryKey.toLowerCase())
         values.push('\'' + primaryId + '\'')
       }
       if (!keys.includes('createuserid')) {
@@ -1359,6 +1409,50 @@
   static getexcelInfunc (param, btn, menu) {
     let _verify = btn.verify
 
+    let _uniquesql = ''
+    if (_verify.uniques && _verify.uniques.length > 0) {
+      _verify.uniques.forEach(unique => {
+        if (unique.status === 'false') return
+
+        let _fields = unique.field.split(',')
+        let _fields_ = _fields.map(_field => {
+          return `a.${_field}=b.${_field}`
+        })
+        _fields_ = _fields_.join(' and ')
+
+        if (unique.verifyType !== 'physical') {
+          _fields_ += ' and b.deleted=0'
+        }
+
+        _uniquesql += `
+        Set @tbid=''
+        Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${unique.field} from @${btn.sheet} ) a group by ${unique.field} having sum(n)>1
+
+        If @tbid!=''
+        Begin
+          select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 閲嶅'
+          goto aaa
+        end
+
+        Set @tbid=''
+        Select top 1 @tbid=${_fields.join('+\' \'+')} from  @${btn.sheet} a
+        Inner join ${btn.sheet} b on ${_fields_}
+
+        If @tbid!=''
+        Begin
+          select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 涓庡凡鏈夋暟鎹噸澶�'
+          goto aaa
+        end
+        `
+      })
+
+      if (_uniquesql) {
+        _uniquesql = `
+        Declare @tbid Nvarchar(512)
+        ${_uniquesql}`
+      }
+    }
+
     let declarefields = []
     let fields = []
 
@@ -1378,7 +1472,7 @@
 
       exec s_KeyWords_Replace
       @LText=@LText, @BID=@BID,@LoginUID=@LoginUID,@SessionUid=@SessionUid,@UserID=@UserID,@ID=@ID
-
+      ${_uniquesql}
       Insert into ${btn.sheet} (${fields},createuserid,createuser,createstaff,bid) 
       Select ${fields},@userid,@username,@fullname,@BID From @${btn.sheet}
 

--
Gitblit v1.8.0