From 669d7cc31eb3728ad09bfb7ce6e615f5c571c14e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 08 一月 2020 15:58:39 +0800
Subject: [PATCH] 2020-01-08

---
 src/templates/tableshare/verifycard/billcodeform/index.jsx |  244 ++++++++++++++++++++++++++++--------------------
 1 files changed, 143 insertions(+), 101 deletions(-)

diff --git a/src/templates/tableshare/verifycard/billcodeform/index.jsx b/src/templates/tableshare/verifycard/billcodeform/index.jsx
index 34674b5..4ea880c 100644
--- a/src/templates/tableshare/verifycard/billcodeform/index.jsx
+++ b/src/templates/tableshare/verifycard/billcodeform/index.jsx
@@ -1,30 +1,54 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Form, Row, Col, Input, Select, Button, notification } from 'antd'
+import { Form, Row, Col, Select, Button, InputNumber } from 'antd'
 import './index.scss'
 
 
 class UniqueForm extends Component {
   static propTpyes = {
     dict: PropTypes.object,  // 瀛楀吀椤�
+    fields: PropTypes.array,  // 琛ㄥ崟
+    columns: PropTypes.array,  // 琛ㄥ崟
     modular: PropTypes.array,  // 琛ㄥ崟
     modularDetail: PropTypes.array,  // 琛ㄥ崟
-    orderChange: PropTypes.func,  // 琛ㄥ崟
-    orderCheck: PropTypes.func  // 琛ㄥ崟
+    orderChange: PropTypes.func  // 琛ㄥ崟
   }
 
   state = {
     editItem: null,
-    modularDetail: []
+    modularDetail: [],
+    funFields: [],
+    billFields: [],
+    type: '1'
   }
 
   UNSAFE_componentWillMount() {
+    let _modularDetail = []
+    let _billFields = []
     if (this.props.modular.length > 0) {
-      this.setState({
-        modularDetail: this.props.modularDetail.filter(item => item.BID === this.props.modular[0].ID)
-      })
+      _modularDetail = this.props.modularDetail.filter(item => item.BID === this.props.modular[0].ID)
     }
+
+    let fieldMap = new Map()
+    this.props.fields.forEach(_field => {
+      if (_field.type === 'text' && !fieldMap.has(_field.field)) {
+        _billFields.push(_field)
+        fieldMap.set(_field.field, true)
+      }
+    })
+    this.props.columns.forEach(_field => {
+      if (_field.type === 'text' && !fieldMap.has(_field.field)) {
+        _billFields.push(_field)
+        fieldMap.set(_field.field, true)
+      }
+    })
+
+    this.setState({
+      modularDetail: _modularDetail,
+      funFields: this.props.fields.filter(field => field.type === 'funcvar'),
+      billFields: _billFields
+    })
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
@@ -34,34 +58,41 @@
       this.setState({
         modularDetail: _detail
       })
-
-      this.props.form.setFieldsValue({
-        ModularCode: nextProps.modular[0].ID,
-        ModularDetailCode: _detail[0] ? _detail[0].ModularDetailCode : ''
-      })
     }
   }
 
   edit = (record) => {
-    let _detail = this.props.modularDetail.filter(item => item.BID === record.ModularCode)
-    let _modularDetailCode = ''
+    if (record.TypeCharOne === 'Y' || record.TypeCharOne === 'n') {
+      let _detail = this.props.modularDetail.filter(item => item.BID === record.ModularCode)
+      let _modularDetailCode = ''
 
-    if (_detail.filter(item => item.ModularDetailCode === record.ModularDetailCode).length > 0) {
-      _modularDetailCode = record.ModularDetailCode
+      if (_detail.filter(item => item.ModularDetailCode === record.ModularDetailCode).length > 0) {
+        _modularDetailCode = record.ModularDetailCode
+      }
+
+      this.setState({
+        type: '2',
+        editItem: record,
+        modularDetail: _detail
+      })
+      this.props.form.setFieldsValue({
+        field: record.field,
+        TypeCharOne: record.TypeCharOne,
+        ModularCode: record.ModularCode,
+        ModularDetailCode: _modularDetailCode,
+      })
+    } else {
+      this.setState({
+        type: '1',
+        editItem: record,
+      })
+      this.props.form.setFieldsValue({
+        field: record.field,
+        TypeCharOne: record.TypeCharOne,
+        Type: record.Type,
+        linkField: record.linkField,
+      })
     }
-
-    this.setState({
-      editItem: record,
-      modularDetail: _detail
-    })
-    this.props.form.setFieldsValue({
-      field: record.field,
-      TypeCharOne: record.TypeCharOne,
-      ModularCode: record.ModularCode,
-      ModularDetailCode: _modularDetailCode,
-      errmsg: record.errmsg,
-      errorCode: record.errorCode
-    })
   }
 
   voucherChange = (value) => {
@@ -75,12 +106,28 @@
     })
   }
 
