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

export default (props) => {

  const { formData } = props;

  const [loading, setLoading] = React.useState(false);

  // 新增问题单
  const onSubmit = () => {
    try {
      warn(!formData.addr, '请填写地址')
      warn(!formData.locId, '请选择点位')
      warn(!formData.content, '请填写问题描述')
      warn(!formData.typeId, '请选择问题分类')
      warn(!formData.attachList || formData.attachList.length < 1, '请上传照片')
    } catch (e) {
      return;
    }

    setLoading(true)
    postTaIssue(formData).then(() => {
      setLoading(false);
      Taro.navigateBack({
        delta: 1,
        fail: () => {
          Taro.reLaunch({
            url: '/pages/home/index'
          });
        }
      });
    }).catch(() => {
      setLoading(false);
    })
  }

  return (
    <Button block type="primary" loading={loading} onClick={onSubmit}>提交</Button>
  )
}
