Commit 3280ec6b authored by 杜欣's avatar 杜欣

二级方案

parent fea4eaf7
...@@ -5,98 +5,73 @@ ...@@ -5,98 +5,73 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_common/commonModel/live/BaseModel.dart'; import 'package:flutter_common/commonModel/live/BaseModel.dart';
import 'package:flutter_common/commonModel/live/LiveData.dart'; import 'package:flutter_common/commonModel/live/LiveData.dart';
import 'package:flutter_common/commonModel/toast/NativeToast.dart';
import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart'; import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart';
import 'package:gm_flutter/ClueModel/server/entity/LevelOneFeedList.dart'; import 'package:gm_flutter/ClueModel/server/entity/LevelOneFeedList.dart';
import 'package:gm_flutter/ClueModel/server/entity/PlanOverviewBean.dart';
import 'package:gm_flutter/commonModel/GMBase.dart'; import 'package:gm_flutter/commonModel/GMBase.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
import 'package:gm_flutter/commonModel/rx/RxDispose.dart'; import 'package:gm_flutter/commonModel/rx/RxDispose.dart';
import 'package:gm_flutter/commonModel/util/PrintUtil.dart'; import 'package:gm_flutter/commonModel/util/PrintUtil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:gm_flutter/commonModel/bean/Pair.dart';
class LevelTwoModel extends BaseModel { import '../../../commonModel/bean/Pair.dart';
LiveData<double> appBarLive = LiveData();
LiveData<List<String>> rectLive = LiveData();
LiveData<List<String>> explainLive = LiveData();
LiveData<bool> showTab = LiveData();
LiveData<int> topIndexLive = new LiveData();
LiveData<double> topScrollLive = new LiveData();
LiveData<bool> loadingLive = LiveData();
RxDispose rxDispose = RxDispose();
LiveData<Pair<int, List<Cards>>> cardsLive = LiveData();
Map<int, List<Cards>> data = new Map(); class LevelTwoModel extends BaseModel {
List list = ["hospital", "doctor"]; LiveData<Pair<int, String>> nameLive = LiveData();
List pageList = [1, 1]; LiveData<Pair<int, String>> imageUrlLive = LiveData();
List pageHeightList = [149, 118]; LiveData<Pair<int, List<OverviewAttrsEntity>>> overviewAttrsLive = LiveData();
LiveData<Pair<int, List<ExplanationAttrsEntity>>> explanationAttrsLive =
LiveData();
LiveData<Pair<int, List<Tabs>>> tabsLive = LiveData();
void refreshView(bool clear, {RefreshController refreshListener}) { LiveData<int> stateLive = LiveData();
Future.delayed(Duration(seconds: 1), () { LiveData<Pair<int, List<Cards>>> cardsLive = LiveData();
Cards cards = Cards( RxDispose rxDispose = RxDispose();
cardType: "plan",
plan: Plan(planName: "ww", minPrice: "50", maxPrice: "500"));
List<Cards> a = [
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
];
List<Cards> b = [cards];
print("INDEX ${currentIndex}");
if (currentIndex == 1) {
data[currentIndex] = b;
} else {
data[currentIndex] = a;
}
cardsLive.notifyView(Pair(ENDLOADING, data)); getPlanOverview(int plan_id) {
});
int index = currentIndex;
if (clear) {
data.clear();
pageList = [1, 1];
}
ClueApiImpl.getInstance() ClueApiImpl.getInstance()
.getLevelOneList( .getPlanOverviewBean(DioUtil.getInstance().getDio(), plan_id)
DioUtil.getInstance().getDio(), 123, list[index], pageList[index]) .listen((event) {
.listen((event) {}) if (event.error == 0) {
stateLive.notifyView(ENDLOADING);
nameLive.notifyView(Pair(ENDLOADING, event.data.name));
imageUrlLive
.notifyView(Pair(ENDLOADING, event.data.banner.imageUrl));
overviewAttrsLive
.notifyView(Pair(ENDLOADING, event.data.overviewAttrs));
explanationAttrsLive
.notifyView(Pair(ENDLOADING, event.data.explanationAttrs));
tabsLive.notifyView(Pair(ENDLOADING, event.data.tabs));
} else {
NativeToast.showNativeToast(event.message);
commonError();
}
})
.addToDispose(rxDispose) .addToDispose(rxDispose)
.onError((err) { .onError((err) {
PrintUtil.printBug(err); commonError();
}); PrintUtil.printBug(err);
});
} }
int currentIndex = 0; commonError() {
stateLive.notifyView(FAIL);
nameLive.notifyView(Pair(FAIL, null));
imageUrlLive.notifyView(Pair(FAIL, null));
overviewAttrsLive.notifyView(Pair(FAIL, null));
explanationAttrsLive.notifyView(Pair(FAIL, null));
tabsLive.notifyView(Pair(FAIL, null));
}
@override @override
void dispose() { void dispose() {
showTab.dispost(); nameLive.dispost();
cardsLive.dispost(); imageUrlLive.dispost();
appBarLive.dispost(); overviewAttrsLive.dispost();
rectLive.dispost(); explanationAttrsLive.dispost();
topIndexLive.dispost(); tabsLive.dispost();
topScrollLive.dispost(); stateLive.dispost();
loadingLive.dispost(); rxDispose.dispose();
}
void selectPage(int index) {
if (currentIndex == index) {
return;
}
currentIndex = index;
if (data[currentIndex] == null) {
cardsLive.notifyView(Pair(LOADING, null));
refreshView(true);
} else {
cardsLive.notifyView(Pair(ENDLOADING, data[currentIndex]));
}
} }
void loadMore() {} void loadMore() {}
......
...@@ -5,6 +5,7 @@ import 'package:flutter_common/commonModel/toast/NativeToast.dart'; ...@@ -5,6 +5,7 @@ import 'package:flutter_common/commonModel/toast/NativeToast.dart';
import 'package:gm_flutter/ClueModel/view/FiveStarView.dart'; import 'package:gm_flutter/ClueModel/view/FiveStarView.dart';
import 'package:gm_flutter/commonModel/base/BaseComponent.dart'; import 'package:gm_flutter/commonModel/base/BaseComponent.dart';
import 'package:gm_flutter/ClueModel/page/mechanismBox/MechanismModel.dart'; import 'package:gm_flutter/ClueModel/page/mechanismBox/MechanismModel.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
class MechanismBox implements IBottomPicker { class MechanismBox implements IBottomPicker {
VoidCallback dismissCall; VoidCallback dismissCall;
...@@ -24,6 +25,30 @@ class MechanismBox implements IBottomPicker { ...@@ -24,6 +25,30 @@ class MechanismBox implements IBottomPicker {
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
return StreamBuilder(
stream: _model.stateLive.stream,
initialData: _model.stateLive.data ?? LOADING,
builder: (c, data) {
if (data.data == FAIL) {
return errorItem(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height, () {
_model.getQuestions(plan_id);
});
}
if (data.data == LOADING) {
return loadingItem();
}
return setupHome(context);
},
);
}
@override
void dispose() {
textController.dispose();
}
setupHome(context) {
MediaQueryData mq = MediaQuery.of(context); MediaQueryData mq = MediaQuery.of(context);
double keyHeight = MediaQuery.of(context).viewInsets.bottom; double keyHeight = MediaQuery.of(context).viewInsets.bottom;
return ClipRRect( return ClipRRect(
...@@ -44,11 +69,6 @@ class MechanismBox implements IBottomPicker { ...@@ -44,11 +69,6 @@ class MechanismBox implements IBottomPicker {
); );
} }
@override
void dispose() {
textController.dispose();
}
// 弹窗标题 // 弹窗标题
Widget title(mq) { Widget title(mq) {
return Container( return Container(
...@@ -197,14 +217,16 @@ class MechanismBox implements IBottomPicker { ...@@ -197,14 +217,16 @@ class MechanismBox implements IBottomPicker {
fontSize: 12), fontSize: 12),
)), )),
Expanded( Expanded(
child: StreamBuilder<List<String>>( child: StreamBuilder<Pair<int, List<String>>>(
stream: _model.questionsLive.stream, stream: _model.questionsLive.stream,
initialData: _model.questionsLive.data ?? null, initialData: _model.questionsLive.data ?? null,
builder: (c, e) { builder: (c, e) {
print('dssdadsadas');
print(e.data.toString());
if (e.data == null) { if (e.data == null) {
return Container(); return Container();
} }
List<String> questions = e.data; List<String> questions = e.data.second;
return ListView.builder( return ListView.builder(
scrollDirection: Axis.horizontal, //横向滚动 scrollDirection: Axis.horizontal, //横向滚动
itemBuilder: (c, index) { itemBuilder: (c, index) {
......
...@@ -9,17 +9,15 @@ import 'package:flutter_common/commonModel/live/BaseModel.dart'; ...@@ -9,17 +9,15 @@ import 'package:flutter_common/commonModel/live/BaseModel.dart';
import 'package:flutter_common/commonModel/live/LiveData.dart'; import 'package:flutter_common/commonModel/live/LiveData.dart';
import 'package:flutter_common/commonModel/toast/NativeToast.dart'; import 'package:flutter_common/commonModel/toast/NativeToast.dart';
import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart'; import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart';
import 'package:gm_flutter/ClueModel/server/entity/ConsultQuestionsBean.dart';
import 'package:gm_flutter/commonModel/net/DioUtil.dart'; import 'package:gm_flutter/commonModel/net/DioUtil.dart';
import 'package:gm_flutter/commonModel/rx/RxDispose.dart'; import 'package:gm_flutter/commonModel/rx/RxDispose.dart';
import 'package:gm_flutter/commonModel/util/PrintUtil.dart'; import 'package:gm_flutter/commonModel/util/PrintUtil.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
import '../../../commonModel/net/DioUtil.dart';
import '../../../commonModel/util/PrintUtil.dart';
import '../../server/api/ClueApi.serv.dart';
class MechanismModel extends BaseModel { class MechanismModel extends BaseModel {
LiveData<List<String>> questionsLive = LiveData(); LiveData<Pair<int, List<String>>> questionsLive = LiveData();
LiveData<int> stateLive = LiveData();
LiveData messageLive = LiveData(); LiveData messageLive = LiveData();
RxDispose rxDispose = RxDispose(); RxDispose rxDispose = RxDispose();
...@@ -28,26 +26,28 @@ class MechanismModel extends BaseModel { ...@@ -28,26 +26,28 @@ class MechanismModel extends BaseModel {
.getConsultQuestions(DioUtil.getInstance().getDio(), plan_id) .getConsultQuestions(DioUtil.getInstance().getDio(), plan_id)
.listen((event) { .listen((event) {
if (event.error == 0) { if (event.error == 0) {
questionsLive.notifyView(event.data.questions); stateLive.notifyView(ENDLOADING);
questionsLive.notifyView(Pair(ENDLOADING, event.data.questions));
} else { } else {
stateLive.notifyView(FAIL);
questionsLive.notifyView(Pair(FAIL, null));
NativeToast.showNativeToast(event.message); NativeToast.showNativeToast(event.message);
//TODO
} }
}) })
.addToDispose(rxDispose) .addToDispose(rxDispose)
.onError((err) { .onError((err) {
stateLive.notifyView(FAIL);
questionsLive.notifyView(Pair(FAIL, null));
PrintUtil.printBug(err); PrintUtil.printBug(err);
}); });
} }
sendMessage(List<int> doctor_ids, String question, int plan_id) { sendMessage(List<int> doctor_ids, String question, int plan_id) {
ClueApiImpl.getInstance() ClueApiImpl.getInstance()
.sendMessage(DioUtil.getInstance().getDio(), doctor_ids, .sendMessage(
question, plan_id) DioUtil.getInstance().getDio(), doctor_ids, question, plan_id)
.listen((event) { .listen((event) {
print('11111');
if (event.error == 0) { if (event.error == 0) {
print('kljfjkfdhkhkdfsklkds');
messageLive.notifyView(event.data.success); messageLive.notifyView(event.data.success);
} else { } else {
NativeToast.showNativeToast(event.message); NativeToast.showNativeToast(event.message);
...@@ -62,6 +62,7 @@ class MechanismModel extends BaseModel { ...@@ -62,6 +62,7 @@ class MechanismModel extends BaseModel {
@override @override
void dispose() { void dispose() {
questionsLive.dispost(); questionsLive.dispost();
stateLive.dispost();
rxDispose.dispose(); rxDispose.dispose();
} }
} }
...@@ -58,8 +58,9 @@ class Data { ...@@ -58,8 +58,9 @@ class Data {
String positiveRate; String positiveRate;
String salesCount; String salesCount;
String planDescription; String planDescription;
List<OverviewAttrs> overviewAttrs; String guidePrice;
List<ExplanationAttrs> explanationAttrs; List<OverviewAttrsEntity> overviewAttrs;
List<ExplanationAttrsEntity> explanationAttrs;
List<Tabs> tabs; List<Tabs> tabs;
Data( Data(
...@@ -68,6 +69,7 @@ class Data { ...@@ -68,6 +69,7 @@ class Data {
this.positiveRate, this.positiveRate,
this.salesCount, this.salesCount,
this.planDescription, this.planDescription,
this.guidePrice,
this.overviewAttrs, this.overviewAttrs,
this.explanationAttrs, this.explanationAttrs,
this.tabs}); this.tabs});
...@@ -79,16 +81,17 @@ class Data { ...@@ -79,16 +81,17 @@ class Data {
positiveRate = json['positive_rate']; positiveRate = json['positive_rate'];
salesCount = json['sales_count']; salesCount = json['sales_count'];
planDescription = json['plan_description']; planDescription = json['plan_description'];
guidePrice = json['guide_price'];
if (json['overview_attrs'] != null) { if (json['overview_attrs'] != null) {
overviewAttrs = new List<OverviewAttrs>(); overviewAttrs = new List<OverviewAttrsEntity>();
json['overview_attrs'].forEach((v) { json['overview_attrs'].forEach((v) {
overviewAttrs.add(new OverviewAttrs.fromJson(v)); overviewAttrs.add(new OverviewAttrsEntity.fromJson(v));
}); });
} }
if (json['explanation_attrs'] != null) { if (json['explanation_attrs'] != null) {
explanationAttrs = new List<ExplanationAttrs>(); explanationAttrs = new List<ExplanationAttrsEntity>();
json['explanation_attrs'].forEach((v) { json['explanation_attrs'].forEach((v) {
explanationAttrs.add(new ExplanationAttrs.fromJson(v)); explanationAttrs.add(new ExplanationAttrsEntity.fromJson(v));
}); });
} }
if (json['tabs'] != null) { if (json['tabs'] != null) {
...@@ -108,6 +111,7 @@ class Data { ...@@ -108,6 +111,7 @@ class Data {
data['positive_rate'] = this.positiveRate; data['positive_rate'] = this.positiveRate;
data['sales_count'] = this.salesCount; data['sales_count'] = this.salesCount;
data['plan_description'] = this.planDescription; data['plan_description'] = this.planDescription;
data['guide_price'] = this.guidePrice;
if (this.overviewAttrs != null) { if (this.overviewAttrs != null) {
data['overview_attrs'] = data['overview_attrs'] =
this.overviewAttrs.map((v) => v.toJson()).toList(); this.overviewAttrs.map((v) => v.toJson()).toList();
...@@ -145,14 +149,14 @@ class Banner { ...@@ -145,14 +149,14 @@ class Banner {
} }
} }
class OverviewAttrs { class OverviewAttrsEntity {
int attrId; int attrId;
String attrName; String attrName;
String attrValue; String attrValue;
OverviewAttrs({this.attrId, this.attrName, this.attrValue}); OverviewAttrsEntity({this.attrId, this.attrName, this.attrValue});
OverviewAttrs.fromJson(Map<String, dynamic> json) { OverviewAttrsEntity.fromJson(Map<String, dynamic> json) {
attrId = json['attr_id']; attrId = json['attr_id'];
attrName = json['attr_name']; attrName = json['attr_name'];
attrValue = json['attr_value']; attrValue = json['attr_value'];
...@@ -167,14 +171,14 @@ class OverviewAttrs { ...@@ -167,14 +171,14 @@ class OverviewAttrs {
} }
} }
class ExplanationAttrs { class ExplanationAttrsEntity {
int attrId; int attrId;
String attrName; String attrName;
String attrValue; String attrValue;
ExplanationAttrs({this.attrId, this.attrName, this.attrValue}); ExplanationAttrsEntity({this.attrId, this.attrName, this.attrValue});
ExplanationAttrs.fromJson(Map<String, dynamic> json) { ExplanationAttrsEntity.fromJson(Map<String, dynamic> json) {
attrId = json['attr_id']; attrId = json['attr_id'];
attrName = json['attr_name']; attrName = json['attr_name'];
attrValue = json['attr_value']; attrValue = json['attr_value'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment