index.jsx 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. // console.log('showIssueType', showIssueType)
  102. return (
  103. <View>
  104. <LocType
  105. show={showLocType}
  106. value={formData.locId}
  107. onCancel={() => setShowLocType(false)}
  108. onChange={onLocTypeChange}
  109. />
  110. <IssueType
  111. show={showIssueType}
  112. value={formData.typeName}
  113. onCancel={() => setShowIssueType(false)}
  114. onChange={onIssueTypeChange}
  115. />
  116. <OrgPicker
  117. show={showOrgPicker}
  118. value={formData.orgName}
  119. onCancel={() => setShowOrgPicker(false)}
  120. onChange={onOrgChange}
  121. />
  122. <DatePicker
  123. type="date"
  124. minDate={today}
  125. show={showDatePicker}
  126. value={formData.expireDate}
  127. onCancel={() => setShowDatePicker(false)}
  128. onChange={onDateChange}
  129. />
  130. {/* 地图只在新增的时候允许修改 */}
  131. <Map
  132. readOnly={issue?.issueId}
  133. location={formData.location}
  134. onChange={e => !formData.location && setFieldChange('location', e)}
  135. />
  136. <CellGroup>
  137. <Cell
  138. title="点位"
  139. isLink={!readOnly}
  140. value={formData.locName}
  141. onClick={() => !readOnly && setShowLocType(true)}
  142. />
  143. <Field
  144. placeholder="请输入地址"
  145. value={formData.addr}
  146. leftIcon={mapIcon}
  147. readonly={readOnly}
  148. onChange={e => setFieldChange('addr', e.detail)}
  149. />
  150. </CellGroup>
  151. {
  152. readOnly && (
  153. <CellGroup style={{ marginTop: '20px' }}>
  154. <IssueStatus issue={issue} />
  155. </CellGroup>
  156. )
  157. }
  158. <CellGroup style={{ marginTop: '20px' }}>
  159. <Cell
  160. title="问题分类"
  161. isLink={!readOnly}
  162. style={{ marginTop: '20px' }}
  163. value={formData.typeName}
  164. onClick={() => !readOnly && setShowIssueType(true)}
  165. />
  166. <Cell title="问题描述" border={false} />
  167. <Field
  168. type="textarea"
  169. placeholder="请输入问题描述"
  170. readonly={readOnly}
  171. autosize={{ minHeight: '120px' }}
  172. value={formData.content}
  173. onChange={e => setFieldChange('content', e.detail)}
  174. />
  175. </CellGroup>
  176. <CellGroup style={{ marginTop: '20px' }}>
  177. <Cell title="拍照或视频" border={false} />
  178. <Cell
  179. renderTitle={
  180. <Uploader
  181. value={formData.attachList}
  182. disabled={readOnly}
  183. onChange={e => setFieldChange('attachList', e)}
  184. />
  185. }
  186. />
  187. </CellGroup>
  188. {
  189. (showOrg || showExpireDate) && (
  190. <CellGroup style={{ marginTop: '20px' }}>
  191. {
  192. showOrg && (
  193. <Cell
  194. title="交办单位"
  195. isLink={!readOnly}
  196. value={formData.orgName}
  197. onClick={() => !readOnly && setShowOrgPicker(true)}
  198. />
  199. )
  200. }
  201. {
  202. showExpireDate && (
  203. <Cell
  204. title="办结时间"
  205. isLink={!readOnly}
  206. value={endDate}
  207. onClick={() => !readOnly && setShowDatePicker(true)}
  208. />
  209. )
  210. }
  211. </CellGroup>
  212. )
  213. }
  214. {
  215. renderFields ?
  216. renderFields(
  217. formData,
  218. {
  219. setFieldChange,
  220. setFormData,
  221. showOrgPicker,
  222. setShowOrgPicker,
  223. }
  224. ) : null
  225. }
  226. {
  227. renderAction ? (
  228. <View style={{ margin: '20px auto' }}>
  229. {renderAction(formData)}
  230. </View>
  231. ) : null
  232. }
  233. </View>
  234. )
  235. }