payment_gift_page.dart 35.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
import 'dart:convert';

import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_picker_plus/picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:provider/provider.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';

import '../../../models/coupon_model.dart';
import '../../../models/ladder_coupons_model.dart';
import '../../../provider/finance_provider.dart';
import '../../../route/navigator_util.dart';
import '../../../utils/dialog_util.dart';
import '../../../utils/screen_util.dart';
import '../../../utils/utils.dart';
import '../../../widgets/round_button.dart';
import '../../../widgets/v_empty_view.dart';

/**
 * 支付返券
 */
class PaymentGiftPage extends StatefulWidget {
  const PaymentGiftPage({super.key});

  @override
  State<PaymentGiftPage> createState() => _PaymentGiftPageState();
}

class _PaymentGiftPageState extends State<PaymentGiftPage> {
  bool fullReduction = false; //默认都不选中
  bool stairs = false; //默认都不选中

  String fromDateFull = '选择日期';
  String endDateFull = '选择日期';

  String fromDateLadder = '选择日期';
  String endDateLadder = '选择日期';

  final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

  FinanceProvider? financeProvider;
  TextEditingController fullC = TextEditingController();
  FocusNode fullNode = FocusNode();

  List<CouponSunModel>? couponSelectFree = [];
  bool rule = true;

  List<LadderCouponsModelDataStairsDataLadderData> ladderSelectFree = [];

  ScrollController controller = ScrollController();

  @override
  void initState() {
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((_) {
      // _getCountCommentLabel(isShowLoading: false);
      _getActivityConfig();
    });
    // bus.on("refresh_discount_order_list", (args) {
    //   // _getReserveDetail(isShowLoading: false);
    //   _getDiscountOrderList(isShowLoading: false);
    // });
  }

  // giftData
  _getActivityConfig({bool isShowLoading = true}) async {
    Map<String, String> params = {
      'sellerid': Provider.of<UserModel>(context, listen: false).user!.sellerid!
    };
    await financeProvider!
        .getActivityConfig(context, params, isShowLoading: isShowLoading);
    if (financeProvider!.giftData != null) {
      //已经设置了数据
      fullReduction =
          financeProvider!.giftData!.fullReduction == '1' ? true : false;
      stairs = financeProvider!.giftData!.stairs == '1' ? true : false;
      if (financeProvider!.giftData!.fullReductionData != null) {
        rule = financeProvider!.giftData!.fullReductionData!.rule == '1'
            ? true
            : financeProvider!.giftData!.fullReductionData!.rule == '0'
                ? false
                : true;
        if (financeProvider!.giftData!.fullReductionData!.stime != null) {
          DateTime dateTimes = DateTime.fromMillisecondsSinceEpoch(int.parse(
                  financeProvider!.giftData!.fullReductionData!.stime
                      .toString()) *
              1000);
          fromDateFull =
              DateUtil.formatDate(dateTimes, format: DateFormats.y_mo_d);
        }
        if (financeProvider!.giftData!.fullReductionData!.etime != null) {
          DateTime dateTimee = DateTime.fromMillisecondsSinceEpoch(int.parse(
                  financeProvider!.giftData!.fullReductionData!.etime
                      .toString()) *
              1000);
          endDateFull =
              DateUtil.formatDate(dateTimee, format: DateFormats.y_mo_d);
        }

        fullC.text = financeProvider!.giftData!.fullReductionData!.price ?? '';

        couponSelectFree =
            financeProvider!.giftData!.fullReductionData!.coupons ?? [];
      }
      if (financeProvider!.giftData!.stairsData != null) {
        if (financeProvider!.giftData!.stairsData!.stime != null) {
          DateTime dateTimes = DateTime.fromMillisecondsSinceEpoch(int.parse(
                  financeProvider!.giftData!.stairsData!.stime.toString()) *
              1000);
          fromDateLadder =
              DateUtil.formatDate(dateTimes, format: DateFormats.y_mo_d);
        }
        if (financeProvider!.giftData!.stairsData!.etime != null) {
          DateTime dateTimee = DateTime.fromMillisecondsSinceEpoch(int.parse(
                  financeProvider!.giftData!.stairsData!.etime.toString()) *
              1000);
          endDateLadder =
              DateUtil.formatDate(dateTimee, format: DateFormats.y_mo_d);
        }

        ladderSelectFree =
            financeProvider!.giftData!.stairsData!.ladderData ?? [];
      }
    }
  }

