/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-08-17 15:56:02
 * @LastEditTime : 2023-08-18 11:17:37
 * @Description  : Do not edit
 */
import 'package:get/get.dart';

import '../impl/task_service_impl.dart';

class ScanFilterStore extends GetxController {
  /// 任务类型
  var type = ''.obs;

  /// 任务状态
  var status = ''.obs;

  /// 任务清单列表
  var taskTypeList = [].obs;

  /// 初始化筛选页面
  init() async {
    await onGetTaskListItem();
    type.value = Get.arguments['type'];
    status.value = Get.arguments['status'];
    // type.refresh();
    // status.refresh();
  }

  /// 获取预设清单列表
  onGetTaskListItem() async {
    if (taskTypeList.length != 0) {
      return;
    }
    var res =
        await TaskServiceImpl.instance!.getInventoryList({"preset": true});
    taskTypeList.value = res.data ?? [];
    taskTypeList.refresh();
    // final lastId = taskTypeList.last.id ?? null;
    // onSelectInventor(lastId!);
  }

  /// 任务状态列表
  List statusList = [
    {'code': '', 'name': '全部'},
    {'code': 'no_open', 'name': '未开始'},
    {'code': 'doing', 'name': '进行中'},
    {'code': 'waitReceive', 'name': '待领取'}
  ];

  ///筛选任务状态
  chooseStatus(data) {
    status.value = data;
  }

  ///筛选任务类型
  chooseType(data) {
    type.value = data;
  }

  /// 筛选重置
  onResetInner() {
    status.value = '';
    type.value = '';
    Get.back(result: {
      'status': status.value,
      'type': type.value,
    });
  }

  back() {
    Get.back();
  }

  /// 确认筛选
  submit() {
    Get.back(result: {
      'status': status.value,
      'type': type.value,
    });
  }
}
