| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import 'package:deus_app/common/event/RefreshPatrolEdit.dart';
- import 'package:deus_app/common/event/multiple_choice.dart';
- import 'package:deus_app/common/style/TitleBar.dart';
- import 'package:deus_app/common/style/gsy_style.dart';
- import 'package:deus_app/common/utils/CommonUtils.dart';
- import 'package:deus_app/common/utils/ConstantString.dart';
- import 'package:deus_app/common/utils/DioUtil.dart';
- import 'package:deus_app/common/utils/ToastUtils.dart';
- import 'package:deus_app/main.dart';
- import 'package:deus_app/model/patrol_job_select_entity_entity.dart';
- import 'package:flutter/material.dart';
- class PatrolJobAdd extends StatefulWidget {
- var id;
- final PatrolJobSelectEntityDataPatrolItemModelVOS responseData;
- PatrolJobAdd({super.key,required this.responseData,required this.id});
- @override
- State createState() {
- return new _PatrolJobAdd(responseData,id);
- }
- }
- class _PatrolJobAdd extends State<PatrolJobAdd> {
- PatrolJobSelectEntityDataPatrolItemModelVOS responseData;
- var id;
- _PatrolJobAdd(this.responseData,this.id);
- String groupValue = '';
- List<MultipleChoice>mList=[];
- @override
- void initState() {
- super.initState();
- if(responseData.type==2){
- groupValue=responseData.param[0];
- }else if(responseData.type==3){
- for (var element in responseData.param) {
- mList.add(MultipleChoice(element, false));
- }
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: TitleBar().backAppbar("添加巡检项目"),
- // backgroundColor: const Color(0xfff2f2f2),
- body: Stack(
- children: [
- Column(
- children: [
- Container(
- padding: const EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 15.0),
- child: Column(
- children: [
- Container(
- alignment: Alignment.centerLeft,
- child: Text(
- responseData.name,
- style: const TextStyle(
- fontSize: GSYConstant.TextSize15,
- color: Colors.black,
- ),
- ),
- ),
- Container(
- margin: const EdgeInsets.only(top: 10),
- // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 10.0),
- // alignment: Alignment.centerLeft,
- alignment: Alignment.centerLeft,
- child: Text(
- responseData.params,
- style: GSYConstant.textLight,
- textAlign: TextAlign.left,
- ),
- ),
- SizedBox(
- height: 10,
- ),
- Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
- Container(
- child: Text(
- '类型:',
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.TextSize15,
- ),
- ),
- ),
- Container(
- child: Text(
- responseData.type == 0
- ? '数值'
- : responseData.type == 1
- ? '长文本'
- : responseData.type == 2
- ? '单选'
- : '多选',
- textAlign: TextAlign.right,
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.TextSize15,
- ),
- ),
- ),
- ]),
- ],
- ),
- ),
- Divider(
- height: 0.8,
- color: Colors.grey,
- ),
- SizedBox(
- height: 10,
- ),
- Expanded(
- child:responseData.type==2||responseData.type==3? Container(
- child: ListView.builder(
- itemCount: responseData.param.length,
- itemBuilder: (context, index) {
- return Container(
- child: ListTile(
- title:responseData.type==2?Row(
- children: [
- Radio(
- value: responseData.param[index],
- groupValue: groupValue,
- onChanged: (value) {
- // groupValue = value;
- setState(() {
- groupValue = value!;
- });
- },
- // selected: groupValue == index,
- ),
- Text(responseData.param[index],style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.TextSize15,
- ),)
- ],
- ):Row(
- children: [
- Checkbox(
- value: mList[index].isCheck,
- activeColor: Colors.blue,
- onChanged: (bool? value) {
- setState(() {
- mList[index].isCheck=value!;
- });
- },
- ),
- Text(responseData.param[index],style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.TextSize15,
- )),
- ],
- )
- )
- );
- },
- ),
- ):Container(
- padding: EdgeInsets.only(left: 12,right: 12,bottom: 12),
- decoration: BoxDecoration(color: Colors.white),
- child: Column(
- children: [
- const SizedBox(
- height: 10,
- ),
- TextField(
- maxLines: 5,
- decoration: InputDecoration(border: OutlineInputBorder()),
- style: TextStyle(fontSize: 14),
- onChanged: (value) {
- groupValue = value;
- },
- )
- ],
- ),
- )
- ),
- ],
- ),
- Positioned(
- left: 0,
- right: 0,
- bottom:0,
- // flex: 7,
- child:SizedBox(
- height: 50,
- width: double.infinity,
- child: TextButton(
- onPressed: () {
- appAddItem();
- // Navigator.push(
- // context,
- // MaterialPageRoute(
- // builder: (context) =>
- // PatrolJobEdit(id: responseData.id)));
- // Navigator.pushAndRemoveUntil()
- },
- style: ButtonStyle(
- backgroundColor: MaterialStateProperty.all<Color>(
- Color(0xFF4875EC)),
- shape: MaterialStateProperty.all(
- BeveledRectangleBorder(
- borderRadius: BorderRadius.circular(0))),
- foregroundColor:
- MaterialStateProperty.all<Color>(Colors.white),
- // padding: MaterialStateProperty.all(EdgeInsets.zero)
- ),
- child: const Text(ConstantString.complete),
- ),
- ),
- )
- ],
- ),
- );
- }
- appAddItem() async {
- // Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
- // builder: (context) =>
- // PatrolJobEdit(id: responseData.id)), (route) => false);
- if(responseData.type==3){
- for (var element in mList) {
- if(element.isCheck){
- if(!CommonUtils.validationInput(groupValue)){
- groupValue=element.name;
- }else{
- groupValue='$groupValue,${element.name}';
- }
- }
- }
- }
- if(!CommonUtils.validationInput(groupValue)){
- showToast(ConstantString.patrolAddNull);
- return;
- }
- var result = await DioUtil().request("patrolItem/appAddItem",
- method: DioMethod.post,
- data: {'id': responseData.id,'patrolJobId':id,'result':groupValue});
- if (result['code'] == 0) {
- setState(() {
- eventBus.fire(RefreshPatrolEdit());
- Navigator.of(context)..pop()..pop();
- });
- } else {
- showToast(result['msg']);
- }
- }
- }
|