/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2021-09-27 17:46:07
 * @LastEditTime: 2024-01-04 10:03:39
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:mobx/mobx.dart';
import 'package:task_package/src/pages/detail/equipment/index.dart';
import 'package:task_package/src/impl/qrcode_impl.dart';
part 'equipment_store.g.dart';

class EquipmentListStore = _EquipmentListStore
    with _$EquipmentListStore, ChangeNotifier;

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

  ///路由参数（请勿修改）
  EquipmentListArguments get arguments =>
      EquipmentListArguments.fromRouteArguments(context1);

  _EquipmentListStore(this.context1) {
    ///可在此处理进入页面前的操作，比如响应路由的传参进行赋值。
  }

  String? get id => arguments.id;
  String? get childId => arguments.childId;
  String? get type => arguments.type;
  String? get relationIds => arguments.relationIds;
  bool? get seqencing => arguments.seqencing;
  get detailData => arguments.detailData ?? null;
  get detailStatus => arguments.detailStatus ?? null;
  get routeList => arguments.route ?? null;

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

  @observable
  ObservableList listData = ObservableList.of([]);
  onGetList() async {
    //
    var res = await QrcodeServiceImpl.instance!.getOperationNodeChildList({
      'id': childId,
    });
    equipList = ObservableList.of(res.data ?? []);
    listData = ObservableList.of(res.data ?? []);
  }

  /// 搜索设备
  onSearchList(text) {
    List list = [];
    (listData
            .map((element) =>
                element.relationName.contains(text) ? element : null)
            .toList())
        .forEach((element) {
      if (element != null) {
        list.add(element);
      }
    });
    equipList = ObservableList.of(list.length > 0 ? list : []);
  }

  void toEquipDetail(item) async {
    await Navigator.pushNamed(
      context1,
      'task/point_form',
      arguments: {
        'id': id,
        'relationIds': relationIds,
        'detailData': detailData,
        'detailStatus': detailStatus,
        'seqencing': seqencing ?? false,
        'isEquipment': true,
        'cid': item.id,
        'platformId': item.id,
      },
    );
    await onGetList();
    //     await onGetTaskChildList();
  }
}
