From 390c5026c78d2be9dca4357041f4a0ec8ac3668f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 04 二月 2020 13:57:31 +0800
Subject: [PATCH] 2020-02-04

---
 src/templates/tableshare/verifycard/customscript/index.jsx  |   94 ++++++++++++++++++
 src/templates/tableshare/verifycard/index.jsx               |   94 ++++++++++++++++++
 src/templates/tableshare/verifycard/index.scss              |   11 ++
 src/utils/utils.js                                          |   32 +++++-
 src/tabviews/tableshare/actionList/index.jsx                |   18 +-
 src/templates/tableshare/verifycard/customscript/index.scss |    0 
 6 files changed, 230 insertions(+), 19 deletions(-)

diff --git a/src/tabviews/tableshare/actionList/index.jsx b/src/tabviews/tableshare/actionList/index.jsx
index 0bf9060..f277389 100644
--- a/src/tabviews/tableshare/actionList/index.jsx
+++ b/src/tabviews/tableshare/actionList/index.jsx
@@ -226,14 +226,14 @@
         }
         
 
-        Api.genericInterface(param).then((res) => {
-          if (res.status) {
-            this.execSuccess(btn, res)
-          } else {
-            this.execError(res, btn)
-          }
-          _resolve()
-        })
+        // Api.genericInterface(param).then((res) => {
+        //   if (res.status) {
+        //     this.execSuccess(btn, res)
+        //   } else {
+        //     this.execError(res, btn)
+        //   }
+        //   _resolve()
+        // })
       } else if (btn.Ot === 'required' || (btn.Ot === 'requiredOnce' && btn.OpenType === 'pop')) {
         let deffers = data.map(cell => {
           let param = {
@@ -382,7 +382,7 @@
           _outParam = JSON.parse(JSON.stringify(res))
 
           res.appkey = window.GLOB.appkey || '' // 澶栭儴璇锋眰鏃讹紝缁熶竴娣诲姞appkey
-          
+
           return Api.genericInterface(res)
         }).then(response => {
           if (!response) return
diff --git a/src/templates/tableshare/verifycard/customscript/index.jsx b/src/templates/tableshare/verifycard/customscript/index.jsx
new file mode 100644
index 0000000..aa52edc
--- /dev/null
+++ b/src/templates/tableshare/verifycard/customscript/index.jsx
@@ -0,0 +1,94 @@
+import React, {Component} from 'react'
+import PropTypes from 'prop-types'
+import { Form, Row, Col, Input, Button } from 'antd'
+import './index.scss'
+
+const { TextArea } = Input
+
+class CustomForm extends Component {
+  static propTpyes = {
+    dict: PropTypes.object,       // 瀛楀吀椤�
+    fields: PropTypes.array,      // 琛ㄥ崟
+    scriptsChange: PropTypes.func  // 琛ㄥ崟
+  }
+
+  state = {
+    editItem: null
+  }
+
+  edit = (record) => {
+    this.setState({
+      editItem: record
+    })
+
+    this.props.form.setFieldsValue({
+      sql: record.sql
+    })
+  }
+
+
+  handleConfirm = () => {
+    // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
+    this.props.form.validateFieldsAndScroll((err, values) => {
+      if (!err) {
+        values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
+
+        this.props.scriptsChange(values)
+        this.setState({
+          editItem: null
+        })
+        this.props.form.setFieldsValue({
+          sql: ''
+        })
+      }
+    })
+  }
+
+  render() {
+    const { fields } = this.props
+    const { getFieldDecorator } = this.props.form
+    const formItemLayout = {
+      labelCol: {
+        xs: { span: 24 },
+        sm: { span: 8 }
+      },
+      wrapperCol: {
+        xs: { span: 24 },
+        sm: { span: 16 }
+      }
+    }
+    let _fields = fields.map(item => item.field)
+
+    return (
+      <Form {...formItemLayout} className="verify-form" id="verifycard2">
+        <Row gutter={24}>
+          {fields && fields.length > 0 ? <Col span={21} className="sqlfield">
+            <Form.Item label={'琛ㄥ崟瀛楁'}>
+              {_fields.join(', ')}
+            </Form.Item>
+          </Col> : null}
+          <Col span={21} className="sql">
+            <Form.Item label={'sql'}>
+              {getFieldDecorator('sql', {
+                initialValue: '',
+                rules: [
+                  {
+                    required: true,
+                    message: this.props.dict['form.required.input'] + 'sql!'
+                  }
+                ]
+              })(<TextArea rows={2} />)}
+            </Form.Item>
+          </Col>
+          <Col span={3} className="add">
+            <Button onClick={this.handleConfirm} type="primary" className="add-row">
+              纭畾
+            </Button>
+          </Col>
+        </Row>
+      </Form>
+    )
+  }
+}
+
+export default Form.create()(CustomForm)
\ No newline at end of file
diff --git a/src/templates/tableshare/verifycard/customscript/index.scss b/src/templates/tableshare/verifycard/customscript/index.scss
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/templates/tableshare/verifycard/customscript/index.scss
diff --git a/src/templates/tableshare/verifycard/index.jsx b/src/templates/tableshare/verifycard/index.jsx
index 698b9c3..70059db 100644
--- a/src/templates/tableshare/verifycard/index.jsx
+++ b/src/templates/tableshare/verifycard/index.jsx
@@ -2,12 +2,15 @@
 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 Api from '@/api'
 import Utils from '@/utils/utils.js'
+
 import UniqueForm from './uniqueform'
 import CustomForm from './customform'
+import CustomScript from './customscript'
 import BillcodeForm from './billcodeform'
 import VoucherForm from './voucherform'
-import Api from '@/api'
 import './index.scss'
 
 const { TabPane } = Tabs
@@ -91,6 +94,28 @@
           </div>)
       }
     ],
+    scriptsColumns: [
+      {
+        title: 'SQL',
+        dataIndex: 'sql',
+        width: '80%'
+      },
+      {
+        title: '鎿嶄綔',
+        align: 'center',
+        width: '20%',
+        dataIndex: 'operation',
+        render: (text, record) =>
+          (<div>
+            <span className="operation-btn" onClick={() => this.handleEdit(record, 'scripts')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
+            <Popconfirm title="纭畾鍒犻櫎鍚�?" onConfirm={() => this.handleDelete(record, 'scripts')}>
+              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
+            </Popconfirm>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'scripts', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
+            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'scripts', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
+          </div>)
+      }
+    ],
     orderColumns: [
       {
         title: '鍑芥暟鍙橀噺',
@@ -153,6 +178,7 @@
         customverifys: _verify.customverifys || [],
         billcodes: _verify.billcodes || [],
         voucher: _verify.voucher || {enabled: false},
+        scripts: _verify.scripts || []
       }
     })
 
@@ -369,6 +395,27 @@
     })
   }
 
