/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2021-08-17 14:36:52
 * @LastEditTime: 2023-12-29 11:29:27
 * @Description  : 作业指导--列表
 */
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:task_package/src/view_models/work_instructions_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'index.g.dart';

///路由传递的参数

class WorkInstructionsListArguments {
  final String? relationId;
  final String? type;
  final String? platformNodeId;
  final String? relationType;
  WorkInstructionsListArguments({
    this.relationId,
    this.type,
    this.relationType,
    this.platformNodeId,
  });

  ///
  ///
  ///
  ///
  ///
  ///
  ///
//***以下为模板代码谨慎修改***
  factory WorkInstructionsListArguments.fromJson(Map<String, dynamic> json) {
    return _$WorkInstructionsListArgumentsFromJson(json);
  }
  factory WorkInstructionsListArguments.fromRouteArguments(
      BuildContext context) {
    return _$WorkInstructionsListArgumentsFromJson(
        (ModalRoute.of(context)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>);
  }
  Map<String, dynamic> toJson() => _$WorkInstructionsListArgumentsToJson(this);
}

///
///
///
///
///
//***以下为模板代码谨慎修改***
class WorkInstructionsListPage extends StatelessWidget {
  const WorkInstructionsListPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
            create: (_) => WorkInstructionsListStore(context)),
      ],
      child: _PageView(),
    );
  }
}

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);

  @override
  __PageViewState createState() => __PageViewState();
}

class __PageViewState extends State<_PageView> {
  WorkInstructionsListStore get store =>
      Provider.of<WorkInstructionsListStore>(context, listen: false);
  @override
  void initState() {
    super.initState();
    store.onGetList();
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('作业指导目录',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: Column(
        children: [
          WSearch(
            hintText: '输入作业指导名称搜索',
            onSubmitted: (v) => store.onSearchList(v),
          ),
          _BuildInstructionsList(),
        ],
      ),
    );
  }
}

class _BuildInstructionsList extends StatelessWidget {
  const _BuildInstructionsList({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<WorkInstructionsListStore>(context);
    return SingleChildScrollView(
      child: Observer(builder: (_) {
        return Wisdom.column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          color: Colors.white,
          children: [
            if (store.instructionList.length > 0) ...[
              for (var i = 0; i < store.instructionList.length; i++)
                Wisdom(
                  onTap: () =>
                      store.toWorkInstructionsDetail(store.instructionList[i]),
                  border: Border(
                    bottom: BorderSide(
                      color: colorScheme.divider,
                    ),
                  ),
                  padding: EdgeInsets.all(15.pt),
                  child: WisText('${store.instructionList[i]?.name ?? ''}'),
                ),
            ] else ...[
              WEmptyWidget(
                text: WisText('没有找到作业指导'),
              ),
            ]
          ],
        );
      }),
    ).asExpanded();
  }
}
