123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import 'package:flutter/material.dart';
- import 'package:lszlgl/base/base_lifecycle_state.dart';
- import 'package:lszlgl/main.dart';
- import 'package:lszlgl/model/rsp/deviation_loaction_rsp.dart';
- import 'package:lszlgl/model/rsp/sample_task_rsp.dart';
- import 'package:lszlgl/network/my_api.dart';
- import 'package:lszlgl/widget/button.dart';
- import 'package:lszlgl/widget/card_item.dart';
- class DeviationLocationWidget extends StatefulWidget {
- final DeviationLoactionRsp rsp; //
- final SampleTaskItem req; // 扦样信息 取区域code用
- final Function(SampleTaskItem req) pCodeCallBack;
- const DeviationLocationWidget({super.key,required this.rsp, required this.req ,required this.pCodeCallBack});
- @override
- State<DeviationLocationWidget> createState() => _DeviationLocationWidgetState();
- }
- class _DeviationLocationWidgetState extends State<DeviationLocationWidget> {
- final CityList = <CardMenuData>[].notifier<List<CardMenuData>>();
- final citysel = null.notifier<CardMenuData?>();
- final QuList = <CardMenuData>[].notifier<List<CardMenuData>>();
- final qusel = null.notifier<CardMenuData?>();
- /// 获取行政区划列表
- Future<List<CardMenuData>?> getDistrictList(num level, {num? id}) async {
- MyNavigator.showLoading();
- try {
- var rsp = await MyApi.get().districtList(level, id: id);
- List<CardMenuData> list = (rsp.data ?? []).map((e) => CardMenuData(e.uname, e.id)).toList();
- MyNavigator.dismissLoading();
- return list;
- } catch (e) {
- logger.e(e);
- }
- MyNavigator.dismissLoading();
- return null;
- }
- void getCityList(num? code) async{
- var cityList = await getDistrictList(2, id: code);
- if (cityList == null) return;
- CityList.value = cityList;
- }
- void getquList(num? code) async{
- var quList = await getDistrictList(3, id: code);
- if (quList == null) return;
- QuList.value = quList;
- }
- @override
- void initState() {
- super.initState();
- // 获取市列表
- if(widget.rsp.errorBj ==2 || widget.rsp.errorBj ==4 ){
- getCityList(widget.req.shengXzqh);
- }
- if(widget.rsp.errorBj ==3){
- getquList(widget.req.shiXzqh);
- }
- }
- @override
- Widget build(BuildContext context) {
- return PopScope(
- canPop: false,
- child: SafeArea(
- child: SingleChildScrollView(
- padding: EdgeInsets.fromLTRB(12, 22, 12, MediaQuery.of(context).viewInsets.bottom),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- mainAxisSize: MainAxisSize.min,
- children: [
- const Text(
- '扦样位置确认',
- style: TextStyle(fontSize: 14),
- textAlign: TextAlign.center,
- ),
- const SizedBox(height: 28),
- if(widget.rsp.errorBj == 1)
- Text(
- widget.rsp.errorZn ?? '',
- style: const TextStyle(fontSize: 14,fontWeight: FontWeight.bold),
- textAlign: TextAlign.center,
- ),
- if(widget.rsp.errorBj == 2) ...[
- const Text('您目前定位所在位置与任务不符,请选择您当前所在的市县',style: TextStyle(fontSize: 14,color: Colors.grey),),
- const SizedBox(height: 18),
- CardWidgets.buildMenu(
- false,
- '市/州',
- CityList,
- citysel,
- (_, sel) {
- widget.req.shiXzqh = sel.value;
- widget.req.quXzqh = null;
- qusel.value = null;
- getquList(sel.value!);
- },
- showTopLine: true
- ),
- CardWidgets.buildMenu(
- false,
- '区县',
- QuList,
- qusel,
- (_, sel) => widget.req.quXzqh = sel.value,
- ),
- ],
- if(widget.rsp.errorBj == 3) ...[
- const Text('您目前定位所在位置与任务不符,请选择您当前所在的区县',style: TextStyle(fontSize: 14,color: Colors.grey),),
- const SizedBox(height: 18),
- CardWidgets.buildMenu(
- false,
- '区县',
- QuList,
- qusel,
- (_, sel) => widget.req.quXzqh = sel.value,
- showTopLine: true,
- ),
- ],
- if(widget.rsp.errorBj == 4) ...[
- const Text('您目前定位所在位置与任务不符,请选择您当前所在的市',style: TextStyle(fontSize: 14,color: Colors.grey),),
- const SizedBox(height: 18),
- CardWidgets.buildMenu(
- false,
- '市/州',
- CityList,
- citysel,
- (_, sel) => widget.req.shiXzqh = sel.value,
- showTopLine: true
- )
- ],
- const SizedBox(height: 32),
- Row(
- children: [
- Expanded(
- child: MyButton(
- '返回',
- onTap: (){
- if(widget.rsp.errorBj == 2){
- widget.req.shiXzqh = null;
- widget.req.quXzqh = null;
- }
- if(widget.rsp.errorBj == 3){
- widget.req.quXzqh = null;
- }
- if(widget.rsp.errorBj == 4){
- widget.req.shiXzqh = null;
- }
- Navigator.pop(context);
- },
- radius: 10,
- fountSize: 15,
- padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
- fountColor: const Color(0xFF25A6EE),
- backgroundColor: const Color(0xFFDFF4FD),
- border: Border.all(color: const Color(0xFF25A6EE))),
- ),
- const SizedBox(width: 46),
- Expanded(
- child: MyButton(
- '确定',
- onTap: (){
- if(widget.rsp.errorBj == 2 && widget.req.shiXzqh ==null){
- MyNavigator.showToast('市/州不能为空');
- return;
- }
- if(widget.rsp.errorBj == 2 && widget.req.quXzqh ==null){
- MyNavigator.showToast('区县不能为空');
- return;
- }
- if(widget.rsp.errorBj == 3 && widget.req.quXzqh ==null){
- MyNavigator.showToast('区县不能为空');
- return;
- }
- if(widget.rsp.errorBj == 4 && widget.req.shiXzqh ==null){
- MyNavigator.showToast('市/州不能为空');
- return;
- }
- widget.pCodeCallBack.call(widget.req);
- Navigator.pop(context);
- },
- radius: 10,
- fountSize: 15,
- padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
- gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
- ),
- ),
- ],
- ),
- const SizedBox(height: 22),
- ],
- ),
- ),
- ),
- );
- }
- }
|