+  scriptsChange = (values) => {
+    let verify = JSON.parse(JSON.stringify(this.state.verify))
+
+    if (values.uuid) {
+      verify.scripts = verify.scripts.map(item => {
+        if (item.uuid === values.uuid) {
+          return values
+        } else {
+          return item
+        }
+      })
+    } else {
+      values.uuid = Utils.getuuid()
+      verify.scripts.push(values)
+    }
+
+    this.setState({
+      verify: verify
+    })
+  }
+
   orderChange = (values) => {
     let verify = JSON.parse(JSON.stringify(this.state.verify))
 
@@ -408,6 +455,8 @@
       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)
     }
 
     this.setState({ verify: verify })
@@ -420,6 +469,8 @@
       this.uniqueForm.edit(record)
     } else if (type === 'ordercode') {
       this.orderForm.edit(record)
+    } else if (type === 'scripts') {
+      this.scriptsForm.edit(record)
     }
   }
 
@@ -490,6 +541,27 @@
       this.setState({
         verify: verify
       })
+    } else if (type === 'scripts') {
+      verify.scripts = verify.scripts.filter((item, i) => {
+        if (item.uuid === record.uuid) {
+          index = i
+        }
+
+        return item.uuid !== record.uuid
+      })
+      if ((index === 0 && direction === 'up') || (index === verify.scripts.length && direction === 'down')) {
+        return
+      }
+
+      if (direction === 'up') {
+        verify.scripts.splice(index - 1, 0, record)
+      } else {
+        verify.scripts.splice(index + 1, 0, record)
+      }
+  
+      this.setState({
+        verify: verify
+      })
     }
   }
 
