index.jsx 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 { getTaOrgIssueByIssueId } from '@/services/taorgissue';
  14. import { PROCESS_END } from '@/utils/biz';
  15. import IssueStatus from './IssueStatus';
  16. const today = new Date();
  17. export default (props) => {
  18. const {
  19. issueId,
  20. issue,
  21. readOnly,
  22. showOrg,
  23. showExpireDate,
  24. renderFields,
  25. renderAction
  26. } = props;
  27. const fmRef = React.useRef({
  28. typeId: undefined,
  29. typeName: undefined,
  30. locId: undefined,
  31. locName: undefined,
  32. location: undefined,
  33. addr: undefined,
  34. content: undefined,
  35. attachList: [],
  36. });
  37. const [formData, setFormData] = React.useState(fmRef.current);
  38. const [showLocType, setShowLocType] = React.useState(false);
  39. const [showIssueType, setShowIssueType] = React.useState(false);
  40. const [showOrgPicker, setShowOrgPicker] = React.useState(false);
  41. const [showDatePicker, setShowDatePicker] = React.useState(false);
  42. const [orgIssue, setOrgIssue] = React.useState();
  43. // 办结时间
  44. const endDate = React.useMemo(() => {
  45. if (!formData) return null;
  46. // 如果单子办结了就是实际办结时间
  47. // 否则就是预计办结时间
  48. return formData.processNode == PROCESS_END ? formData.endDate : formData.expireDate;
  49. }, [formData]);
  50. const onLocTypeChange = (_, it) => {
  51. const data = {
  52. ...fmRef.current,
  53. locId: it.typeId,
  54. locName: it.name,
  55. }
  56. fmRef.current = data;
  57. setFormData(data);
  58. setShowLocType(false);
  59. }
  60. const onIssueTypeChange = (_, it) => {
  61. const data = {
  62. ...fmRef.current,
  63. typeId: it.typeId,
  64. typeName: it.name,
  65. }
  66. fmRef.current = data;
  67. setFormData(data);
  68. setShowIssueType(false);
  69. }
  70. const onOrgChange = (_, it) => {
  71. const data = {
  72. ...fmRef.current,
  73. orgId: it.orgId,
  74. orgName: it.name,
  75. }
  76. fmRef.current = data;
  77. setFormData(data);
  78. setShowOrgPicker(false);
  79. }
  80. const onDateChange = (dt) => {
  81. const date = getDateStr(dt);
  82. const data = {
  83. ...fmRef.current,
  84. expireDate: date,
  85. }
  86. fmRef.current = data;
  87. setFormData(data);
  88. setShowDatePicker(false);
  89. }
  90. const setFieldChange = (field, value) => {
  91. const data = {
  92. ...fmRef.current,
  93. [field]: value,
  94. }
  95. fmRef.current = data;
  96. setFormData(data);
  97. }
  98. React.useEffect(() => {
  99. if (issue) {
  100. fmRef.current = issue;
  101. setFormData(issue);
  102. // console.log('---------issue-------->', issue)
  103. getTaOrgIssueByIssueId(issue.issueId, issue.orgId).then(r => {
  104. setOrgIssue(r);
  105. });
  106. }
  107. }, [issue]);
  108. // console.log('showIssueType', showIssueType)
  109. // console.log('readOnly', readOnly)
  110. return (
  111. <View>
  112. <LocType
  113. show={showLocType}
  114. value={formData.locId}
  115. onCancel={() => setShowLocType(false)}
  116. onChange={onLocTypeChange}
  117. />
  118. <IssueType
  119. show={showIssueType}
  120. value={formData.typeName}
  121. onCancel={() => setShowIssueType(false)}
  122. onChange={onIssueTypeChange}
  123. />
  124. <OrgPicker
  125. show={showOrgPicker}
  126. value={formData.orgName}
  127. onCancel={() => setShowOrgPicker(false)}
  128. onChange={onOrgChange}
  129. />
  130. <DatePicker
  131. type="date"
  132. minDate={today}
  133. show={showDatePicker}
  134. value={formData.expireDate}
  135. onCancel={() => setShowDatePicker(false)}
  136. onChange={onDateChange}
  137. />
  138. {/* 地图只在新增的时候允许修改 */}
  139. <Map
  140. readOnly={!!issueId}
  141. location={formData.location}
  142. onChange={e => !formData.location && setFieldChange('location', e)}
  143. />
  144. <CellGroup>
  145. {
  146. issue?.issueId && (
  147. <Cell
  148. title="ID"
  149. value={issue.issueId}
  150. />
  151. )
  152. }
  153. <Cell
  154. title="点位"
  155. isLink={!readOnly}
  156. value={formData.locName}
  157. onClick={() => !readOnly && setShowLocType(true)}
  158. />
  159. <Field
  160. placeholder="请输入地址"
  161. value={formData.addr}
  162. leftIcon={mapIcon}
  163. readonly={readOnly}
  164. onChange={e => setFieldChange('addr', e.detail)}
  165. />
  166. </CellGroup>
  167. {
  168. readOnly && (
  169. <CellGroup style={{ marginTop: '20px' }}>
  170. <IssueStatus issue={issue} />
  171. </CellGroup>
  172. )
  173. }
  174. <CellGroup style={{ marginTop: '20px' }}>
  175. <Cell
  176. title="问题分类"
  177. isLink={!readOnly}
  178. style={{ marginTop: '20px' }}
  179. value={formData.typeName}
  180. onClick={() => !readOnly && setShowIssueType(true)}
  181. />
  182. <Cell title="问题描述" border={false} />
  183. <Field
  184. type="textarea"
  185. placeholder="请输入问题描述"
  186. readonly={readOnly}
  187. autosize={{ minHeight: '120px' }}
  188. value={formData.content}
  189. onChange={e => setFieldChange('content', e.detail)}
  190. />
  191. </CellGroup>
  192. <CellGroup style={{ marginTop: '20px' }}>
  193. <Cell title="拍照或视频" border={false} />
  194. <Cell
  195. renderTitle={
  196. <Uploader
  197. value={formData.attachList}
  198. disabled={readOnly}
  199. onChange={e => setFieldChange('attachList', e)}
  200. />
  201. }
  202. />
  203. </CellGroup>
  204. {
  205. (showOrg || showExpireDate) && (
  206. <CellGroup style={{ marginTop: '20px' }}>
  207. {
  208. showOrg && (
  209. <Cell
  210. title="交办单位"
  211. isLink={!readOnly}
  212. value={formData.orgName}
  213. onClick={() => !readOnly && setShowOrgPicker(true)}
  214. />
  215. )
  216. }
  217. {
  218. showExpireDate && (
  219. <Cell
  220. title="办结时间"
  221. isLink={!readOnly}
  222. value={endDate}
  223. onClick={() => !readOnly && setShowDatePicker(true)}
  224. />
  225. )
  226. }
  227. </CellGroup>
  228. )
  229. }
  230. {
  231. orgIssue && issue?.processNode == PROCESS_END && (
  232. <CellGroup style={{ marginTop: '20px' }}>
  233. <Cell title="整改结果" />
  234. <Field
  235. readonly
  236. type="textarea"
  237. autosize={{ minHeight: '120px' }}
  238. value={orgIssue?.result}
  239. />
  240. <Cell title="整改照片" border={false} />
  241. <Cell
  242. renderTitle={
  243. <Uploader
  244. disabled
  245. value={orgIssue?.attachList}
  246. />
  247. }
  248. />
  249. </CellGroup>
  250. )
  251. }
  252. {
  253. renderFields ?
  254. renderFields(
  255. formData,
  256. {
  257. setFieldChange,
  258. setFormData,
  259. showOrgPicker,
  260. setShowOrgPicker,
  261. }
  262. ) : null
  263. }
  264. {
  265. renderAction ? (
  266. <View style={{ margin: '20px auto' }}>
  267. {renderAction(formData)}
  268. </View>
  269. ) : null
  270. }
  271. </View>
  272. )
  273. }