123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import 'package:cpt_services/components/chooseVisitTimeContent_vm.dart';
- import 'package:cpt_services/modules/services/service_order_confirm/service_order_confirm_vm.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:riverpod_annotation/riverpod_annotation.dart';
- import 'package:router/ext/auto_router_extensions.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:widgets/dialog/dialog_content_wrap.dart';
- import '../../../respository/services_respository.dart';
- import 'chooseVisitTimeTitle_state.dart';
- part 'chooseVisitTimeTitle_vm.g.dart';
- List<Map<String, dynamic>> dayInfoList = [
- {
- "id": 1,
- "day": 'Tody',
- "date": '2022-01-01',
- "isSelected": true,
- "isIntrady": true,
- },
- {
- "id": 2,
- "day": 'Tommorow',
- "date": '2022-01-01',
- "isSelected": false,
- "isIntrady": false,
- },
- {
- "id": 3,
- "day": '周三',
- "date": '2022-01-01',
- "isSelected": false,
- "isIntrady": false,
- },
- {
- "id": 4,
- "day": '周四',
- "date": '2022-01-01',
- "isSelected": false,
- "isIntrady": false,
- },
- {
- "id": 5,
- "day": '周五',
- "date": '2022-01-01',
- "isSelected": false,
- "isIntrady": false,
- },
- {
- "id": 6,
- "day": '周六',
- "date": '2022-01-01',
- "isSelected": false,
- "isIntrady": false,
- },
- {
- "id": 7,
- "day": '周天',
- "date": '2022-01-01',
- "isSelected": false,
- "isIntrady": false,
- },
- ];
- ChooseVisitTimeTitleState initState(){
- Log.d("--------------------------initState---------------------");
- List<DayInfoItem> dayInfoListNew = [];
- dayInfoList.forEach((item) {
- DayInfoItem newItem = DayInfoItem()
- ..id = item['id']
- ..day = item['day']
- ..date = item['date']
- ..isSelected = item['isSelected']
- ..isIntrady = item['isIntrady'];
- dayInfoListNew.add(newItem);
- });
- return ChooseVisitTimeTitleState(
- dayInfoList: dayInfoListNew,
- );
- }
- @riverpod
- class ChooseVisitTimeTitleVm extends _$ChooseVisitTimeTitleVm {
- late ServicesRespository serviceRespositoryInstance;
- @override
- ChooseVisitTimeTitleState build(){
- // 引入数据仓库
- serviceRespositoryInstance = ref.read(servicesRespositoryProvider);
- ChooseVisitTimeTitleState state = initState();
- Log.d("--------------------------build---------------------");
- return state;
- }
- handlerChangeNum(BuildContext context, int num, int index){
- // state.dayInfoList[index].tu = num;
- // state = state.copyWith(
- // dayInfoList: state.dayInfoList,
- // );
- }
- // 点击某一天
- handlerClicKSomeDay(BuildContext context, DayInfoItem dayInfoItem, int index){
- state.currentSelectIndex = index;
- // 循环 state.dayInfoList 需要索引值为index 的 设置isSelected 为true 其他设置为false
- state.dayInfoList?.asMap().forEach((idx, value) {
- if(idx == index){
- value.isSelected = true;
- }else{
- value.isSelected = false;
- }
- });
- state = state.copyWith(
- currentSelectIndex: state.currentSelectIndex,
- dayInfoList: state.dayInfoList,
- );
- // 触发 chooseVisitTimeContent 的刷新
- final chooseVisitTimeContentVm = ref.read(chooseVisitTimeContentVmProvider.notifier);
- chooseVisitTimeContentVm?.getVisitTimeList(context);
- }
- // 点击某一时间段
- handlerTimeItemClick(BuildContext context, int index, bool isSelected){
- // 修改 状态
- // state.dayInfoList[index].isChecked = isSelected;
- // state = state.copyWith(
- // dayInfoList: state.dayInfoList,
- // );
- //
- // ref.read(serviceOrderConfirmVmProvider.notifier).setConfirmOrderTotalPrice(context);
- }
- }
|