LocForm.jsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View, CoverView } from '@tarojs/components';
  4. import { CellGroup, Cell, Field, RadioGroup, Radio, Icon } from '@antmjs/vantui';
  5. import Map from '@/components/map';
  6. import { getTaCheckItemAnswer } from '@/services/tacheckitem';
  7. import { getTaCheckAnswer } from '@/services/tacheckanswer';
  8. import mapIcon from '@/assets/icons/marker.png';
  9. import AgePicker from './AgePicker';
  10. export default (props) => {
  11. const { checkItemInfo, checkType, answer, readonly, onChange, onLoadingChange } = props;
  12. const [showAgePicker, setShowAgePicker] = React.useState(false);
  13. const [count, setCount] = React.useState();
  14. const setLoading = (v) => {
  15. if (onLoadingChange) {
  16. onLoadingChange(v)
  17. }
  18. }
  19. const setFieldChange = (key, val) => {
  20. onChange({
  21. ...answer || {},
  22. [key]: val,
  23. })
  24. }
  25. React.useEffect(() => {
  26. getTaCheckAnswer().then((res) => {
  27. setCount(res.total);
  28. })
  29. })
  30. // // 获取答题主记录信息
  31. // React.useEffect(() => {
  32. // if (checkItemInfo?.itemId) {
  33. // setLoading(true);
  34. // getTaCheckItemAnswer(checkItemInfo?.itemId).then((res) => {
  35. // if (res) {
  36. // onChange(res);
  37. // }
  38. // setLoading(false);
  39. // }).catch(() => {
  40. // setLoading(false);
  41. // });
  42. // }
  43. // }, [checkItemInfo?.itemId])
  44. // console.log('answer', answer);
  45. return (
  46. <View>
  47. <Map
  48. readOnly={readonly}
  49. location={answer?.location}
  50. onChange={e => setFieldChange('location', e)}
  51. />
  52. <CellGroup>
  53. {
  54. checkType == 'loc' && (
  55. <Cell
  56. title="点位"
  57. value={checkItemInfo?.name}
  58. />
  59. )
  60. }
  61. {
  62. checkType == 'survey' && (
  63. <Field
  64. label="社区"
  65. placeholder="请填写社区名称"
  66. readonly={readonly}
  67. value={answer?.communityName}
  68. onChange={e => setFieldChange('communityName', e.detail)}
  69. />
  70. )
  71. }
  72. <Field
  73. readonly={readonly}
  74. label={checkType == 'loc' ? '地址' : '小区'}
  75. placeholder={checkType == 'loc' ? '请输入地址' : '请填写小区名称'}
  76. value={answer?.addr}
  77. onChange={e => setFieldChange('addr', e.detail)}
  78. />
  79. </CellGroup>
  80. {
  81. checkType == 'survey' && (
  82. <CellGroup style={{ marginTop: '20px' }}>
  83. <Cell title="性别">
  84. <View style={{ textAlign: 'right' }}>
  85. <RadioGroup
  86. disabled={readonly}
  87. direction="horizontal"
  88. value={answer?.sex}
  89. style={{ display: 'inline-flex' }}
  90. onChange={(e) => setFieldChange('sex', e.detail)}
  91. >
  92. <Radio name="1" checkedColor="var(--main-bg-color)">男</Radio>
  93. <Radio name="2" checkedColor="red">女</Radio>
  94. </RadioGroup>
  95. </View>
  96. </Cell>
  97. <Cell
  98. title="年龄"
  99. isLink
  100. value={answer?.age}
  101. onClick={() => !readonly && setShowAgePicker(true)}
  102. />
  103. <AgePicker
  104. show={showAgePicker}
  105. onShowChange={setShowAgePicker}
  106. onChange={(e) => setFieldChange('age', e)}
  107. />
  108. </CellGroup>
  109. )
  110. }
  111. <CellGroup style={{ marginTop: '20px' }}>
  112. <Cell>
  113. <View style={{ textAlign: 'center', color: '#000' }}>
  114. 您已完成{count}份
  115. </View>
  116. </Cell>
  117. </CellGroup>
  118. </View >
  119. )
  120. }