123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- import React, { useState, useEffect } from 'react';
- import { Form, Input, Button, Icon, Select, Tabs, Radio, DatePicker, message, Upload } from 'antd';
- import { FormattedMessage } from 'umi-plugin-react/locale';
- import Prompt from 'umi/prompt';
- import router from 'umi/router';
- import styles from '../style/GoodsList.less';
- import apis from '../../services/apis';
- import moment from 'moment';
- import ActivityType from '../../components/SelectButton/ActivityType'
- import XForm, { FieldTypes } from '../../components/XForm';
- import Wangedit from '../../components/Wangedit/Wangedit'
- import request from '../../utils/request'
- import yinhao from '../../assets/yinhao.png'
- import ImageUploader from '../../components/XForm/ImageUpload';
- import logo from '../../assets/logo.png';
- import touxiang from '../../assets/touxiang.jpg';
- import poster1 from '../../assets/poster1.png';
- import poster2 from '../../assets/poster2.png';
- import xiaochengxu from '../../assets/xiaochengxu.png'
-
- const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
- const { TextArea } = Input;
-
- const formItemLayout = {
- labelCol: { span: 6 },
- wrapperCol: { span: 14 },
- };
-
- const cancelPage = () => {
- router.push({
- pathname: '/activity/ActivityList',
- });
- }
-
- const BasicForm = props => {
- const [isEnlist, setIsEnlist] = useState(1)
- const [activityStatus, setActivityStatus] = useState(1)
- const [disable, setDisable] = useState(false)
- const [data, setData] = useState(1)
- const [showSignupTime, setShowSignupTime] = useState([])
-
-
- const radioOnChange = e => {
- setIsEnlist(e.target.value)
- }
-
- const { dynamicId } = props
-
- // 查询详情
- const getDynamicData = dynamicId => {
- request({ ...apis.activity.details, params: { dynamicId } }).then(data => {
-
- data.activityTime = [moment(data.startDate), moment(data.endDate)]
- data.signupTime = [moment(data.enlistStart), moment(data.enlistEnd)]
- // setSignupTime([moment(data.enlistStart), moment(data.enlistEnd)])
- setData(data)
- setIsEnlist(data.isEnlist)
- setActivityStatus(data.activityStatus)
- setDisable(data.activityStatus === 0)
- props.form.setFieldsValue(data)
- })
- }
-
- // eslint-disable-next-line react-hooks/rules-of-hooks
- useEffect(() => {
- props.form.setFieldsValue({ isEnlist })
- if (dynamicId) {
- getDynamicData(dynamicId);
- }
- }, [])
- const checkTime = () => {
- function compareDate(dateTime1, dateTime2) {
- return new Date(dateTime1) > new Date(dateTime2)
- }
- // 1)修改后的开始时间不得大于当前时间(会存在已经成功报名的用户)
-
- // (2)修改后开始时间<当前时间<修改后结束时间:活动进行中
-
- // (3)修改后结束时间<当前时间:活动已结束
- if (showSignupTime[0]) {
- // const date = data.signupTime
- const nowDate = new Date()
- // console.log(compareDate(nowDate, showSignupTime[0]))
- if (compareDate(nowDate, showSignupTime[0])) {
- return true
- } else {
- // return '修改后的开始时间不得大于当前时间(会存在已经成功报名的用户)'
- }
- }
- return true
- }
-
-
- const handleSubmit = e => {
- e.preventDefault();
- props.form.validateFields((err, values) => {
-
- if (!err) {
- console.log('Received values of form: ', values);
- const { activityTime, signupTime } = values
- const [startDate, endDate] = activityTime
- values.startDate = moment(startDate).format('YYYY-MM-DD HH:mm');
- values.endDate = moment(endDate).format('YYYY-MM-DD HH:mm');
- if (signupTime) {
- const [enlistStart, enlistEnd] = signupTime
- values.enlistStart = moment(enlistStart).format('YYYY-MM-DD HH:mm');
- values.enlistEnd = moment(enlistEnd).format('YYYY-MM-DD HH:mm');
- }
-
- console.log('submit data --->', values)
- if (dynamicId) {
- const checks = checkTime()
- if (checks != true) {
- message.info(checks)
- return
- }
- console.log(data.enlistNum,values.personNum,'143')
-
- if (data.enlistNum > values.personNum) {
- message.info('活动人数必须大于已报名人数')
- return
- }
-
- values.dynamicId = dynamicId
- request({ ...apis.activity.update, data: values }).then(data => {
- message.info('保存成功')
- cancelPage()
- }).catch((err) => {
- message.info(err.msg || err.message)
- })
- } else {
- request({ ...apis.activity.add, data: { ...values } }).then((data) => {
- message.info('保存成功')
- cancelPage()
- // router.push({
- // pathname: '/activity/editActivity',
- // query: {
- // dynamicId: data.dynamicId,
- // },
- // });
- // router.go(-1)
- }).catch((err) => {
- message.info(err.msg || err.message)
- })
- }
- }
- });
- }
- const changeTime = (value, date) => {
- // console.log(value, data, '-----checkTime---------')
- // console.log(props.form.getFieldsValue(), '--------time1-----------')
- // let datas = data
- // console.log(value, date, datas)
- // datas.signupTime = date
-
- // // data.signupTime = [moment(data.enlistStart), moment(data.enlistEnd)]
-
- // console.log(datas,'-------datas--------')
- // props.form.setFieldsValue(data)
- setShowSignupTime(date)
- // props.form.setFieldsValue(datas)
- // // form.setFieldsValue
- // console.log('-------1--------')
- }
-
- const { getFieldDecorator } = props.form;
- return (
- <>
- <Form {...formItemLayout} onSubmit={handleSubmit}>
- <Form.Item label="活动类型">
- {getFieldDecorator('dynamicTypeId', {
- rules: [
- {
- required: true,
- message: '请选择活动类型',
- },
- ],
- })(<ActivityType disabled={disable} />)}
- </Form.Item>
- <Form.Item label="活动封面图" help="建议图片尺寸:690px*388px,比例16:9,格式:jpg,用于:首页推荐/活动列表">
- {getFieldDecorator('listImgUrl', {
- rules: [
- {
- required: true,
- message: '请选择活动封面图1',
- },
- ],
- })(<ImageUploader />)}
- </Form.Item>
- {/* <Form.Item label="活动封面图2" help="建议图片尺寸:750*250,比例3:1,格式:jpg,用于:项目详情页">
- {getFieldDecorator('bannerListImg', {
- rules: [
- {
- required: true,
- message: '请选择活动封面图2',
- },
- ],
- })(<ImageUploader />)}
- </Form.Item> */}
- <Form.Item label="活动详情主图" help="建议图片尺寸:750*564px,比例4:3,格式:jpg,用于:普通活动详情">
- {getFieldDecorator('imgUrl', {
- rules: [
- {
- required: true,
- message: '请选择活动详情主图',
- },
- ],
- })(<ImageUploader />)}
- </Form.Item>
- <Form.Item label="活动标题">
- {getFieldDecorator('title', {
- rules: [
- {
- required: true,
- message: '请输入活动标题',
- },
- ],
- })(<Input />)}
- </Form.Item>
- <Form.Item label="活动时间">
- {getFieldDecorator('activityTime', {
- rules: [
- {
- required: true,
- message: '请选择活动时间',
- },
- ],
- })(<RangePicker showTime={{ format: 'HH:mm' }}
- format="YYYY-MM-DD HH:mm" />)}
- </Form.Item>
- <Form.Item label="活动地点">
- {getFieldDecorator('address', {
- rules: [
- {
- required: true,
- message: '请输入活动地点',
- },
- ],
- })(<Input />)}
- </Form.Item>
- {/* disabled={activityStatus === 0 ? true : false} */}
- <Form.Item label="活动人数" help="当前活动最多可报名人数">
- {getFieldDecorator('personNum', {
- rules: [
- {
- required: true,
- message: '请输入活动人数',
- },
- // {
- // min: data.personNum,min={data.personNum || 0}
- // message: '活动人数必须大于已报名人数',
- // },
- ],
- })(<Input type="number" />)}
- </Form.Item>
- <Form.Item label="用户携带人数" help="每个用户最多可携带参与活动的人数">
- {getFieldDecorator('maxEnlistByPerson', {
- rules: [
- {
- required: true,
- message: '请输入用户携带人数',
- },
- ],
- })(<Input type="number" min={1} />)}
- </Form.Item>
- <Form.Item label="活动详情">
- {getFieldDecorator('desc')(<Wangedit />)}
- </Form.Item>
- <Form.Item label="报名时间">
- {getFieldDecorator('signupTime', {
- rules: [
- {
- required: true,
- message: '请选择报名时间',
- },
- ],
- })(<RangePicker showTime={{ format: 'HH:mm' }}
- format="YYYY-MM-DD HH:mm" onChange={changeTime} />)}
- </Form.Item>
- <Form.Item label="权重">
- {getFieldDecorator('heavy', {
-
- rules: [
- {
- required: true,
- message: '请输入权重',
- },
- ],
- })(<Input type="number" style={{ width: 80 }} />)}<span style={{ marginLeft: 30, color: 'grey' }}>数字越大越靠前</span>
- </Form.Item>
- <Form.Item wrapperCol={{ span: 12, offset: 8 }}>
- <Button type="primary" htmlType="submit">
- 确认
- </Button>
-
- <Button onClick={() => cancelPage()}>
- 取消
- </Button>
- </Form.Item>
- </Form>
- </>
- )
- }
-
- const Basic = Form.create({ name: 'BasicForm' })(BasicForm);
-
- const Poster = props => {
- const { dynamicId } = props
- const [inputValue, changeInput] = useState('')
- const [textAreaValue, changeTextArea] = useState('')
- const [imgValue, changeImg] = useState('')
- const [posterId, setPosterId] = useState('')
-
- useEffect(() => {
- if (dynamicId) {
- request({ ...apis.activity.poster, params: { targetId: dynamicId, targetType: 'activity' } }).then(data => {
-
- if (data.length > 0) {
- setPosterId(data[0].posterId)
- changeImg(data[0].posterImg)
- changeTextArea(data[0].posterDescription)
- changeInput(data[0].posterTitle)
- }
- }).catch(err => {
- message.info(err.msg || err.message)
- })
- }
- // getMiniappName()
- }, [])
-
- // 获取小程序名称
- // const [miniappName, setMiniappName] = useState('')
- // function getMiniappName() {
- // request({ ...apis.building.getMiniappName }).then(res => {
- // console.log(res, "0000000000000")
- // setMiniappName(res)
- // })
- // }
-
- const submitPoster = () => {
- if (dynamicId) {
- if (posterId) {
- request({ ...apis.activity.updatePoster, urlData: { id: posterId }, data: { targetId: dynamicId, targetType: 'activity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue } }).then(data => {
- message.info('保存成功')
- }).catch(err => {
- message.info(err.msg || err.message)
- })
- } else {
- request({ ...apis.activity.addPoster, data: { targetId: dynamicId, targetType: 'activity', posterImg: imgValue, posterTitle: inputValue, posterDescription: textAreaValue } }).then(data => {
- setPosterId(data.posterId)
- message.info('保存成功')
- }).catch(err => {
- message.info(err.msg || err.message)
- })
- }
- } else {
- message.warn('请先保存基本信息数据')
- }
- }
-
- return <div>
- <div style={{ display: 'flex' }}>
- <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>
- <div style={{ width: '375px', height: '700px', backgroundColor: '#fff', boxShadow: '0px 0px 16px 6px rgba(0,0,0,0.15)', position: 'relative', margin: '0 auto' }}>
- <img style={{ width: '100%', height: '300px' }} src={imgValue || poster1} alt="" />
- <div style={{ display: 'flex', alignItems: 'center', marginTop: '-24px' }}>
- <img style={{ width: '70px', height: '70px', border: '4px solid #fff', borderRadius: '35px', marginLeft: '16px' }} src={touxiang} alt="" />
- <span style={{ color: '#222', fontWeight: '600', margin: '24px 10px 0 14px', fontSize: '17px' }}>喵喵</span>
- <span style={{ color: '#999', marginTop: '25px', fontSize: '17px' }}>邀您参与</span>
- <span style={{ color: '#999', margin: '25px 0 0 60px', fontSize: '17px' }}>2019.09.21</span>
- </div>
- <p style={{
- margin: '10px 20px',
- fontSize: '20px',
- color: '#222',
- fontWeight: '600',
- display: '-webkit-box',
- lineClamp: '3',
- height: '60px',
- WebkitLineClamp: '2',
- WebkitBoxOrient: 'vertical',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- }}>{inputValue || '海报标题'}</p>
-
- <img src={yinhao} style={{ width: '30px', marginLeft: '20px' }} alt="" />
- <p style={{
- margin: '16px 20px 28px 20px',
- fontSize: '17px',
- color: '#999',
- display: '-webkit-box',
- lineClamp: '3',
- height: '72px',
- WebkitLineClamp: '3',
- WebkitBoxOrient: 'vertical',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- }}>{textAreaValue || '海报描述'}</p>
- <div style={{ backgroundColor: '#f1f1f1', padding: '22px 30px', boxShadow: '0px 6px 12px -4px #dcdcdc', position: 'relative' }}>
- <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>长按识别小程序码</p>
- <p style={{ margin: '0', fontSize: '18px', color: '#888' }}>进入活动查看详情</p>
- <img style={{ width: '80px', position: 'absolute', right: '30px', top: '10px' }} src={xiaochengxu} alt="" />
- </div>
- </div>
- <p style={{ textAlign: 'center', fontSize: '19px', color: '#666', marginTop: '30px' }}>海报模板</p>
- </div>
-
- <div >
- <div style={{ display: 'flex', width: '100%', margin: '60px 0' }}>
- <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>活动海报图</p>
- <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
- </div>
- <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginBottom: '30px' }}>建议图片尺寸:640*670px,比例64:67,格式:jpg,用于普通活动海报</p>
- <div style={{ display: 'flex', alignItems: 'center', width: '100%', marginBottom: '60px' }}>
- <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
- <Input style={{ width: '20vw' }} value={inputValue} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
- </div>
- <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
- <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报描述</p>
- <TextArea rows={5} maxLength={1024} value={textAreaValue} onChange={e => changeTextArea(e.target.value)} />
- </div>
-
- </div>
- </div>
- <Button type="primary" onClick={submitPoster} style={{ margin: '40px 40px 40px 30vw' }}> 确定</Button>
- <Button onClick={() => cancelPage()}>
- 取消
- </Button>
- </div>
- }
-
- const Share = props => {
- const { dynamicId } = props
- const [inputValue, changeInput] = useState('')
- const [imgValue, changeImg] = useState('')
- const [shareContentId, setShareContentId] = useState('')
-
- useEffect(() => {
- if (dynamicId) {
- request({ ...apis.activity.shareContent, params: { targetId: dynamicId, targetType: 'activity' } }).then(data => {
-
- if (data.length > 0) {
- setShareContentId(data[0].shareContentId)
- changeImg(data[0].shareContentImg)
- changeInput(data[0].shareContentTitle)
- }
- }).catch(err => {
- message.info(err.msg || err.message)
- })
- }
- }, [dynamicId])
-
- const submitShare = () => {
- if (dynamicId) {
- if (shareContentId) {
- request({ ...apis.activity.updateShareContent, urlData: { id: shareContentId }, data: { targetId: dynamicId, shareContentType: 'activity', shareContentImg: imgValue, shareContentTitle: inputValue } }).then(data => {
- message.info('保存成功')
- }).catch(err => {
- message.info(err.msg || err.message)
- })
- } else {
- request({ ...apis.activity.addShareContent, data: { targetId: dynamicId, shareContentType: 'activity', shareContentImg: imgValue, shareContentTitle: inputValue } }).then(data => {
- setShareContentId(data.shareContentId)
- message.info('保存成功')
- }).catch(err => {
- message.info(err.msg || err.message)
- })
- }
- } else {
- message.warn('请先保存基本信息数据')
- }
- }
-
- return <div style={{ padding: '20px' }}>
- <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
- <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享模板</p>
- <div>
- {/* <p style={{ display: 'flex', alignItems: 'center', fontSize: '14px', color: '#999', margin: '0', lineHeight: '0' }}>
- <img src={logo} style={{ width: '22px', marginRight: '10px' }} alt=""/>南京云致</p> */}
- <p style={{ fontSize: '16px', color: '#222', fontWeight: '600', margin: '0' }}>{inputValue || ''}</p>
- <img style={{ width: '200px', height: '160px' }} src={imgValue || poster2} alt="" />
- </div>
- </div>
- <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
- <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享标题</p>
- <Input placeholder="请输入分享标题" value={inputValue} onChange={e => changeInput(e.target.value)} />
- </div>
- <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
- <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>活动分享图</p>
- <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
- </div>
- <p style={{ fontSize: '0.5vw', color: '#A9A9A9', marginLeft: '230px', marginTop: '20px' }}>建议图片尺寸:750*600px,比例5:4,格式:jpg,用于活动分享好友</p>
- <Button type="primary" htmlType="submit" onClick={submitShare} style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
- <Button onClick={() => cancelPage()}>
- 取消
- </Button>
- </div>
- }
-
-
- /**
- *
- *
- * @param {*} props
- * @returns
- */
- const Edit = props => {
- const [tab, changeTab] = useState('basic')
- const { dynamicId } = props.location.query
-
- return (
- <div>
- {/* <div>
- <Radio.Group value={tab} buttonStyle="solid" onChange={e => changeTab(e.target.value)}>
- <Radio.Button value="basic">基本信息</Radio.Button>
- <Radio.Button value="poster">海报图片</Radio.Button>
- <Radio.Button value="share">分享设置</Radio.Button>
- </Radio.Group>
- </div> */}
- <div>
- {tab === 'basic' && <Basic dynamicId={dynamicId} />}
- {tab === 'poster' && <Poster dynamicId={dynamicId}/>}
- {tab === 'share' && <Share dynamicId={dynamicId}/>}
- </div>
- <Prompt message={location =>
- (location.pathname.startsWith('/activity/ActivityList')
- ? true
- : (location.pathname.startsWith("/activity/detailActivity") ? true : localStorage.removeItem("activePageParams")))} />
- </div>
- );
- }
-
- export default Edit
|