+  TypeCharOneChange = (value) => {
+    if (value === 'Y' || value === 'n') {
+      this.setState({
+        type: '2'
+      })
+    } else {
+      this.setState({
+        type: '1'
+      })
+    }
+  }
 
   handleConfirm = () => {
+    const { funFields, billFields } = this.state
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
         values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
+
+        let _funField = funFields.filter(item => item.field === values.field)[0]
+        values.fieldName = _funField ? _funField.label : ''
+
         // 涓�绾ц彍鍗曞�间负20190203125926873D6029A9C511041719420鏃禩ypeCharTwo=TableCode锛屽叾浠栫敤BillCode
         if (values.ModularCode === '20190203125926873D6029A9C511041719420') {
           values.TypeCharTwo = 'TableCode'
@@ -96,22 +143,17 @@
         }
         values.billType = billType[values.TypeCharOne]
 
-        // 璁剧疆鍑瘉绫诲瀷涓枃鍚�
-        let ModularCode = this.props.modular.filter(item => item.ID === values.ModularCode)[0]
-        values.ModularCodeName = ModularCode.NameNO
+        if (values.TypeCharOne === 'Y' || values.TypeCharOne === 'n') {
+          // 璁剧疆鍑瘉绫诲瀷涓枃鍚�
+          let ModularCode = this.props.modular.filter(item => item.ID === values.ModularCode)[0]
+          values.ModularCodeName = ModularCode.NameNO
 
-        // 璁剧疆娴佹按鍙蜂綅鏁�
-        let _detail = this.state.modularDetail.filter(item => item.ModularDetailCode === values.ModularDetailCode)[0]
-        values.Type = _detail.Type
-        let _vaild = this.props.orderCheck(values)
-
-        if (!_vaild) {
-          notification.warning({
-            top: 92,
-            message: '瀛楁鍊间笉鍙噸澶�',
-            duration: 10
-          })
-          return
+          // 璁剧疆娴佹按鍙蜂綅鏁�
+          let _detail = this.state.modularDetail.filter(item => item.ModularDetailCode === values.ModularDetailCode)[0]
+          values.Type = _detail.Type
+        } else {
+          let _billField = billFields.filter(item => item.field === values.linkField)[0]
+          values.linkFieldName = _billField ? _billField.label : ''
         }
 
         this.props.orderChange(values)
@@ -120,7 +162,6 @@
         })
         this.props.form.setFieldsValue({
           field: '',
-          errmsg: ''
         })
       }
     })
@@ -128,6 +169,7 @@
 
   render() {
     const { getFieldDecorator } = this.props.form
+    const { type } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -138,34 +180,35 @@
         sm: { span: 14 }
       }
     }
