index.jsx 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View } from '@tarojs/components';
  4. import { Field, Cell, CellGroup } from '@antmjs/vantui';
  5. import LocType from '@/components/LocType';
  6. import IssueType from '@/components/IssueType';
  7. import OrgPicker from '@/components/OrgPicker';
  8. import DatePicker from '@/components/DatePicker';
  9. import Map from '@/components/map';
  10. import Uploader from '@/components/Uploader/index';
  11. import { getDateStr } from '@/utils/date';
  12. import mapIcon from '@/assets/icons/marker.png';
  13. import { PROCESS_END } from '@/utils/biz';
  14. import IssueStatus from './IssueStatus';
  15. const today = new Date();
  16. export default (props) => {
  17. const {
  18. issue,
  19. readOnly,
  20. showOrg,
  21. showExpireDate,
  22. renderFields,
  23. renderAction
  24. } = props;
  25. const fmRef = React.useRef({
  26. typeId: undefined,
  27. typeName: undefined,
  28. locId: undefined,
  29. locName: undefined,
  30. location: undefined,
  31. addr: undefined,
  32. content: undefined,
  33. attachList: [],
  34. });
  35. const [formData, setFormData] = React.useState(fmRef.current);
  36. const [showLocType, setShowLocType] = React.useState(false);
  37. const [showIssueType, setShowIssueType] = React.useState(false);
  38. const [showOrgPicker, setShowOrgPicker] = React.useState(false);
  39. const [showDatePicker, setShowDatePicker] = React.useState(false);
  40. // 办结时间
  41. const endDate = React.useMemo(() => {
  42. if (!formData) return null;
  43. // 如果单子办结了就是实际办结时间
  44. // 否则就是预计办结时间
  45. return formData.processNode == PROCESS_END ? formData.endDate : formData.expireDate;
  46. }, [formData]);
  47. const onLocTypeChange = (_, it) => {
  48. const data = {
  49. ...fmRef.current,
  50. locId: it.typeId,
  51. locName: it.name,
  52. }
  53. fmRef.current = data;
  54. setFormData(data);
  55. setShowLocType(false);
  56. }
  57. const onIssueTypeChange = (_, it) => {
  58. const data = {
  59. ...fmRef.current,
  60. typeId: it.typeId,
  61. typeName: it.name,
  62. }
  63. fmRef.current = data;
  64. setFormData(data);
  65. setShowIssueType(false);
  66. }
  67. const onOrgChange = (_, it) => {
  68. const data = {
  69. ...fmRef.current,
  70. orgId: it.orgId,
  71. orgName: it.name,
  72. }
  73. fmRef.current = data;
  74. setFormData(data);
  75. setShowOrgPicker(false);
  76. }
  77. const onDateChange = (dt) => {
  78. const date = getDateStr(dt);
  79. const data = {
  80. ...fmRef.current,
  81. expireDate: date,
  82. }
  83. fmRef.current = data;
  84. setFormData(data);
  85. setShowDatePicker(false);
  86. }
  87. const setFieldChange = (field, value) => {
  88. const data = {
  89. ...fmRef.current,
  90. [field]: value,
  91. }
  92. fmRef.current = data;
  93. setFormData(data);
  94. }
  95. React.useEffect(() => {
  96. if (issue) {
  97. fmRef.current = issue;
  98. setFormData(issue);
  99. }
  100. }, [issue]);
  101. return (
  102. <View>
  103. <LocType
  104. show={showLocType}
  105. value={formData.locId}
  106. onCancel={() => setShowLocType(false)}
  107. onChange={onLocTypeChange}
  108. />
  109. <IssueType
  110. show={showIssueType}
  111. value={formData.typeName}
  112. onCancel={() => setShowIssueType(false)}
  113. onChange={onIssueTypeChange}
  114. />
  115. <OrgPicker
  116. show={showOrgPicker}
  117. value={formData.orgName}
  118. onCancel={() => setShowOrgPicker(false)}
  119. onChange={onOrgChange}
  120. />
  121. <DatePicker
  122. type="date"
  123. minDate={today}
  124. show={showDatePicker}
  125. value={formData.expireDate}
  126. onCancel={() => setShowDatePicker(false)}
  127. onChange={onDateChange}
  128. />
  129. <Map
  130. readOnly={readOnly}
  131. location={formData.location}
  132. onChange={e => !formData.location && setFieldChange('location', e)}
  133. />
  134. <CellGroup>
  135. <Cell
  136. title="点位"
  137. isLink={!readOnly}
  138. value={formData.locName}
  139. onClick={() => !readOnly && setShowLocType(true)}
  140. />
  141. <Field
  142. placeholder="请输入地址"
  143. value={formData.addr}
  144. leftIcon={mapIcon}
  145. readonly={readOnly}
  146. onChange={e => setFieldChange('addr', e.detail)}
  147. />
  148. </CellGroup>
  149. {
  150. readOnly && (
  151. <CellGroup style={{ marginTop: '20px' }}>
  152. <IssueStatus issue={issue} />
  153. </CellGroup>
  154. )
  155. }
  156. <CellGroup style={{ marginTop: '20px' }}>
  157. <Cell
  158. title="问题分类"
  159. isLink={!readOnly}
  160. style={{ marginTop: '20px' }}
  161. value={formData.typeName}
  162. onClick={() => !readOnly && setShowIssueType(true)}
  163. />
  164. <Cell title="问题描述" border={false} />
  165. <Field
  166. type="textarea"
  167. placeholder="请输入问题描述"
  168. readonly={readOnly}
  169. autosize={{ minHeight: '120px' }}
  170. value={formData.content}
  171. onChange={e => setFieldChange('content', e.detail)}
  172. />
  173. </CellGroup>
  174. <CellGroup style={{marginTop: '20px'}}>
  175. <Cell title="拍照或视频" border={false} />
  176. <Cell
  177. renderTitle={
  178. <Uploader
  179. value={formData.attachList}
  180. disabled={readOnly}
  181. onChange={e => setFieldChange('attachList',e)}
  182. />
  183. }
  184. />
  185. </CellGroup>
  186. {
  187. (showOrg || showExpireDate) && (
  188. <CellGroup style={{ marginTop: '20px' }}>
  189. {
  190. showOrg && (
  191. <Cell
  192. title="交办单位"
  193. isLink={!readOnly}
  194. value={formData.orgName}
  195. onClick={() => !readOnly && setShowOrgPicker(true)}
  196. />
  197. )
  198. }
  199. {
  200. showExpireDate && (
  201. <Cell
  202. title="办结时间"
  203. isLink={!readOnly}
  204. value={endDate}
  205. onClick={() => !readOnly && setShowDatePicker(true)}
  206. />
  207. )
  208. }
  209. </CellGroup>
  210. )
  211. }
  212. {
  213. renderFields ?
  214. renderFields(
  215. formData,
  216. {
  217. setFieldChange,
  218. setFormData,
  219. showOrgPicker,
  220. setShowOrgPicker,
  221. }
  222. ) : null
  223. }
  224. {
  225. renderAction ? (
  226. <View style={{ margin: '20px auto' }}>
  227. {renderAction(formData)}
  228. </View>
  229. ) : null
  230. }
  231. </View>
  232. )
  233. }