import 'package:flutter/material.dart';
import 'package:flutterappfuyou/code/base/YSBase.dart';
import 'package:flutterappfuyou/code/version3/view/YSWriteOffListItemView.dart';

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

class YSWriteOff extends StatefulWidget {
  const YSWriteOff({Key key}) : super(key: key);

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

class _YSWriteOffState extends State<YSWriteOff> with SingleTickerProviderStateMixin{
  List _dataArray = [];
  List _titles = [
    {'title':'已核销','type':1},
    {'title':'已作废','type':2}
  ];
  TabController _tabController;
  @override
  void initState() {
    _tabController = TabController(
      vsync: this,
      length: _titles.length,
    );
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return YSBase(
      ysBgColor: Colors.white,
      ystitle: '核销记录',
      yschild: DefaultTabController(
        length: _titles.length,
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                height: 50,
                child: TabBar(
                  controller: _tabController,
                  indicatorColor: Color(0xFFEE6B8F),
                  labelColor: Color(0xFFEE6B8F),
                  indicatorWeight: 3,
                  indicatorSize: TabBarIndicatorSize.label,
                  labelStyle: TextStyle(fontSize: 14),
                  unselectedLabelColor: Color(0xFFC8C9CC),
                  tabs: _titles.map((f) {
                    return Tab(
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(f['title'])
                        ],
                      ),
                    );
                  }).toList(),
                ),
              ),
              Container(
                height: ysHeight(context)-ysTOP(context)-100,
                child: TabBarView(
                  controller: _tabController,
                  children: _titles.map((f) {
                    return YSWriteOffDataView(f: f,);
                  }).toList(),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

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

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

class _YSWriteOffDataViewState extends State<YSWriteOffDataView> {
  List _dataArray = [];
  @override
  Widget build(BuildContext context) {
    return Container(
      height: ysHeight(context)-ysTOP(context)-100,
      child: YSRefreshLoad2(
        url: widget.f['type']==1?'transfer/coupon/getWriteOffRecord':'transfer/coupon/queryExpired',
        request: {'idcard':User().idCard,'pageSize':10},
        postData: (value){
          _dataArray = value;
          setState(() {});
        },
        dataWidget: SingleChildScrollView(
          child: ListView.separated(
            itemBuilder: (context,index){
              Map item = _dataArray[index];
              return YSWriteOffListItemView(item: item,);
            },
            separatorBuilder: (context,index){
              return Container(height: 15,);
            },
            itemCount: _dataArray.length,
            padding: EdgeInsets.all(15),
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
          ),
        ),
      ),
    );
  }
}

