index.jsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View } from '@tarojs/components';
  4. import { Button, Notify, Field, Cell, CellGroup, Uploader } from '@antmjs/vantui';
  5. import Page from '@/layouts/index';
  6. import LocType from '@/components/locType';
  7. import IssueType from '@/components/issueType';
  8. import Map from '@/components/map';
  9. import ImageUploader from '@/components/Uploader/ImageUploader';
  10. import getAuthorize from '@/utils/authorize';
  11. import { ROLE_INSPECTOR } from '@/utils/user';
  12. import mapIcon from '@/assets/icons/marker.png';
  13. export default (props) => {
  14. const [formData, setFormData] = React.useState({
  15. typeId: undefined,
  16. typeName: undefined,
  17. locId: undefined,
  18. locName: undefined,
  19. location: undefined,
  20. addr: undefined,
  21. content: undefined,
  22. images: [],
  23. });
  24. const [showLocType, setShowLocType] = React.useState(false);
  25. const [showIssueType, setShowIssueType] = React.useState(false);
  26. const onLocTypeChange = (_, it) => {
  27. setFormData({
  28. ...formData,
  29. locId: it.typeId,
  30. locName: it.name,
  31. });
  32. setShowLocType(false);
  33. }
  34. const onIssueTypeChange = (_, it) => {
  35. setFormData({
  36. ...formData,
  37. typeId: it.typeId,
  38. typeName: it.name,
  39. });
  40. setShowIssueType(false);
  41. }
  42. const onFieldChange = (field, value) => {
  43. setFormData({
  44. ...formData,
  45. [field]: value,
  46. })
  47. }
  48. React.useMemo(() => {
  49. getAuthorize('scope.userLocation').then(() => {
  50. Taro.getLocation({
  51. success(res) {
  52. onFieldChange('location', `${res.longitude},${res.latitude}`);
  53. },
  54. fail() {
  55. Notify.show({
  56. message: '获取位置失败, 请退出重试',
  57. type: 'warning',
  58. })
  59. }
  60. });
  61. }).catch((err) => {
  62. Notify.show({
  63. message: '未能获取位置, 程序部分功能将不能正常使用',
  64. type: 'warning',
  65. })
  66. });
  67. }, []);
  68. return (
  69. <Page roles={[ROLE_INSPECTOR]}>
  70. <LocType
  71. show={showLocType}
  72. value={formData.addr}
  73. onCancel={() => setShowLocType(false)}
  74. onChange={onLocTypeChange}
  75. />
  76. <IssueType
  77. show={showIssueType}
  78. value={formData.typeName}
  79. onCancel={() => setShowIssueType(false)}
  80. onChange={onIssueTypeChange}
  81. />
  82. <Map location={formData.location} />
  83. <Field
  84. value={formData.addr}
  85. leftIcon={mapIcon}
  86. placeholder="请输入地址"
  87. onChange={e => onFieldChange('addr', e.detail)}
  88. />
  89. <CellGroup style={{marginTop: '20px'}}>
  90. <Cell
  91. isLink
  92. title="点位"
  93. value={formData.locName}
  94. onClick={() => setShowLocType(true)}
  95. />
  96. <Cell title="问题描述" border={false} />
  97. <Field
  98. type="textarea"
  99. placeholder="请输入问题描述"
  100. autosize={{ minHeight: '120px' }}
  101. value={formData.content}
  102. onChange={e => onFieldChange('content', e.detail)}
  103. />
  104. </CellGroup>
  105. <Cell
  106. isLink
  107. title="问题分类"
  108. style={{marginTop: '20px'}}
  109. value={formData.typeName}
  110. onClick={() => setShowIssueType(true)}
  111. />
  112. <CellGroup style={{marginTop: '20px'}}>
  113. <Cell title="拍照" border={false} />
  114. <Cell
  115. renderTitle={
  116. <ImageUploader value={formData.images} onChange={e => onFieldChange('images',e)} />
  117. }
  118. />
  119. </CellGroup>
  120. <View style={{margin: '20px auto', padding: '0 1em'}}>
  121. <Button block type="primary">提交</Button>
  122. </View>
  123. </Page>
  124. )
  125. }