index.jsx 7.3KB

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