123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import React from 'react';
- import Taro from '@tarojs/taro';
- import { View } from '@tarojs/components';
- import Page from '@/layouts/index';
- import { Button, Notify, Field, Cell, CellGroup } from '@antmjs/vantui';
- import Map from '@/components/map';
- import Uploader from '@/components/Uploader/index';
- import mapIcon from '@/assets/icons/marker.png';
- import { warn } from '@/utils/message';
- import { postTaFeedback } from '@/services/tafeedback';
-
- export default (props) => {
- const readOnly = false;
-
- const [loading, setLoading] = React.useState(false);
- const fmRef = React.useRef({
- typeId: undefined,
- typeName: undefined,
- locId: undefined,
- locName: undefined,
- location: undefined,
- addr: undefined,
- content: undefined,
- attachList: [],
- });
- const [formData, setFormData] = React.useState(fmRef.current);
-
- const setFieldChange = (field, value) => {
- const data = {
- ...fmRef.current,
- [field]: value,
- };
-
- fmRef.current = data;
- setFormData(data);
- }
-
- const onSubmit = () => {
- try {
- warn(!formData.addr, '请填写地址')
- warn(!formData.content, '请填写问题描述')
- warn(!formData.attachList || formData.attachList.length < 1, '请上传照片')
- } catch (e) {
- return;
- }
-
- setLoading(true)
- postTaFeedback(formData).then(() => {
- setLoading(false);
- Taro.navigateBack({
- delta: 1,
- fail: () => {
- Taro.reLaunch({
- url: '/pages/home/index'
- })
- }
- });
- }).catch(() => {
- setLoading(false);
- })
-
- }
-
- return (
- <Page tabBar="feedback">
- <Map
- readOnly={readOnly}
- location={formData.location}
- onChange={e => !formData.location && setFieldChange('location', e)}
- />
-
- <CellGroup>
- <Field
- placeholder="请填写当前位置"
- value={formData.addr}
- leftIcon={mapIcon}
- readonly={readOnly}
- onChange={e => setFieldChange('addr', e.detail)}
- />
- </CellGroup>
-
- <CellGroup style={{ marginTop: '20px' }}>
-
- <Cell title="问题描述" size="large" border={false} />
-
- <Field
- type="textarea"
- placeholder="请输入问题描述"
- readonly={readOnly}
- autosize={{ minHeight: '120px' }}
- value={formData.content}
- onChange={e => setFieldChange('content', e.detail)}
- />
- </CellGroup>
-
- <CellGroup style={{ marginTop: '20px' }}>
- <Cell title="拍照" size="large" border={false} />
-
- <Cell
- renderTitle={
- <Uploader
- value={formData.attachList}
- disabled={readOnly}
- onChange={e => setFieldChange('attachList', e)}
- />
- }
- />
- </CellGroup>
-
- <View style={{ padding: 'var(--main-space)', background: '#fff' }}>
- <Button block type="primary" onClick={onSubmit}>提交</Button>
- </View>
- </Page>
- )
- }
|