From 45466976d272c7b406b0e3d8b8fba92f3eb20524 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 07 一月 2020 17:55:13 +0800
Subject: [PATCH] 2020-01-07

---
 src/templates/tableshare/verifycard/index.jsx |  426 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 355 insertions(+), 71 deletions(-)

diff --git a/src/templates/tableshare/verifycard/index.jsx b/src/templates/tableshare/verifycard/index.jsx
index b4052da..5fb055e 100644
--- a/src/templates/tableshare/verifycard/index.jsx
+++ b/src/templates/tableshare/verifycard/index.jsx
@@ -1,10 +1,12 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { Form, Tabs, Row, Col, Radio, Button, Table, Popconfirm, Icon, notification, Modal, message, InputNumber } from 'antd'
+import moment from 'moment'
 import Utils from '@/utils/utils.js'
 import UniqueForm from './uniqueform'
 import CustomForm from './customform'
 import BillcodeForm from './billcodeform'
+import VoucherForm from './voucherform'
 import Api from '@/api'
 import './index.scss'
 
@@ -19,7 +21,132 @@
 
   state = {
     verify: {},
-    fields: []
+    fields: [],
+    orderModular: [],
+    orderModularDetail: [],
+    voucher: [],
+    voucherDetail: [],
+    uniqueColumns: [
+      {
+        title: '瀛楁鍚�',
+        dataIndex: 'field',
+        width: '50%'
+      },
+      {
+        title: '鎻愮ず淇℃伅',
+        dataIndex: 'errmsg',
+        width: '25%'
+      },
+      {
+        title: 'ErrorCode',
+        dataIndex: 'errorCode',
+        width: '10%'
+      },
+      {
+        title: '鎿嶄綔',
+        align: 'center',
+        width: '15%',
+        dataIndex: 'operation',
+        render: (text, record) =>
+          (<div>
+            <span className="operation-btn" onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
+            <Popconfirm title="纭畾鍒犻櫎鍚�?" onConfirm={() => this.handleDelete(record, 'unique')}>
+              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
+            </Popconfirm>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'unique', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'unique', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
+          </div>)
+      }
+    ],
+    customColumns: [
+      {
+        title: 'SQL',
+        dataIndex: 'sql',
+        width: '40%'
+      },
+      {
+        title: '缁撴灉',
+        dataIndex: 'resultName',
+        width: '10%'
+      },
+      {
+        title: '鎻愮ず淇℃伅',
+        dataIndex: 'errmsg',
+        width: '25%'
+      },
+      {
+        title: 'ErrorCode',
+        dataIndex: 'errorCode',
+        width: '10%'
+      },
+      {
+        title: '鎿嶄綔',
+        align: 'center',
+        width: '15%',
+        dataIndex: 'operation',
+        render: (text, record) =>
+          (<div>
+            <span className="operation-btn" onClick={() => this.handleEdit(record, 'customverify')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
+            <Popconfirm title="纭畾鍒犻櫎鍚�?" onConfirm={() => this.handleDelete(record, 'customverify')}>
+              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
+            </Popconfirm>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'customverify', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'customverify', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
+          </div>)
+      }
+    ],
+    orderColumns: [
+      {
+        title: '瀛楁',
+        dataIndex: 'field',
+        width: '15%'
+      },
+      {
+        title: '绫诲瀷',
+        dataIndex: 'billType',
+        width: '10%',
+      },
+      {
+        title: '鍑瘉绫诲瀷',
+        dataIndex: 'ModularCodeName',
+        width: '10%'
+      },
+      {
+        title: '鍑瘉鏍囪瘑',
+        dataIndex: 'ModularDetailCode',
+        width: '10%'
+      },
+      {
+        title: '娴佹按鍙蜂綅鏁�',
+        dataIndex: 'Type',
+        width: '10%'
+      },
+      {
+        title: '鎻愮ず淇℃伅',
+        dataIndex: 'errmsg',
+        width: '20%'
+      },
+      {
+        title: 'ErrorCode',
+        dataIndex: 'errorCode',
+        width: '10%'
+      },
+      {
+        title: '鎿嶄綔',
+        align: 'center',
+        width: '15%',
+        dataIndex: 'operation',
+        render: (text, record) =>
+          (<div>
+            <span className="operation-btn" onClick={() => this.handleEdit(record, 'ordercode')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
+            <Popconfirm title="纭畾鍒犻櫎鍚�?" onConfirm={() => this.handleDelete(record, 'ordercode')}>
+              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
+            </Popconfirm>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'ordercode', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'ordercode', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
+          </div>)
+      }
+    ]
   }
 
   UNSAFE_componentWillMount() {
@@ -31,7 +158,8 @@
         uniques: _verify.uniques || [],
         accountdate: _verify.accountdate || 'false',
         customverifys: _verify.customverifys || [],
-        billCode: _verify.billCode || {}
+        billcodes: _verify.billcodes || [],
+        voucher: _verify.voucher || {enabled: false},
       }
     })
 
@@ -78,6 +206,134 @@
     }
   }
 
+  componentDidMount() {
+    // 鑾峰彇鐢熸垚鍗曞彿涓�绾ц彍鍗�
+    let defer1 = new Promise(resolve => {
+      let _orderSql = 'select ID,ModularCode+ModularName+ModularNo as NameNO from sModular where deleted=0 order by ID asc'
+      _orderSql = Utils.formatOptions(_orderSql)
+
+      let orderParam = {
+        func: 'sPC_Get_SelectedList',
+        LText: _orderSql,
+        obj_name: 'data',
+        arr_field: 'ID,NameNO'
+      }
+
+      orderParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      orderParam.secretkey = Utils.encrypt(orderParam.LText, orderParam.timestamp)
+      
+      Api.getSystemConfig(orderParam).then(res => {
+        if (res.status) {
+          resolve(res)
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 10
+          })
+        }
+      })
+    })
+
+    // 鑾峰彇鐢熸垚鍗曞彿浜岀骇鑿滃崟
+    let defer2 = new Promise(resolve => {
+      let _orderDetailSql = 'select ModularDetailCode,ModularDetailCode+ModularDetailName as CodeName,BID,Type from sModularDetail where Deleted=0'
+      _orderDetailSql = Utils.formatOptions(_orderDetailSql)
+
+      let orderDetailParam = {
+        func: 'sPC_Get_SelectedList',
+        LText: _orderDetailSql,
+        obj_name: 'data',
+        arr_field: 'ModularDetailCode,CodeName,BID,Type'
+      }
+
+      orderDetailParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      orderDetailParam.secretkey = Utils.encrypt(orderDetailParam.LText, orderDetailParam.timestamp)
+      
+      Api.getSystemConfig(orderDetailParam).then(res => {
+        if (res.status) {
+          resolve(res)
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 10
+          })
+        }
+      })
+    })
+    
+    Promise.all([defer1, defer2]).then(result => {
+      this.setState({
+        orderModular: result[0].data,
+        orderModularDetail: result[1].data
+      })
+    })
+
+    // 鑾峰彇鍑瘉浜岀骇鑿滃崟
+    let defer3 = new Promise(resolve => {
+      let _voucherSql = 'select ID,ModularCode+ModularName+ModularNo as NameNO,TypeCharOne from sModular where deleted=0'
+      _voucherSql = Utils.formatOptions(_voucherSql)
+
+      let voucherParam = {
+        func: 'sPC_Get_SelectedList',
+        LText: _voucherSql,
+        obj_name: 'data',
+        arr_field: 'ID,NameNO,TypeCharOne'
+      }
+
+      voucherParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      voucherParam.secretkey = Utils.encrypt(voucherParam.LText, voucherParam.timestamp)
+      
+      Api.getSystemConfig(voucherParam).then(res => {
+        if (res.status) {
+          resolve(res)
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 10
+          })
+        }
+      })
+    })
+
+    // 鑾峰彇鍑瘉涓夌骇鑿滃崟
+    let defer4 = new Promise(resolve => {
+      let _voucherDetailSql = 'select ModularDetailCode,ModularDetailCode+ModularDetailName as CodeName,BID, VoucherTypeTwo, IDefine1 from sModularDetail where Deleted=0 and VoucherTypeTwo!=\'\''
+      _voucherDetailSql = Utils.formatOptions(_voucherDetailSql)
+
+      let voucherDetailParam = {
+        func: 'sPC_Get_SelectedList',
+        LText: _voucherDetailSql,
+        obj_name: 'data',
+        arr_field: 'ModularDetailCode,CodeName,BID,VoucherTypeTwo,IDefine1'
+      }
+
+      voucherDetailParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      voucherDetailParam.secretkey = Utils.encrypt(voucherDetailParam.LText, voucherDetailParam.timestamp)
+      
+      Api.getSystemConfig(voucherDetailParam).then(res => {
+        if (res.status) {
+          resolve(res)
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 10
+          })
+        }
+      })
+    })
+    
+    Promise.all([defer3, defer4]).then(result => {
+      this.setState({
+        voucher: result[0].data,
+        voucherDetail: result[1].data
+      })
+    })
+  }
+
   uniqueChange = (values) => {
     let verify = JSON.parse(JSON.stringify(this.state.verify))
 
@@ -120,6 +376,38 @@
     })
   }
 
+  orderChange = (values) => {
+    let verify = JSON.parse(JSON.stringify(this.state.verify))
+
+    if (values.uuid) {
+      verify.billcodes = verify.billcodes.map(item => {
+        if (item.uuid === values.uuid) {
+          return values
+        } else {
+          return item
+        }
+      })
+    } else {
+      values.uuid = Utils.getuuid()
+      verify.billcodes.push(values)
+    }
+
+    this.setState({
+      verify: verify
+    })
+  }
+
+  orderCheck = (values) => {
+    let verify = JSON.parse(JSON.stringify(this.state.verify))
+    let valid = true
+    verify.billcodes.forEach(item => {
+      if (item.uuid !== values.uuid && item.field === values.field) {
+        valid = false
+      }
+    })
+    return valid
+  }
+
   onOptionChange = (e, key) => {
     const { verify } = this.state
     let value = e.target.value
@@ -136,6 +424,8 @@
       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)
     }
 
     this.setState({ verify: verify })
