From 0f79daefced8980fa571dd3d2c781a0e3646614f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 24 十一月 2020 16:57:19 +0800
Subject: [PATCH] 2020-11-24

---
 src/templates/zshare/verifycard/index.jsx |  313 +++++++++++++++++++++++-----------------------------
 1 files changed, 138 insertions(+), 175 deletions(-)

diff --git a/src/templates/zshare/verifycard/index.jsx b/src/templates/zshare/verifycard/index.jsx
index a1c1109..b067018 100644
--- a/src/templates/zshare/verifycard/index.jsx
+++ b/src/templates/zshare/verifycard/index.jsx
@@ -13,11 +13,13 @@
 import CustomScript from './customscript'
 import BillcodeForm from './billcodeform'
 import VoucherForm from './voucherform'
+import asyncComponent from '@/utils/asyncComponent'
 import './index.scss'
 
 const { TabPane } = Tabs
 const { confirm } = Modal
 const { Paragraph } = Typography
+const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
 
 class VerifyCard extends Component {
   static propTpyes = {
@@ -43,25 +45,50 @@
     columnsFields: [],
     uniqueColumns: [
       {
-        title: '瀛楁鍚�',
+        title: '鍚嶇О',
+        dataIndex: 'fieldlabel',
+        width: '20%'
+      },
+      {
+        title: '瀛楁',
         dataIndex: 'field',
-        width: '35%'
+        width: '20%',
+        editable: true,
+        inputType: 'multiStr',
+        options: []
       },
       {
         title: '鎶ラ敊缂栫爜',
         dataIndex: 'errorCode',
-        width: '12%'
+        width: '12%',
+        editable: true,
+        inputType: 'select',
+        options: [
+          { value: 'E', text: 'E' },
+          { value: 'N', text: 'N' },
+          { value: 'F', text: 'F' },
+          { value: 'NM', text: 'NM' }
+        ]
       },
       {
         title: '楠岃瘉绫诲瀷',
         dataIndex: 'verifyType',
         width: '13%',
-        render: (text, record) => record.verifyType === 'logic' ? '閫昏緫楠岃瘉' : '鐗╃悊楠岃瘉'
+        render: (text, record) => record.verifyType === 'logic' ? '閫昏緫楠岃瘉' : '鐗╃悊楠岃瘉',
+        inputType: 'select',
+        editable: true,
+        options: [
+          { value: 'physical', text: '鐗╃悊楠岃瘉' },
+          { value: 'logic', text: '閫昏緫楠岃瘉' }
+        ]
       },
       {
-        title: '鐘舵��',
+        title: '鏄惁鍚敤',
         dataIndex: 'status',
-        width: '15%',
+        width: '13%',
+        editable: true,
+        required: false,
+        inputType: 'switch',
         render: (text, record) => record.status === 'false' ?
           (
             <div>
@@ -75,38 +102,29 @@
               <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['model.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
-              overlayClassName="popover-confirm"
-              title={this.props.dict['model.query.delete']}
-              onConfirm={() => this.handleDelete(record, 'unique')
-            }>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
-            </Popconfirm>
-          </div>)
       }
     ],
     onceUniqueColumns: [
       {
-        title: '瀛楁鍚�',
-        dataIndex: 'field',
-        width: '45%'
+        title: '鍚嶇О',
+        dataIndex: 'fieldlabel',
+        width: '30%'
       },
       {
-        title: '鐘舵��',
-        dataIndex: 'status',
+        title: '瀛楁',
+        dataIndex: 'field',
         width: '30%',
+        editable: true,
+        inputType: 'multiStr',
+        options: []
+      },
+      {
+        title: '鏄惁鍚敤',
+        dataIndex: 'status',
+        width: '20%',
+        editable: true,
+        required: false,
+        inputType: 'switch',
         render: (text, record) => record.status === 'false' ?
           (
             <div>
@@ -121,57 +139,66 @@
             </div>
           )
       },
-      {
-        title: '鎿嶄綔',
-        align: 'center',
-        width: '25%',
-        dataIndex: 'operation',
-        render: (text, record) =>
-          (<div>
-            <span className="operation-btn" title={this.props.dict['model.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
-              overlayClassName="popover-confirm"
-              title={this.props.dict['model.query.delete']}
-              onConfirm={() => this.handleDelete(record, 'unique')
-            }>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
-            </Popconfirm>
-          </div>)
-      }
     ],
     contrastColumns: [
       {
         title: '鍐呭1',
         dataIndex: 'frontfield',
-        width: '13%'
+        width: '14%',
+        inputType: 'input',
+        editable: true
       },
       {
         title: '杩愮畻绗�',
         dataIndex: 'operator',
-        width: '13%'
+        width: '14%',
+        editable: true,
+        inputType: 'select',
+        options: [
+          { value: '=', text: '=' },
+          { value: '!=', text: '!=' },
+          { value: '>', text: '>' },
+          { value: '<', text: '<' },
+          { value: '>=', text: '>=' },
+          { value: '<=', text: '<=' },
+          { value: 'in', text: 'in' },
+          { value: 'like', text: 'like' }
+        ]
       },
       {
         title: '鍐呭2',
         dataIndex: 'backfield',
-        width: '13%',
+        width: '14%',
+        inputType: 'input',
+        editable: true
       },
       {
         title: '鎻愮ず淇℃伅',
         dataIndex: 'errmsg',
-        width: '13%'
+        width: '14%',
+        inputType: 'input',
+        editable: true
       },
       {
         title: '鎶ラ敊缂栫爜',
         dataIndex: 'errorCode',
-        width: '13%'
+        width: '14%',
+        editable: true,
+        inputType: 'select',
+        options: [
+          { value: 'E', text: 'E' },
+          { value: 'N', text: 'N' },
+          { value: 'F', text: 'F' },
+          { value: 'NM', text: 'NM' }
+        ]
       },
       {
-        title: '鐘舵��',
+        title: '鏄惁鍚敤',
         dataIndex: 'status',
-        width: '15%',
+        width: '13%',
+        editable: true,
+        required: false,
+        inputType: 'switch',
         render: (text, record) => record.status === 'false' ?
           (
             <div>
@@ -185,26 +212,6 @@
               <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
             </div>
           )
-      },
-      {
-        title: '鎿嶄綔',
-        align: 'center',
-        width: '20%',
-        dataIndex: 'operation',
-        render: (text, record) =>
-          (<div>
-            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'contrast')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
-            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'contrast', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
-            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'contrast', '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, 'contrast')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
-            <Popconfirm
-              overlayClassName="popover-confirm"
-              title={this.props.dict['model.query.delete']}
-              onConfirm={() => this.handleDelete(record, 'contrast')
-            }>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
-            </Popconfirm>
-          </div>)
       }
     ],
     customColumns: [
@@ -779,7 +786,19 @@
         columnsFields: _columns,
         initsql: _sql,
         defaultsql: _defaultsql,
-        usefulfields: _usefulfields.join(', ')
+        usefulfields: _usefulfields.join(', '),
+        uniqueColumns: this.state.uniqueColumns.map(col => {
+          if (col.dataIndex === 'field') {
+            col.options = _fields
+          }
+          return col
+        }),
+        onceUniqueColumns: this.state.onceUniqueColumns.map(col => {
+          if (col.dataIndex === 'field') {
+            col.options = _columns
+          }
+          return col
+        })
       })
     })
   }
