|
@@ -0,0 +1,129 @@
|
|
|
+import React, { useCallback, useEffect, useRef } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import { A4tableType } from '../data'
|
|
|
+import { Button, Form, FormInstance, Input, InputNumber, Modal } from 'antd'
|
|
|
+import { A4_APIsave } from '@/store/action/A4evaluate'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+import TextArea from 'antd/es/input/TextArea'
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ info: A4tableType
|
|
|
+ closeFu: () => void
|
|
|
+ addTableFu: () => void
|
|
|
+ upTableFu: () => void
|
|
|
+}
|
|
|
+
|
|
|
+function A4add({ info, closeFu, addTableFu, upTableFu }: Props) {
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null)
|
|
|
+
|
|
|
+ // 编辑进来获取详情
|
|
|
+ const getInfoFu = useCallback(
|
|
|
+ (id: number) => {
|
|
|
+ FormBoxRef.current?.setFieldsValue(info)
|
|
|
+ },
|
|
|
+ [info]
|
|
|
+ )
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (info.id > 0) getInfoFu(info.id)
|
|
|
+ else FormBoxRef.current?.setFieldsValue({ sort: 999 })
|
|
|
+ }, [getInfoFu, info.id])
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {}, [])
|
|
|
+
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ const obj = {
|
|
|
+ ...values,
|
|
|
+ id: info.id > 0 ? info.id : null
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (1 + 1 === 2) {
|
|
|
+ // console.log('------222', obj)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+
|
|
|
+ const res = await A4_APIsave(obj)
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(`${info.id > 0 ? '编辑' : '新增'}成功`)
|
|
|
+ if (info.id > 0) upTableFu()
|
|
|
+ else addTableFu()
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [addTableFu, closeFu, info.id, upTableFu]
|
|
|
+ )
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal
|
|
|
+ wrapClassName={styles.A4add}
|
|
|
+ open={true}
|
|
|
+ title={info.id > 0 ? '编辑评价' : '新增评价'}
|
|
|
+ footer={
|
|
|
+ [] // 设置footer为空,去掉 取消 确定默认按钮
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className='A4aMain'>
|
|
|
+ <Form
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name='basic'
|
|
|
+ labelCol={{ span: 2 }}
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete='off'
|
|
|
+ scrollToFirstError
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label='姓名'
|
|
|
+ name='name'
|
|
|
+ rules={[{ required: true, message: '请输入姓名' }]}
|
|
|
+ // getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ getValueFromEvent={e => e.target.value.trim()}
|
|
|
+ >
|
|
|
+ <Input maxLength={10} showCount placeholder='请输入内容' />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label='留言'
|
|
|
+ name='intro'
|
|
|
+ getValueFromEvent={e => e.target.value.trim()}
|
|
|
+ rules={[{ required: true, message: '请输入留言' }]}
|
|
|
+ >
|
|
|
+ <TextArea maxLength={200} showCount placeholder='请输入内容' />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <div className='A4fromRow'>
|
|
|
+ <Form.Item
|
|
|
+ label='排序值'
|
|
|
+ name='sort'
|
|
|
+ rules={[{ required: true, message: '请输入排序值' }]}
|
|
|
+ >
|
|
|
+ <InputNumber min={1} max={999} precision={0} placeholder='请输入' />
|
|
|
+ </Form.Item>
|
|
|
+ <div className='A4_6Frow'>
|
|
|
+ 请输入1~999的数字。数字越小,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <Form.Item className='A4aBtn'>
|
|
|
+ <Button type='primary' htmlType='submit'>
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} />
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA4add = React.memo(A4add)
|
|
|
+
|
|
|
+export default MemoA4add
|