/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-09-13 20:32:21
 * @LastEditTime : 2023-09-20 10:51:18
 * @Description  : Do not edit
 */
import 'package:get/get.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../api/api.dart';

class FilterStore extends GetxController {
  var classList = [].obs;
  var dynamicTypeList = [
    {'code': '', 'name': '全部'},
    {'code': 'serviceBulletin', 'name': '服务简报'},
    {'code': 'serviceDetailedReport', 'name': '服务详报'},
  ];

  /// 类型
  var classId = ''.obs;

  /// 服务分类
  var type = ''.obs;

  bool get isFilterStatus => true;

  onInitData() async {
    await onGetClassList();
    classId.value = Get.arguments['classId'];
    type.value = Get.arguments['type'];
  }

  /// 获取类型列表
  Future onGetClassList() async {
    var res = await DynamicServiceImpl().getClassIdList();
    var _list = [
      GlobalIdToNameModel(id: '', name: '全部'),
    ];
    res.data?.forEach((item) {
          _list.add(item);
        });
    classList.value = _list;
  }

  back() {
    final params = 
      {
        'isRefresh': false,
      }
    ;
    backByParams(params);
  }

  backByParams(data) {
    Get.back(result: data);
  }

  changeClass(code) {
    classId.value = code;
  }

  /// 选择任务分类
  changeDynamicType(code) {
    type.value = code;
  }

  onResetInner() {
    changeClass('');
    changeDynamicType('');
    final params = {
      'type': '',
      'classId': '',
      'isRefresh': true,
    };
    backByParams(params);
  }

  submit() {
    final params = {
      'classId': classId.value,
      'type': type.value,
      'isRefresh': true,
    };
    backByParams(params);
  }
}
