index.jsx 7.8KB

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