|
@@ -1,58 +1,13 @@
|
|
|
-import { ZhButton } from '@/components/Button'
|
|
|
import DatePicker from '@/components/DatePicker'
|
|
|
import { tenderStore } from '@/store/mobx'
|
|
|
-import { dayjsFomrat } from '@/utils/util'
|
|
|
-import { Form, Input, InputNumber, Modal, Select, Tabs, Tag } from 'antd'
|
|
|
+import consts from '@/utils/consts'
|
|
|
+import { Form, Input, Modal } from 'antd'
|
|
|
import locale from 'antd/es/date-picker/locale/zh_CN'
|
|
|
-import { TweenOneGroup } from 'rc-tween-one'
|
|
|
-import React, { useEffect, useState } from 'react'
|
|
|
+import React, { useEffect } from 'react'
|
|
|
+import { apiAutoCode } from './api'
|
|
|
import styles from './index.module.scss'
|
|
|
-const { TabPane } = Tabs
|
|
|
-const { Option } = Select
|
|
|
-
|
|
|
-interface iTags {
|
|
|
- ruleArr: any[]
|
|
|
- setRuleArr: (arr: any[]) => void
|
|
|
-}
|
|
|
-const RenderTags:React.FC<iTags> = ({ ruleArr, setRuleArr }) => {
|
|
|
- const handleClose = (removedTag: any) => {
|
|
|
- const tags = ruleArr.filter(tag => tag !== removedTag)
|
|
|
- setRuleArr(tags)
|
|
|
- }
|
|
|
- return (
|
|
|
- <div>
|
|
|
- <TweenOneGroup
|
|
|
- enter={{
|
|
|
- scale: 0.8,
|
|
|
- opacity: 0,
|
|
|
- type: 'from',
|
|
|
- duration: 100
|
|
|
- // onComplete: (e: ) => {
|
|
|
- // e.target.style = ''
|
|
|
- // }
|
|
|
- }}
|
|
|
- leave={{ opacity: 0, width: 0, scale: 0, duration: 200 }}
|
|
|
- appear={false}
|
|
|
- >
|
|
|
- {
|
|
|
- ruleArr.map((tag, idx) => {
|
|
|
- return (
|
|
|
- <span key={idx} style={{ display: 'inline-block' }}>
|
|
|
- <Tag closable onClose={(e: Event) => {e.preventDefault();handleClose(tag)}}>
|
|
|
- {tag}
|
|
|
- </Tag>
|
|
|
- </span>
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
- </TweenOneGroup>
|
|
|
- </div>
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
interface iSafeCreateFormProps {
|
|
|
visible: boolean;
|
|
|
- type: string;
|
|
|
loading: boolean;
|
|
|
onCreate: (values: any) => void;
|
|
|
onCancel: () => void;
|
|
@@ -61,41 +16,31 @@ interface iSafeCreateFormProps {
|
|
|
const SafeCreateForm: React.FC<iSafeCreateFormProps> = ({
|
|
|
visible,
|
|
|
loading,
|
|
|
- type,
|
|
|
onCreate,
|
|
|
onCancel
|
|
|
}) => {
|
|
|
const [ form ] = Form.useForm()
|
|
|
- const [ ruleType, setRuleType ] = useState<string>('3')
|
|
|
- const [ ruleArr, setRuleArr ] = useState<any[]>([])
|
|
|
- useEffect(() => {
|
|
|
- form.setFieldsValue({ bidsectionId: tenderStore.bidsectionId })
|
|
|
- }, [ tenderStore.bidsectionId ])
|
|
|
- const ruleHandler = () => {
|
|
|
- switch (ruleType) {
|
|
|
- case '0':
|
|
|
- setRuleArr([ ...ruleArr, tenderStore.name ])
|
|
|
- break
|
|
|
- case '1':
|
|
|
- setRuleArr([ ...ruleArr, form.getFieldValue('ruleText') ])
|
|
|
- break
|
|
|
- case '2':
|
|
|
- setRuleArr([ ...ruleArr, dayjsFomrat(new Date(), 'YYYYMM') ])
|
|
|
- break
|
|
|
- default:
|
|
|
- setRuleArr([ ...ruleArr, form.getFieldValue('initCode') ])
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- // 处理自动位数编号 -> 联动起始编号
|
|
|
- const digitHandler = (value: any) => {
|
|
|
- if (value) {
|
|
|
- const length = form.getFieldValue('digits')
|
|
|
- const code = parseInt(form.getFieldValue('initCode'))
|
|
|
- const newCode = (Array(length).join('0') + code).slice(-length)
|
|
|
- form.setFieldsValue({ initCode: newCode })
|
|
|
+ const autoCodeHandler = async () => {
|
|
|
+ const { code = -1, data = "" } = await apiAutoCode(tenderStore.bidsectionId, 'safeRule')
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ if (data) {
|
|
|
+ const ruleArr: string[] = []
|
|
|
+ const code = JSON.parse(data)
|
|
|
+ for (const key in code) {
|
|
|
+ if (Object.prototype.hasOwnProperty.call(code, key)) {
|
|
|
+ const element = code[key]
|
|
|
+ if (element) {
|
|
|
+ ruleArr.push(element)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ form.setFieldsValue({ code: ruleArr.join("-") })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ useEffect(() => {
|
|
|
+ form.setFieldsValue({ bidsectionId: tenderStore.bidsectionId })
|
|
|
+ }, [])
|
|
|
return (
|
|
|
<Modal
|
|
|
getContainer={false}
|
|
@@ -110,7 +55,7 @@ const SafeCreateForm: React.FC<iSafeCreateFormProps> = ({
|
|
|
onOk={() => {
|
|
|
form
|
|
|
.validateFields()
|
|
|
- .then(values => {
|
|
|
+ .then((values) => {
|
|
|
form.resetFields()
|
|
|
onCreate(values)
|
|
|
})
|
|
@@ -120,73 +65,26 @@ const SafeCreateForm: React.FC<iSafeCreateFormProps> = ({
|
|
|
}}
|
|
|
>
|
|
|
<Form form={form} layout="vertical" size="middle" className={styles.SafeModalForm}>
|
|
|
- {
|
|
|
- type === 'add' ?
|
|
|
- <>
|
|
|
- <Form.Item name="bidsectionId" hidden>
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item
|
|
|
- name="position"
|
|
|
- label="部位"
|
|
|
- rules={[ { required: true, message: '请选择' } ]}
|
|
|
- >
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="code" label="安全编号" rules={[ { required: true, message: '请输入/生成安全编号' } ]}>
|
|
|
- <Input addonAfter={<span>自动编号</span>}/>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="inspection" label="检查项" rules={[ { required: true, message: '请填写检查项' } ]}>
|
|
|
- <Input placeholder="请填写巡检项"/>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="createTime" label="日期" rules={[ { required: true, message: '请选择日期' } ]}>
|
|
|
- <DatePicker locale={locale} allowClear style={{ width: '100%' }}></DatePicker>
|
|
|
- </Form.Item>
|
|
|
- <div className={styles.warningFooter}>添加后再补充完善其余信息</div>
|
|
|
- </>
|
|
|
- :
|
|
|
- <>
|
|
|
- <Tabs defaultActiveKey="1" type="card" size="small">
|
|
|
- <TabPane tab="编号规则设置" key="1">
|
|
|
- <div className={styles.ruleContaniner}>
|
|
|
- <h5 className={styles.ruleText}>当前规则:{ruleArr.join('-')}</h5>
|
|
|
- <div><RenderTags ruleArr={ruleArr} setRuleArr={setRuleArr}></RenderTags></div>
|
|
|
- </div>
|
|
|
- <Form.Item label="添加新组建规则" name="ruleType" initialValue="3">
|
|
|
- <Select onChange={(value: string) => setRuleType(value)}>
|
|
|
- <Option value="0">标段名</Option>
|
|
|
- <Option value="1">文本</Option>
|
|
|
- <Option value="2">当前年月</Option>
|
|
|
- <Option value="3">自动编号</Option>
|
|
|
- </Select>
|
|
|
- </Form.Item>
|
|
|
- {
|
|
|
- ruleType === '3' ?
|
|
|
- <>
|
|
|
- <Form.Item label="自动编号位数" name="digits" initialValue="3">
|
|
|
- <InputNumber size="small" min={1} style={{ width: '100%' }} onChange={(value) => digitHandler(value)}></InputNumber>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item label="起始编号" name="initCode" initialValue="001">
|
|
|
- <Input type="number"></Input>
|
|
|
- </Form.Item>
|
|
|
- </>
|
|
|
- : ''
|
|
|
- }
|
|
|
- {
|
|
|
- ruleType === '1' ?
|
|
|
- <>
|
|
|
- <Form.Item label="规则文本" name="ruleText">
|
|
|
- <Input></Input>
|
|
|
- </Form.Item>
|
|
|
- </>
|
|
|
- : ''
|
|
|
- }
|
|
|
- <ZhButton size="small" onClick={() => ruleHandler()}>添加组件</ZhButton>
|
|
|
- </TabPane>
|
|
|
- <TabPane tab="部位设置" key="2"></TabPane>
|
|
|
- </Tabs>
|
|
|
- </>
|
|
|
- }
|
|
|
+ <Form.Item name="bidsectionId" hidden>
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ name="position"
|
|
|
+ label="部位"
|
|
|
+ rules={[ { required: true, message: '请选择' } ]}
|
|
|
+ >
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name="code" label="安全编号" rules={[ { required: true, message: '请输入/生成安全编号' } ]}>
|
|
|
+ <Input addonAfter={<span onClick={() => autoCodeHandler()}>自动编号</span>}/>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name="inspection" label="检查项" rules={[ { required: true, message: '请填写检查项' } ]}>
|
|
|
+ <Input placeholder="请填写巡检项"/>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name="createTime" label="日期" rules={[ { required: true, message: '请选择日期' } ]}>
|
|
|
+ <DatePicker locale={locale} allowClear style={{ width: '100%' }}></DatePicker>
|
|
|
+ </Form.Item>
|
|
|
+ <div className={styles.warningFooter}>添加后再补充完善其余信息</div>
|
|
|
</Form>
|
|
|
</Modal>
|
|
|
)
|