sms_manager.dart 15.6 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/sms_info.dart';
import 'package:one_key/provider/my_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/utils/screen_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';

import '../../constant/state.dart';
import '../../widgets/page_exception.dart';

class SmsManagerPage extends StatefulWidget {
  SmsManagerPage({Key? key}) : super(key: key);

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

class _SmsManagerPageState extends State<SmsManagerPage> {
  bool isShow = false;
  SmsInfoData? smsInfoData;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    Utils.changeStatusColor(color: MyColours.color_199095);
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      _getSmsInfo(context);
    });
    EventBus().on('refreshSmsNum', (arg) {
      _getSmsInfo(context);
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    EventBus().emit('changeStatusColor');
    // EventBus().emit('refreshMySms');
    EventBus().off('refreshSmsNum');
  }

  _getSmsInfo(context) async {
    MyModel myModel = Provider.of<MyModel>(context, listen: false);
    smsInfoData = await myModel.getSmsInfo(context);
    isShow = smsInfoData!.meals!.any((element) => element!.discount != '0');

    setState(() {});
    // setState(() {
    //   if (smsInfoData != null) {
    //     smsInfo = smsInfoData?.lastNum;
    //   }
    // });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: SystemAppBar(
          '短信管理',
          bgColor: MyColours.color_199095,
          needWhite: true,
        ),
        body: Consumer<MyModel>(builder: (context1, model, _) {
          if (model.pageState != PageState.Success) {
            return ExceptionPage(
              pageState: model.pageState,
              callback: () async {
                _getSmsInfo(context);
              },
              emptyMsg: "暂时没有信息哦",
              emptyImg: "empty_search",
              showMsg: "加载中,请稍候...",
            );
          } else {
            return NestedScrollView(
                // controller: _scrollViewController,
                headerSliverBuilder:
                    (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                SliverAppBar(
                  pinned: false,
                  floating: false,
                  leading: Container(),
                  backgroundColor: MyColours.color_F8F9FD,
                  expandedHeight: ScreenUtil().setWidth(320 + 40),
                  flexibleSpace: FlexibleSpaceBar(
                    title: null,
                    collapseMode: CollapseMode.pin,
                    background: Consumer<MyModel>(builder:
                        (BuildContext context, MyModel model, Widget? child) {
                      return Container(
                        width: double.infinity,
                        height: ScreenUtil().setHeight(320 + 30),
                        color: MyColours.color_199095,
                        child: Padding(
                            padding: EdgeInsets.only(
                                left: ScreenUtil().setWidth(30)),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                VEmptyView(80),
                                Container(
                                  height: ScreenUtil().setWidth(40),
                                  child: Text(
                                    '短信余量',
                                    style: TextStyle(
                                        color: MyColours.color_ffffff,
                                        fontSize: ScreenUtil().setSp(30)),
                                  ),
                                ),
                                VEmptyView(10),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Container(
                                        // height: ScreenUtil().setWidth(40),
                                        child: Text(
                                      smsInfoData!.lastNum!,
                                      style: TextStyle(
                                          color: MyColours.color_ffffff,
                                          fontWeight: FontWeight.bold,
                                          fontSize: ScreenUtil().setSp(36)),
                                    )),
                                    Container(
                                        // height: ScreenUtil().setWidth(40),
                                        child: Text(
                                      ' 条',
                                      style: TextStyle(
                                          color: MyColours.color_ffffff,
                                          fontSize: ScreenUtil().setSp(30)),
                                    ))
                                  ],
                                ),
                                VEmptyView(80),
                                Stack(children: [
                                  RoundButton(
                                    text: '立即充值',
                                    gradientStart: MyColours.color_ffffff,
                                    gradientEnd: MyColours.color_ffffff,
                                    borderColor:
                                        Color.fromRGBO(255, 255, 255, 0.2),
                                    width: ScreenUtil().setWidth(225),
                                    height: ScreenUtil().setWidth(80),
                                    textColor: MyColours.color_199095,
                                    radius: ScreenUtil().setWidth(10),
                                    fontSize: 28,
                                    isBold: true,
                                    imgWidth: 26,
                                    onPressed: () {
                                      NavigatorUtil.goSmsRechargePage(context,
                                          smsInfoData: smsInfoData);
                                    },
                                  ),
                                  isShow
                                      ? Positioned(
                                          top: 0,
                                          right: 0,
                                          child: Container(
                                              // padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(16),vertical: ScreenUtil().setWidth(4)),
                                              padding: EdgeInsets.only(
                                                  left:
                                                      ScreenUtil().setWidth(6)),
                                              alignment: Alignment.center,
                                              width:
                                                  ScreenUtil().setWidth(34 * 2),
                                              height: ScreenUtil().setWidth(30),
                                              decoration: BoxDecoration(
                                                // color: Colors.red,
                                                image: DecorationImage(
                                                  image: ExactAssetImage(
                                                    Utils.getImgPath(
                                                        'sms_manager'),
                                                  ),
                                                  fit: BoxFit.cover,
                                                ),
                                              ),
                                              child: Text(
                                                '特惠',
                                                style: TextStyle(
                                                    color:
                                                        MyColours.color_fefefe,
                                                    fontSize:
                                                        ScreenUtil().setSp(24)),
                                              )),
                                        )
                                      : SizedBox()
                                ])
                              ],
                            )),
                      );
                    }),
                  ),
                )
              ];
            }, body: Consumer<MyModel>(builder:
                    (BuildContext context, MyModel model, Widget? child) {
              return MediaQuery.removePadding(
                  context: context,
                  child: SingleChildScrollView(
                      child: Padding(
                          padding: EdgeInsets.symmetric(
                              horizontal: ScreenUtil().setWidth(40)),
                          child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                VEmptyView(60),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    MyDivider(ScreenUtil().setWidth(130),
                                        ScreenUtil().setWidth(2)),
                                    HEmptyView(40),
                                    Text(
                                      '常见问题说明',
                                      style: TextStyle(
                                          fontSize: ScreenUtil().setSp(28),
                                          color: MyColours.color_333333),
                                    ),
                                    HEmptyView(40),
                                    MyDivider(ScreenUtil().setWidth(130),
                                        ScreenUtil().setWidth(2))
                                  ],
                                ),
                                VEmptyView(40),
                                Text(
                                  "1.短信计费",
                                  style: TextStyle(
                                      color: MyColours.color_333333,
                                      fontSize: ScreenUtil().setSp(28),
                                      fontWeight: FontWeight.bold),
                                ),
                                Container(
                                  margin: EdgeInsets.only(
                                      top: ScreenUtil().setWidth(20),
                                      bottom: ScreenUtil().setWidth(20)),
                                  child: Text(
                                    "· 短信计费统一根据三大运营商标注计算;\n· 当短信内容字符数≤70,短信按照一条计费;\n· 当短信内容字符数>70个字符时,按照每条短信67字计算为一条短信;\n· 举个例子,如果发了一条160个字符的短信,就会按照每条67、67、26字符拆分成3条短信,按照3条短信计费。",
                                    style: TextStyle(
                                      color: MyColours.color_333333,
                                      fontSize: ScreenUtil().setSp(28),
                                    ),
                                    strutStyle: StrutStyle(
                                        forceStrutHeight: true,
                                        height: w(1),
                                        leading: w(0.3)),
                                  ),
                                ),
                                MyDivider(
                                    double.infinity, ScreenUtil().setWidth(1)),
                                VEmptyView(40),
                                Text(
                                  "2.短信统计",
                                  style: TextStyle(
                                      color: MyColours.color_333333,
                                      fontSize: ScreenUtil().setSp(28),
                                      fontWeight: FontWeight.bold),
                                ),
                                Container(
                                  margin: EdgeInsets.only(
                                      top: ScreenUtil().setWidth(20),
                                      bottom: ScreenUtil().setWidth(20)),
                                  child: Text(
                                    "· 短信统计只统计计费短信,与订单数量无关,一个订单可能会发送多条短信,则计费时按照多条短信计费。",
                                    style: TextStyle(
                                      color: MyColours.color_333333,
                                      fontSize: ScreenUtil().setSp(28),
                                    ),
                                    strutStyle: StrutStyle(
                                        forceStrutHeight: true,
                                        height: w(1),
                                        leading: w(0.3)),
                                  ),
                                ),
                                // MyDivider(
                                //     double.infinity, ScreenUtil().setWidth(1)),
                                // VEmptyView(40),
                                // Text(
                                //   "3.充值说明",
                                //   style: TextStyle(
                                //       color: MyColours.color_333333,
                                //       fontSize: ScreenUtil().setSp(28),
                                //       fontWeight: FontWeight.bold),
                                // ),
                                // Container(
                                //   margin: EdgeInsets.only(
                                //       top: ScreenUtil().setWidth(20),
                                //       bottom: ScreenUtil().setWidth(20)),
                                //   child: Text(
                                //     "· 短信统一在订座商户小程序上进行充值,充值记录和详细使用情况统一在小程序上查看。",
                                //     style: TextStyle(
                                //       color: MyColours.color_333333,
                                //       fontSize: ScreenUtil().setSp(28),
                                //     ),
                                //     strutStyle: StrutStyle(
                                //         forceStrutHeight: true,
                                //         height: 1,
                                //         leading: 0.3),
                                //   ),
                                // ),
                              ]))));
            }));
          }
        }));
  }
}