import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';

import '../../base/YSTools.dart';

class YSWriteOffListItemView extends StatefulWidget {
  final Map item;
  const YSWriteOffListItemView({Key key, this.item}) : super(key: key);

  @override
  _YSWriteOffListItemViewState createState() => _YSWriteOffListItemViewState();
}

class _YSWriteOffListItemViewState extends State<YSWriteOffListItemView> {
  Map _item = {};
  @override
  void initState() {
    _item.addAll(widget.item);
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    if(_item['isOpen']==null){
      _item['isOpen'] = false;
    }
    bool isOpen = _item['isOpen']??false;
    return DottedBorder(
      color: Color(0xFFFF6D96),
      borderType: BorderType.RRect,
      radius: Radius.circular(9),
      strokeWidth: 1,
      child: Container(
        color: Colors.white,
        width: ysWidth(context)-30,
        child: LayoutBuilder(
          builder: (context,conSize){
            return Column(
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      width: conSize.maxWidth-80,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            child: Text('编        号：${widget.item['couponCode']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                            height: 25,
                          ),
                          Container(
                            child: Text('${widget.item['couponTypeName']}',style: TextStyle(fontSize: 16,color: Color(0xFFEE6B8F)),maxLines: 1,),
                            height: 30,
                          ),
                          Container(
                            child: Text('时        间：${widget.item['applicableRange']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                            height: 25,
                          ),
                          Container(
                            child: Text('母亲姓名：${widget.item['pregnantWomanName']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                            height: 25,
                          ),
                          Container(
                            child: Text('发券机构：${widget.item['sendHospitalName']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                            height: 25,
                          ),
                          if(widget.item['status']=='2'||widget.item['status']=='10010')Container(
                            child: Text(widget.item['status']=='2'?'失效日期：${widget.item['overdueTime']??''}':
                            widget.item['status']=='10010'?'取消日期：${widget.item['cancelTime']}':'',
                              style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,
                            ),
                            height: 25,
                          ),
                          if(isOpen==true)Container(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                // Padding(
                                //   padding: EdgeInsets.only(bottom: 10),
                                //   child: DashLine(height: 1,color: Color(0xFF979797),),
                                // ),
                                Container(
                                  child: Text('核销机构：${widget.item['useHospitalName']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                                  height: 25,
                                ),
                                Container(
                                  child: Text('发券日期：${widget.item['createTime']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                                  height: 25,
                                ),
                                Container(
                                  child: Text('核销日期：${widget.item['useTime']}',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),maxLines: 1,),
                                  height: 25,
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      height: 80,
                      width: 80,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(50))
                      ),
                      child: Image.asset('lib/images/已核销备份 ${_item['status']=='2'?'18':_item['status']=='10010'?'20':'13'}.png'),
                    )
                  ],
                ),
                _item['useTime']!=null?Container(
                  height: 30,
                  child: GestureDetector(
                    onTap: (){
                      if(_item['isOpen']==true){
                        _item['isOpen'] = false;
                      }else{
                        _item['isOpen'] = true;
                      }
                      setState(() {});
                    },
                    behavior: HitTestBehavior.opaque,
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text(isOpen?'收起':'显示更多',style: TextStyle(fontSize: 10,color: Color(0xFFD8D8D8)),),
                        Icon(isOpen?Icons.keyboard_arrow_up:Icons.keyboard_arrow_down,size: 15,color: Color(0xFFD8D8D8),)
                      ],
                    ),
                  ),
                ):Container(height: 10,),
              ],
            );
          },
        ),
        padding: EdgeInsets.only(left: 15,right: 15,top: 15),
      ),
    );
  }
}