|
@@ -0,0 +1,259 @@
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import classNames from 'classnames'
|
|
|
+import { Button, Form, FormInstance, Input, InputNumber, Select } from 'antd'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import ZupOne from '@/components/ZupOne'
|
|
|
+import TextArea from 'antd/es/input/TextArea'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+import { useSelector } from 'react-redux'
|
|
|
+import { RootState } from '@/store'
|
|
|
+import ZupTypes from '@/components/ZupTypes'
|
|
|
+import { A1EditInfoType } from '@/pages/A1goods/data'
|
|
|
+import { A2_APIgetInfo, A2_APIsave } from '@/store/action/A2expert'
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ editInfo: A1EditInfoType
|
|
|
+ closeFu: () => void
|
|
|
+ addTableFu: () => void
|
|
|
+ editTableFu: () => void
|
|
|
+}
|
|
|
+
|
|
|
+function A2add({ editInfo, closeFu, addTableFu, editTableFu }: Props) {
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null)
|
|
|
+
|
|
|
+ // 肖像的ref
|
|
|
+ const ZupThumbRef = useRef<any>(null)
|
|
|
+
|
|
|
+ // 多张图片的ref
|
|
|
+ const ZupImgsRef = useRef<any>(null)
|
|
|
+
|
|
|
+ // 编辑/查看 进入页面 获取信息
|
|
|
+ const getInfoFu = useCallback(async (id: number) => {
|
|
|
+ const res = await A2_APIgetInfo(id)
|
|
|
+ if (res.code === 0) {
|
|
|
+ const info = res.data.entity
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...info,
|
|
|
+ dictId: Number(info.dictId)
|
|
|
+ }
|
|
|
+
|
|
|
+ FormBoxRef.current?.setFieldsValue(obj)
|
|
|
+
|
|
|
+ // 设置肖像
|
|
|
+ ZupThumbRef.current?.setFileComFileFu({
|
|
|
+ fileName: '',
|
|
|
+ thumb: info.thumb,
|
|
|
+ filePath: info.thumbPc
|
|
|
+ })
|
|
|
+
|
|
|
+ // 设置文件
|
|
|
+ const file = res.data.file || []
|
|
|
+
|
|
|
+ // 传给 附件 组件的
|
|
|
+ const sonInfo = {
|
|
|
+ type: info.fileType,
|
|
|
+ fileList: file
|
|
|
+ }
|
|
|
+ ZupImgsRef.current?.setFileComFileFu(sonInfo)
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 附件 是否 已经点击过确定
|
|
|
+ const [fileCheck, setFileCheck] = useState(false)
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (editInfo.id > 0) {
|
|
|
+ getInfoFu(editInfo.id)
|
|
|
+ } else {
|
|
|
+ FormBoxRef.current?.setFieldsValue({
|
|
|
+ sort: 999
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }, [editInfo.id, getInfoFu])
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {
|
|
|
+ setFileCheck(true)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ setFileCheck(true)
|
|
|
+
|
|
|
+ const coverUrl1 = ZupThumbRef.current?.fileComFileResFu()
|
|
|
+ // 没有传 肖像
|
|
|
+ if (!coverUrl1.filePath) return MessageFu.warning('请上传肖像!')
|
|
|
+
|
|
|
+ const { sonFileIds, sonIsOk, sonType } = ZupImgsRef.current?.fileComFileResFu()
|
|
|
+ if (sonIsOk) return
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...values,
|
|
|
+ id: editInfo.id > 0 ? editInfo.id : null,
|
|
|
+ thumb: coverUrl1.thumb,
|
|
|
+ thumbPc: coverUrl1.filePath,
|
|
|
+ fileIds: sonFileIds ? sonFileIds.join(',') : null,
|
|
|
+ fileType: sonType ? sonType.join(',') : null
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (obj) {
|
|
|
+ // console.log(123, obj);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ const res = await A2_APIsave(obj)
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(`${editInfo.txt}成功!`)
|
|
|
+ editInfo.id > 0 ? editTableFu() : addTableFu()
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [addTableFu, closeFu, editInfo.id, editInfo.txt, editTableFu]
|
|
|
+ )
|
|
|
+
|
|
|
+ const { sortList } = useSelector((state: RootState) => state.A2expert)
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.A2add}>
|
|
|
+ <div className={classNames('A2aMain', editInfo.txt === '查看' ? 'A2aMainLook' : '')}>
|
|
|
+ <Form
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name='basic'
|
|
|
+ labelCol={{ span: 3 }}
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete='off'
|
|
|
+ scrollToFirstError
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label='姓名'
|
|
|
+ name='name'
|
|
|
+ rules={[{ required: true, message: '请输入姓名!' }]}
|
|
|
+ getValueFromEvent={e => e.target.value.trim()}
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ readOnly={editInfo.txt === '查看'}
|
|
|
+ placeholder='请输入内容'
|
|
|
+ maxLength={20}
|
|
|
+ showCount
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {/* 肖像 */}
|
|
|
+ <div className='formRow'>
|
|
|
+ <div className='formLeft'>
|
|
|
+ <span>* </span>
|
|
|
+ 肖像:
|
|
|
+ </div>
|
|
|
+ <div className='formRight'>
|
|
|
+ <ZupOne
|
|
|
+ ref={ZupThumbRef}
|
|
|
+ isLook={editInfo.txt === '查看'}
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ size={5}
|
|
|
+ dirCode={'A2expert'}
|
|
|
+ myUrl='cms/expert/upload'
|
|
|
+ format={['image/jpeg', 'image/png']}
|
|
|
+ formatTxt='png、jpg和jpeg'
|
|
|
+ checkTxt='请上传肖像!'
|
|
|
+ upTxt='最多1张'
|
|
|
+ myType='thumb'
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {editInfo.txt === '查看' ? <br /> : null}
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label='类别'
|
|
|
+ name='dictId'
|
|
|
+ rules={[{ required: true, message: '请选择类别!' }]}
|
|
|
+ >
|
|
|
+ <Select
|
|
|
+ placeholder='请选择'
|
|
|
+ style={{ width: 200 }}
|
|
|
+ fieldNames={{ label: 'name', value: 'id' }}
|
|
|
+ options={sortList}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {/* 文件类型 */}
|
|
|
+ <div className='formRow'>
|
|
|
+ <div className='formLeft'>
|
|
|
+ <span>* </span>
|
|
|
+ 文件类型:
|
|
|
+ </div>
|
|
|
+ <div className='formRight'>
|
|
|
+ <ZupTypes
|
|
|
+ ref={ZupImgsRef}
|
|
|
+ selecFlag='图片/视频'
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ dirCode={'A2expertType'}
|
|
|
+ myUrl='cms/expert/upload'
|
|
|
+ isEdit={editInfo.id > 0}
|
|
|
+ isLook={editInfo.txt === '查看'}
|
|
|
+ isTypeShow={true}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {editInfo.txt === '查看' ? <br /> : null}
|
|
|
+
|
|
|
+ <Form.Item label='简介' name='intro' getValueFromEvent={e => e.target.value.trim()}>
|
|
|
+ <Input
|
|
|
+ readOnly={editInfo.txt === '查看'}
|
|
|
+ placeholder='请输入内容'
|
|
|
+ maxLength={20}
|
|
|
+ showCount
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item label='介绍' name='remark'>
|
|
|
+ <TextArea
|
|
|
+ readOnly={editInfo.txt === '查看'}
|
|
|
+ maxLength={800}
|
|
|
+ showCount
|
|
|
+ placeholder='请输入内容'
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <div className='A2fromRow'>
|
|
|
+ <Form.Item
|
|
|
+ label='排序值'
|
|
|
+ name='sort'
|
|
|
+ rules={[{ required: true, message: '请输入排序值!' }]}
|
|
|
+ >
|
|
|
+ <InputNumber min={1} max={999} precision={0} placeholder='请输入' />
|
|
|
+ </Form.Item>
|
|
|
+ <div className='A2_6Frow' hidden={editInfo.txt === '查看'}>
|
|
|
+ 请输入1~999的数字。数字越小,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <Form.Item className='A2abtn'>
|
|
|
+ {editInfo.txt === '查看' ? (
|
|
|
+ <Button onClick={closeFu}>返回</Button>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Button type='primary' htmlType='submit'>
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+ <br />
|
|
|
+ <br />
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA2add = React.memo(A2add)
|
|
|
+
|
|
|
+export default MemoA2add
|