@@ -885,18 +904,9 @@
   contrastChange = (values) => {
     let verify = fromJS(this.state.verify).toJS()
 
-    if (values.uuid) {
-      verify.contrasts = verify.contrasts.map(item => {
-        if (item.uuid === values.uuid) {
-          return values
-        } else {
-          return item
-        }
-      })
-    } else {
-      values.uuid = Utils.getuuid()
-      verify.contrasts.push(values)
-    }
+    values.status = 'true'
+    values.uuid = Utils.getuuid()
+    verify.contrasts.push(values)
 
     this.setState({ verify })
   }
@@ -980,14 +990,10 @@
 
     if (type === 'customverify') {
       verify.customverifys = verify.customverifys.filter(item => item.uuid !== record.uuid)
-    } else if (type === 'unique') {
-      verify.uniques = verify.uniques.filter(item => item.uuid !== record.uuid)
     } else if (type === 'ordercode') {
       verify.billcodes = verify.billcodes.filter(item => item.uuid !== record.uuid)
     } else if (type === 'scripts') {
       verify.scripts = verify.scripts.filter(item => item.uuid !== record.uuid)
-    } else if (type === 'contrast') {
-      verify.contrasts = verify.contrasts.filter(item => item.uuid !== record.uuid)
     }
 
     this.setState({ verify })
