Question.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View, RichText, Text } from '@tarojs/components';
  4. import { CellGroup, Cell, Field, Radio, RadioGroup, Button } from '@antmjs/vantui';
  5. import Uploader from '@/components/Uploader/index';
  6. import { getTaCheckAnswerItem } from '@/services/tacheckansweritem';
  7. export default (props) => {
  8. const { quInfo, answerItem, readonly, onChange, onLoadingChange } = props;
  9. const setLoading = (v) => {
  10. if (onLoadingChange) {
  11. onLoadingChange(v);
  12. }
  13. }
  14. const setFieldChange = (key, val) => {
  15. if (readonly) return;
  16. onChange({
  17. ...(answerItem || {}),
  18. quId: quInfo.quId,
  19. [key]: val,
  20. })
  21. }
  22. React.useEffect(() => {
  23. if (quInfo?.quId) {
  24. setLoading(true);
  25. getTaCheckAnswerItem({ quId: quInfo.quId, isMine: true }).then(res => {
  26. onChange(res && res.length ? res[0] : {});
  27. setLoading(false);
  28. }).catch(() => {
  29. setLoading(false);
  30. });
  31. }
  32. }, [quInfo?.quId]);
  33. return (
  34. <View>
  35. <RadioGroup value={answerItem?.answerCode}>
  36. <CellGroup>
  37. <Cell
  38. border={false}
  39. renderTitle={(
  40. <View style={{fontWeight: 'bold'}}>
  41. <Text>{quInfo?.sortNo}、</Text>
  42. <Text>{quInfo?.title}</Text>
  43. </View>
  44. )}
  45. />
  46. {
  47. quInfo?.quType == 'fill' && (
  48. <Field
  49. label="答案:"
  50. clearable
  51. readonly={readonly}
  52. value={answerItem?.answer}
  53. placeholder="填写数字"
  54. renderButton={quInfo?.fillUnit}
  55. onChange={(e) => setFieldChange('answer', e.detail - 0)}
  56. />
  57. )
  58. }
  59. {
  60. (quInfo?.answerList || []).map((it) => {
  61. return (
  62. <Cell
  63. key={it.answerId}
  64. title={it.answer}
  65. clickable
  66. border={false}
  67. onClick={() => setFieldChange('answerCode', it.answerCode)}
  68. renderRightIcon={<Radio checkedColor="var(--main-bg-color)" readonly={readonly} name={it.answerCode}></Radio>}
  69. />
  70. );
  71. })
  72. }
  73. </CellGroup>
  74. </RadioGroup>
  75. <CellGroup style={{marginTop: '20px'}}>
  76. <Cell title="测评标准" />
  77. <Cell
  78. renderTitle={
  79. <RichText nodes={quInfo?.stand} />
  80. }
  81. />
  82. </CellGroup>
  83. <CellGroup style={{marginTop: '20px'}}>
  84. <Cell title="拍照或视频" border={false} />
  85. <Cell
  86. renderTitle={
  87. <Uploader
  88. disabled={readonly}
  89. value={answerItem?.attachList}
  90. onChange={e => setFieldChange('attachList',e)}
  91. />
  92. }
  93. />
  94. </CellGroup>
  95. </View>
  96. )
  97. }