/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2021-08-17 14:38:01
 * @LastEditTime: 2024-01-05 16:14:41
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:mobx/mobx.dart';
// import 'package:get/get.dart';
import 'package:task_package/src/impl/qrcode_impl.dart';
import 'package:task_package/src/models/tak_operation_instruction.dart';
import 'package:task_package/src/pages/work_instructions/detail/index.dart';
import 'package:task_package/src/pages/work_instructions/list/index.dart';
part 'work_instructions_store.g.dart';

class WorkInstructionsListStore = _WorkInstructionsListStore
    with _$WorkInstructionsListStore, ChangeNotifier;

abstract class _WorkInstructionsListStore with Store {
  ///上下文（请勿修改）
  final BuildContext context1;

  late Map<String, dynamic> routingArgs;

  ///路由参数（请勿修改）
  WorkInstructionsListArguments get argumentsList =>
      WorkInstructionsListArguments.fromRouteArguments(context1);
  String get relationId => argumentsList.relationId!;
  String get relationType => argumentsList.relationType ?? '';
  String get type => argumentsList.type!;
  String? get platformNodeId => argumentsList.platformNodeId;
  WorkInstructionsDetailArguments get argumentsDetail =>
      WorkInstructionsDetailArguments.fromRouteArguments(this.context1);

  _WorkInstructionsListStore(this.context1) {
    ///可在此处理进入页面前的操作，比如响应路由的传参进行赋值。
    routingArgs = (ModalRoute.of(context1)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>? ??
        {};
  }
  String get id => argumentsDetail.id!;

  @observable
  ObservableList instructionList = ObservableList.of([]);

  @observable
  ObservableList listData = ObservableList.of([]);

  /// 获取作业指导列表
  /// @platformNodeId	任务节点id
  @action
  Future<void> onGetList() async {
    var res = await QrcodeServiceImpl.instance!.getOperationInstructionList({
      'platformNodeId': routingArgs['platformNodeId'],
    });
    instructionList = ObservableList.of(res.data ?? []);
    listData = ObservableList.of(res.data ?? []);
  }

  ///名称搜索
  void onSearchList(text) {
    List list = [];
    (listData
            .map((element) => element.name.contains(text) ? element : null)
            .toList())
        .forEach((element) {
      if (element != null) {
        list.add(element);
      }
    });
    instructionList = ObservableList.of(list.length > 0 ? list : []);
  }

  ///
  //@observable
  //int value;
  /// 查看作业指导详情
  toWorkInstructionsDetail(item) async {
    await Navigator.pushNamed(
      context1,
      'task/work_instructions_detail',
      arguments: {
        'id': item.id,
      },
    );
  }

  /// 获取作业指导详情
  @observable
  TakOperationInstruction? instructionDetail;
  @action
  Future<void> onGetDetail() async {
    var res = await QrcodeServiceImpl.instance!
        .getOperationInstructionDetail({'id': id});
    instructionDetail = res.data ?? TakOperationInstruction();
  }
}
