LocForm.jsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import React from "react";
  2. import Taro from "@tarojs/taro";
  3. import { View, CoverView } from "@tarojs/components";
  4. import {
  5. CellGroup,
  6. Cell,
  7. Field,
  8. RadioGroup,
  9. Radio,
  10. Icon,
  11. Loading,
  12. } from "@antmjs/vantui";
  13. import Map from "@/components/map";
  14. import { getTaCheckItemAnswer } from "@/services/tacheckitem";
  15. import { getTaCheckAnswer } from "@/services/tacheckanswer";
  16. import { geocoder } from "@/utils/map";
  17. import mapIcon from "@/assets/icons/marker.png";
  18. import AgePicker from "./AgePicker";
  19. export default (props) => {
  20. const {
  21. checkItemInfo,
  22. checkType,
  23. answer,
  24. readonly,
  25. onChange,
  26. onLoadingChange,
  27. } = props;
  28. const [showAgePicker, setShowAgePicker] = React.useState(false);
  29. const answerRef = React.useRef();
  30. answerRef.current = answer;
  31. const setLoading = (v) => {
  32. if (onLoadingChange) {
  33. onLoadingChange(v);
  34. }
  35. };
  36. const setFieldChange = (key, val) => {
  37. const newAnswer = {
  38. ...(answerRef.current || {}),
  39. [key]: val,
  40. };
  41. answerRef.current = newAnswer;
  42. onChange(newAnswer);
  43. };
  44. const onLocationChange = (loc) => {
  45. setFieldChange("location", loc);
  46. if (checkType == "loc" && loc) {
  47. // 交换经纬度位置
  48. const [x, y] = loc.split(",");
  49. const reLoc = [y, x].join(",");
  50. geocoder(reLoc)
  51. .then((e) =>
  52. setFieldChange(
  53. "addr",
  54. e?.address_component?.street_number || e?.address
  55. )
  56. )
  57. .catch(console.error);
  58. }
  59. };
  60. return (
  61. <View>
  62. <Map
  63. readOnly={readonly}
  64. location={answer?.location}
  65. onChange={onLocationChange}
  66. />
  67. {/* <View style={{ position: 'fixed', zIndex: '3000', top: '50%', color: 'red', display: 'grid', width: '50px', height: '50px' }}>
  68. <Loading type="spinner" vertical />
  69. </View> */}
  70. <CellGroup>
  71. {checkType == "loc" && (
  72. <Cell title="点位" value={checkItemInfo?.name} />
  73. )}
  74. {checkType == "survey" && <Cell title="文明用语" value={checkItemInfo?.cultureTerm} />}
  75. {checkType == "survey" && (
  76. <Field
  77. key="01"
  78. label="社区"
  79. placeholder="请填写社区名称"
  80. readonly={readonly}
  81. value={answer?.communityName}
  82. onChange={(e) => setFieldChange("communityName", e.detail)}
  83. />
  84. )}
  85. <Field
  86. key="02"
  87. readonly={readonly}
  88. label={checkType == "loc" ? "地址" : "小区"}
  89. placeholder={checkType == "loc" ? "请输入地址" : "请填写小区名称"}
  90. value={answer?.addr}
  91. onChange={(e) => setFieldChange("addr", e.detail)}
  92. />
  93. {checkType == "loc" && (
  94. <Field
  95. key="03"
  96. readonly={readonly}
  97. label="名称"
  98. placeholder="请输入名称"
  99. />
  100. )}
  101. </CellGroup>
  102. {checkType == "survey" && (
  103. <CellGroup style={{ marginTop: "20px" }}>
  104. <Cell title="性别">
  105. <View style={{ textAlign: "right" }}>
  106. <RadioGroup
  107. disabled={readonly}
  108. direction="horizontal"
  109. value={answer?.sex}
  110. style={{ display: "inline-flex" }}
  111. onChange={(e) => setFieldChange("sex", e.detail)}
  112. >
  113. <Radio name="1" checkedColor="var(--main-bg-color)">
  114. </Radio>
  115. <Radio name="2" checkedColor="red">
  116. </Radio>
  117. </RadioGroup>
  118. </View>
  119. </Cell>
  120. <Cell
  121. title="年龄"
  122. isLink
  123. value={answer?.age}
  124. onClick={() => !readonly && setShowAgePicker(true)}
  125. />
  126. <AgePicker
  127. show={showAgePicker}
  128. onShowChange={setShowAgePicker}
  129. onChange={(e) => setFieldChange("age", e)}
  130. />
  131. </CellGroup>
  132. )}
  133. {checkType == "survey" && (
  134. <CellGroup style={{ marginTop: "20px" }}>
  135. <Cell title="已完成" value={`${checkItemInfo?.answerNum || 0} 份`} />
  136. </CellGroup>
  137. )}
  138. </View>
  139. );
  140. };