invitation_page.dart 24.7 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
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/user.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/navigator_util.dart';
import 'package:one_key/utils/utils.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';

class InvicationPage extends StatefulWidget {
  final String rid; //预订订单id
  final String tableInfo; //桌位信息
  final String ddate;
  final String ddateStr;
  final String phone;

  InvicationPage(
      this.rid, this.tableInfo, this.ddate, this.ddateStr, this.phone);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new InvicationPageState();
  }
}

class InvicationPageState extends State<InvicationPage> {
  User user;
  DateTime dateTime;
  String dateTimeStr = "";
  ScrollController controller = ScrollController();
  double couponHeight = 180.0;
  CouponProvider couponProvider;

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

    WidgetsBinding.instance.addPostFrameCallback((_) {
      _getActivityByRid();
    });
    Utils.changeStatusColor(color: Colors.transparent);
    dateTime =
        DateTime.fromMillisecondsSinceEpoch(int.parse(widget.ddate) * 1000);
    user = Provider.of<UserModel>(context, listen: false).user;
    dateTimeStr =
        "${dateTime.year}/${Utils.addZeroNumber(dateTime.month)}/${Utils.addZeroNumber(dateTime.day)} 星期${Utils.formatWeekDayNum(dateTime.weekday)} ${widget.ddateStr}";
  }

  _getActivityByRid() async {
    Map<String, String> params = {
      "rid": widget.rid,
    };
    await couponProvider.getActivityByRid(context, params, isShowLoading: true);
    //flase默认5个  true 不默认5个
    if (!couponProvider.hasModify) {
      //没有绑定的券,默认给5个,获取优惠券列表
      _couponNetworkData(isShowLoading: true);
    }
  }

  ///消费券默认5张
  _couponNetworkData({bool isShowLoading = true}) async {
    Map<String, String> params = {
      "uid": Provider.of<UserModel>(context, listen: false).user.openid,
      'status': '1'
    };
    await couponProvider.getCustomerSelectActivity(context, params,
        isShowLoading: isShowLoading);
    //此人已经新建好券
    if (couponProvider.couponListSelect.length > 0) {
      couponProvider.initCouponSelect(context);

      if (couponProvider.coupons.length == 0) {
        setState(() {
          couponHeight = 0;
        });
      } else {
        setState(() {
          couponHeight = 180.0;
        });
      }
    } else {
      //没有新建的优惠券
      setState(() {
        couponHeight = 0;
      });
    }
  }

  @override
  void dispose() {
    Utils.changeStatusColor();
    couponProvider.clearSelect();
    super.dispose();
  }

  //中间内容显示组件
  Widget _middleWidget(String title, String content) {
    return Column(
      children: <Widget>[
        VEmptyView(80),
        Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Image.asset(
              "assets/invication_line_left.png",
              width: ScreenUtil().setWidth(44),
              height: ScreenUtil().setWidth(4),
            ),
            Container(
              margin:
                  EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(13)),
              child: Text(title,
                  style: TextStyle(
                      color: MyColours.color_CEB689,
                      fontSize: ScreenUtil().setSp(28))),
            ),
            Image.asset(
              "assets/invication_line_right.png",
              width: ScreenUtil().setWidth(44),
              height: ScreenUtil().setWidth(4),
            )
          ],
        ),
        Container(
          margin: EdgeInsets.only(top: ScreenUtil().setHeight(20)),
          child: Text(
            content,
            style: TextStyle(
                color: MyColours.color_F2F2F2,
                fontSize: ScreenUtil().setSp(36)),
          ),
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    couponProvider = Provider.of<CouponProvider>(context, listen: true);
    return Container(
        width: double.infinity,
        // height: double.infinity,
        decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage("assets/bg_invication.png"), fit: BoxFit.cover),
        ),
        child: Scaffold(
            backgroundColor: Colors.transparent,
            body: SafeArea(
                child: Stack(
              children: [
                Padding(
                    padding:
                        EdgeInsets.only(top: ScreenUtil().setWidth(35 * 2)),
                    child: Column(children: [
                      Expanded(
                          child: ListView(
                              controller: controller,
                              physics: BouncingScrollPhysics(),
                              children: <Widget>[
                            Center(
                              child: Column(
                                children: <Widget>[
                                  Image.asset(
                                    "assets/img_ydap.png",
                                    width: ScreenUtil().setWidth(220 * 2),
                                    height: ScreenUtil().setHeight(120 * 2),
                                  ),
                                  VEmptyView(20),
                                  Container(
                                    margin: EdgeInsets.symmetric(
                                        horizontal: ScreenUtil().setWidth(40)),
                                    padding: EdgeInsets.all(
                                        ScreenUtil().setWidth(60)),
                                    decoration: BoxDecoration(
                                        gradient: LinearGradient(
                                          begin: Alignment.topCenter,
                                          end: Alignment.bottomCenter,
                                          colors: [
                                            MyColours.color_F7F1E8,
                                            MyColours.color_E3D6C7,
                                          ],
                                        ),
                                        borderRadius: BorderRadius.circular(
                                            ScreenUtil().setWidth(10))),
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.center,
                                      children: [
                                        Container(
                                          color: Colors.red,
                                          height: 160,
                                        ),
                                        VEmptyView(40),
                                        Image.asset(
                                          "assets/yd_up.png",
                                          width: ScreenUtil().setWidth(195 * 2),
                                          height:
                                              ScreenUtil().setHeight(33 * 2),
                                        ),
                                        VEmptyView(60),
                                        Container(
                                          height: ScreenUtil().setWidth(48),
                                          child: Text(
                                            user.sellername,
                                            style: TextStyle(
                                                letterSpacing: ScreenUtil()
                                                    .setWidth(2.13 * 2),
                                                color: MyColours.color_794F28,
                                                fontWeight: FontWeight.bold,
                                                fontSize:
                                                    ScreenUtil().setSp(34)),
                                          ),
                                        ),
                                        VEmptyView(30),
                                        Container(
                                          height: ScreenUtil().setWidth(36),
                                          child: Text(
                                            '已为您安排在包间',
                                            style: TextStyle(
                                                letterSpacing: ScreenUtil()
                                                    .setWidth(1.7 * 2),
                                                color: MyColours.color_C19E5B,
                                                fontSize:
                                                    ScreenUtil().setSp(26)),
                                          ),
                                        ),
                                        VEmptyView(12),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: [
                                            Image.asset(
                                              "assets/bj_left.png",
                                              width:
                                                  ScreenUtil().setWidth(30 * 2),
                                              height: ScreenUtil()
                                                  .setHeight(58 * 2),
                                            ),
                                            Container(
                                              height: ScreenUtil().setWidth(48),
                                              child: Text(
                                                widget.tableInfo
                                                    .replaceAll("\n", ""),
                                                style: TextStyle(
                                                    letterSpacing: ScreenUtil()
                                                        .setWidth(2.13 * 2),
                                                    color:
                                                        MyColours.color_794F28,
                                                    fontWeight: FontWeight.bold,
                                                    fontSize:
                                                        ScreenUtil().setSp(34)),
                                              ),
                                            ),
                                            Image.asset(
                                              "assets/bj_right.png",
                                              width:
                                                  ScreenUtil().setWidth(30 * 2),
                                              height: ScreenUtil()
                                                  .setHeight(58 * 2),
                                            ),
                                          ],
                                        ),
                                        VEmptyView(18),
                                        RoundButton(
                                          text: '浏览照片',
                                          width: ScreenUtil().setWidth(68 * 2),
                                          height: ScreenUtil().setWidth(24 * 2),
                                          fontSize: 24,
                                          textColor: MyColours.color_794F28,
                                          isBold: false,
                                          gradientStart:
                                              Color.fromRGBO(121, 79, 40, 0.1),
                                          gradientEnd:
                                              Color.fromRGBO(121, 79, 40, 0.1),
                                        ),
                                        VEmptyView(60),
                                        Container(
                                          height: ScreenUtil().setWidth(40),
                                          child: Text(
                                            '时间:${dateTimeStr}',
                                            style: TextStyle(
                                                letterSpacing: ScreenUtil()
                                                    .setWidth(1.8 * 2),
                                                color: MyColours.color_794F28,
                                                fontWeight: FontWeight.bold,
                                                fontSize:
                                                    ScreenUtil().setSp(28)),
                                          ),
                                        ),
                                        VEmptyView(20),
                                        Container(
                                          // height: ScreenUtil().setWidth(40),
                                          child: Text(
                                            '地址:${user.sellerAddr}',
                                            maxLines: 3,
                                            overflow: TextOverflow.ellipsis,
                                            textAlign: TextAlign.center,
                                            style: TextStyle(
                                                letterSpacing: ScreenUtil()
                                                    .setWidth(1.8 * 2),
                                                color: MyColours.color_794F28,
                                                fontWeight: FontWeight.bold,
                                                fontSize:
                                                    ScreenUtil().setSp(28)),
                                          ),
                                        ),
                                        // VEmptyView(20),
                                        // RoundButton(
                                        //   text: '一键导航',
                                        //   width: ScreenUtil().setWidth(68 * 2),
                                        //   height: ScreenUtil().setWidth(24 * 2),
                                        //   fontSize: 24,
                                        //   textColor: MyColours.color_794F28,
                                        //   isBold: false,
                                        //   gradientStart:
                                        //       Color.fromRGBO(121, 79, 40, 0.1),
                                        //   gradientEnd:
                                        //       Color.fromRGBO(121, 79, 40, 0.1),
                                        // ),
                                        VEmptyView(60),
                                        Image.asset(
                                          "assets/yd_down.png",
                                          width: ScreenUtil().setWidth(195 * 2),
                                          height:
                                              ScreenUtil().setHeight(33 * 2),
                                        ),
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                            VEmptyView(couponHeight),
                          ])),
                      Container(
                        width: double.infinity,
                        height: ScreenUtil().setHeight(99),
                        child: Row(
                          children: <Widget>[
                            GestureDetector(
                              onTap: () {
                                if (widget.phone.isEmpty) {
                                  Utils.showToast("没有预订人电话信息");
                                  return;
                                }
                                NavigatorUtil.goSmsPage(context, widget.rid);
                              },
                              child: Container(
                                width: ScreenUtil().setWidth(135 * 2),
                                height: double.infinity,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: MyColours.color_262628,
                                    border: Border(
                                        top: BorderSide(
                                            width: ScreenUtil().setWidth(1),
                                            color: MyColours.color_ECD9B7))),
                                child: Text(
                                  "发短信",
                                  style: TextStyle(
                                      color: MyColours.color_ECD9B7,
                                      fontSize: ScreenUtil().setSp(28)),
                                ),
                              ),
                            ),
                            Expanded(
                              child: GestureDetector(
                                onTap: () async {
                                  if (!couponProvider.hasModify &&
                                      couponProvider.coupons.length > 0) {
                                    Map<String, String> params = {
                                      "rid": widget.rid,
                                      "aid": Utils.listToStringEnglish(
                                          couponProvider.coupons)
                                    };
                                    bool isSuc = await couponProvider
                                        .setActivityAsReserve(context, params);
                                    if (isSuc) {
                                      couponProvider.hasModify = true;
                                      bool isSuccess =
                                          await Utils.goShareInvicationToWeChat(
                                              widget.rid);
                                      print(isSuccess);
                                      // couponProvider.couponsShow = [];
                                      // couponProvider.couponsShow
                                      //     .addAll(couponProvider.coupons);
                                      // couponProvider.coupons = [];
                                      // couponProvider.notifyListeners();
                                    }
                                  } else {
                                    bool isSuccess =
                                        await Utils.goShareInvicationToWeChat(
                                            widget.rid);
                                    print(isSuccess);
                                  }
                                },
                                child: Container(
                                  width: double.infinity,
                                  height: double.infinity,
                                  color: MyColours.color_ECD9B7,
                                  alignment: Alignment.center,
                                  child: Text(
                                    "通知客户",
                                    style: TextStyle(
                                        color: MyColours.color_7B512A,
                                        fontSize: ScreenUtil().setSp(30)),
                                  ),
                                ),
                              ),
                            )
                          ],
                        ),
                      )
                    ])),
                Positioned(
                  left: ScreenUtil().setWidth(0),
                  top: ScreenUtil().setWidth(0),
                  child: GestureDetector(
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                    behavior: HitTestBehavior.opaque,
                    child: Container(
                        padding: EdgeInsets.fromLTRB(
                          ScreenUtil().setWidth(40),
                          ScreenUtil().setWidth(40),
                          ScreenUtil().setWidth(200),
                          ScreenUtil().setWidth(100),
                        ),
                        alignment: Alignment.centerLeft,
                        // color: Colors.red,
                        child: Image.asset(
                          "assets/invication_back.png",
                          width: ScreenUtil().setWidth(20),
                          height: ScreenUtil().setHeight(31),
                        )),
                  ),
                ),
                Positioned(
                  // left: ScreenUtil().setWidth(180),
                  bottom: ScreenUtil().setWidth(110),
                  right: ScreenUtil().setWidth(40),
                  child: couponProvider.hasModify ||
                          couponProvider.coupons.length > 0 ||
                          couponProvider.couponListSelect.length > 0
                      ? GestureDetector(
                          onTap: () async {
                            NavigatorUtil.goCouponSelectPage(context,
                                rid: widget.rid,
                                hasModify: couponProvider.hasModify);
                          },
                          behavior: HitTestBehavior.opaque,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Container(
                                  padding: EdgeInsets.symmetric(
                                      horizontal: ScreenUtil().setWidth(40),
                                      vertical: ScreenUtil().setWidth(16)),
                                  height: ScreenUtil().setWidth(35 * 2),
                                  decoration: BoxDecoration(
                                      color: MyColours.color_000000,
                                      borderRadius: BorderRadius.circular(
                                          ScreenUtil().setWidth(20))),
                                  child: Row(
                                    children: [
                                      Text(
                                        '并赠送给顾客${couponProvider.coupons.length}张优惠券',
                                        textAlign: TextAlign.center,
                                        style: TextStyle(
                                          color: MyColours.color_f5f5f5,
                                          fontWeight: FontWeight.bold,
                                          fontSize: ScreenUtil().setSp(28),
                                        ),
                                      ),
                                      HEmptyView(40),
                                      RoundButton(
                                        width: ScreenUtil().setWidth(124),
                                        height: ScreenUtil().setWidth(46),
                                        text: '点击查看',
                                        textColor: MyColours.color_FDA31D,
                                        fontSize: 24,
                                        isBold: true,
                                        radius: ScreenUtil().setWidth(10),
                                        gradientStart: MyColours.color_f5f5f5,
                                        gradientEnd: MyColours.color_f5f5f5,
                                        onPressed: () async {
                                          NavigatorUtil.goCouponSelectPage(
                                              context,
                                              rid: widget.rid,
                                              hasModify:
                                                  couponProvider.hasModify);
                                        },
                                      )
                                    ],
                                  )),
                              Image.asset(Utils.getImgPath('jian'),
                                  width: ScreenUtil().setWidth(28),
                                  height: ScreenUtil().setWidth(20))
                            ],
                          ))
                      : Container(),
                )
              ],
            ))));
  }
}