import React from 'react';
import Taro from '@tarojs/taro';
import { View } from '@tarojs/components';
import { Button } from '@antmjs/vantui';
import { putTaOrgIssue } from '@/services/taorgissue';
import { warn } from '@/utils/message';

export default (props) => {
  const { orgIssue } = props;
  
  const [submitting, setSubmitting] = React.useState(false);
  
  const onSubmit = () => {
    try {
      warn(!orgIssue || !orgIssue.issueId, '未找打问题单');
      warn(!orgIssue.result, '请填写整改结果');
      warn(!orgIssue.attachList || !orgIssue.attachList, '请上传照片或视频');
    } catch (e) {
      return ;
    }

    setSubmitting(true);
    putTaOrgIssue(orgIssue.orgIssueId, orgIssue).then(() => {
      Taro.navigateBack({delta: 1});
      setSubmitting(false);
    }).catch(() => {
      setSubmitting(false);
    })
  }

  return (
    <Button block type="primary" loading={submitting} onClick={onSubmit}>保存修改</Button>
  )
}
