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 styles from '../../style/GoodsList.less';
import apis from '../../../services/apis';
import moment from 'moment';
import router from 'umi/router';
import BuildSelect from '../../../components/SelectButton/BuildSelect'
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 header = props => {
const [isEnlist, setIsEnlist] = useState(1)
const radioOnChange = e => {
// console.log(e.target.value)
setIsEnlist(e.target.value)
}
// eslint-disable-next-line react-hooks/rules-of-hooks
const [data, setData] = useState({ channelNmae: [], result: [] })
// eslint-disable-next-line react-hooks/rules-of-hooks
const { helpActivityId } = props
const [dynamicData, setDynamicData] = useState({ isEnlist: 1 })
// 详情
const getDynamicData = helpActivityId => {
request({ ...apis.helpActivity.details, params: { helpActivityId } }).then((data) => {
data.activityTime = [moment(data.startDate), moment(data.endDate)]
const num = data.helpNum > 0 ? 1 : 0
setIsEnlist(num)
data.isEnlist = num
props.form.setFieldsValue(data)
setDynamicData(data)
})
}
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
// eslint-disable-next-line no-use-before-define
if (helpActivityId) {
getDynamicData(helpActivityId)
}
}, [])
// function addChannel(params) {
// request({ ...apis.channelList.addChannel, data: { ...params } }).then((data) => {
// setData(data)
// }).catch((err) => {
// console.log(err)
// message.info(err.msg || err.message)
// })
// }
const cancelPage = () => {
router.push({
pathname: '/activity/helpActivity/list',
});
}
function handleSubmit(e) {
e.preventDefault();
props.form.validateFields((err, values) => {
if (!err) {
if (values.isEnlist === 0) {
values.helpNum = 0
}
// 判断助力人数不得超过200
if (values.personNum > 200) {
message.error('助力邀请人数不能超过200')
return
}
// 助力邀请人数>0
if (values.personNum <= 0) {
message.error('助力邀请人数大于0')
return
}
// 判断助力人数必须大于0
if (values.isEnlist === 1) {
if (values.helpNum <= 0) {
message.error('限制助力次数必须大于0')
return
}
}
const { activityTime, signupTime, ...submitValue } = values
const [startDate, endDate] = activityTime
console.log('startDate', activityTime)
submitValue.startDate = moment(startDate).format('YYYY-MM-DD HH:mm:ss');
submitValue.endDate = moment(endDate).format('YYYY-MM-DD HH:mm:ss');
// const [enlistStart, enlistEnd] = signupTime
// submitValue.enlistStart = moment(enlistStart).format('YYYY-MM-DD HH:mm');
// submitValue.enlistEnd = moment(enlistEnd).format('YYYY-MM-DD HH:mm');
console.log('submit data --->', submitValue)
if (helpActivityId) {
submitValue.helpActivityId = helpActivityId
request({ ...apis.helpActivity.update, data: submitValue }).then((data) => {
message.info("保存成功")
cancelPage()
}).catch((err) => {
message.info(err.msg || err.message)
})
} else {
request({ ...apis.helpActivity.add, data: submitValue }).then((data) => {
message.info("保存成功")
cancelPage()
}).catch((err) => {
message.info(err.msg || err.message)
})
}
}
});
}
const { getFieldDecorator } = props.form;
return (
<>
{getFieldDecorator('buildingId', {
rules: [
{
required: true,
message: '请选择所属项目',
},
],
})()}
{getFieldDecorator('title', {
rules: [
{
required: true,
message: '请输入活动标题',
},
],
})()}
{getFieldDecorator('img', {
rules: [
{
required: true,
message: '活动主图不能为空',
},
],
})()}
{getFieldDecorator('activityTime', {
rules: [
{
required: true,
message: '请选择活动时间',
},
],
})()}
{getFieldDecorator('personNum', {
rules: [
{
required: true,
message: '请输入活动人数',
},
],
})()}
{getFieldDecorator('isEnlist', {
rules: [
{
required: true,
message: '请选择助力次数',
},
],
})(
radioOnChange(e)}>
不限制
限制
,
)}
{
isEnlist === 1 &&
{getFieldDecorator('helpNum', {
rules: [
{
required: true,
message: '请输入助力人数',
},
],
})()}
}
{getFieldDecorator('activityInstructions', {
rules: [
{
required: true,
message: '活动说明不能为空',
},
],
})()}
>
)
}
const Basic = Form.create({ name: 'header' })(header);
/**
*
*
* @param {*} props
* @returns
*/
const Edit = props => {
const [tab, changeTab] = useState('basic')
// 判断是否展示助力次数的输入框
// const [help, helpTab] = useState('1')
const { helpActivityId } = props.location.query
const [dynamicData, setDynamicData] = useState({ isEnlist: 1 })
if (helpActivityId) {
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
// eslint-disable-next-line no-use-before-define
getDynamicData(helpActivityId);
}, [])
// 详情
const getDynamicData = (helpActivityId) => {
request({ ...apis.helpActivity.details, params: { helpActivityId } }).then((data) => {
console.log(data)
setDynamicData(data)
})
}
}
const cancelPage = () => {
router.push({
pathname: '/activity/helpActivity/list',
});
}
const radioOnChange = e => {
console.log(e.target.value)
setDynamicData({ ...dynamicData, isEnlist: e.target.value })
}
const Poster = (props) => {
const [inputValue, changeInput] = useState('')
const [textAreaValue, changeTextArea] = useState('')
const [imgValue, changeImg] = useState('')
const [posterId, setPosterId] = useState('')
if (helpActivityId) {
console.log(helpActivityId, 'helpActivityId')
useEffect(() => {
request({ ...apis.activity.poster, params: { targetId: helpActivityId, targetType: 'helpActivity' } }).then((data) => {
console.log(data, "2222")
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()
}, [])
}else{
getMiniappName()
}
// 获取小程序名称
const [miniappName, setMiniappName] = useState('')
function getMiniappName() {
request({ ...apis.building.getMiniappName }).then(res => {
console.log(res, "0000000000000")
setMiniappName(res)
})
}
const submitPoster = () => {
if (helpActivityId) {
if (posterId) {
request({ ...apis.activity.updatePoster, urlData: { id: posterId }, data: { targetId: helpActivityId, targetType: 'helpActivity', 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: helpActivityId, targetType: 'helpActivity', 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
喵喵
邀您参与
2019.09.21
{inputValue ? inputValue : '海报标题'}
{textAreaValue ? textAreaValue : '海报描述'}
长按识别小程序码
进入{miniappName || '置业V顾问'}报名活动
海报模板
}
const Share = (props) => {
const [inputValue, changeInput] = useState('')
const [imgValue, changeImg] = useState('')
const [shareContentId, setShareContentId] = useState('')
if (helpActivityId) {
useEffect(() => {
request({ ...apis.activity.shareContent, params: { targetId: helpActivityId, targetType: 'helpActivity' }, }).then((data) => {
console.log(data, "2222")
if (data.length > 0) {
setShareContentId(data[0].shareContentId)
changeImg(data[0].shareContentImg)
changeInput(data[0].shareContentTitle)
}
}).catch((err) => {
message.info(err.msg || err.message)
})
}, [])
}
const submitShare = () => {
if (helpActivityId) {
if (shareContentId) {
request({ ...apis.activity.updateShareContent, urlData: { id: shareContentId }, data: { targetId: helpActivityId, shareContentType: 'helpActivity', shareContentImg: imgValue, shareContentTitle: inputValue }, }).then((data) => {
message.info("保存成功")
}).catch((err) => {
message.info(err.msg || err.message)
})
} else {
request({ ...apis.activity.addShareContent, data: { targetId: helpActivityId, shareContentType: 'helpActivity', shareContentImg: imgValue, shareContentTitle: inputValue }, }).then((data) => {
setShareContentId(data.shareContentId)
message.info("保存成功")
}).catch((err) => {
message.info(err.msg || err.message)
})
}
} else {
message.warn("请先保存基本信息数据")
}
}
return
分享模板
知与行互动
{inputValue ? inputValue : '置业V客厅 精准获客平台'}
图片比例: 5:4
}
return (
changeTab(e.target.value)}>
基本信息
海报图片
分享设置
{tab === 'basic' &&
}
{tab === 'poster' && }
{tab === 'share' && }
);
}
export default Edit