@@ -996,14 +1002,10 @@
   handleEdit = (record, type) => {
     if (type === 'customverify') {
       this.customForm.edit(record)
-    } else if (type === 'unique') {
-      this.uniqueForm.edit(record)
     } else if (type === 'ordercode') {
       this.orderForm.edit(record)
     } else if (type === 'scripts') {
       this.scriptsForm.edit(record)
-    } else if (type === 'contrast') {
-      this.contrastForm.edit(record)
     }
 
     let node = document.getElementById('verify-card-box-tab').parentNode
@@ -1028,22 +1030,6 @@
 
     if (type === 'customverify') {
       verify.customverifys = verify.customverifys.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 {
-          return item
-        }
-      })
-    } else if (type === 'contrast') {
-      verify.contrasts = verify.contrasts.map(item => {
         if (item.uuid === record.uuid) {
           return record
         } else {
@@ -1091,40 +1077,6 @@
         verify.customverifys.splice(index - 1, 0, record)
       } else {
         verify.customverifys.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 === 'contrast') {
-      verify.contrasts = verify.contrasts.filter((item, i) => {
-        if (item.uuid === record.uuid) {
-          index = i
-        }
-
-        return item.uuid !== record.uuid
-      })
-      if ((index === 0 && direction === 'up') || (index === verify.contrasts.length && direction === 'down')) {
-        return
-      }
-
-      if (direction === 'up') {
-        verify.contrasts.splice(index - 1, 0, record)
-      } else {
-        verify.contrasts.splice(index + 1, 0, record)
       }
     } else if (type === 'ordercode') {
       verify.billcodes = verify.billcodes.filter((item, i) => {
@@ -1217,6 +1169,40 @@
     })
   }
 
+  changeUniques = (uniques) => {
+    const { card } = this.props
+    const { verify, fields, columnsFields } = this.state
+
+    let _fields = []
+    let change = {}
+    if (card.Ot !== 'requiredOnce') {
+      _fields = fields
+    } else {
+      _fields = columnsFields
+    }
+    
+    _fields.forEach(col => {
+      change[col.field] = col.label
+    })
+    
+    uniques = uniques.map(item => {
+      item.status = item.status || 'true'
+
+      if (Array.isArray(item.field)) {
+        item.fieldlabel = item.field.map(field => {
+          return change[field] || ''
+        })
+
+        item.fieldlabel = item.fieldlabel.join(',')
+        item.field = item.field.join(',')
+      }
+
+      return item
+    })
+
+    this.setState({verify: {...verify, uniques}})
+  }
+
   handleConfirm = () => {
     const { card } = this.props
     let verify = fromJS(this.state.verify).toJS()
@@ -1235,13 +1221,9 @@
       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
       }
 
@@ -1383,19 +1365,8 @@
               {verify.contrasts.length ? <span className="count-tip">{verify.contrasts.length}</span> : null}
             </span>
           } key="2x">
-            <ContrastForm
-              dict={this.props.dict}
-              contrastChange={this.contrastChange}
-              wrappedComponentRef={(inst) => this.contrastForm = inst}
-            />
-            <Table
-              bordered
-              rowKey="uuid"
-              className="custom-table"
-              dataSource={verify.contrasts}
-              columns={contrastColumns}
-              pagination={false}
-            />
+            <ContrastForm dict={this.props.dict} contrastChange={this.contrastChange}/>
+            <EditTable data={verify.contrasts} columns={contrastColumns} onChange={(contrasts) => this.setState({verify: {...verify, contrasts}})}/>
           </TabPane>
           <TabPane tab={
             <span>
@@ -1457,16 +1428,8 @@
               fields={card.Ot !== 'requiredOnce' ? fields : columnsFields}
               dict={this.props.dict}
               uniqueChange={this.uniqueChange}
-              wrappedComponentRef={(inst) => this.uniqueForm = inst}
             />
-            <Table
-              bordered
-              rowKey="uuid"
-              className="custom-table"
-              dataSource={verify.uniques}
-              columns={card.Ot !== 'requiredOnce' ? uniqueColumns : onceUniqueColumns}
-              pagination={false}
-            />
+            <EditTable data={verify.uniques} columns={card.Ot !== 'requiredOnce' ? uniqueColumns : onceUniqueColumns} onChange={this.changeUniques}/>
           </TabPane>
           <TabPane tab={
             <span>

--
Gitblit v1.8.0