import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/utils/time_format.dart';
import 'package:liftmanager/utils/toast.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/widgets/divider.dart';
import 'package:liftmanager/widgets/load_image.dart';

class ProductDetail extends StatefulWidget {
  ProductDetail(this.id);

  final String id;

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

class ProductDetailState extends State<ProductDetail> {
  @override
  void initState() {
    super.initState();
    getShopDetail();
  }

  bool _hasData = false;
  dynamic detailObj;

  Future getShopDetail() async {
    await NewApiService().getPunishmentsDetail(widget.id, onSuccess: (res) {
      if (res != null) {
        _hasData = true;
        detailObj = res;
        setState(() {});
      }
    }, onError: (code, msg) {
      toasts(msg);
    });
  }

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;

    return Scaffold(
      resizeToAvoidBottomPadding: false, //不让键盘弹上去
      appBar: MyAppBar(
        centerTitle: "处罚详情",
      ),
      body: _hasData
          ? Stack(
              children: <Widget>[
                Container(
                    child: ListView(children: <Widget>[
                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Container(
                        // padding: EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10)),
                        // decoration: BoxDecoration(
                        //   border: Border(
                        //     bottom: BorderSide(width: 0.5, color: Colours.line),

                        //   ),
                        // ),
                        child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              //                   Container(
                              //                     width: width,
                              //       height: ScreenUtil().setWidth(220),
                              //                           padding: EdgeInsets.only(bottom:10),
                              //                     child: ClipRRect(
                              //                     borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
                              //                     child: Container(
                              //                       // width:width,
                              //                       // height: ScreenUtil().setWidth(220),
                              //                       child:
                              //                       Swiper(
                              //   itemBuilder: (BuildContext context, index) {
                              //     return Container(
                              //       width: width,
                              //       height: ScreenUtil().setWidth(220),
                              //       key: Key(detailObj.imgs.split(",")[index]),
                              //       child:
                              //           LoadNetworkImage(
                              //         detailObj.imgs.split(",")[index],
                              //         width: width,
                              //         height: ScreenUtil().setWidth(220),
                              //         fit: BoxFit.fill,
                              //       ),
                              //     );
                              //   },
                              //   pagination: SwiperPagination(
                              //       builder: DotSwiperPaginationBuilder(
                              //           color: Colors.grey,
                              //           activeColor: Colors.white,
                              //           size: 6,
                              //           activeSize: 6)),
                              //   itemCount: detailObj.imgs.split(",").length,
                              //   scrollDirection: Axis.horizontal,
                              //   autoplay: false,
                              //   onTap: (index) {
                              //     // print(index);
                              //   },
                              // ),
                              //                       // LoadNetworkImage(
                              //                       //   detailObj.imgs.split(",")[i],
                              //                       //   fit: BoxFit.cover,

                              //                       // ),
                              //                     ),
                              //                   ),
                              //                   ),

                              Container(
                                padding: EdgeInsets.only(
                                    left: ScreenUtil().setWidth(15),
                                    right: ScreenUtil().setWidth(15),
                                    top: ScreenUtil().setHeight(10),
                                    bottom: ScreenUtil().setHeight(10)),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    ClipRRect(
                                      borderRadius: BorderRadius.circular(18),
                                      child: Container(
                                        // padding: EdgeInsets.only(
                                        //     right: ScreenUtil().setWidth(10)),
                                        child: LoadNetworkImage(
                                          detailObj.picUrl,
                                          // fit: BoxFit.cover,
                                          width: ScreenUtil().setWidth(36),
                                          height: ScreenUtil().setWidth(36),
                                        ),
                                      ),
                                    ),
                                    SizedBox(
                                      width: 5,
                                    ),
                                    Expanded(
                                        child: Column(
                                      // mainAxisAlignment: MainAxisAlignment.start,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text('${detailObj.title ?? ""}',
                                                style: TextStyle(
                                                    color: Colours.text,
                                                    fontSize: 14)),
                                            Expanded(child: Container()),
                                            Text(
                                                '扣款：￥${detailObj.punishAmount ?? '0'}',
                                                style: TextStyle(
                                                    color: Color(0xffFD5D61),
                                                    fontSize: 14)),
                                          ],
                                        ),

                                        // Text('处罚原因：${detailObj.des??""}',style: TextStyle(color: Colours.text_gray,fontSize: 12)),
                                        Text(
                                            '${DateUtils.instance.getFormartData(timeSamp: detailObj.createTime, format: "yyyy-MM-dd HH:mm")}',
                                            style: TextStyle(
                                                color: Colours.text_gray,
                                                fontSize: 12)),
                                      ],
                                    ))
                                  ],
                                ),
                              ),
                              CzDivider(
                                  margin: EdgeInsets.only(
                                      top: 23,
                                      bottom: 15,
                                      left: ScreenUtil().setWidth(50)),
                                  width: double.infinity),

                              SizedBox(height: 15),

                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Container(
                                    height: 13,
                                    width: 2,
                                    color: Colours.blue_app_main,
                                  ),
                                  SizedBox(
                                    width: ScreenUtil().setWidth(13),
                                  ),
                                  Text(
                                    "处罚描述",
                                    style: TextStyle(
                                        color: Color(0xff666666),
                                        fontSize: ScreenUtil().setSp(14)),
                                    textAlign: TextAlign.start,
                                  ),
                                  // Container(
                                  //   width: width*0.7,
                                  //   child: Text(
                                  //     detailObj.title!=null?detailObj.title.toString():"",
                                  //     style: TextStyle(
                                  //       color:Color(0xff666666),
                                  //       fontSize:ScreenUtil().setSp(16)
                                  //     ),
                                  //     textAlign:TextAlign.start,
                                  //   ),
                                  // )
                                ],
                              ),
                              SizedBox(height: 15),
                              // Row(
                              //   crossAxisAlignment: CrossAxisAlignment.start,
                              //   children: <Widget>[
                              //     SizedBox(width: ScreenUtil().setWidth(15),),
                              //     // Text(
                              //     //   "描述：",
                              //     //   style: TextStyle(
                              //     //     color:Color(0xff666666),
                              //     //     fontSize:ScreenUtil().setSp(14)
                              //     //   ),
                              //     //   textAlign:TextAlign.start,
                              //     // ),

