artifact.dart 15.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
import 'package:flutter/material.dart';
import 'package:flutter_mes2/bean/PdaError.dart';
import 'package:flutter_mes2/bean/PdaHandleModel.dart';
import 'package:flutter_mes2/bean/PdaStation.dart';
import 'package:flutter_mes2/bean/PdaWeld.dart';
import 'package:flutter_mes2/https/http_utils.dart';
import 'package:flutter_mes2/utils/Constant.dart';
import 'package:flutter_mes2/view/MyPainter.dart';
import 'package:flutter_mes2/view/Theme.dart';

List<Color> list1 = new List();
List<bool> list2 = new List();
List<PdaError> mPdaErrors;
List<PdaStation> mPdaStations;
bool value1;
String value2;
bool value3;

class artifact extends StatefulWidget{

  final PdaWeld pdaWeld;

  artifact({Key key, @required this.pdaWeld}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _artifact(pdaWeld);
  }
}

//序列号的控制器
TextEditingController noController = TextEditingController();

class _artifact extends State<artifact>{

  PdaWeld mPdaWeld;

  _artifact(PdaWeld pdaWeld) {
    mPdaWeld = pdaWeld;
  }

  @override
  void initState() {
    // TODO: implement initState
    for(int i=0; i<8; i++) {
      list1.add(Colors.grey);
    }
    for(int i=0; i<8; i++) {
      list2.add(true);
    }
    Future.delayed( Duration.zero, () => setState(() {
      _pdaStation();
    }));
    Future.delayed( Duration.zero, () => setState(() {
      _pdaError();
    }));
    super.initState();
  }

  List<DropdownMenuItem> getListData(){
    List<DropdownMenuItem> items = new List();
      DropdownMenuItem dropdownMenuItem1 = new DropdownMenuItem(
        child: new Text("合格"),
        value: true,
      );
      items.add(dropdownMenuItem1);
    DropdownMenuItem dropdownMenuItem2 = new DropdownMenuItem(
      child: new Text("不合格"),
      value: false,
    );
    items.add(dropdownMenuItem2);
    return items;
  }

  List<DropdownMenuItem> getListData2(){
    List<DropdownMenuItem> items = new List();
    for(PdaError pdaError in mPdaErrors) {
      DropdownMenuItem dropdownMenuItem1 = new DropdownMenuItem(
        child: new Text(pdaError.name),
        value: pdaError.code,
      );
      items.add(dropdownMenuItem1);
    }
    return items;
  }

  List<DropdownMenuItem> getListData3(){
    List<DropdownMenuItem> items = new List();
    DropdownMenuItem dropdownMenuItem1 = new DropdownMenuItem(
      child: new Text("去机加"),
      value: true,
    );
    items.add(dropdownMenuItem1);
    DropdownMenuItem dropdownMenuItem2 = new DropdownMenuItem(
      child: new Text("不去机加"),
      value: false,
    );
    items.add(dropdownMenuItem2);
    return items;
  }




  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    var stack = new Stack(
      alignment: const Alignment(0.0, 0.0),  //分析 2
      children: [

        Container(
            width: 300,
            height: 500,
            alignment: Alignment.center,
            child: Image.asset("images/land.png",
              fit:BoxFit.cover,
            ),
          ),
        Visibility(
          visible:  list2[0],
           child: Container(
              margin: EdgeInsets.only(right: 180,  bottom: 140),
              width: 20,
              height: 80,
              child:  RaisedButton( onPressed: _register1, color: list1[0]),
            ),
          ),
        Visibility(
          visible:  list2[1],
          child: Container(
            margin: EdgeInsets.only(right: 60,  bottom: 140),
            width: 20,
            height: 80,
            child: RaisedButton( onPressed: _register2,  color: list1[1]),
          ),
        ),

        Visibility(
          visible: list2[2],
          child:  Container(
            margin: EdgeInsets.only(left: 60,  bottom: 140),
            width: 20,
            height: 80,
            child: RaisedButton( onPressed: _register3,  color: list1[2]),
          ),
        ),

        Visibility(
          visible: list2[3],
          child:  Container(
            margin: EdgeInsets.only(left: 220, bottom: 40),
            width: 80,
            height:20,
            child: RaisedButton( onPressed: _register4,  color: list1[3]),
          ),
        ),

        Visibility(
          visible: list2[4],
          child:  Container(
            margin: EdgeInsets.only(left: 220, top: 40),
            width: 80,
            height:20,
            child: RaisedButton( onPressed: _register5,  color: list1[4]),
          ),
        ),

        Visibility(
          visible: list2[5],
          child:  Container(
            margin: EdgeInsets.only(left: 60,  top: 140),
            width: 20,
            height: 80,
            child: RaisedButton( onPressed: _register6,  color: list1[5]),
          ),
        ),

        Visibility(
          visible: list2[6],
          child: Container(
            margin: EdgeInsets.only(right: 60,  top: 140),
            width: 20,
            height: 80,
            child: RaisedButton( onPressed: _register7,  color: list1[6]),
          ),
        ),

        Visibility(
          visible: list2[7],
          child: Container(
            margin: EdgeInsets.only(right: 180,  top: 140),
            width: 20,
            height: 80,
            child: RaisedButton( onPressed: _register8,  color: list1[7]),
          ),
        ),
      ],
    );

