import 'package:flutter/material.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/utils/toast.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/internal/search/search_router.dart';
import 'package:liftmanager/widgets/app_search_bar.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/widgets/selected_image.dart';
import 'package:image_picker/image_picker.dart';
import 'package:liftmanager/internal/bbs/bbs_router.dart';
import 'dart:io';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:convert';
import 'package:liftmanager/utils/url.dart';
import 'package:liftmanager/utils/time_format.dart';
import 'package:liftmanager/utils/fast_notification.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'dart:math';

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(
        child: LoadNetworkImage(
              detailObj.picUrl,
              width: width,
              height: ScreenUtil().setWidth(220),
              fit: BoxFit.fill,
            ),
      ),
                        SizedBox(
                          height:15
                        ),
                        
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            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>[
                            Text(
                              "描述：",
                              style: TextStyle(
                                color:Color(0xff666666),
                                fontSize:ScreenUtil().setSp(14)
                              ),
                              textAlign:TextAlign.start,
                            ),
                            Container(
                              width: width*0.7,
                              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,
                            ),
                          ],
                        ),
                        
                        SizedBox(
                          height:15
                        ),
                      ]
                    ),
                  ),
                  
                  
                  
                  // SizedBox(height:ScreenUtil().setWidth(70))
                ],
              ),
                ]
              )
              
            ),
            
          ],
      
    ): Center(
              child: Text("正在加载..."),
            ),
    );
  }
}
