store_detail_model.dart
4.66 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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/seller_table_class_entity.dart';
import 'package:one_key/models/table_class_model.dart';
import 'package:one_key/models/table_fill_up_date_model.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:one_key/utils/utils.dart';
/**
* 餐厅详情
*/
class StoreDetailModel with ChangeNotifier {
List<SellerTableClassEntity> tables = []; //商家包间类型
TableClassSunModel? tableClassSunModel;
PageState pageState = PageState.Loading;
///添加/修改包间分类
Future<bool> setTableClass(
BuildContext context, Map<String, String?> params,
{bool showLoading = false}) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.set_table_class,
data: params, showLoading: showLoading);
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data != null) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
} catch (error) {
print(error.toString());
}
return false;
}
//获取包间分类
Future<TableClassSunModel?> getTableClassById(
BuildContext context, Map<String, String?> params) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.get_table_class_by_id,
data: params, showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {
tableClassSunModel = TableClassModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
} else {
Utils.showToast(baseResp.msg ?? "");
}
notifyListeners();
return tableClassSunModel;
} catch (error) {
print(error.toString());
}
return null;
}
//获取商家包间类型
Future<List<SellerTableClassEntity>> getSellerTableClass(
BuildContext context, Map<String, String?> params) async {
try {
BaseResp<List?> baseResp = await DioUtil().request<List>(
context, Method.post, HttpUrl.get_seller_tableclass,
data: params, showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {
tables.clear();
tables.addAll(baseResp.data!.map<SellerTableClassEntity>((value) {
return SellerTableClassEntity.fromJson(value);
}).toList());
} else {
tables.clear();
Utils.showToast(baseResp.msg ?? "");
}
notifyListeners();
return tables;
} catch (error) {
print(error.toString());
}
return [];
}
//在线预订配置-置满包间分类
Future<bool> setTableClassFull(
BuildContext context, Map<String, String?> params, int index) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.set_table_class_full,
data: params, showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {
if (params.containsKey('id')) {
if (baseResp.data == true) {
tables[index].isFull = null;
tables[index].fid = null;
return true;
}
} else {
if (baseResp.data != null) {
tables[index].isFull = 1;
tables[index].fid = baseResp.data;
return true;
}
}
notifyListeners();
} else {
Utils.showToast(baseResp.msg ?? "");
}
} catch (error) {
print(error.toString());
}
return false;
}
// 根据指定日期,返回当前商家包间类型置满情况的日期
Future<List<String>?> getTableFillUpDate(
BuildContext context, Map<String, String?> params) async {
try {
BaseResp<List?> baseResp = await DioUtil().request<List>(
context, Method.post, HttpUrl.get_table_fill_update,
data: params, showLoading: false);
List<String>? fillTimes = []; //置满的时间 2020-11-01
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data!.length > 0) {
fillTimes = TableFillUpDateModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return fillTimes;
} catch (error) {
print(error.toString());
}
return null;
}
}