@@ -146,6 +436,8 @@
       this.customForm.edit(record)
     } else if (type === 'unique') {
       this.uniqueForm.edit(record)
+    } else if (type === 'ordercode') {
+      this.orderForm.edit(record)
     }
   }
 
@@ -195,7 +487,39 @@
       this.setState({
         verify: verify
       })
+    } else if (type === 'ordercode') {
+      verify.billcodes = verify.billcodes.filter((item, i) => {
+        if (item.uuid === record.uuid) {
+          index = i
+        }
+
+        return item.uuid !== record.uuid
+      })
+      if ((index === 0 && direction === 'up') || (index === verify.billcodes.length && direction === 'down')) {
+        return
+      }
+
+      if (direction === 'up') {
+        verify.billcodes.splice(index - 1, 0, record)
+      } else {
+        verify.billcodes.splice(index + 1, 0, record)
+      }
+  
+      this.setState({
+        verify: verify
+      })
     }
+  }
+
+  voucherChange = (voucher) => {
+    const { verify } = this.state
+
+    this.setState({
+      verify: {
+        ...verify,
+        voucher: voucher
+      }
+    })
   }
 
   showError = (errorType) => {
@@ -237,7 +561,7 @@
 
   render() {
     // const { getFieldDecorator } = this.props.form
-    const { verify, fields } = this.state
+    const { verify, fields, uniqueColumns, customColumns, orderColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -248,71 +572,6 @@
         sm: { span: 16 }
       }
     }
-    let uniqueColumns = [
-      {
-        title: '瀛楁鍚�',
-        dataIndex: 'field',
-        width: '50%'
-      },
-      {
-        title: 'ErrorMessage',
-        dataIndex: 'errmsg',
-        width: '25%'
-      },
-      {
-        title: 'ErrorCode',
-        dataIndex: 'errorCode',
-        width: '10%'
-      },
-      {
-        title: '鎿嶄綔',
-        align: 'center',
-        width: '15%',
-        dataIndex: 'operation',
-        render: (text, record) =>
-          (<div>
-            <span className="operation-btn" onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
-            <Popconfirm title="纭畾鍒犻櫎鍚�?" onConfirm={() => this.handleDelete(record, 'unique')}>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
-            </Popconfirm>
-            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'unique', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
-            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'unique', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
-          </div>)
-      }
-    ]
-
-    let columns = [
-      {
-        title: 'SQL',
-        dataIndex: 'sql',
-        width: '50%'
-      },
-      {
-        title: 'ErrorMessage',
-        dataIndex: 'errmsg',
-        width: '25%'
-      },
-      {
-        title: 'ErrorCode',
-        dataIndex: 'errorCode',
-        width: '10%'
-      },
-      {
-        title: '鎿嶄綔',
-        align: 'center',
-        width: '15%',
-        dataIndex: 'operation',
-        render: (text, record) =>
-          (<div>
-            <span className="operation-btn" onClick={() => this.handleEdit(record, 'customverify')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
-            <Popconfirm title="纭畾鍒犻櫎鍚�?" onConfirm={() => this.handleDelete(record, 'customverify')}>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
-            </Popconfirm>
-            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'customverify', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
-            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'customverify', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
-          </div>)
-      }
-    ]
 
     return (
       <Tabs defaultActiveKey="1" className="verify-card-box" onChange={this.tabchange}>
@@ -365,14 +624,39 @@
             rowKey="uuid"
             className="custom-table"
             dataSource={verify.customverifys}
-            columns={columns}
+            columns={customColumns}
             pagination={false}
           />
         </TabPane>
         <TabPane tab="鍗曞彿鐢熸垚" key="4">
-          {verify.billCode ? <BillcodeForm dict={this.props.dict} billCode={verify.billCode} /> : null}
+          <BillcodeForm
+            dict={this.props.dict}
+            modular={orderModular}
+            modularDetail={orderModularDetail}
+            orderChange={this.orderChange}
+            orderCheck={this.orderCheck}
+            wrappedComponentRef={(inst) => this.orderForm = inst}
+          />
+          <Table
+            bordered
+            rowKey="uuid"
+            className="custom-table"
+            dataSource={verify.billcodes}
+            columns={orderColumns}
+            pagination={false}
+          />
         </TabPane>
-        <TabPane tab="淇℃伅鎻愮ず" key="5">
+        <TabPane tab="鍒涘缓鍑瘉" key="5">
+          <VoucherForm
+            dict={this.props.dict}
+            voucher={voucher}
+            voucherobj={verify.voucher}
+            voucherDetail={voucherDetail}
+            voucherChange={this.voucherChange}
+            wrappedComponentRef={(inst) => this.voucherForm = inst}
+          />
+        </TabPane>
+        <TabPane tab="淇℃伅鎻愮ず" key="6">
           <Form {...formItemLayout}>
             <Row gutter={24}>
               <Col offset={6} span={6}>

--
Gitblit v1.8.0