@@ -543,7 +615,7 @@
 
   render() {
     // const { getFieldDecorator } = this.props.form
-    const { verify, fields, uniqueColumns, customColumns, orderColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state
+    const { verify, fields, uniqueColumns, customColumns, orderColumns, scriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -641,7 +713,23 @@
             wrappedComponentRef={(inst) => this.voucherForm = inst}
           />
         </TabPane>
-        <TabPane tab="淇℃伅鎻愮ず" key="6">
+        <TabPane tab="鑷畾涔夎剼鏈�" key="6">
+          <CustomScript
+            fields={fields}
+            dict={this.props.dict}
+            scriptsChange={this.scriptsChange}
+            wrappedComponentRef={(inst) => this.scriptsForm = inst}
+          />
+          <Table
+            bordered
+            rowKey="uuid"
+            className="custom-table"
+            dataSource={verify.scripts}
+            columns={scriptsColumns}
+            pagination={false}
+          />
+        </TabPane>
+        <TabPane tab="淇℃伅鎻愮ず" key="7">
           <Form {...formItemLayout}>
             <Row gutter={24}>
               <Col offset={6} span={6}>
diff --git a/src/templates/tableshare/verifycard/index.scss b/src/templates/tableshare/verifycard/index.scss
index 831a328..f34c770 100644
--- a/src/templates/tableshare/verifycard/index.scss
+++ b/src/templates/tableshare/verifycard/index.scss
@@ -15,6 +15,17 @@
         padding-top: 4px;
       }
     }
+    .sqlfield {
+      .ant-form-item {
+        margin-bottom: 5px;
+      }
+      .ant-col-sm-8 {
+        width: 10.5%;
+      }
+      .ant-col-sm-16 {
+        width: 89.5%;
+      }
+    }
     .add {
       padding-top: 4px;
     }
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 3492fa5..3a83691 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -459,8 +459,17 @@
 
     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 @BVoucher='',@FIBVoucherDate='',@FiYear=''
+    let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50)
+      `
+    if (verify && verify.scripts && verify.scripts.length > 0 && formdata) {
+      let _formfields = formdata.filter(form => !['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear'].includes(form.key))
+      _formfields = _formfields.map(form => `@${form.key} nvarchar(50)`)
+      _formfields = _formfields.join(',')
+      _sql += `${_formfields}
+        `
+    }
+
+    _sql += `Select @BVoucher='',@FIBVoucherDate='',@FiYear=''
       `
 
     if (verify && verify.accountdate === 'true') { // 鍚敤璐︽湡楠岃瘉
@@ -555,7 +564,7 @@
           let _val = ''
           if (item.linkField === 'BID' && BID) { // 鏇挎崲bid
             _val = BID
-          } else if (data.hasOwnProperty(item.linkField)) {
+          } else if (data && data.hasOwnProperty(item.linkField)) {
             _val = data[item.linkField]
           }
           _ModularDetailCode = item.TypeCharOne + _val
@@ -582,7 +591,7 @@
 
     let _updateconfig = ''
 
-    if (verify && verify.voucher && verify.voucher.enabled) { // 鍑瘉-鏄剧ず鍒椾腑閫夊彇,蹇呴』閫夎
+    if (verify && verify.voucher && verify.voucher.enabled && data) { // 鍑瘉-鏄剧ず鍒椾腑閫夊彇,蹇呴』閫夎
       let _voucher = verify.voucher
 
       _updateconfig = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear'
@@ -643,9 +652,18 @@
     } 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 retmsg
+
+    if (verify && verify.scripts && verify.scripts.length > 0) {
+      let _scripts = ''
+      verify.scripts.forEach(item => {
+        _scripts += `${item.sql}
+        `
+      })
+      _sql += `
+        ${_scripts}`
+    }
+
+    _sql += `aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg
       `
     console.log(_sql)
     return _sql

--
Gitblit v1.8.0