import 'package:cpt_services/components/status_card_item.dart'; import 'package:cs_resources/theme/app_colors_theme.dart'; import 'package:flutter/material.dart'; import 'package:auto_route/auto_route.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:shared/utils/color_utils.dart'; import 'package:shared/utils/log_utils.dart'; import 'package:widgets/my_button.dart'; import 'package:widgets/my_text_view.dart'; import 'package:widgets/widget_export.dart'; import 'package:widgets/my_cart_num.dart'; import 'chooseHouseCleanContent_state.dart'; import 'chooseHouseCleanContent_vm.dart'; class ChooseHouseCleanContent extends HookConsumerWidget { final int id; final int serviceTypeCode; final String? useScence; const ChooseHouseCleanContent({Key? key,required this.id, required this.serviceTypeCode, this.useScence}) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { final vm = ref.read(chooseHouseCleanContentVmProvider.notifier); final state = ref.watch(chooseHouseCleanContentVmProvider); final totalPrice = ref.watch(chooseHouseCleanContentVmProvider.select((state)=>state.totalPrice)); useEffect((){ vm.setInitPageData(context, { 'id': id, 'serviceTypeCode': serviceTypeCode, 'useScence': useScence, }); // 组件挂载时执行 - 执行接口请求 // Future.microtask(() => vm.initPageData()); return () { // 组件卸载时执行 }; },[]); return Container( padding: EdgeInsets.only(left: 0, right: 0, top: 10, bottom: 10), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: List.generate(state.HouseCleanList.length, (index){ return _buildItem(context, state.HouseCleanList[index], index, vm); }), ), ); } Widget _buildItem(BuildContext context, HouseCleanContentItem HouseCleanItem, int index, ChooseHouseCleanContentVm vm){ final title = HouseCleanItem.name??''; final areaSizeRange = HouseCleanItem.areaSizeRange??''; final num = HouseCleanItem.num?? 1; final price = HouseCleanItem.price?? 0; Log.d("6666 ${HouseCleanItem.isDisable}"); bool isChecked = HouseCleanItem.isChecked??false; bool disabled = HouseCleanItem.isDisable??false; if(useScence !=null){ disabled = true; }else { disabled = false; } final isDisable = useState(disabled); return Container( padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10), margin: EdgeInsets.only(left: 15, right: 15, top: 0, bottom: 0), color: ColorUtils.string2Color('#F8F8F8'), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisSize: MainAxisSize.max, children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ MyTextView( title, fontSize: 16, isFontMedium: true, textColor: context.appColors.textBlack, ), MyTextView( areaSizeRange, fontSize: 15, isFontRegular: true, textColor: context.appColors.textDarkGray999, marginTop: 5, ), ], ), ), // MyCartNum(onChange: (value){ // vm.handlerChangeNum(context, value, index); // }) // MyButton( // text: '\$$price', // onPressed: (){ // // vm.handlerChangeNum(context, value, index); // }, // fontSize: 19, // fontWeight: FontWeight.w500, // ) Container( child: MyButton( text: '\$$price', onPressed: (){ Log.d("$isChecked $isDisable"); if(!isDisable.value){ isChecked = !isChecked; vm.handlerChangeNum(context, isChecked, index); } }, minWidth: 80, minHeight: 40, fontSize: 19, fontWeight: FontWeight.w500, // enable: !isDisable.value, textColor: isChecked? context.appColors.textWhite: context.appColors.textPrimary, backgroundColor: isChecked? context.appColors.textPrimary:context.appColors.textWhite, disabledBackgroundColor: context.appColors.disEnableGray, disabledTextColor: context.appColors.textWhite, ), ), ], ), // Divider(), ], ), ); } }