marketing_center_provider.dart 3.84 KB
import 'package:flutter/material.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:provider/provider.dart';

import '../constant/constant.dart';
import '../models/mark_data_model.dart';
import '../models/tableOuter.dart';
import '../net/base_resp.dart';
import '../net/dio_util.dart';
import '../net/http_url.dart';
import '../utils/utils.dart';
import 'choose_table_model.dart';

class MarketingCenterProvider extends ChangeNotifier {
  List<TableOuter> tableOuterList = []; //区域-桌位列表
  MarkDataModel markDataModel;

  PageState pageState = PageState.Loading;

  //获取桌位列表
  getTableList(context, {needLoading = true}) async {
    UserModel userModel = Provider.of<UserModel>(context, listen: false);
    Map<String, String> params = {"sellerid": userModel.user.sellerid};
    ChooseTableModel _chooseTableModel = ChooseTableModel();
    tableOuterList = await _chooseTableModel.getTableList(context, params,
        needLoading: needLoading);
    notifyListeners();
  }

  // 商家设置预订安排模板页面
  Future<bool> setSellerTemplateConf(
      BuildContext context, Map<String, String> params,
      {bool showLoading = true}) async {
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(context, Method.get, HttpUrl.set_seller_template_conf,
            data: params, showLoading: showLoading)
        .catchError((error) {
      print(error.toString());
      Utils.showToast('商家设置预订安排模板页面失败,请重试');
      return false;
    });
    if (baseResp.code == Constant.status_success) {
      if (baseResp.data == 0 || baseResp.data == 1) {
        return true;
      } else {
        Utils.showToast('商家设置预订安排模板页面失败,请重试');
      }
    } else {
      Utils.showToast(baseResp.msg ?? '商家设置预订安排模板页面失败,请重试');
    }
    return false;
  }

  // 设置订座商家配置信息
  Future<bool> setConfing(BuildContext context, Map<String, String> params,
      {bool showLoading = true}) async {
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(context, Method.get, HttpUrl.set_confing,
            data: params, showLoading: showLoading)
        .catchError((error) {
      print(error.toString());
      Utils.showToast('设置失败,请重试');
      return false;
    });
    if (baseResp.code == Constant.status_success) {
      if (baseResp.data == 0 || baseResp.data == 1) {
        Utils.showToast('设置成功');
        return true;
      } else {
        Utils.showToast('设置失败,请重试');
      }
    } else {
      Utils.showToast(baseResp.msg ?? '设置失败,请重试');
    }
    return false;
  }

  // 获取商家获取预订安排模板页面
  Future<bool> getSellerTemplateConf(BuildContext context,
      {bool showLoading = true}) async {
    UserModel userModel = Provider.of<UserModel>(context, listen: false);
    Map<String, String> params = {"sid": userModel.user.sellerid};
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(context, Method.get, HttpUrl.get_seller_template_conf,
            data: params, showLoading: showLoading)
        .catchError((error) {
      pageState = PageState.ConnectivityError;
      print(error.toString());
      Utils.showToast('获取商家设置预订安排模板页面失败,请重试');
      notifyListeners();
      return false;
    });
    if (baseResp.code == Constant.status_success) {
      if (baseResp.data == false) {
        pageState = PageState.Empty;
      } else {
        markDataModel = MarkDataModel.fromJson(baseResp.data);
        pageState = PageState.Success;
      }
      notifyListeners();
      return true;
    } else {
      Utils.showToast(baseResp.msg);
      pageState = PageState.ConnectivityError;
    }
    notifyListeners();
    return false;
  }
}