index.jsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View } from '@tarojs/components';
  4. import Page from '@/layouts/index';
  5. import { Button, Notify, Field, Cell, CellGroup } from '@antmjs/vantui';
  6. import Map from '@/components/map';
  7. import Uploader from '@/components/Uploader/index';
  8. import mapIcon from '@/assets/icons/marker.png';
  9. import { warn } from '@/utils/message';
  10. import { postTaFeedback } from '@/services/tafeedback';
  11. export default (props) => {
  12. const readOnly = false;
  13. const [loading, setLoading] = React.useState(false);
  14. const fmRef = React.useRef({
  15. typeId: undefined,
  16. typeName: undefined,
  17. locId: undefined,
  18. locName: undefined,
  19. location: undefined,
  20. addr: undefined,
  21. content: undefined,
  22. attachList: [],
  23. });
  24. const [formData, setFormData] = React.useState(fmRef.current);
  25. const setFieldChange = (field, value) => {
  26. const data = {
  27. ...fmRef.current,
  28. [field]: value,
  29. };
  30. fmRef.current = data;
  31. setFormData(data);
  32. }
  33. const onSubmit = () => {
  34. try {
  35. warn(!formData.addr, '请填写地址')
  36. warn(!formData.content, '请填写问题描述')
  37. warn(!formData.attachList || formData.attachList.length < 1, '请上传照片')
  38. } catch (e) {
  39. return;
  40. }
  41. setLoading(true)
  42. postTaFeedback(formData).then(() => {
  43. setLoading(false);
  44. Taro.navigateBack({
  45. delta: 1,
  46. fail: () => {
  47. Taro.reLaunch({
  48. url: '/pages/home/index'
  49. })
  50. }
  51. });
  52. }).catch(() => {
  53. setLoading(false);
  54. })
  55. }
  56. return (
  57. <Page tabBar="feedback">
  58. <Map
  59. readOnly={readOnly}
  60. location={formData.location}
  61. onChange={e => !formData.location && setFieldChange('location', e)}
  62. />
  63. <CellGroup>
  64. <Field
  65. placeholder="请填写当前位置"
  66. value={formData.addr}
  67. leftIcon={mapIcon}
  68. readonly={readOnly}
  69. onChange={e => setFieldChange('addr', e.detail)}
  70. />
  71. </CellGroup>
  72. <CellGroup style={{ marginTop: '20px' }}>
  73. <Cell title="问题描述" size="large" border={false} />
  74. <Field
  75. type="textarea"
  76. placeholder="请输入问题描述"
  77. readonly={readOnly}
  78. autosize={{ minHeight: '120px' }}
  79. value={formData.content}
  80. onChange={e => setFieldChange('content', e.detail)}
  81. />
  82. </CellGroup>
  83. <CellGroup style={{ marginTop: '20px' }}>
  84. <Cell title="拍照" size="large" border={false} />
  85. <Cell
  86. renderTitle={
  87. <Uploader
  88. value={formData.attachList}
  89. disabled={readOnly}
  90. onChange={e => setFieldChange('attachList', e)}
  91. />
  92. }
  93. />
  94. </CellGroup>
  95. <View style={{ padding: 'var(--main-space)', background: '#fff' }}>
  96. <Button block type="primary" onClick={onSubmit}>提交</Button>
  97. </View>
  98. </Page>
  99. )
  100. }