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

二级方案

parent fea4eaf7
......@@ -5,98 +5,73 @@
import 'package:flutter/material.dart';
import 'package:flutter_common/commonModel/live/BaseModel.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/entity/LevelOneFeedList.dart';
import 'package:gm_flutter/ClueModel/server/entity/PlanOverviewBean.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/util/PrintUtil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
import '../../../commonModel/bean/Pair.dart';
class LevelTwoModel extends BaseModel {
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();
LiveData<Pair<int, String>> nameLive = LiveData();
LiveData<Pair<int, String>> imageUrlLive = LiveData();
LiveData<Pair<int, List<OverviewAttrsEntity>>> overviewAttrsLive = LiveData();
LiveData<Pair<int, List<ExplanationAttrsEntity>>> explanationAttrsLive =
LiveData();
LiveData<Pair<int, List<Tabs>>> tabsLive = LiveData();
Map<int, List<Cards>> data = new Map();
List list = ["hospital", "doctor"];
List pageList = [1, 1];
List pageHeightList = [149, 118];
LiveData<int> stateLive = LiveData();
LiveData<Pair<int, List<Cards>>> cardsLive = LiveData();
RxDispose rxDispose = RxDispose();
void refreshView(bool clear, {RefreshController refreshListener}) {
Future.delayed(Duration(seconds: 1), () {
Cards cards = Cards(
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;
getPlanOverview(int plan_id) {
ClueApiImpl.getInstance()
.getPlanOverviewBean(DioUtil.getInstance().getDio(), plan_id)
.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 {
data[currentIndex] = a;
}
cardsLive.notifyView(Pair(ENDLOADING, data));
});
int index = currentIndex;
if (clear) {
data.clear();
pageList = [1, 1];
NativeToast.showNativeToast(event.message);
commonError();
}
ClueApiImpl.getInstance()
.getLevelOneList(
DioUtil.getInstance().getDio(), 123, list[index], pageList[index])
.listen((event) {})
})
.addToDispose(rxDispose)
.onError((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
void dispose() {
showTab.dispost();
cardsLive.dispost();
appBarLive.dispost();
rectLive.dispost();
topIndexLive.dispost();
topScrollLive.dispost();
loadingLive.dispost();
}
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]));
}
nameLive.dispost();
imageUrlLive.dispost();
overviewAttrsLive.dispost();
explanationAttrsLive.dispost();
tabsLive.dispost();
stateLive.dispost();
rxDispose.dispose();
}
void loadMore() {}
......
......@@ -11,6 +11,7 @@ import 'package:flutter_common/commonModel/picker/base/BaseBottomPicker.dart';
import 'package:gm_flutter/ClueModel/page/levelTwo/LevelTwoModel.dart';
import 'package:gm_flutter/ClueModel/page/mechanismBox/MechanismBoxPage.dart';
import 'package:gm_flutter/ClueModel/server/entity/LevelOneFeedList.dart';
import 'package:gm_flutter/ClueModel/server/entity/PlanOverviewBean.dart';
import 'package:gm_flutter/ClueModel/view/FiveStarView.dart';
import 'package:gm_flutter/commonModel/base/BaseState.dart';
import 'package:gm_flutter/commonModel/base/BaseUtil.dart';
......@@ -18,6 +19,10 @@ import 'package:gm_flutter/commonModel/base/BaseComponent.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
import '../../../commonModel/bean/Pair.dart';
import '../../../commonModel/bean/Pair.dart';
import '../../../commonModel/bean/Pair.dart';
class LevelTwoPage extends StatefulWidget {
@required
final int plan_id;
......@@ -39,6 +44,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
void initState() {
super.initState();
this.tabController = TabController(length: 2, vsync: this);
_model.getPlanOverview(this.widget.plan_id);
}
@override
......@@ -52,11 +58,13 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
@override
Widget buildItem(BuildContext context) {
return Scaffold(
body: StreamBuilder<bool>(
stream: _model.loadingLive.stream,
initialData: true,
body: StreamBuilder<int>(
stream: _model.stateLive.stream,
initialData: _model.stateLive.data ?? LOADING,
builder: (c, data) {
if (!data.data) {
print("ddsadsadsadsa");
print(data);
if (data.data == FAIL) {
return loadingItem();
} else {
return home();
......@@ -73,7 +81,9 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
pinned: true,
elevation: 0,
expandedHeight: 0,
flexibleSpace: FlexibleSpaceBar(title: Text('二级方案')),
flexibleSpace: FlexibleSpaceBar(title: title((data) {
return Text(data);
})),
),
SliverToBoxAdapter(
child: Column(
......@@ -89,48 +99,70 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
scroll: false),
),
),
SliverFillRemaining(child: pages())
// SliverFillRemaining(child: pages())
]),
Positioned(left: 0, right: 0, bottom: 0, child: bottomWidget())
],
);
}
// 方案名称
Widget title(Function text) {
return StreamBuilder<Pair<int, String>>(
stream: _model.nameLive.stream,
initialData: _model.nameLive.data ?? Pair(LOADING, null),
builder: (context, e) {
if (e.data.first == FAIL) {
return Text('');
}
return text(e.data.second);
},
);
}
// 方案顶部
Widget good() {
return StreamBuilder(
stream: _model.rectLive.stream,
initialData: ["w", "w", "q", "w"],
builder: (context, data) {
return Padding(
padding: EdgeInsets.only(left: 15.0, right: 15.0, top: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
ClipRRect(
StreamBuilder<Pair<int, String>>(
stream: _model.imageUrlLive.stream,
initialData: _model.imageUrlLive.data ?? null,
builder: (context, e) {
if (e.data.first == FAIL) {
return Container();
}
return ClipRRect(
borderRadius: BorderRadius.circular(6),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17),
border: Border.all(color: Color(0xffF9F8FB), width: 1)),
border:
Border.all(color: Color(0xffF9F8FB), width: 1)),
child: Image.network(
'https://img1.gamersky.com/image2019/07/20190725_ll_red_136_2/gamersky_07small_14_201972510258D0.jpg',
e.data.second,
width: 86,
height: 86,
fit: BoxFit.cover,
),
)),
));
}),
Padding(
padding: EdgeInsets.only(left: 12, top: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text('乔雅登玻尿酸(药品类)',
title((data) {
return Text(data,
style: TextStyle(
color: Color(0xff333333),
fontSize: 15,
fontWeight: FontWeight.bold)),
fontWeight: FontWeight.bold));
}),
Padding(padding: EdgeInsets.only(top: 5)),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
......@@ -141,8 +173,8 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
color: Color(0xff999999), fontSize: 12)),
Text(
'¥2000-5000',
style: TextStyle(
color: Color(0xffFF5963), fontSize: 12),
style:
TextStyle(color: Color(0xffFF5963), fontSize: 12),
)
],
)
......@@ -151,19 +183,22 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
],
),
);
},
);
}
// 方案属性
Widget rect() {
return Padding(
padding: EdgeInsets.only(top: 20),
child: StreamBuilder<List<String>>(
stream: _model.rectLive.stream,
initialData: ["w", "w", "q", "w", "w", "w", "q", "w"],
child: StreamBuilder<Pair<int, List<OverviewAttrsEntity>>>(
stream: _model.overviewAttrsLive.stream,
initialData: _model.overviewAttrsLive.data ?? Pair(LOADING, null),
builder: (c, data) {
if (data.data.first == FAIL) {
return Center();
}
final overviewAttrs = data.data.second;
List<Widget> list = List();
for (int i = 0; i < data.data.length; i += 2) {
for (int i = 0; i < overviewAttrs.length; i += 2) {
list.add(Expanded(
child: Container(
alignment: Alignment.center,
......@@ -171,13 +206,14 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
baseText(data.data[i], 14, Color(0xff282828), bold: true),
baseText(data.data[i + 1], 11, Color(0xff999999)),
baseText(overviewAttrs[i].attrName, 14, Color(0xff282828),
bold: true),
baseText(overviewAttrs[i].attrValue, 11, Color(0xff999999)),
],
),
),
));
if (i < data.data.length - 2) {
if (i < overviewAttrs.length - 2) {
list.add(Container(
width: 0.5,
height: 18,
......@@ -203,12 +239,14 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
);
}
// 方案项目说明
Widget explain() {
return StreamBuilder<List<String>>(
stream: _model.explainLive.stream,
initialData: ["www", "www", "www", "??"],
return StreamBuilder<Pair<int, List<ExplanationAttrsEntity>>>(
stream: _model.explanationAttrsLive.stream,
initialData: _model.explanationAttrsLive.data ?? Pair(LOADING, null),
builder: (c, data) {
List<Widget> list = [];
List<ExplanationAttrsEntity> explanationAttrs = data.data.second;
list.add(Container(
height: 31,
child: Row(
......@@ -227,15 +265,16 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
],
),
));
for (int i = 0; i < data.data.length; i += 2) {
for (int i = 0; i < explanationAttrs.length; i += 2) {
list.add(Container(
height: 28,
child: Row(
children: <Widget>[
baseText(data.data[i], 13, Color(0xff999999)),
baseText(explanationAttrs[i].attrName, 13, Color(0xff999999)),
Container(
margin: EdgeInsets.only(left: 12),
child: baseText(data.data[i + 1], 13, Color(0xff666666)),
child: baseText(
explanationAttrs[i].attrValue, 13, Color(0xff666666)),
)
],
),
......@@ -252,6 +291,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
);
}
// 底部按钮
Widget bottomWidget() {
return Container(
width: double.maxFinite,
......@@ -316,6 +356,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
);
}
// 列表页面
Widget pages() {
return StreamBuilder<Pair<int, List<Cards>>>(
stream: _model.cardsLive.stream,
......@@ -326,7 +367,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
width: double.maxFinite,
child: TabBarView(
controller: tabController,
children: _model.data[tabController.index].map((e) {
children: data.data.second[tabController.index].map((e) {
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemBuilder: (c, index) {
......@@ -338,6 +379,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
});
}
// 医生卡片
Widget DoctorItem(BuildContext context, cards) {
if (cards.doctor == null && isDebug) {
throw new Exception();
......@@ -406,6 +448,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
);
}
// 医院卡片
Widget HospitalItem(BuildContext context, cards) {
if (cards.hospital == null && isDebug) {
throw new Exception();
......@@ -476,6 +519,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
));
}
// 获取低价按钮
Widget lowPriceWidget() {
return GestureDetector(
behavior: HitTestBehavior.opaque,
......@@ -491,6 +535,7 @@ class _LevelTwoPageState extends BaseState<LevelTwoPage>
);
}
// 咨询按钮
Widget askWidget() {
return GestureDetector(
behavior: HitTestBehavior.opaque,
......
......@@ -5,6 +5,7 @@ import 'package:flutter_common/commonModel/toast/NativeToast.dart';
import 'package:gm_flutter/ClueModel/view/FiveStarView.dart';
import 'package:gm_flutter/commonModel/base/BaseComponent.dart';
import 'package:gm_flutter/ClueModel/page/mechanismBox/MechanismModel.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
class MechanismBox implements IBottomPicker {
VoidCallback dismissCall;
......@@ -24,6 +25,30 @@ class MechanismBox implements IBottomPicker {
}
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);
double keyHeight = MediaQuery.of(context).viewInsets.bottom;
return ClipRRect(
......@@ -44,11 +69,6 @@ class MechanismBox implements IBottomPicker {
);
}
@override
void dispose() {
textController.dispose();
}
// 弹窗标题
Widget title(mq) {
return Container(
......@@ -197,14 +217,16 @@ class MechanismBox implements IBottomPicker {
fontSize: 12),
)),
Expanded(
child: StreamBuilder<List<String>>(
child: StreamBuilder<Pair<int, List<String>>>(
stream: _model.questionsLive.stream,
initialData: _model.questionsLive.data ?? null,
builder: (c, e) {
print('dssdadsadas');
print(e.data.toString());
if (e.data == null) {
return Container();
}
List<String> questions = e.data;
List<String> questions = e.data.second;
return ListView.builder(
scrollDirection: Axis.horizontal, //横向滚动
itemBuilder: (c, index) {
......
......@@ -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/toast/NativeToast.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/rx/RxDispose.dart';
import 'package:gm_flutter/commonModel/util/PrintUtil.dart';
import '../../../commonModel/net/DioUtil.dart';
import '../../../commonModel/util/PrintUtil.dart';
import '../../server/api/ClueApi.serv.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
class MechanismModel extends BaseModel {
LiveData<List<String>> questionsLive = LiveData();
LiveData<Pair<int, List<String>>> questionsLive = LiveData();
LiveData<int> stateLive = LiveData();
LiveData messageLive = LiveData();
RxDispose rxDispose = RxDispose();
......@@ -28,26 +26,28 @@ class MechanismModel extends BaseModel {
.getConsultQuestions(DioUtil.getInstance().getDio(), plan_id)
.listen((event) {
if (event.error == 0) {
questionsLive.notifyView(event.data.questions);
stateLive.notifyView(ENDLOADING);
questionsLive.notifyView(Pair(ENDLOADING, event.data.questions));
} else {
stateLive.notifyView(FAIL);
questionsLive.notifyView(Pair(FAIL, null));
NativeToast.showNativeToast(event.message);
//TODO
}
})
.addToDispose(rxDispose)
.onError((err) {
stateLive.notifyView(FAIL);
questionsLive.notifyView(Pair(FAIL, null));
PrintUtil.printBug(err);
});
}
sendMessage(List<int> doctor_ids, String question, int plan_id) {
ClueApiImpl.getInstance()
.sendMessage(DioUtil.getInstance().getDio(), doctor_ids,
question, plan_id)
.sendMessage(
DioUtil.getInstance().getDio(), doctor_ids, question, plan_id)
.listen((event) {
print('11111');
if (event.error == 0) {
print('kljfjkfdhkhkdfsklkds');
messageLive.notifyView(event.data.success);
} else {
NativeToast.showNativeToast(event.message);
......@@ -62,6 +62,7 @@ class MechanismModel extends BaseModel {
@override
void dispose() {
questionsLive.dispost();
stateLive.dispost();
rxDispose.dispose();
}
}
......@@ -58,8 +58,9 @@ class Data {
String positiveRate;
String salesCount;
String planDescription;
List<OverviewAttrs> overviewAttrs;
List<ExplanationAttrs> explanationAttrs;
String guidePrice;
List<OverviewAttrsEntity> overviewAttrs;
List<ExplanationAttrsEntity> explanationAttrs;
List<Tabs> tabs;
Data(
......@@ -68,6 +69,7 @@ class Data {
this.positiveRate,
this.salesCount,
this.planDescription,
this.guidePrice,
this.overviewAttrs,
this.explanationAttrs,
this.tabs});
......@@ -79,16 +81,17 @@ class Data {
positiveRate = json['positive_rate'];
salesCount = json['sales_count'];
planDescription = json['plan_description'];
guidePrice = json['guide_price'];
if (json['overview_attrs'] != null) {
overviewAttrs = new List<OverviewAttrs>();
overviewAttrs = new List<OverviewAttrsEntity>();
json['overview_attrs'].forEach((v) {
overviewAttrs.add(new OverviewAttrs.fromJson(v));
overviewAttrs.add(new OverviewAttrsEntity.fromJson(v));
});
}
if (json['explanation_attrs'] != null) {
explanationAttrs = new List<ExplanationAttrs>();
explanationAttrs = new List<ExplanationAttrsEntity>();
json['explanation_attrs'].forEach((v) {
explanationAttrs.add(new ExplanationAttrs.fromJson(v));
explanationAttrs.add(new ExplanationAttrsEntity.fromJson(v));
});
}
if (json['tabs'] != null) {
......@@ -108,6 +111,7 @@ class Data {
data['positive_rate'] = this.positiveRate;
data['sales_count'] = this.salesCount;
data['plan_description'] = this.planDescription;
data['guide_price'] = this.guidePrice;
if (this.overviewAttrs != null) {
data['overview_attrs'] =
this.overviewAttrs.map((v) => v.toJson()).toList();
......@@ -145,14 +149,14 @@ class Banner {
}
}
class OverviewAttrs {
class OverviewAttrsEntity {
int attrId;
String attrName;
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'];
attrName = json['attr_name'];
attrValue = json['attr_value'];
......@@ -167,14 +171,14 @@ class OverviewAttrs {
}
}
class ExplanationAttrs {
class ExplanationAttrsEntity {
int attrId;
String attrName;
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'];
attrName = json['attr_name'];
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