coupon_item_f.dart 17.8 KB
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/coupon_model.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/screen_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/dashed_line_widget.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/v_empty_view.dart';

class CouponItemF extends StatefulWidget {
  final String from;
  final VoidCallback onPressed;
  final VoidCallback onPressedSwich;
  final CouponSunModel couponSonModel;
  final bool showBtn;
  final bool showCheck;
  CouponItemF(
      {Key key,
      this.from,
      this.onPressed,
      this.onPressedSwich,
      this.couponSonModel,
      this.showBtn = false,
      this.showCheck = false})
      : super(key: key);

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

class _CouponItemFState extends State<CouponItemF> {
  // bool showText = false;
  @override
  Widget build(BuildContext context) {
    CouponSunModel sunModel = widget.couponSonModel;
    bool notSelect = false;
    if (widget.from == 'history') {
      notSelect = false;
    } else {
      notSelect = sunModel.isOpenBool;
    }
    double explainH = 0.0;

    if (ObjectUtil.isNotEmpty(sunModel.explain)) {
      explainH = Utils.calculateTextHeight(
          '说明:${sunModel.explain}',
          ScreenUtil().setSp(20),
          FontWeight.normal,
          ScreenUtil().screenWidth -
              ScreenUtil().setWidth(92 * 2) +
              ScreenUtil().setWidth(20),
          5,
          context);
    }
    return Stack(
        alignment: widget.from == 'select'
            ? Alignment.centerLeft
            : AlignmentDirectional.topStart,
        children: [
          InkWell(
              onTap: widget.onPressed,
              child: Container(
                // width: ScreenUtil().setWidth(610),
                margin: EdgeInsets.fromLTRB(
                    ScreenUtil().setWidth(40),
                    ScreenUtil().setWidth(0),
                    ScreenUtil().setWidth(40),
                    ScreenUtil().setWidth(32)),
                decoration: BoxDecoration(
                  color: MyColours.color_ffffff,
                  boxShadow: [
                    BoxShadow(
                        spreadRadius: ScreenUtil().setWidth(2),
                        color: Color.fromRGBO(0, 0, 0, 0.25),
                        offset: Offset(0, ScreenUtil().setWidth(8)),
                        blurRadius: ScreenUtil().setWidth(8))
                  ],
                  borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(16)),
                  ),
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: ScreenUtil().setWidth(40),
                      padding: EdgeInsets.symmetric(
                          horizontal: ScreenUtil().setWidth(24)),
                      decoration: BoxDecoration(
                          color: widget.from == 'history'
                              ? MyColours.color_BFC4D4
                              : notSelect
                                  ? sunModel.isType == '1'
                                      ? MyColours.color_438E93
                                      : MyColours.color_ED7B2F
                                  : MyColours.color_999999,
                          borderRadius: BorderRadius.only(
                              topLeft:
                                  Radius.circular(ScreenUtil().setWidth(16)),
                              topRight:
                                  Radius.circular(ScreenUtil().setWidth(16)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            sunModel.isType == '1'
                                ? sunModel.isExamine == '1'
                                    ? '店铺优惠券(核销)'
                                    : '店铺优惠券'
                                : '我的优惠券',
                            style: TextStyle(
                                color: MyColours.color_ffffff,
                                fontSize: ScreenUtil().setSp(24)),
                          ),
                          InkWell(
                            onTap: widget.onPressedSwich,
                            child: Text(
                                sunModel.isType == '1'
                                    ? sunModel.isExamine == '1'
                                        ? '被领取:${sunModel.receiveNum}张  已核销:${sunModel.useNum}张'
                                        : '创建人:${sunModel.nickname ?? sunModel.uid}  被领取:${sunModel.receiveNum}张'
                                    : '被领取:${sunModel.receiveNum}张',
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    color: MyColours.color_ffffff,
                                    fontSize: ScreenUtil().setSp(20))),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.fromLTRB(
                          ScreenUtil().setWidth(24 * 2),
                          ScreenUtil().setWidth(9 * 2),
                          ScreenUtil().setWidth(10),
                          ScreenUtil().setWidth(20)),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                              width: ScreenUtil().setWidth(232 * 2),
                              child: Container(
                                height: ScreenUtil().setWidth(25 * 2),
                                constraints: BoxConstraints(
                                    maxWidth: ScreenUtil().setWidth(190)),
                                child: Text(
                                  sunModel.aname,
                                  maxLines: 2,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: widget.from == 'history'
                                          ? MyColours.color_BFC4D4
                                          : notSelect
                                              ? MyColours.color_515151
                                              : MyColours.color_999999,
                                      fontSize: ScreenUtil().setSp(36),
                                      fontWeight: FontWeight.bold),
                                ),
                              )),
                          Container(
                            height: ScreenUtil().setWidth(14 * 2),
                            width: ScreenUtil().setWidth(232 * 2),
                            child: Text('${sunModel.desc}',
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: widget.from == 'history'
                                      ? MyColours.color_BFC4D4
                                      : notSelect
                                          ? MyColours.color_515151
                                          : MyColours.color_999999,
                                  fontSize: ScreenUtil().setSp(20),
                                )),
                          ),
                          VEmptyView(16),
                          (ObjectUtil.isNotEmpty(sunModel.stime) &&
                                      sunModel.stime != '0') ||
                                  (ObjectUtil.isNotEmpty(sunModel.etime) &&
                                      sunModel.etime != '0')
                              ? Container(
                                  child: Text(
                                      '使用时间:${ObjectUtil.isNotEmpty(sunModel.stime) ? Utils.getDateStrFromJiekou(sunModel.stime) : '--'} 至 ${ObjectUtil.isNotEmpty(sunModel.etime) ? Utils.getDateStrFromJiekou(sunModel.etime) : '--'}',
                                      style: TextStyle(
                                          color: widget.from == 'history'
                                              ? MyColours.color_BFC4D4
                                              : MyColours.color_999999,
                                          fontSize: ScreenUtil().setSp(20))),
                                )
                              : Container(),
                        ],
                      ),
                      // widget.from == 'select'
                      //     ? widget.showCheck
                      //         ? Positioned(
                      //             right: 0,
                      //             top: ScreenUtil().setWidth(20),
                      //             child: Image.asset(
                      //               Utils.getImgPath(widget.couponSonModel.isCheck
                      //                   ? 'check_r'
                      //                   : 'check_un'),
                      //               width: ScreenUtil().setWidth(40),
                      //               height: ScreenUtil().setWidth(40),
                      //             ))
                      //         : Container()
                      //     :
                    ),
                    ObjectUtil.isNotEmpty(sunModel.explain)
                        ? const MySeparator(
                            width: 3, color: MyColours.color_f3f3f3)
                        : SizedBox(),
                    ObjectUtil.isNotEmpty(sunModel.explain)
                        ? InkWell(
                            onTap: () {
                              if (explainH > 19) {
                                setState(() {
                                  widget.couponSonModel.showText =
                                      !widget.couponSonModel.showText;
                                });
                              }
                            },
                            child: Container(
                                width: double.infinity,
                                decoration: BoxDecoration(
                                    color: widget.from == 'history'
                                        ? MyColours.color_ffffff
                                        : notSelect
                                            ? MyColours.color_ffffff
                                            : MyColours.color_FAFAFA,
                                    borderRadius: BorderRadius.only(
                                        bottomLeft: Radius.circular(
                                            ScreenUtil().setWidth(20)),
                                        bottomRight: Radius.circular(
                                            ScreenUtil().setWidth(20)))),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    widget.couponSonModel.showText
                                        ? Container(
                                            padding: EdgeInsets.fromLTRB(
                                                ScreenUtil().setWidth(24 * 2),
                                                ScreenUtil().setWidth(14),
                                                ScreenUtil().setWidth(0),
                                                ScreenUtil().setWidth(14)),
                                            width: ScreenUtil().screenWidth -
                                                ScreenUtil().setWidth(92 * 2),
                                            child: Text(
                                                '说明:${sunModel.explain}',
                                                maxLines: 5,
                                                style: TextStyle(
                                                    color: widget.from ==
                                                            'history'
                                                        ? MyColours.color_BFC4D4
                                                        : MyColours
                                                            .color_999999,
                                                    fontSize: ScreenUtil()
                                                        .setSp(20))),
                                          )
                                        : Container(
                                            padding: EdgeInsets.fromLTRB(
                                                ScreenUtil().setWidth(24 * 2),
                                                ScreenUtil().setWidth(14),
                                                ScreenUtil().setWidth(0),
                                                ScreenUtil().setWidth(14)),
                                            width: ScreenUtil().screenWidth -
                                                ScreenUtil().setWidth(92 * 2) +
                                                ScreenUtil().setWidth(20),
                                            child: Text(
                                                '说明:${sunModel.explain}',
                                                maxLines: 1,
                                                overflow: TextOverflow.fade,
                                                softWrap: false,
                                                style: TextStyle(
                                                    color: widget.from ==
                                                            'history'
                                                        ? MyColours.color_BFC4D4
                                                        : MyColours
                                                            .color_999999,
                                                    fontSize: ScreenUtil()
                                                        .setSp(20))),
                                          ),
                                    Spacer(),
                                    explainH > 19
                                        ? Container(
                                            margin: EdgeInsets.only(
                                                top: ScreenUtil().setWidth(10),
                                                right:
                                                    ScreenUtil().setWidth(16)),
                                            child: Image.asset(
                                                !widget.couponSonModel.showText
                                                    ? Utils.getImgPath(
                                                        'quan_down_f')
                                                    : Utils.getImgPath(
                                                        'quan_up_f'),
                                                width:
                                                    ScreenUtil().setWidth(28),
                                                height:
                                                    ScreenUtil().setWidth(28)),
                                          )
                                        : Container(),
                                    HEmptyView(14)
                                  ],
                                )),
                          )
                        : Container(),
                  ],
                ),
              )),
          Positioned(
              left: ScreenUtil().setWidth(21),
              child: widget.from == 'select'
                  ? Image.asset(
                      Utils.getImgPath(
                          sunModel.isCheck ? 'c_mul_select' : 'c_not_edit'),
                      width: w(21),
                    )
                  : Container()),
          Positioned(
              right: ScreenUtil().setWidth(100),
              top: ScreenUtil().setWidth(37 * 2),
              child: widget.showBtn
                  ? RoundButton(
                      width: widget.from == 'history'
                          ? ScreenUtil().setWidth(44 * 2)
                          : ScreenUtil().setWidth(32 * 2),
                      height: ScreenUtil().setWidth(21 * 2),
                      radius: ScreenUtil().setWidth(10),
                      text: widget.from == 'history'
                          ? '已过期'
                          : notSelect
                              ? '停用'
                              : '启用',
                      fontSize: 24,
                      textColor: widget.from == 'history'
                          ? MyColours.color_BFC4D4
                          : notSelect
                              ? MyColours.color_438E93
                              : MyColours.color_999999,
                      gradientStart: MyColours.color_ffffff,
                      gradientEnd: MyColours.color_ffffff,
                      borderColor: widget.from == 'history'
                          ? MyColours.color_BFC4D4
                          : notSelect
                              ? MyColours.color_438E93
                              : MyColours.color_999999,
                      onPressed: widget.onPressedSwich,
                    )
                  : Container())
        ]);
  }
}