import 'package:electronic_assistant/base/base_controller.dart';
import 'package:electronic_assistant/data/repositories/account_repository.dart';
import 'package:electronic_assistant/utils/error_handler.dart';
import 'package:electronic_assistant/utils/toast_util.dart';
import 'package:get/get.dart';
import 'package:retrofit/http.dart';

class ComplaintOpinionController extends BaseController {
  var title = ''.obs;

  var numCount = 0.obs;

  var content = "".obs;

  @override
  void onInit() {
    super.onInit();

    title.value = Get.arguments;
  }

  void requestSubmit() {
    if (content.value.isEmpty) {
      if (title.value == "投诉举报") {
        ToastUtil.showToast("请输入投诉内容后重试");
      } else {
        ToastUtil.showToast("请输入意见建议后重试");
      }
      return;
    }

    var type = 1;
    if (title.value == "投诉举报") {
      type = 2;
    } else {
      type = 1;
    }
    accountRepository.complaintSubmit(type, content.value).then((data) {
      if (type == 2) {
        ToastUtil.showToast("提交成功");
      } else {
        ToastUtil.showToast("感谢您的意见与反馈");
      }
      Get.back();
    }).catchError((error) {
      ErrorHandler.toastError(error);
    });
  }
}
