collect_store_info_page.dart 13.8 KB
import 'package:city_pickers/city_pickers.dart';
import 'package:city_pickers/modal/result.dart';
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';

import '../../provider/collect_store_provider.dart';
import '../../route/navigator_util.dart';
import '../../utils/screen_util.dart';
import '../../utils/utils.dart';
import '../../widgets/round_button.dart';

/**
 * 店铺信息收集
 *  */

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

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

class _CollectStoreInfoPageState extends State<CollectStoreInfoPage> {
  TextEditingController nameC = TextEditingController();
  TextEditingController phoneC = TextEditingController();
  TextEditingController personC = TextEditingController();
  String storeAddress = '点击设置您的地址';
  double lat;
  double lng;
  String proCode;
  String cityCode;
  String disCode;

  String cityString = '点击设置您的城市';

  CollectStoreProvider collectStoreProvider;

  /// 高级筛选输入框
  Widget _textFeildWidget(
      TextEditingController controller, String name, String hintText) {
    return Container(
        padding: EdgeInsets.symmetric(
          horizontal: ScreenUtil().setWidth(32),
        ),
        height: w(48),
        alignment: Alignment.center,
        child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
          _textWidget(name, MyColours.color_515151, FontWeight.normal, 32),
          Expanded(
            child: TextField(
              maxLines: 1,
              controller: controller,
              // focusNode: _focusNode,
              // autofocus: true,
              textAlign: TextAlign.right,
              style: TextStyle(
                  color: MyColours.color_515151,
                  fontSize: ScreenUtil().setSp(32)),
              // textAlignVertical: TextAlignVertical.center,
              decoration: InputDecoration(
                hintText: hintText,
                hintStyle: TextStyle(
                  color: MyColours.color_66000000,
                  fontSize: ScreenUtil().setSp(32),
                ),
                isCollapsed: true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度
                border: OutlineInputBorder(borderSide: BorderSide.none),
                contentPadding: EdgeInsets.zero,
              ),
              keyboardType: TextInputType.text,
              textInputAction: TextInputAction.done,

              onChanged: (value) {
                // setState(() {});
                // _searchSellerLocation();
                // customerProvider.searchData(value);
              },
              onEditingComplete: () {
                FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
                // contantShowModel.searchData(
                //     contantShowModel.controller.text);
                // _searchSellerLocation();
                // _focusNode.unfocus();
              },
            ),
          ),
        ]));
  }

  ///弹框text
  _textWidget(String title, Color textColor, FontWeight fontWeight, int size) {
    return Text(title,
        style: TextStyle(
            color: textColor,
            decoration: TextDecoration.none,
            fontWeight: fontWeight,
            fontSize: ScreenUtil().setSp(size)));
  }

  _addressWidget(String name, String subtitle, GestureTapCallback onTap) {
    return InkWell(
        onTap: onTap,
        child: Container(
            padding: EdgeInsets.symmetric(
              horizontal: ScreenUtil().setWidth(32),
            ),
            height: w(48),
            alignment: Alignment.center,
            child: Row(
                // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  _textWidget(
                      name, MyColours.color_515151, FontWeight.normal, 32),
                  Expanded(
                      child: Text(
                    subtitle,
                    textAlign: TextAlign.right,
                    style: TextStyle(
                      color: subtitle == '点击设置您的地址' || subtitle == '点击设置您的城市'
                          ? MyColours.color_66000000
                          : MyColours.color_515151,
                      fontSize: ScreenUtil().setSp(32),
                    ),
                  )),
                  HEmptyView(20),
                  Image.asset(
                    "assets/arrow_right_new.png",
                    width: ScreenUtil().setWidth(14),
                    height: ScreenUtil().setWidth(22),
                  )
                ])));
  }

  Widget _divider() {
    return Padding(
        padding: EdgeInsets.only(left: w(16)),
        child: MyDivider(
          double.infinity,
          w(1),
          color: MyColours.color_E7E7E7,
        ));
  }

  @override
  Widget build(BuildContext context) {
    collectStoreProvider =
        Provider.of<CollectStoreProvider>(context, listen: true);
    return KeyboardDismissOnTap(
        child: Scaffold(
            backgroundColor: MyColours.color_ffffff,
            appBar: SystemAppBar('店铺信息'),
            body: Column(
              children: [
                Expanded(
                    child: SingleChildScrollView(
                        child: Column(
                  children: [
                    Container(
                        padding: EdgeInsets.symmetric(
                            horizontal: w(20), vertical: w(15)),
                        child: Text('在开始之前,请告诉我们关于您的一些信息,以方便专属客服给您提供周到的服务。',
                            style: TextStyle(
                                height: 1.5,
                                fontSize: font(16),
                                color: MyColours.color_000000))),
                    VEmptyView(40),
                    _textFeildWidget(nameC, '店铺名称:', '点击输入店铺名称'),
                    _divider(),
                    VEmptyView(20),
                    _addressWidget('店铺地址:', storeAddress, () {
                      //
                      FocusScope.of(context)
                          .requestFocus(FocusNode()); //点击空白处隐藏键盘
                      Utils.getPickPermission(context, () async {
                        Map address =
                            await NavigatorUtil.goMapChoicePointPage(context);
                        if (address != null) {
                          setState(() {
                            storeAddress = address['address'];

                            lat = double.parse(address['lat'].toString());
                            lng = double.parse(address['lng'].toString());
                          });
                        }
                      }, Permission.location);
                    }),
                    _divider(),
                    VEmptyView(20),
                    _textFeildWidget(phoneC, '联系电话:', '点击输入您的电话号码'),
                    _divider(),
                    VEmptyView(20),
                    _textFeildWidget(personC, '联系人:', '点击输入您的姓名'),
                    _divider(),
                    VEmptyView(20),
                    _addressWidget('城市选择:', cityString, () async {
                      FocusScope.of(context)
                          .requestFocus(FocusNode()); //点击空白处隐藏键盘
                      Result result = await CityPickers.showCityPicker(
                          context: context,
                          borderRadius: r(8),
                          cancelWidget: Container(
                            padding: EdgeInsets.symmetric(
                                horizontal: w(20), vertical: w(20)),
                            child: Text(
                              '取消',
                              style: TextStyle(
                                  color: MyColours.color_515151,
                                  fontSize: ScreenUtil().setSp(32)),
                            ),
                          ),
                          confirmWidget: Container(
                            padding: EdgeInsets.symmetric(
                                horizontal: w(20), vertical: w(20)),
                            child: Text(
                              '确定',
                              style: TextStyle(
                                  color: MyColours.color_438E93,
                                  fontSize: ScreenUtil().setSp(32)),
                            ),
                          ),
                          theme: ThemeData(
                              textTheme: TextTheme(
                            bodyText1: TextStyle(
                              fontSize: font(11),
                              // fontWeight: FontWeight.w200,
                            ),
                          )));
                      print(result);
                      if (result != null) {
                        proCode = result.provinceId;
                        cityCode = result.cityId;
                        disCode = result.areaId;
                        cityString = result.provinceName +
                            result.cityName +
                            result.areaName;
                        setState(() {});
                      }
                    }),
                    _divider(),
                  ],
                ))),
                Container(
                  height: ScreenUtil().setWidth(91 * 2),
                  width: double.infinity,
                  padding: EdgeInsets.only(
                    top: ScreenUtil().setWidth(16 * 2),
                    bottom: ScreenUtil().setWidth(35 * 2),
                    left: ScreenUtil().setWidth(45 * 2),
                    right: ScreenUtil().setWidth(45 * 2),
                  ),
                  decoration: BoxDecoration(
                    color: MyColours.color_ffffff,
                    boxShadow: [
                      BoxShadow(
                          spreadRadius: ScreenUtil().setWidth(2),
                          color: Color.fromRGBO(0, 0, 0, 0.1),
                          offset: Offset(0, ScreenUtil().setWidth(-2)),
                          blurRadius: ScreenUtil().setWidth(8))
                    ],
                    borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setWidth(16)),
                    ),
                  ),
                  child: RoundButton(
                    text: '提交',
                    height: ScreenUtil().setWidth(80),
                    radius: ScreenUtil().setWidth(10),
                    isBold: true,
                    fontSize: 32,
                    textColor: MyColours.color_F8F9FD,
                    onPressed: () async {
                      //判空
                      if (nameC.text.trim().length == 0) {
                        Utils.showToast('请输入店铺名称');
                        return;
                      }
                      // if (storeAddress == '点击设置您的地址') {
                      //   Utils.showToast('请设置您的地址');
                      //   return;
                      // }
                      if (phoneC.text.trim().length == 0) {
                        Utils.showToast('请输入联系电话');
                        return;
                      }
                      if (personC.text.trim().length == 0) {
                        Utils.showToast('请输入联系人');
                        return;
                      }
                      if (cityString == '点击设置您的城市') {
                        Utils.showToast('请设置您的城市');
                        return;
                      }
                      FocusScope.of(context)
                          .requestFocus(FocusNode()); //点击空白处隐藏键盘
                      Map<String, String> params = {
                        'sellername': nameC.text,
                        'phone': phoneC.text,
                        'rname': personC.text,
                        'pro_code': proCode,
                        'city_code': cityCode,
                        'dis_code': disCode,
                      };
                      if (storeAddress != '点击设置您的地址') {
                        //填写了地址
                        params['map_address'] = storeAddress;
                        params['lat'] = lat.toString();
                        params['long'] = lng.toString();
                      }
                      bool success = await collectStoreProvider
                          .setSellerCollect(context, params);
                      if (success) {
                        await collectStoreProvider.sendIntention(context, {
                          "shopname": nameC.text,
                          "shopnumber": phoneC.text,
                          "name": personC.text,
                          "address": storeAddress
                        });
                        //成功
                        NavigatorUtil.goCompleteStorePage(context,
                            replace: true);
                      }
                    },
                  ),
                )
              ],
            )));
  }
}