LocForm.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 mapIcon from '@/assets/icons/marker.png';
  8. import AgePicker from './AgePicker';
  9. export default (props) => {
  10. const { checkItemInfo, checkType, answer, readonly, onChange, onLoadingChange } = props;
  11. const [loc, setLoc] = React.useState();
  12. const [showAgePicker, setShowAgePicker] = React.useState(false);
  13. const setLoading = (v) => {
  14. if (onLoadingChange) {
  15. onLoadingChange(v)
  16. }
  17. }
  18. const setFieldChange = (key, val) => {
  19. onChange({
  20. location: loc,
  21. ...answer || {},
  22. [key]: val,
  23. })
  24. }
  25. // // 获取答题主记录信息
  26. // React.useEffect(() => {
  27. // if (checkItemInfo?.itemId) {
  28. // setLoading(true);
  29. // getTaCheckItemAnswer(checkItemInfo?.itemId).then((res) => {
  30. // if (res) {
  31. // onChange(res);
  32. // }
  33. // setLoading(false);
  34. // }).catch(() => {
  35. // setLoading(false);
  36. // });
  37. // }
  38. // }, [checkItemInfo?.itemId])
  39. // console.log('answer', answer);
  40. return (
  41. <View>
  42. <Map location={answer?.location} onLocChange={setLoc} />
  43. <CellGroup>
  44. {
  45. checkType == 'loc' && (
  46. <Cell
  47. title="点位"
  48. value={checkItemInfo?.name}
  49. />
  50. )
  51. }
  52. <Field
  53. readonly={readonly}
  54. placeholder={checkType == 'loc' ? '请输入地址' : '请填写社区名称'}
  55. // value={answer}
  56. leftIcon={mapIcon}
  57. // onChange={e => setFieldChange('', e.detail)}
  58. />
  59. <Field
  60. readonly={readonly}
  61. placeholder={checkType == 'loc' ? '请输入地址' : '请填写小区名称'}
  62. value={answer?.addr}
  63. leftIcon={mapIcon}
  64. onChange={e => setFieldChange('addr', e.detail)}
  65. />
  66. </CellGroup>
  67. {
  68. checkType == 'survey' && (
  69. <CellGroup style={{ marginTop: '20px' }}>
  70. <Cell title="性别">
  71. <View style={{ textAlign: 'right' }}>
  72. <RadioGroup
  73. disabled={readonly}
  74. direction="horizontal"
  75. value={answer?.sex}
  76. style={{ display: 'inline-flex' }}
  77. onChange={(e) => setFieldChange('sex', e.detail)}
  78. >
  79. <Radio name="1" checkedColor="var(--main-bg-color)">男</Radio>
  80. <Radio name="2" checkedColor="red">女</Radio>
  81. </RadioGroup>
  82. </View>
  83. </Cell>
  84. <Cell
  85. title="年龄"
  86. isLink
  87. value={answer?.age}
  88. onClick={() => !readonly && setShowAgePicker(true)}
  89. />
  90. <AgePicker
  91. show={showAgePicker}
  92. onShowChange={setShowAgePicker}
  93. onChange={(e) => setFieldChange('age', e)}
  94. />
  95. </CellGroup>
  96. )
  97. }
  98. </View >
  99. )
  100. }