                              //   ],
                              // ),
                              Container(
                                padding: EdgeInsets.only(
                                  left: ScreenUtil().setWidth(15),
                                  right: ScreenUtil().setWidth(15),
                                ),
                                width: width * 0.8,
                                child: Text(
                                  detailObj.des != null
                                      ? detailObj.des.toString()
                                      : "",
                                  style: TextStyle(
                                      color: Color(0xff666666),
                                      fontSize: ScreenUtil().setSp(16)),
                                  textAlign: TextAlign.start,
                                ),
                              ),
                              SizedBox(height: 15),
                              // Row(
                              //   crossAxisAlignment: CrossAxisAlignment.start,
                              //   children: <Widget>[
                              //     Text(
                              //       "惩罚金额：",
                              //       style: TextStyle(
                              //         color:Color(0xff666666),
                              //         fontSize:ScreenUtil().setSp(14)
                              //       ),
                              //       textAlign:TextAlign.start,
                              //     ),
                              //     Text(
                              //       detailObj.punishAmount!=null?"￥"+detailObj.punishAmount.toString():"",
                              //       style: TextStyle(
                              //         color:Color(0xffff0000),
                              //         fontSize:ScreenUtil().setSp(16)
                              //       ),
                              //       textAlign:TextAlign.start,
                              //     ),
                              //   ],
                              // ),
                              Container(
                                padding: EdgeInsets.only(
                                    left: ScreenUtil().setWidth(15),
                                    right: ScreenUtil().setWidth(15),
                                    top: ScreenUtil().setHeight(10),
                                    bottom: ScreenUtil().setHeight(10)),
                                child: LoadNetworkImage(
                                  detailObj.picUrl,
                                  width: width,
                                  height: ScreenUtil().setWidth(220),
                                  fit: BoxFit.fill,
                                ),
                              ),

                              SizedBox(height: 15),
                            ]),
                      ),

                      // SizedBox(height:ScreenUtil().setWidth(70))
                    ],
                  ),
                ])),
              ],
            )
          : Center(
              child: Text("正在加载..."),
            ),
    );
  }
}
