import 'package:zhiying_comm/zhiying_comm.dart';

class GoodsDetailsPageRepository {
  List<Map<String, dynamic>> _pageData = [];

  /// 初始化
  Future<List<Map<String, dynamic>>> fetchInitData(Map<String, dynamic> model) async {
    int id = 13;
    var result = await NetUtil.post('/api/v1/mod',
        method: NetMethod.POST,
        params: Map<String, dynamic>.from({
          'ids': [id]
        }));
    try {
      if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
        return _loadData(id, result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
      }
    } catch (e) {
      Logger.log(e);
    }
    return null;
  }

  /// 处理数据
  List<Map<String, dynamic>> _loadData(int id, dynamic data) {
    String key = id.toString();
    Map<String, dynamic> json = Map<String, dynamic>.from(data);
    if (json.containsKey(key)) {
      List<dynamic> list = json[key];
      _pageData = list.map((item) {
        return Map<String, dynamic>.from(item);
      }).toList();
      return _pageData;
    }
    return null;
  }

  /// 获取缓存数据？

}
