Commit 47d17e5f authored by cellee's avatar cellee

设施新增重做

Signed-off-by: cellee's avatarcellee <893264950@qq.com>
parent 4ac63b98
import React, { useState, useEffect, useRef } from 'react';
import './index.less';
import { Input, Button, Upload, Form, Select, message, Modal } from 'antd';
const { Option } = Select;
import { PlusOutlined } from '@ant-design/icons';
import { Link, useIntl, connect, Dispatch, history } from 'umi';
import { event } from '@/.umi/plugin-locale/locale';
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
}
const Facilitys = (props: any) => {
//传递值
const { updata, disabled } = props;
console.log(disabled);
//上传列表
const [fileList, setFileList] = useState([]);
//显示隐藏
const [previewVisible, setpreviewVisible] = useState(false);
// 名称
const [previewTitle, setpreviewTitle] = useState('');
// 图片地址
const [previewImage, setpreviewImage] = useState(null);
// 新增按钮
const uploadButton = (
<div>
<PlusOutlined />
<div className="ant-upload-text">Upload</div>
</div>
);
// 上传属性
const uploadProps = {
listType: 'picture-card',
accept: '.jpeg,.png,.jpg',
action: '/tos/image/upload',
// fileList: fileList,
onChange(info: any) {
console.log(info);
if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`);
// 拿到key 值 开始存储
let list = fileList;
// setFileList(list); // 注意 不能直接赋值 因为使用完全绑定需要全部更新
setFileList([...list]);
console.log(fileList);
} else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
// 上传
const carryData = (key: any) => {
console.log(`key值是${key}`);
updata.identification = key;
console.log(updata);
return updata;
};
// 预览
const handlePreview = async (file) => {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
setpreviewImage(file.url || file.preview);
setpreviewTitle(file.name);
setpreviewVisible(true);
};
// 点击遮罩回调
const handleCancel = () => {
setpreviewVisible(false);
};
// 点击移除图片
const handRemove = () => {
setFileList([...fileList]);
};
return (
<>
<Form.List
name="names"
rules={[
{
validator: async (_, names) => {
// if (!names || names.length < 2) {
// return Promise.reject(new Error('At least 2 passengers'));
// }
},
},
]}
>
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field, index) => (
<Form.Item required={false} key={field.key} style={{ marginBottom: 0 }}>
{/* 每一个上传的组件 */}
<div className={'test'}>
<div className={'diybox'}>
<Upload
fileList={fileList}
data={carryData(index)}
{...uploadProps}
disabled={disabled}
onPreview={handlePreview}
onRemove={handRemove}
>
{/* 这里存在一个bug 当 key 超过 fileList 的默认值后 会报错 */}
{fileList.length >= 1 ? null : uploadButton}
</Upload>
<div className={'Facility'}>
<Form.Item
label={`Facility Name ${index}`}
name={field.key}
rules={[{ required: true, message: 'Please input Facility Name!' }]}
>
<Input placeholder="Facility Name" disabled={disabled} />
</Form.Item>
<div className={'over'}>
{fields.length > 1 ? (
<Button
type="link"
disabled={disabled}
onClick={() => remove(field.name)}
>
Delete
</Button>
) : null}
</div>
</div>
</div>
</div>
</Form.Item>
))}
{fields.length < 5 ? (
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
style={{ width: '100px', height: '100px' }}
icon={<PlusOutlined />}
disabled={disabled}
></Button>
<Form.ErrorList errors={errors} />
</Form.Item>
) : null}
</>
)}
</Form.List>
{/* 预览表格 */}
<Modal visible={previewVisible} title={previewTitle} footer={null} onCancel={handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
</Modal>
</>
);
};
export default Facilitys;
import React, { useState } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import './index.less';
import { Button, Form, message, Modal } from 'antd';
import { Button, Form, message, Modal, Input, Upload } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import FacilitysTow from './FacilitysTow';
// import FacilitysTow from './FacilitysTow';
import { Link, useIntl, connect, Dispatch, history } from 'umi';
function getBase64(file) {
function getBase64(file: any) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
......@@ -13,54 +13,218 @@ function getBase64(file) {
reader.onerror = (error) => reject(error);
});
}
const module = 'FacilityBookings';
const Facilitys = (props: any) => {
//传递值
const { updata, disabled } = props;
const { updata, disabled, FacilitysList, dispatch, dumps } = props;
//上传列表
// const [FacilitysList, setFileList] = useState(FacilitysList);
//显示隐藏
const [previewVisible, setpreviewVisible] = useState(false);
// 名称
const [previewTitle, setpreviewTitle] = useState('');
// 图片地址
const [previewImage, setpreviewImage] = useState('');
// 传递给后台加 key
const updetaTow = (key: any) => {
let data = updata;
data.identification = key;
return data;
};
//绑定值
const updetaList = (key: any) => {
return FacilitysList[key].fileList;
};
// 预览
const handlePreview = async (file: any) => {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
setpreviewImage(file.url || file.preview);
setpreviewTitle(file.name);
setpreviewVisible(true);
};
// 点击移除图片
const handRemove = (key: any) => {
// let list = fileList;
// 将图片信息提交给state
deleteImg(key);
};
// 点击遮罩回调
const handleCancel = () => {
setpreviewVisible(false);
};
// 上传属性
const uploadProps: any = {
listType: 'picture-card',
accept: '.jpeg,.png,.jpg',
action: '/tos/image/upload',
onChange(info: any) {
// console.log(info);
if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`);
// 拿到key 值 开始存储
let key = info.fileList[0].response.data.identification;
let list = FacilitysList;
list[key].id = key;
list[key].fileList = info.fileList;
// 存储到mode里面去
dispatch({ type: module + '/genxin', list });
// 当前页面也要刷新
// let list = fileList;
// setFileList(list); // 注意 不能直接赋值 因为使用完全绑定需要全部更新
// setFileList(list);
// let list: any = [...fileList, ...info.fileList];
// setFileList(list);
console.log(list);
// 将图片信息提交给state
// let data = { val: info.file.name, key: keys };
// dispatch({ type: module + '/retImgsList', data });
// 结束
} else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
// 新增动作
const add = () => {
let list = FacilitysList;
let adds = {
id: '-1',
fileList: [],
name: '',
};
// 验证已添加的是否上传完整
let complete = list.every((item: any) => {
// return item.fileList.length > 0 && item.name !== '';
return item.fileList.length > 0;
});
if (list.length == 0 || complete) {
list.push(adds);
// 存储到mode里面去
dispatch({ type: module + '/genxin', list });
} else {
// 提示每一项都要填写完
message.error('Please fill out each item !');
}
};
//删除动作
const deleteImg = (key: any) => {
let list = FacilitysList;
list[key].name = '';
// 这里还要清除表单的值,否则再次新增输入框的值会重复出现
dumps(key);
list.splice(key, 1);
// 存储到mode里面去
dispatch({ type: module + '/genxin', list });
};
// 新增按钮
const uploadButton = (
<div>
<PlusOutlined />
<div className="ant-upload-text">Upload</div>
</div>
);
// 输入框内容
const monitor = (e: any) => {
let list = FacilitysList;
let { id, value } = e.target;
if (id == 'basic_shebei_0') {
id = 0;
}
list[id].name = value;
dispatch({ type: module + '/genxin', list });
};
return (
<>
<Form.List
name="picList"
rules={[
{
validator: async (_, names) => {
// if (!names || names.length < 2) {
// return Promise.reject(new Error('At least 2 passengers'));
// }
},
},
]}
>
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field, index) => (
<Form.Item required={false} key={field.key} style={{ marginBottom: 0 }}>
<FacilitysTow updata={updata} disabled={disabled} keys={field.key}></FacilitysTow>
</Form.Item>
))}
{fields.length < 5 ? (
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
style={{ width: '100px', height: '100px' }}
icon={<PlusOutlined />}
disabled={disabled}
></Button>
<Form.ErrorList errors={errors} />
</Form.Item>
) : null}
</>
)}
</Form.List>
<Form.Item name="picList" required={false} style={{ marginBottom: 0 }}>
{FacilitysList.map((item: any, index: any, key: any) => {
return (
<div className={'test'} key={'pic_' + index}>
<div className={'diybox'} key={'pic_' + index}>
<Upload
{...uploadProps}
fileList={
FacilitysList[index].fileList.length > 0 ? FacilitysList[index].fileList : false
}
// data={updata}
data={updetaTow(index)} // 携带数据
disabled={disabled} // 禁止
onPreview={handlePreview} // 预览
onRemove={() => {
handRemove(index);
}} //移除
>
{FacilitysList[index].fileList.length > 0 ? null : uploadButton}
</Upload>
<div className={'Facility'} key={'pic_' + index}>
<Form.Item
label={`Facility Name ${index + 1}`}
name={'shebei_' + index}
rules={[{ required: true, message: 'Please input Facility Name!' }]}
>
<Input
placeholder="Facility Name"
disabled={disabled}
id={index}
onChange={(e: any) => monitor(e)}
value={FacilitysList[index].name}
/>
</Form.Item>
<div className={'over'}>
<Button type="link" disabled={disabled} onClick={() => deleteImg(index)}>
Delete
</Button>
</div>
</div>
</div>
</div>
);
})}
</Form.Item>
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
style={{ width: '100px', height: '100px' }}
icon={<PlusOutlined />}
disabled={disabled}
></Button>
</Form.Item>
{/* 预览表格 */}
<Modal visible={previewVisible} title={previewTitle} footer={null} onCancel={handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
</Modal>
</>
);
};
function mapStateToProps(state: any) {
const { imgList } = state.FacilityBookings;
const { FacilitysList } = state.FacilityBookings;
console.log(FacilitysList);
return {
imgList,
FacilitysList,
};
}
export default connect(mapStateToProps)(Facilitys);
import React, { useState, useEffect, useRef } from 'react';
import './index.less';
import { Input, Upload, Form, Select, message, Modal } from 'antd';
const { Option } = Select;
import { PlusOutlined } from '@ant-design/icons';
import { Link, useIntl, connect, Dispatch, history } from 'umi';
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
}
const module = 'FacilityBookings';
const FacilitysTow = (props: any) => {
const { updata, disabled, keys, dispatch } = props;
//上传列表
const [fileList, setFileList] = useState([]);
//显示隐藏
const [previewVisible, setpreviewVisible] = useState(false);
// 名称
const [previewTitle, setpreviewTitle] = useState('');
// 图片地址
const [previewImage, setpreviewImage] = useState('');
// 新增按钮
const uploadButton = (
<div>
<PlusOutlined />
<div className="ant-upload-text">Upload</div>
</div>
);
// 上传属性
const uploadProps = {
listType: 'picture-card',
accept: '.jpeg,.png,.jpg',
action: '/tos/image/upload',
// fileList: fileList,
onChange(info: any) {
console.log(info);
if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`);
// 拿到key 值 开始存储
// let key = info.fileList[0].response.data.identification;
// let list = fileList;
// list[key] = info.fileList;
// setFileList(list); // 注意 不能直接赋值 因为使用完全绑定需要全部更新
// setFileList(list);
let list: any = [...fileList, ...info.fileList];
setFileList(list);
console.log(info);
// 将图片信息提交给state
let data = { val: info.file.name, key: keys };
dispatch({ type: module + '/retImgsList', data });
// 结束
} else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
// 预览
const handlePreview = async (file) => {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
setpreviewImage(file.url || file.preview);
setpreviewTitle(file.name);
setpreviewVisible(true);
};
// 点击遮罩回调
const handleCancel = () => {
setpreviewVisible(false);
};
// 点击移除图片
const handRemove = () => {
// let list = fileList;
setFileList([]);
// 将图片信息提交给state
let data = { key: keys };
dispatch({ type: module + '/overImgList', data });
};
// 输入框内容
const monitor = (e: any) => {
let data = { val: e.target.value, key: keys };
dispatch({ type: module + '/retImgsName', data });
};
return (
<div>
{}
{/* 每一个上传的组件 */}
<div className={'test'}>
<div className={'diybox'}>
<Upload
fileList={fileList}
data={updata}
{...uploadProps}
disabled={disabled}
onPreview={handlePreview}
onRemove={handRemove}
>
{/* 这里存在一个bug 当 key 超过 fileList 的默认值后 会报错 */}
{fileList.length >= 1 ? null : uploadButton}
</Upload>
<div className={'Facility'}>
<Form.Item
label={`Facility Name ${keys}`}
name={keys.key}
rules={[{ required: true, message: 'Please input Facility Name!' }]}
>
<Input placeholder="Facility Name" onChange={monitor} disabled={disabled} />
</Form.Item>
<div className={'over'}>
{/* {fields.length > 1 ? (
<Button type="link" disabled={disabled} onClick={() => remove(field.name)}>
Delete
</Button>
) : null} */}
</div>
</div>
</div>
</div>
{/* 预览表格 */}
<Modal visible={previewVisible} title={previewTitle} footer={null} onCancel={handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
</Modal>
</div>
);
};
function mapProps(state: any) {
console.log(state.FacilityBookings);
console.log('------------------');
const { imgList } = state.FacilityBookings;
return {
imgList,
};
}
export default connect(mapProps)(FacilitysTow);
......@@ -3,9 +3,11 @@ import { Select } from 'antd';
const Option = Select.Option;
const OnTime = (porps: any) => {
// placeholder 默认显示 disabled 是否禁止 openSelect 选中函数 limit 限制时间
let { placeholder, disabled, openSelect, limit } = porps;
// placeholder 默认显示 disabled 是否禁止
// openSelect 选中函数 limit 限制时间 type 类型 时开始还是结束 1 就是结束 结尾是59
let { placeholder, disabled, openSelect, limit, type } = porps;
console.log(limit);
// 生成数组 -- 时间
const createArray = (num: any) => {
var arr = [];
......@@ -21,11 +23,15 @@ const OnTime = (porps: any) => {
//小时
const hourS = createArray(24).map((item) =>
// 处理限制时间
// 处理限制时间
limit ? (
<Option value={item + ':00'} key={item} disabled={Times(item, limit)}>{`${item}:00`}</Option>
<Option value={item + (type ? ':59' : ':00')} key={item} disabled={Times(item, limit)}>
{item + (type ? ':59' : ':00')}
</Option>
) : (
<Option value={item + ':00'} key={item}>{`${item}:00`}</Option>
<Option value={item + (type ? ':59' : ':00')} key={item}>
{item + (type ? ':59' : ':00')}
</Option>
),
);
......
......@@ -29,8 +29,8 @@ export default {
// 不知道前面是干嘛的,自增公告列表
NoticeList: [],
imgList: [{}, {}, {}, {}, {}], // 设施图片列表
resultTime:null, // 设施已预约时间段
resultTime: null, // 设施已预约时间段
FacilitysList: [],// 动态新增组件
},
reducers: {
......@@ -41,9 +41,9 @@ export default {
},
// 设施图片列表
retImgsList(state,{data}) {
state.imgList[data.key]['pic'] = data.val;
return state
retImgsList(state, { list }) {
let FacilitysList = list;
return { ...state, FacilitysList}
},
// 设施图片名称
......@@ -242,8 +242,10 @@ export default {
yield put({type: 'returnResult', null} )
},
// 更新列表
*genxin({ list }, { put }) {
yield put({type: 'retImgsList', list} )
}
},
......
......@@ -352,15 +352,17 @@ const Bookings = (props: any) => {
disabled={prohibit}
limit={curString.categoriesOpenTime}
openSelect={startTimes}
type={0}
/>
</Form.Item>
<span className="diyspan">-</span>
<Form.Item name="endTime" noStyle>
<OnTime
placeholder={'Closing Time'}
disabled={prohibit}
limit={curString.categoriesOpenTime}
openSelect={endTimes}
placeholder={'Closing Time'} // 默认值
disabled={prohibit} // 是否禁止
limit={curString.categoriesOpenTime} // 禁止时间段
openSelect={endTimes} // 时间类型
type={1}
/>
</Form.Item>
</Form.Item>
......
......@@ -28,7 +28,7 @@ import TimeSelect from '../../../components/TimeSelect/TimeSelect';
import Line from '../../../components/Line/Line';
import { getNumber } from '../../../utils/string';
import SearchOptionsCommnity from '../../../components/SearchOptions/SearchOptionsCommnity';
import SearchOptionsCommnity from '@/components/SearchOptions/SearchOptionsCommnity';
import { NewFaci } from '@/utils/tip';
......@@ -45,7 +45,9 @@ const module = 'FacilityBookings';
import moment from 'moment';
const Facility = (props: any) => {
const { dispatch, location, token, sourceData, DataSave, Result, imgList, load } = props;
const { dispatch, location, token, sourceData, DataSave, Result, load, FacilitysList } = props;
console.log(DataSave);
const RA = (index: any, values: any) => {
dispatch({ type: 'FacilityBookings/RA', playload: { index: index, body: values } });
......@@ -66,15 +68,13 @@ const Facility = (props: any) => {
const formRef = useRef(null);
// 再监听列表
const [extImgList, setextImgList] = useState(imgList);
// 页面进来 先清一遍 图片列表
useEffect(() => {
console.log('变化');
console.log(imgList);
if (imgList != null) {
setextImgList(imgList);
if (DataSave == null) {
let list: any = [];
dispatch({ type: module + '/genxin', list });
}
}, [imgList]);
}, [1]);
useEffect(() => {
if (Result != null) {
......@@ -140,8 +140,12 @@ const Facility = (props: any) => {
const onFinish = (values: any) => {
var result = values;
// 过滤表单;
let imgs = extImgList.filter((item: any) => (Object.keys(item).length == 0 ? false : true));
console.log(imgs.length);
let imgs: any = [];
for (let i in FacilitysList) {
imgs[i] = `${FacilitysList[i].fileList[0].name}&${FacilitysList[i].name}`;
}
// 开放时间判断
if (imgs.length == 0) {
message.error('Please upload at least one facility!');
......@@ -149,24 +153,15 @@ const Facility = (props: any) => {
message.error('Please select the opening time!');
} else {
// 先处理设施和时间
let categoriesName: any = [];
let reservationQuantumTime: any = [
moment(result.startTime, 'HH:mm').format('HH:mm'),
moment(result.endTime, 'HH:mm').format('HH:mm'),
];
for (var i in imgs) {
if (imgs[i].name && imgs[i].pic) {
categoriesName[i] = `${imgs[i].name}&${imgs[i].pic}`;
} else {
message.error('Please fill in the name of the facility!');
return;
}
}
let categoriesName: any = imgs; // 设施图片
result.categoriesName = categoriesName; // 设施内容
result.reservationQuantumTime = reservationQuantumTime; // 开放时间段
result.categoriesOpenTime = `${result.startTime}-${result.endTime}`; // 预约时间段 二开需要
delete result.startTime;
delete result.periodType;
delete result.picList;
console.log(reservationQuantumTime);
console.log(result);
......@@ -272,7 +267,7 @@ const Facility = (props: any) => {
));
// 图片列表
const fileList: any = [];
// 表单标识
const [form] = Form.useForm();
// 选择小区名字并赋值
......@@ -288,6 +283,14 @@ const Facility = (props: any) => {
setImgOpen(true);
}
};
// 子组件清除表单的 输入框值
const dumps = (key: any) => {
form.setFieldsValue({
['shebei_' + key]: '',
});
};
return (
<div className={'base basediy'}>
{/* 头部组件v1.2 */}
......@@ -304,6 +307,7 @@ const Facility = (props: any) => {
<Form.Item label="Community" name="communityName" rules={NewFaci[0]}>
<SearchOptionsCommnity
// ubmit={extendName}
defaultName={DataSave != null ? DataSave.communityName : ''}
opname={opname}
/>
</Form.Item>
......@@ -352,6 +356,7 @@ const Facility = (props: any) => {
imageType: 'categoriesImageName',
extends: ctyName,
}}
dumps={dumps}
></Facilitys>
</Form.Item>
......@@ -360,7 +365,7 @@ const Facility = (props: any) => {
<PictureOptionsRow
over={imgOpen}
data={{
userToken: token,
// userToken: token,
imageType: 'categoriesDetailsImageName',
extends: ctyName,
}}
......@@ -474,19 +479,19 @@ const Facility = (props: any) => {
};
function mapStateToProps(state: any) {
const { sourceData, DataSave, Result, imgList } = state.FacilityBookings;
const { sourceData, DataSave, Result, FacilitysList } = state.FacilityBookings;
const { token } = state.login;
const load =
typeof state.loading.models.FacilityBookings == 'undefined'
? true
? false
: state.loading.models.FacilityBookings;
return {
DataSave,
sourceData,
token,
Result,
imgList,
load,
FacilitysList,
};
}
export default connect(mapStateToProps)(Facility);
......
import React, { useState, useEffect } from 'react';
import { Input, Tabs, Table, Space, Button } from 'antd';
import { Input, Tabs, Pagination, Space, Button } from 'antd';
const { TabPane } = Tabs;
import { Link, useIntl, connect, Dispatch, history } from 'umi';
......@@ -102,7 +102,8 @@ const FacilityBookings = (props: any) => {
(text: any) => (
<div>
<ClockCircleOutlined style={{ color: '#666' }} />
&nbsp;{text}
&nbsp;
{moment(text).format('YYYY-MM-DD')}
</div>
),
],
......@@ -295,12 +296,13 @@ const FacilityBookings = (props: any) => {
rowKey="id"
dataSource={Data.data}
columns={columns}
pagination={{
current: curString.curPage,
total: Data.total.totalRow,
showSizeChanger: false,
onChange: Pagechange,
}}
// pagination={{
// current: curString.curPage,
// total: Data.total.totalRow,
// showSizeChanger: false,
// onChange: Pagechange,
// }}
pagination={false}
search={false}
toolBarRender={() => [
<Button key="3" type="primary" onClick={goToFunction}>
......@@ -318,6 +320,21 @@ const FacilityBookings = (props: any) => {
}}
headerTitle="预约列表"
/>
{curString ? (
<div className="pages">
<Pagination
current={curString.curPage}
total={Data.total.totalRow}
// pageSizeOptions={[]}
showSizeChanger={false}
// pageSize={village.page.curPageSize}
onChange={Pagechange}
/>
</div>
) : (
''
)}
</TabPane>
<TabPane tab="Facility Management" key="2">
......
......@@ -356,3 +356,8 @@ hr {
margin-bottom: 0;
}
}
.pages {
background: #fff;
text-align: right;
padding: 20px 10px 10px;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment