Apply.jsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View } from '@tarojs/components';
  4. import { Cell, CellGroup, Field, Button, Popup } from '@antmjs/vantui';
  5. import DatePicker from '@/components/DatePicker';
  6. import { getDateStr } from '@/utils/date';
  7. import { postTaIssueApply } from '@/services/taissueapply';
  8. import { warn } from '@/utils/message';
  9. const today = new Date();
  10. export default (props) => {
  11. const { orgIssue, applyType, ...leftProps } = props;
  12. const [show, setShow] = React.useState(false);
  13. const [submitting, setSubmitting] = React.useState(false);
  14. const [formData, setFormData] = React.useState({});
  15. const [showDatePicker, setShowDatePicker] = React.useState(false);
  16. const setFieldValue = (key, value) => {
  17. setFormData({
  18. ...formData,
  19. [key]: value,
  20. })
  21. }
  22. const onDateClick = () => {
  23. setShow(false);
  24. setShowDatePicker(true);
  25. }
  26. const onDateChange = (dt) => {
  27. const date = getDateStr(dt);
  28. setFieldValue('content', date);
  29. setShowDatePicker(false);
  30. setShow(true);
  31. }
  32. const onClick = () => {
  33. if (applyType == 'org-verify' || applyType == 'end') {
  34. onSubmit();
  35. } else {
  36. setShow(true);
  37. }
  38. }
  39. const onSubmit = () => {
  40. try {
  41. warn(!orgIssue || !orgIssue.issueId, '未找到问题单');
  42. if (applyType === 'delay') {
  43. warn(!formData.content, '请选择延期时间');
  44. }
  45. if (applyType == 'delay' || applyType == 'reject') {
  46. warn(!formData.remark, '请填写理由说明');
  47. }
  48. } catch (e) {
  49. return ;
  50. }
  51. const data = {
  52. applyType,
  53. issueId: orgIssue.issueId,
  54. ...formData
  55. }
  56. setSubmitting(true);
  57. postTaIssueApply(data).then(() => {
  58. Taro.navigateBack({delta: 1});
  59. setSubmitting(false);
  60. }).catch(() => {
  61. setSubmitting(false);
  62. })
  63. }
  64. return (
  65. <>
  66. <DatePicker
  67. type="date"
  68. minDate={today}
  69. show={showDatePicker}
  70. value={formData.content}
  71. onCancel={() => setShowDatePicker(false)}
  72. onChange={onDateChange}
  73. />
  74. <Popup position="bottom" show={show} onClose={() => setShow(false)}>
  75. <CellGroup>
  76. {
  77. applyType == 'delay' && (
  78. <Cell
  79. isLink
  80. title="延期时间"
  81. value={formData.content}
  82. onClick={onDateClick}
  83. />
  84. )
  85. }
  86. <Cell title="理由说明" />
  87. <Field
  88. type="textarea"
  89. autosize={{ minHeight: '120px' }}
  90. value={formData.remark}
  91. onChange={e => setFieldValue('remark', e.detail)}
  92. />
  93. <View style={{display: 'flex'}}>
  94. <Button block plain type="default" onClick={() => setShow(false)}>取消</Button>
  95. <Button block plain type="primary" loading={submitting} onClick={onSubmit}>确定</Button>
  96. </View>
  97. </CellGroup>
  98. </Popup>
  99. <Button {...leftProps} onClick={onClick}>{props.children}</Button>
  100. </>
  101. )
  102. }