plan_dish_item.dart 11.2 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/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';
import 'package:provider/provider.dart';

import '../../../models/plan_cook_list_model.dart';
import '../../../provider/user_model.dart';
import '../../../utils/screen_util.dart';

class PlanDishItem extends StatefulWidget {
  // final String from;
  final VoidCallback onPressedDel;
  final VoidCallback onPressedReUse;
  final SunList sunList;
  // final bool showBtn;
  // final bool showCheck;
  PlanDishItem({
    Key key,
    // this.from,
    this.onPressedDel,
    this.onPressedReUse,
    this.sunList,
    // this.showBtn = false,
    // this.showCheck = false
  }) : super(key: key);

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

class _PlanDishItemState extends State<PlanDishItem> {
  // 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);
    // }
    UserModel userModel = Provider.of<UserModel>(context, listen: false);
    String dish = '';
    widget.sunList.cookList.forEach((element) {
      element.cookbooklist.forEach((value) {
        if (value.amount > 0) {
          dish += value.name + '、';
        }
      });
    });
    if (dish.endsWith('、')) {
      dish = dish.substring(0, dish.length - 1);
    }
    return 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(60),
                    padding: EdgeInsets.symmetric(
                        horizontal: ScreenUtil().setWidth(24)),
                    decoration: BoxDecoration(
                        color: widget.sunList.status == '1' //开启可用
                            ? widget.sunList.type == '1' //店铺
                                ? MyColours.color_438E93
                                : MyColours.color_ED7B2F
                            : MyColours.color_999999,
                        // 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: [
                        Container(
                          width: w(18),
                          height: w(18),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(w(9)),
                              border: Border.all(
                                  width: w(1), color: MyColours.color_F8F9FD)),
                          child: Text(
                            // sunModel.isType == '1'
                            //     ? sunModel.isExamine == '1'
                            //         ? '店铺优惠券(核销)'
                            //         : '店铺优惠券'
                            //     :
                            widget.sunList.type == '1' ? '店' : '私',
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                color: MyColours.color_F8F9FD,
                                fontSize: ScreenUtil().setSp(20)),
                          ),
                        ),
                        HEmptyView(6),
                        Text(
                          // sunModel.isType == '1'
                          //     ? sunModel.isExamine == '1'
                          //         ? '店铺优惠券(核销)'
                          //         : '店铺优惠券'
                          //     :
                          '${widget.sunList.pname}',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: MyColours.color_ffffff,
                              fontSize: ScreenUtil().setSp(32)),
                        ),
                        Spacer(),
                        InkWell(
                          // onTap: widget.onPressedSwich,
                          child: Text(
                              // sunModel.isType == '1'
                              //     ? sunModel.isExamine == '1'
                              //         ? '被领取:${sunModel.receiveNum}张  已核销:${sunModel.useNum}张'
                              //         : '创建人:${sunModel.nickname ?? sunModel.uid}  被领取:${sunModel.receiveNum}张'
                              //     : '被领取:${sunModel.receiveNum}张',
                              '${widget.sunList.planPrice}元/${widget.sunList.pnum}人',
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  color: MyColours.color_ffffff,
                                  fontSize: ScreenUtil().setSp(24))),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.fromLTRB(
                        ScreenUtil().setWidth(20 * 2),
                        ScreenUtil().setWidth(12 * 2),
                        ScreenUtil().setWidth(20 * 2),
                        ScreenUtil().setWidth(14 * 2)),
                    child: Text(
                      // sunModel.isType == '1'
                      //     ? sunModel.isExamine == '1'
                      //         ? '店铺优惠券(核销)'
                      //         : '店铺优惠券'
                      //     :
                      '${widget.sunList.cookList}',

                      maxLines: 2,
                      style: TextStyle(
                          color: MyColours.color_999999,
                          fontSize: ScreenUtil().setSp(20)),
                    ),
                  ),
                  MySeparator(width: w(3), color: MyColours.color_BFC4D4),
                  Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: w(20), vertical: w(8)),
                      child: Row(
                        children: [
                          Text(
                              // sunModel.isType == '1'
                              //     ? sunModel.isExamine == '1'
                              //         ? '被领取:${sunModel.receiveNum}张  已核销:${sunModel.useNum}张'
                              //         : '创建人:${sunModel.nickname ?? sunModel.uid}  被领取:${sunModel.receiveNum}张'
                              //     : '被领取:${sunModel.receiveNum}张',
                              '更新时间:2022-11-08',
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  color: MyColours.color_999999,
                                  fontSize: ScreenUtil().setSp(20))),
                          Spacer(),
                          //私,则是自己的,可删除
                          true ||
                                  userModel.user.role_name == '管理员' ||
                                  userModel.user.role_name == '店长'
                              ? RoundButton(
                                  width: ScreenUtil().setWidth(50 * 2),
                                  height: ScreenUtil().setWidth(20 * 2),
                                  radius: ScreenUtil().setWidth(10),
                                  text: '删除',
                                  fontSize: 24,
                                  textColor: MyColours.color_E34D59,
                                  borderColor: MyColours.color_E34D59,
                                  gradientStart: MyColours.color_ffffff,
                                  gradientEnd: MyColours.color_ffffff,
                                  onPressed: widget.onPressedDel,
                                )
                              : SizedBox(),
                          HEmptyView(34),
                          RoundButton(
                            width: ScreenUtil().setWidth(50 * 2),
                            height: ScreenUtil().setWidth(20 * 2),
                            radius: ScreenUtil().setWidth(10),
                            text: '复用',
                            fontSize: 24,
                            textColor: MyColours.color_438E93,
                            borderColor: MyColours.color_438E93,
                            gradientStart: MyColours.color_ffffff,
                            gradientEnd: MyColours.color_ffffff,
                            onPressed: widget.onPressedReUse,
                          )
                        ],
                      ))
                ])));
  }
}