    return new Scaffold(
        appBar: new AppBar(
        title: Text(mPdaWeld.name),
        centerTitle: true, // 标题居中),
     ),
        body:  Center(
           child: stack,
        ),
    );
  }

  void showAlertDialog(PdaStation pdaStation) {
    PdaHandleModel pdaHandleModel = new PdaHandleModel(0, "", false, "", false);
    pdaHandleModel.taskNo = int.parse(pdaStation.taskNo);
    pdaHandleModel.productCode = pdaStation.productCode;
    showDialog<Null>(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new AlertDialog(
            title: new Text('请标记工件质检'),
            //可滑动
            content: new SingleChildScrollView(
              child: new ListBody(
                children: <Widget>[
                  Container(
                    child:
                    Text("工件名:" + pdaStation.site,
                        style:TextStyle(fontSize: 16)
                    ),
                  ),
                  Container(
                    child:
                    Text("产品序列:" + pdaStation.productCode,
                        style:TextStyle(fontSize: 16)
                    ),
                  ),
                  Container(
                    child:
                    Text("任务号:" + pdaStation.taskNo,
                        style:TextStyle(fontSize: 16)
                    ),
                  ),
                  Container(
                    height: 40,
                    width: 150,
                    margin: EdgeInsets.only(top: 10, bottom: 5),//根据需求自定义
                    padding: EdgeInsets.only(left: 10),//根据需求自定义
                    //设置边框,参数自定义
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.lightGreenAccent, width: 3),
                      //边框圆角设置
                      borderRadius: BorderRadius.all(Radius.circular(40.0)),
                    ),
                    child: Center(
                      child:DropdownButton(
                        items: getListData(),
                        underline: Container(color: Colors.white),
                        hint: new Text('请选择是否合格'),//当没有默认值的时候可以设置的提示
                        value: value1,//下拉菜单选择完之后显示给用户的值
                        onChanged: (T){//下拉菜单item点击之后的回调
                          setState(() {
                            value1=T;
                            pdaHandleModel.isNG = value1;
                          });
                        },
                        elevation: 24,//设置阴影的高度
                        style: new TextStyle(//设置文本框里面文字的样式
                            color: Colors.grey
                        ),
                        isDense: true,//减少按钮的高度。默认情况下,此按钮的高度与其菜单项的高度相同。如果isDense为true,则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时,非常有用
                        iconSize: 30,//设置三角标icon的大小
                      ),
                    ),
                  ),

                  Container(
                    height: 40,
                    width: 150,
                    margin: EdgeInsets.only(top: 10, bottom: 5),//根据需求自定义
                    padding: EdgeInsets.only(left: 10),//根据需求自定义
                    //设置边框,参数自定义
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.lightGreenAccent, width: 3),
                      //边框圆角设置
                      borderRadius: BorderRadius.all(Radius.circular(40.0)),
                    ),
                    child: Center(
                      child: DropdownButton(
                        items: getListData2(),
                        underline: Container(color: Colors.white),
                        hint: new Text('请选择不合格代码'),//当没有默认值的时候可以设置的提示
                        value: value2,//下拉菜单选择完之后显示给用户的值
                        onChanged: (T){//下拉菜单item点击之后的回调
                          setState(() {
                            value2=T;
                            pdaHandleModel.nGcode = value2;
                          });
                        },
                        elevation: 24,//设置阴影的高度
                        style: new TextStyle(//设置文本框里面文字的样式
                            color: Colors.grey
                        ),
                        isDense: true,//减少按钮的高度。默认情况下,此按钮的高度与其菜单项的高度相同。如果isDense为true,则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时,非常有用
                        iconSize: 30,//设置三角标icon的大小
                      ),
                    ),
                  ),

                  Container(
                    height: 40,
                    width: 150,
                    margin: EdgeInsets.only(top: 10, bottom: 5),//根据需求自定义
                    padding: EdgeInsets.only(left: 10),//根据需求自定义
                    //设置边框,参数自定义
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.lightGreenAccent, width: 3),
                      //边框圆角设置
                      borderRadius: BorderRadius.all(Radius.circular(40.0)),
                    ),
                    child: Center(
                      child: DropdownButton(
                        items: getListData3(),
                        underline: Container(color: Colors.white),
                        hint: new Text('请选择是否去机加'),//当没有默认值的时候可以设置的提示
                        value: value3,//下拉菜单选择完之后显示给用户的值
                        onChanged: (T){//下拉菜单item点击之后的回调
                          setState(() {
                            value3=T;
                            pdaHandleModel.isOnLine = value3;
                          });
                        },
                        elevation: 24,//设置阴影的高度
                        style: new TextStyle(//设置文本框里面文字的样式
                            color: Colors.grey
                        ),
                        isDense: true,//减少按钮的高度。默认情况下,此按钮的高度与其菜单项的高度相同。如果isDense为true,则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时,非常有用
                        iconSize: 30,//设置三角标icon的大小
                      ),
                    ),
                  ),

                ],
              ),
            ),
            actions: <Widget>[
              new FlatButton(
                child: new Text('确定'),
                onPressed: () {
                  _pdaWeidHandle(pdaHandleModel);
                  Navigator.of(context).pop();
                },
              ),
              new FlatButton(
                child: new Text('取消'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        });
  }

  Future  _pdaStation() async {
    HttpUtils.pdaStation(context, {"id": mPdaWeld.id}, success: (result) {
      var moreData = result['data'];
      List<dynamic> json = moreData;
      List<PdaStation> pdaStations = json.map((i) => PdaStation.fromJson(i)).toList();
      mPdaStations = pdaStations;
      setState(() {
        for(int i=0; i < pdaStations.length; i++) {
          PdaStation pdaStation = pdaStations[i];
          if(pdaStation.isPallet == false) {
              list2[i] = false;
          }
          switch(pdaStation.status) {
            case Constant.NO_WORKPIECE:
              break;
            case Constant.NO_DETERMINED:
              list1[i] = Colors.grey;
              break;
            case Constant.QUALIFIED:
              list1[i] = Colors.lightGreen;
              break;
            case Constant.UNQUALIFIED:
              list1[i] = Colors.red;
              break;
            case Constant.Qualified_for_machining:
              list1[i] = Colors.lightBlue;
              break;
            case Constant.UNQualified_for_machining:
              list1[i] = Colors.yellow;
              break;
          }
        }

      });
    }, fail: (code) {

    });
  }

  Future  _pdaError() async {
    HttpUtils.pdaError(context, {}, success: (result) {
      var moreData = result['data'];
      List<dynamic> json = moreData;
      List<PdaError> pdaErrors = json.map((i) => PdaError.fromJson(i)).toList();
      mPdaErrors = pdaErrors;
      setState(() {

      });
    }, fail: (code) {

    });
  }

  Future  _pdaWeidHandle(PdaHandleModel pdaHandleModel) async {
    HttpUtils.pdaWeidHandle(context, pdaHandleModel.toJson(), success: (result) {
      var moreData = result['data'];
      List<dynamic> json = moreData;
      List<PdaError> pdaErrors = json.map((i) => PdaError.fromJson(i)).toList();
      mPdaErrors = pdaErrors;
      setState(() {

      });
    }, fail: (code) {

    });
  }


  void  _register(int index) {
    PdaStation pdaStation = mPdaStations[index];
    showAlertDialog(pdaStation);
    print(index);
  }

  void  _register8() {
    _register(7);
  }

  void  _register7() {
    _register(6);
  }

  void  _register6() {
    _register(5);
  }

  void  _register5() {
    _register(4);
  }

  void  _register4() {
    _register(3);
  }

  void  _register3() {
    _register(2);
  }

  void  _register2() {
    _register(1);
  }

  void  _register1() {
    _register(0);
  }
}

class MyDialog extends StatefulWidget{
  Map arguments;
  MyDialog({Key key,this.arguments}):super(key :key);
  @override
  State<StatefulWidget> createState() => _MyDialogState(r:this.arguments);

}

class _MyDialogState extends State<MyDialog> {
  _MyDialogState({this.r});

  Map r;

  //绑定
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      //...
    );
  }
}