  _setActivityConfig() async {
    FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
    Map<String, String?> fullReductionData = {};
    Map<String, String?> stairsData = {};

    if (fullReduction) {
      if (fromDateFull == '选择日期') {
        Utils.showToast('请选择满减返券活动的开始时间!');
        return;
      }
      if (endDateFull == '选择日期') {
        Utils.showToast('请选择满减返券活动的结束时间!');
        return;
      }
      if (fullC.text.trim().length == 0) {
        Utils.showToast('请输入满减返券活动的门槛金额!');
        return;
      }
      if (couponSelectFree == null || couponSelectFree!.length == 0) {
        Utils.showToast('请选择满减返券活动的优惠券!');
        return;
      }
    }
    if (stairs) {
      //阶梯返券
      if (fromDateLadder == '选择日期') {
        Utils.showToast('请选择阶梯返券活动的开始时间!');
        return;
      }
      if (endDateLadder == '选择日期') {
        Utils.showToast('请选择阶梯返券活动的结束时间!');
        return;
      }

      if (ladderSelectFree.length == 0) {
        Utils.showToast('请点击增加阶梯设置数据!');
        return;
      }
      bool canPrice =
          ladderSelectFree.any((e) => e.priceC.text.trim().length == 0);
      if (canPrice) {
        int index = ladderSelectFree
            .indexWhere((e) => e.priceC.text.trim().length == 0);

        Utils.showToast('请选择阶梯(${index + 1})的消费门槛金额!');
        return;
      }
      bool can = ladderSelectFree
          .any((e) => e.coupons == null || e.coupons?.length == 0);
      if (can) {
        int index = ladderSelectFree
            .indexWhere((e) => e.coupons == null || e.coupons?.length == 0);

        Utils.showToast('请选择阶梯(${index + 1})的优惠券!');
        return;
      }
    }

    List<Map> couponsData = [];
    couponSelectFree?.forEach((e) {
      Map<String, String> coupon = {'id': e.id!, 'aname': e.aname!};
      couponsData.add(coupon);
    });
    if (fromDateFull != '选择日期') {
      String fromfull = fromDateFull + ' 00:00:00';

      String sfull =
          '${(DateUtil.getDateMsByTimeStr(fromfull)! / 1000).floor()}';

      fullReductionData['stime'] = sfull;
    }
    if (endDateFull != '选择日期') {
      String endfull = endDateFull + ' 23:59:59';

      String efull =
          '${(DateUtil.getDateMsByTimeStr(endfull)! / 1000).floor()}';

      fullReductionData['etime'] = efull;
    }

    String ruleString = rule ? '1' : '0'; //发放规则
    fullReductionData['rule'] = ruleString;
    fullReductionData['price'] = fullC.text;
    fullReductionData['coupons'] = jsonEncode(couponsData);

    if (fromDateLadder != '选择日期') {
      String fromLad = fromDateLadder + ' 00:00:00';
      String sLad = '${(DateUtil.getDateMsByTimeStr(fromLad)! / 1000).floor()}';
      stairsData['stime'] = sLad;
    }

    if (endDateLadder != '选择日期') {
      String endLad = endDateLadder + ' 23:59:59';

      String eLad = '${(DateUtil.getDateMsByTimeStr(endLad)! / 1000).floor()}';
      stairsData['etime'] = eLad;
    }

    List<Map<String, String>> ladderData = [];
    ladderSelectFree.forEach((e) {
      List<Map<String, String>> coupons = [];
      e.coupons?.forEach((value) {
        Map<String, String> coupon = {
          'id': value.id!,
          'aname': value.aname!,
        };
        coupons.add(coupon);
      });
      Map<String, String> coupon = {
        'price': e.priceC.text,
        'coupons': jsonEncode(coupons),
      };
      ladderData.add(coupon);
    });

    stairsData['ladder_data'] =
        (ladderData.length == 0 ? null : jsonEncode(ladderData));

    Map<String, String?> pramas = {
      'sellerid':
          Provider.of<UserModel>(context, listen: false).user!.sellerid!,
      'full_reduction': fullReduction ? '1' : '0',
      'stairs': stairs ? '1' : '0',
      'full_reduction_data':
          fullReductionData.length == 0 ? null : jsonEncode(fullReductionData),
      'stairs_data': stairsData.length == 0 ? null : jsonEncode(stairsData),
    };
    // if (fullReductionData != null) {
    //   pramas['full_reduction_data'] = jsonEncode(fullReductionData);
    // }
    // if (stairsData != null) {
    //   pramas['stairs_dat'] = jsonEncode(stairsData);
    // }

    bool success = await financeProvider!.setActivityConfig(context, pramas);
    if (success) {
      if (Navigator.canPop(context)) {
        Navigator.pop(context);
      }
    }
  }