+
     return (
       <Form {...formItemLayout} className="verify-form">
         <Row gutter={24}>
-          <Col span={6}>
-            <Form.Item label={'瀛楁'}>
+          <Col span={5}>
+            <Form.Item label={'鍑芥暟鍙橀噺'}>
               {getFieldDecorator('field', {
                 initialValue: '',
                 rules: [
                   {
                     required: true,
-                    message: this.props.dict['form.required.input'] + '瀛楁!'
-                  },
-                  {
-                    pattern: /^[0-9a-zA-Z_]*$/,
-                    message: '鍚嶇О鍙厑璁稿寘鍚暟瀛椼�佸瓧姣嶅拰涓嬪垝绾匡紝涓斾互鎸囧畾瀛楃寮�濮嬨��'
-                  },
-                  {
-                    max: 50,
-                    message: '鍚嶇О涓嶈秴杩�50涓瓧绗︺��'
+                    message: this.props.dict['form.required.input'] + '鍑芥暟鍙橀噺!'
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" />)}
+              })(
+                <Select>
+                  {this.state.funFields.map(option =>
+                    <Select.Option id={option.uuid} key={option.uuid} value={option.field}>
+                      {option.label}
+                    </Select.Option>
+                  )}
+                </Select>
+              )}
             </Form.Item>
           </Col>
-          <Col span={6}>
+          <Col span={5}>
             <Form.Item label={'绫诲瀷'}>
               {getFieldDecorator('TypeCharOne', {
-                initialValue: 'Y',
+                initialValue: 'Lp',
                 rules: [
                   {
                     required: true,
@@ -173,7 +216,7 @@
                   }
                 ]
               })(
-                <Select>
+                <Select onChange={(value) => {this.TypeCharOneChange(value)}}>
                   <Select.Option value="Y"> 鍗曞彿 </Select.Option>
                   <Select.Option value="n"> 缂栫爜 </Select.Option>
                   <Select.Option value="Lp"> 琛屽彿 </Select.Option>
@@ -182,7 +225,41 @@
               )}
             </Form.Item>
           </Col>
-          <Col span={6}>
+          {type === '1' ? <Col span={5}>
+            <Form.Item label={'鍏宠仈瀛楁'}>
+              {getFieldDecorator('linkField', {
+                initialValue: '',
+                rules: [
+                  {
+                    required: true,
+                    message: this.props.dict['form.required.input'] + '鍏宠仈瀛楁!'
+                  }
+                ]
+              })(
+                <Select>
+                  {this.state.billFields.map(option =>
+                    <Select.Option id={option.uuid} key={option.uuid} value={option.field}>
+                      {option.label}
+                    </Select.Option>
+                  )}
+                </Select>
+              )}
+            </Form.Item>
+          </Col> : null}
+          {type === '1' ? <Col span={5}>
+            <Form.Item label={'浣嶆暟'}>
+              {getFieldDecorator('Type', {
+                initialValue: 4,
+                rules: [
+                  {
+                    required: true,
+                    message: this.props.dict['form.required.input'] + '浣嶆暟!'
+                  }
+                ]
+              })(<InputNumber min={1} max={10} precision={0} />)}
+            </Form.Item>
+          </Col> : null}
+          {type === '2' ? <Col span={5}>
             <Form.Item label={'鍑瘉绫诲瀷'}>
               {getFieldDecorator('ModularCode', {
                 initialValue: this.props.modular[0] ? this.props.modular[0].ID : '',
@@ -206,8 +283,8 @@
                 </Select>
               )}
             </Form.Item>
-          </Col>
-          <Col span={6}>
+          </Col> : null}
+          {type === '2' ? <Col span={5}>
             <Form.Item label={'鍑瘉鏍囪瘑'}>
               {getFieldDecorator('ModularDetailCode', {
                 initialValue: this.state.modularDetail[0] ? this.state.modularDetail[0].ModularDetailCode : '',
@@ -230,44 +307,9 @@
                 </Select>
               )}
             </Form.Item>
-          </Col>
-          <Col span={6}>
-            <Form.Item label={'鎻愮ず淇℃伅'}>
-              {getFieldDecorator('errmsg', {
-                initialValue: '',
-                rules: [
-                  {
-                    required: true,
-                    message: this.props.dict['form.required.input'] + '鎻愮ず淇℃伅!'
-                  }
-                ]
-              })(<Input placeholder="" autoComplete="off" />)}
-            </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.Option value="S"> S </Select.Option>
-                  <Select.Option value="-1"> -1 </Select.Option>
-                </Select>
-              )}
-            </Form.Item>
-          </Col>
-          <Col span={2}>
-            <Button onClick={this.handleConfirm} type="primary" className="add-row">
+          </Col> : null}
+          <Col span={4} className="add">
+            <Button onClick={this.handleConfirm} type="primary">
               纭畾
             </Button>
           </Col>

--
Gitblit v1.8.0