  ///是否立即启用
  Widget _canUse(
    String title,
    bool swich,
    GestureTapCallback onTap,
  ) {
    return InkWell(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(24)),
        margin: EdgeInsets.only(left: ScreenUtil().setWidth(32)),
        decoration: BoxDecoration(
            border: Border(
                bottom:
                    BorderSide(color: MyColours.color_E7E7E7, width: w(0.5)))),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              // height: ScreenUtil().setWidth(40),
              // color: Colors.red,
              child: Text(
                title,
                style: TextStyle(
                    color: MyColours.color_515151, fontSize: font(16)),
              ),
            ),
            Spacer(),
            Image.asset(
              swich
                  ? Utils.getImgPath('swich_on')
                  : Utils.getImgPath('swich_off'),
              width: ScreenUtil().setWidth(44 * 2),
            ),
            HEmptyView(32)
          ],
        ),
      ),
    );
  }

  Widget _priceWidget(TextEditingController controller, FocusNode focusNode,
      {num width = 40}) {
    return Container(
      margin: EdgeInsets.only(left: w(width)),
      padding: EdgeInsets.only(top: w(8), bottom: w(8), right: w(16)),
      // decoration: BoxDecoration(
      //     border: Border(
      //         bottom:
      //             BorderSide(color: MyColours.color_E7E7E7, width: w(0.5)))),
      child: Row(
        children: [
          Text(
            '用户消费满',
            style: TextStyle(color: MyColours.color_515151, fontSize: font(14)),
          ),
          HEmptyView(10),
          Container(
            width: w(70),
            height: w(26),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                border: Border.all(color: MyColours.color_999999, width: w(1))),
            child: TextField(
                controller: controller,
                textAlign: TextAlign.center,
                textAlignVertical: TextAlignVertical.center,
                maxLines: 1,
                // //光标颜色
                // cursorColor:
                //     widget.isSelect ? Colors.white : MyColours.color_199095,
                //输入文本的样式
                inputFormatters: [
                  FilteringTextInputFormatter.allow(RegExp("[0-9.]")),
                ], // 限制输入为数字,
                style: TextStyle(
                  color: MyColours.color_515151,
                  fontSize: ScreenUtil().setSp(24),
                ),
                focusNode: focusNode,
                decoration: InputDecoration(
                  isCollapsed: true,
                  border: OutlineInputBorder(borderSide: BorderSide.none),
                  hintText: '输入门槛',
                  hintStyle: TextStyle(
                    color: MyColours.color_999999,
                    fontSize: ScreenUtil().setSp(24),
                  ),
                  enabledBorder: new UnderlineInputBorder(
                    borderSide: BorderSide.none,
                  ),
                  focusedBorder: new UnderlineInputBorder(
                    borderSide: BorderSide.none,
                  ),
                ),
                onChanged: (value) {},
                onEditingComplete: () {
                  FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                },
                keyboardType: TextInputType.numberWithOptions()),
          ),
          HEmptyView(10),
          Text(
            '元  发放优惠券',
            style: TextStyle(color: MyColours.color_515151, fontSize: font(14)),
          ),
        ],
      ),
    );
  }

  ///时间选择
  Widget _select(String title, String hintText, GestureTapCallback onTap) {
    return InkWell(
      onTap: onTap,
      child: Container(
        margin: EdgeInsets.only(left: w(40)),
        padding: EdgeInsets.only(
          top: w(8),
          bottom: w(8),
        ),
        decoration: BoxDecoration(
            border: Border(
                bottom:
                    BorderSide(color: MyColours.color_E7E7E7, width: w(0.5)))),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              // height: ScreenUtil().setWidth(40),
              // color: Colors.red,
              child: Text(
                title,
                style: TextStyle(
                    color: MyColours.color_515151,
                    fontSize: ScreenUtil().setSp(28)),
              ),
            ),
            HEmptyView(20),
            Spacer(),
            Text(hintText,
                style: TextStyle(
                  color: hintText == '选择日期'
                      ? MyColours.color_999999
                      : MyColours.color_515151,
                  fontSize: ScreenUtil().setSp(24),
                )),
            HEmptyView(20),
            Image.asset(
              Utils.getImgPath('arrow_right_new'),
              width: ScreenUtil().setWidth(16),
            ),
            HEmptyView(32),
          ],
        ),
      ),
    );
  }

  Widget _couponShow(String name, {GestureTapCallback? onTap}) {
    return Row(
      // mainAxisAlignment: MainAxisAlignment.center,
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          height: w(24),
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: w(10)),
          decoration: BoxDecoration(
              border: Border.all(color: MyColours.color_999999, width: w(1)),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(r(5)),
                bottomLeft: Radius.circular(r(5)),
              )),
          child: Text(
            name,
            style: TextStyle(color: MyColours.color_515151, fontSize: font(12)),
          ),
        ),
        InkWell(
            onTap: onTap,
            child: Container(
              height: w(24),
              alignment: Alignment.center,
              padding: EdgeInsets.symmetric(horizontal: w(5)),
              decoration: BoxDecoration(
                  color: MyColours.color_999999,
                  border:
                      Border.all(color: MyColours.color_999999, width: w(1)),
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(r(5)),
                    bottomRight: Radius.circular(r(5)),
                  )),
              child: Text(
                '×',
                style: TextStyle(
                    color: MyColours.color_515151, fontSize: font(12)),
              ),
            ))
      ],
    );
  }

  Widget _selectCouponBtn(VoidCallback? onPressed) {
    return RoundButton(
        text: '+选择优惠券',
        width: w(88),
        height: w(26),
        gradientStart: MyColours.color_ffffff,
        gradientEnd: MyColours.color_ffffff,
        textColor: MyColours.color_438E93,
        borderColor: MyColours.color_438E93,
        radius: r(5),
        fontSize: 24,
        onPressed: onPressed);
  }

  Widget _selectCouponWidget(List<CouponSunModel> coupons,
      {bool needBottom = true, num width = 40, VoidCallback? onPressed}) {
    List<Widget> data = coupons.map((e) {
      return _couponShow(e.aname ?? '', onTap: () {
        //删除选择的券
        coupons.remove(e);
        setState(() {});
      });
    }).toList();
    data.add(_selectCouponBtn(onPressed));
    return Container(
      width: double.infinity,
      padding: EdgeInsets.only(top: w(8), bottom: w(8), right: w(16)),
      margin: EdgeInsets.only(left: w(width)),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  width: w(0.5),
                  color: needBottom
                      ? MyColours.color_E7E7E7
                      : MyColours.color_ffffff))),
      child: Wrap(runSpacing: w(8), spacing: w(6), children: data),
    );
  }

  ///发放阶梯
  Widget _ladderWidget() {
    return ListView.builder(
        controller: controller,
        shrinkWrap: true,
        itemCount: ladderSelectFree.length,
        itemBuilder: (context, index) {
          LadderCouponsModelDataStairsDataLadderData data =
              ladderSelectFree[index];
          return Container(
            padding: EdgeInsets.only(
                left: w(40), top: w(8), bottom: w(8), right: w(16)),
            child: Column(
              children: [
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '发放阶梯(${index + 1})',
                        style: TextStyle(
                            color: MyColours.color_515151, fontSize: font(14)),
                      ),
                      InkWell(
                          onTap: () {
                            //删除券
                            ladderSelectFree.remove(data);
                            setState(() {});
                          },
                          child: Padding(
                            padding: EdgeInsets.only(top: w(8), bottom: w(8)),
                            child: Text(
                              '删除',
                              style: TextStyle(
                                  color: MyColours.color_438E93,
                                  fontSize: font(12)),
                            ),
                          ))
                    ],
                  ),
                ),
                _priceWidget(data.priceC, FocusNode(), width: 20),
                _selectCouponWidget(data.coupons ?? [],
                    width: 20, needBottom: false, onPressed: () async {
                  // 跳转到优惠券选择页面,条件:券的有效期包含活动有效期
                  // 阶梯发券

                  //选择券,满减送的
                  if (fromDateLadder == '选择日期') {
                    Utils.showToast('请选择阶梯返券的开始日期');
                    return;
                  }
                  if (endDateLadder == '选择日期') {
                    Utils.showToast('请选择阶梯返券的结束日期');
                    return;
                  }
                  if (DateUtil.getDateTime(endDateLadder)
                          .compareTo(DateUtil.getDateTime(fromDateLadder)) <
                      0) {
                    Utils.showToast('阶梯返券的活动结束日期不能早于开始日期');
                    return;
                  }
                  dynamic temp = await NavigatorUtil.goPaymentGiftSelectPage(
                      context,
                      '3',
                      {'object': data.coupons ?? []},
                      fromDateLadder,
                      endDateLadder);
                  if (temp != null && temp['coupon'] != null) {
                    data.coupons = temp['coupon'];

                    setState(() {});
                  }
                }),
                // }),
              ],
            ),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    financeProvider = Provider.of<FinanceProvider>(context, listen: true);

    return KeyboardDismissOnTap(
        child: Scaffold(
      backgroundColor: MyColours.color_ffffff,
      appBar: SystemAppBar('支付返券'),
      key: scaffoldKey,
      body: Column(
        children: [
          Expanded(
              child: SingleChildScrollView(
            controller: controller,
            child: Column(
              children: [
                _canUse('开通实际支付满减返券【拉复购】', fullReduction, () {
                  setState(() {
                    fullReduction = !fullReduction;
                    if (fullReduction) {
                      stairs = false;
                    }
                  });
                }),
                _select('活动开始于', fromDateFull, () {
                  FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                  //弹出时间选择器
                  // showPickerDateTime(context);
                  // showDateSelWidget = true;
                  DialogUtil.showPickerDateTime24(
                      context,
                      scaffoldKey,
                      (value) {
                        // {'text': picker.adapter.text, 'select': selecteds}
                        if (value != null) {
                          if (endDateFull != '选择日期') {
                            if (DateUtil.getDateTime(endDateFull).compareTo(
                                    DateUtil.getDateTime(DateUtil.formatDateStr(
                                        value,
                                        format: DateFormats.y_mo_d))) <
                                0) {
                              Utils.showToast('满减返券的活动开始时间不能迟于活动结束时间');
                              return;
                            }
                          }

                          setState(() {
                            print(value);
                            fromDateFull = DateUtil.formatDateStr(value,
                                format: DateFormats.y_mo_d);
                          });
                        }
                        // showDateSelWidget = false;
                      },
                      minValue: DateTime(1987, 1, 1),
                      dateTime: fromDateFull == '选择日期'
                          ? null
                          : DateUtil.getDateTime(fromDateFull),
                      pickerDateTimeType: PickerDateTimeType.kYMD,
                      onCancel: () {
                        // showDateSelWidget = false;
                      });
                }),
                _select('活动结束于', endDateFull, () {
                  FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                  //弹出时间选择器
                  // showPickerDateTime(context);
                  // showDateSelWidget = true;
                  DialogUtil.showPickerDateTime24(
                      context,
                      scaffoldKey,
                      (value) {
                        // {'text': picker.adapter.text, 'select': selecteds}
                        if (value != null) {
                          if (fromDateFull != '选择日期') {
                            if (DateUtil.getDateTime(DateUtil.formatDateStr(
                                        value,
                                        format: DateFormats.y_mo_d))
                                    .compareTo(
                                        DateUtil.getDateTime(fromDateFull)) <
                                0) {
                              Utils.showToast('满减返券的活动结束时间不能早于活动开始时间');
                              return;
                            }
                          }
                          setState(() {
                            print(value);
                            endDateFull = DateUtil.formatDateStr(value,
                                format: DateFormats.y_mo_d);
                          });
                        }
                        // showDateSelWidget = false;
                      },
                      minValue: DateTime(1987, 1, 1),
                      dateTime: endDateFull == '选择日期'
                          ? null
                          : DateUtil.getDateTime(endDateFull),
                      pickerDateTimeType: PickerDateTimeType.kYMD,
                      onCancel: () {
                        // showDateSelWidget = false;
                      });
                }),
                _priceWidget(fullC, fullNode),
                _selectCouponWidget(couponSelectFree!, onPressed: () async {
                  if (fromDateFull == '选择日期') {
                    Utils.showToast('请选择满减返券的开始日期');
                    return;
                  }
                  if (endDateFull == '选择日期') {
                    Utils.showToast('请选择满减返券的结束日期');
                    return;
                  }
                  if (DateUtil.getDateTime(endDateFull)
                          .compareTo(DateUtil.getDateTime(fromDateFull)) <
                      0) {
                    Utils.showToast('满减返券的活动结束日期不能早于开始日期');
                    return;
                  }
                  //选择券,满减送的
                  dynamic temp = await NavigatorUtil.goPaymentGiftSelectPage(
                      context,
                      '3',
                      {'object': couponSelectFree},
                      fromDateFull,
                      endDateFull);
                  if (temp != null && temp['coupon'] != null) {
                    couponSelectFree = temp['coupon'];

                    setState(() {});
                  }
                }),
                Container(
                  padding:
                      EdgeInsets.only(top: w(8), bottom: w(8), right: w(16)),
                  margin: EdgeInsets.only(left: w(40)),
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                              width: w(0.5), color: MyColours.color_E7E7E7))),
                  child: Row(
                    children: [
                      Text(
                        '发放规则',
                        style: TextStyle(
                            color: MyColours.color_515151, fontSize: font(14)),
                      ),
                      Spacer(),
                      InkWell(
                          onTap: () {
                            setState(() {
                              rule = !rule;
                            });
                          },
                          child: Container(
                            // width: w(100),
                            // height: w(30),
                            padding: EdgeInsets.symmetric(
                                horizontal: w(10), vertical: w(5)),
                            decoration: BoxDecoration(
                                color: rule
                                    ? MyColours.color_438E93
                                    : MyColours.color_DBDBDB,
                                borderRadius: BorderRadius.only(
                                    topLeft: Radius.circular(r(5)),
                                    bottomLeft: Radius.circular(r(5)))),
                            child: Text(
                              '每满门槛均发放',
                              style: TextStyle(
                                  color: rule
                                      ? MyColours.color_ffffff
                                      : MyColours.color_438E93,
                                  fontSize: font(14)),
                            ),
                          )),
                      InkWell(
                          onTap: () {
                            setState(() {
                              rule = !rule;
                            });
                          },
                          child: Container(
                            padding: EdgeInsets.symmetric(
                                horizontal: w(10), vertical: w(5)),
                            decoration: BoxDecoration(
                                color: !rule
                                    ? MyColours.color_438E93
                                    : MyColours.color_DBDBDB,
                                borderRadius: BorderRadius.only(
                                    topRight: Radius.circular(r(5)),
                                    bottomRight: Radius.circular(r(5)))),
                            child: Text(
                              '仅发放一次',
                              style: TextStyle(
                                  color: !rule
                                      ? MyColours.color_ffffff
                                      : MyColours.color_438E93,
                                  fontSize: font(14)),
                            ),
                          ))
                    ],
                  ),
                ),
                VEmptyView(22),
                _canUse('开通实际支付阶梯返券【提客单】', stairs, () {
                  //
                  setState(() {
                    stairs = !stairs;
                    if (stairs) {
                      fullReduction = false;
                    }
                  });
                }),
                _select('活动开始于', fromDateLadder, () {
                  FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                  //弹出时间选择器
                  // showPickerDateTime(context);
                  // showDateSelWidget = true;
                  DialogUtil.showPickerDateTime24(
                      context,
                      scaffoldKey,
                      (value) {
                        // {'text': picker.adapter.text, 'select': selecteds}
                        if (value != null) {
                          if (endDateLadder != '选择日期') {
                            if (DateUtil.getDateTime(endDateLadder).compareTo(
                                    DateUtil.getDateTime(DateUtil.formatDateStr(
                                        value,
                                        format: DateFormats.y_mo_d))) <
                                0) {
                              Utils.showToast('阶梯返券的活动开始时间不能迟于活动结束时间');
                              return;
                            }
                          }
                          setState(() {
                            print(value);
                            fromDateLadder = DateUtil.formatDateStr(value,
                                format: DateFormats.y_mo_d);
                          });
                        }
                        // showDateSelWidget = false;
                      },
                      minValue: DateTime(1987, 1, 1),
                      dateTime: fromDateLadder == '选择日期'
                          ? null
                          : DateUtil.getDateTime(fromDateLadder),
                      pickerDateTimeType: PickerDateTimeType.kYMD,
                      onCancel: () {
                        // showDateSelWidget = false;
                      });
                }),
                _select('活动结束于', endDateLadder, () {
                  FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                  //弹出时间选择器
                  // showPickerDateTime(context);
                  // showDateSelWidget = true;
                  DialogUtil.showPickerDateTime24(
                      context,
                      scaffoldKey,
                      (value) {
                        // {'text': picker.adapter.text, 'select': selecteds}
                        if (value != null) {
                          if (fromDateLadder != '选择日期') {
                            if (DateUtil.getDateTime(DateUtil.formatDateStr(
                                        value,
                                        format: DateFormats.y_mo_d))
                                    .compareTo(
                                        DateUtil.getDateTime(fromDateLadder)) <
                                0) {
                              Utils.showToast('阶梯返券的活动结束时间不能早于活动开始时间');
                              return;
                            }
                          }
                          setState(() {
                            print(value);
                            endDateLadder = DateUtil.formatDateStr(value,
                                format: DateFormats.y_mo_d);
                          });
                        }
                        // showDateSelWidget = false;
                      },
                      minValue: DateTime(1987, 1, 1),
                      dateTime: endDateLadder == '选择日期'
                          ? null
                          : DateUtil.getDateTime(endDateLadder),
                      pickerDateTimeType: PickerDateTimeType.kYMD,
                      onCancel: () {
                        // showDateSelWidget = false;
                      });
                }),
                _ladderWidget(),
                InkWell(
                    onTap: () {
                      //  ladderSelectFree.add('${ladderSelectFree.length + 1}');
                      LadderCouponsModelDataStairsDataLadderData data =
                          LadderCouponsModelDataStairsDataLadderData();
                      ladderSelectFree.add(data);
                      setState(() {});
                    },
                    child: Container(
                      // height: w(30),

                      margin: EdgeInsets.only(left: w(60), top: w(8)),
                      padding: EdgeInsets.symmetric(vertical: w(8)),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          // color: Colors.red,
                          border: Border(
                              bottom: BorderSide(
                                  width: w(0.5),
                                  color: MyColours.color_E7E7E7))),
                      child: Text(
                        '增加阶梯',
                        style: TextStyle(
                            color: MyColours.color_438E93, fontSize: font(12)),
                      ),
                    ))
              ],
            ),
          )),
          Container(
            padding: EdgeInsets.only(
                top: w(13), left: w(45), right: w(45), bottom: w(26)),
            child: RoundButton(
              text: '立即提交',
              height: w(43),
              radius: r(5),
              gradientStart: MyColours.color_438E93,
              gradientEnd: MyColours.color_438E93,
              borderColor: MyColours.color_438E93,
              textColor: MyColours.color_ffffff,
              isBold: true,
              fontSize: 32,
              onPressed: () {
                // 调用接口
                _setActivityConfig();
              },
            ),
          )
        ],
      ),
    ));
  }
}