From 69bccd0f71dc9cbb66e9f101b9cbb2b114026830 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Sat, 22 May 2021 18:45:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E6=88=91=E7=9A=84?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=A1=B5=E9=9D=A2=20=E5=AF=B9=E6=8E=A5=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=88=91=E7=9A=84=E8=AE=A2=E5=8D=95=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=20=E5=8F=96=E6=B6=88=E9=A2=84=E7=BA=A6=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=20=E7=94=B3=E8=AF=B7=E9=80=80=E6=8D=A2=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=20=E7=A1=AE=E8=AE=A4=E6=94=B6=E8=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 12 ++ .../market/order/my_order_list_model.dart | 96 ++++++++++ .../market/order/my_order_list_model.g.dart | 25 +++ lib/ui/market/market_page.dart | 8 +- lib/ui/market/order/my_order_card.dart | 169 ++++++++++++++++++ lib/ui/market/order/my_order_func.dart | 20 +++ lib/ui/market/order/my_order_page.dart | 50 ++++++ lib/ui/market/order/my_order_view.dart | 62 +++++++ lib/utils/card_bottom_button.dart | 52 ++++++ 9 files changed, 491 insertions(+), 3 deletions(-) create mode 100644 lib/models/market/order/my_order_list_model.dart create mode 100644 lib/models/market/order/my_order_list_model.g.dart create mode 100644 lib/ui/market/order/my_order_card.dart create mode 100644 lib/ui/market/order/my_order_func.dart create mode 100644 lib/ui/market/order/my_order_page.dart create mode 100644 lib/ui/market/order/my_order_view.dart create mode 100644 lib/utils/card_bottom_button.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index a4a77282..5bfafb53 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -315,6 +315,18 @@ class _Market { ///app商城中心:商品预约 String get appointment => '/user/shop/goodsAppointment'; + + ///app商场中心:我的订单 + String get myOrderList => '/user/shop/myOrder'; + + ///app商场中心:取消预约 + String get cancleOrder => '/user/shop/cancel'; + + ///app商场中心:申请退换 + String get refundOrder => '/user/shop/applicationRefund'; + + ///app商场中心:确认收货 + String get confirmReceive => '/user/shop/confirmReceipt'; } class _Upload { diff --git a/lib/models/market/order/my_order_list_model.dart b/lib/models/market/order/my_order_list_model.dart new file mode 100644 index 00000000..8e117a47 --- /dev/null +++ b/lib/models/market/order/my_order_list_model.dart @@ -0,0 +1,96 @@ +import 'package:equatable/equatable.dart'; + +import 'package:aku_community/model/common/img_model.dart'; +import 'package:flustars/flustars.dart'; +import 'package:flutter/material.dart'; +import 'package:json_annotation/json_annotation.dart'; +part 'my_order_list_model.g.dart'; + +@JsonSerializable() +class MyOrderListModel extends Equatable { + final int id; + final String code; + final int goodsId; + final String goodsName; + final int? backType; + final List goodsImgList; + final double sellingPrice; + final double? markingPrice; + final int num; + final int status; + final String arrivalTime; + MyOrderListModel({ + required this.id, + required this.code, + required this.goodsId, + required this.goodsName, + this.backType, + required this.goodsImgList, + required this.sellingPrice, + this.markingPrice, + required this.num, + required this.status, + required this.arrivalTime, + }); + + factory MyOrderListModel.fromJson(Map json) => + _$MyOrderListModelFromJson(json); + + String get arrivlaTimeString => + DateUtil.formatDateStr(this.arrivalTime, format: 'yyyy-MM-dd HH:mm'); + + String get statusString { + switch (this.status) { + case 1: + return '待发货'; + case 2: + return '已发货'; + case 3: + return '已收货'; + case 4: + return '申请退换货'; + case 5: + return '申请通过'; + case 6: + return '申请驳回'; + default: + return '未知'; + } + } + + Color get statusColor { + switch (this.status) { + case 1: + return Color(0xFFFF8200); + case 2: + return Color(0xFF030303); + case 3: + return Color(0xFF999999); + case 4: + return Color(0xFFFB4702); + case 5: + return Color(0xFF999999); + case 6: + return Color(0xFF999999); + default: + return Colors.black; + } + } + + @override + List get props { + return [ + id, + code, + goodsId, + goodsName, + backType, + goodsImgList, + sellingPrice, + markingPrice, + num, + status, + arrivalTime, + ]; + } +} diff --git a/lib/models/market/order/my_order_list_model.g.dart b/lib/models/market/order/my_order_list_model.g.dart new file mode 100644 index 00000000..1e6984b1 --- /dev/null +++ b/lib/models/market/order/my_order_list_model.g.dart @@ -0,0 +1,25 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'my_order_list_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +MyOrderListModel _$MyOrderListModelFromJson(Map json) { + return MyOrderListModel( + id: json['id'] as int, + code: json['code'] as String, + goodsId: json['goodsId'] as int, + goodsName: json['goodsName'] as String, + backType: json['backType'] as int?, + goodsImgList: (json['goodsImgList'] as List) + .map((e) => ImgModel.fromJson(e as Map)) + .toList(), + sellingPrice: (json['sellingPrice'] as num).toDouble(), + markingPrice: (json['markingPrice'] as num?)?.toDouble(), + num: json['num'] as int, + status: json['status'] as int, + arrivalTime: json['arrivalTime'] as String, + ); +} diff --git a/lib/ui/market/market_page.dart b/lib/ui/market/market_page.dart index d942cb72..96ed037b 100644 --- a/lib/ui/market/market_page.dart +++ b/lib/ui/market/market_page.dart @@ -1,6 +1,6 @@ // import 'package:aku_community/base/base_style.dart'; -import 'package:aku_community/ui/market/second_hand/second_hand_page.dart'; +import 'package:aku_community/ui/market/order/my_order_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -72,7 +72,8 @@ class _MarketPageState extends State minWidth: 108.w, padding: EdgeInsets.zero, onPressed: () async { - Get.to(() => SecondHandPage()); + // Get.to(() => SecondHandPage()); + Get.to(() => MyOrderPage()); }, child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -84,7 +85,8 @@ class _MarketPageState extends State height: 48.w, ), 4.hb, - '二手'.text.size(20.sp).black.make(), + // '二手'.text.size(20.sp).black.make(), + '订单'.text.size(20.sp).black.make(), ], ), ), diff --git a/lib/ui/market/order/my_order_card.dart b/lib/ui/market/order/my_order_card.dart new file mode 100644 index 00000000..5fa83ff1 --- /dev/null +++ b/lib/ui/market/order/my_order_card.dart @@ -0,0 +1,169 @@ +import 'package:aku_community/base/base_style.dart'; +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/model/common/img_model.dart'; +import 'package:aku_community/models/market/order/my_order_list_model.dart'; +import 'package:aku_community/ui/market/order/my_order_func.dart'; +import 'package:aku_community/utils/card_bottom_button.dart'; +import 'package:aku_community/widget/bee_divider.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:aku_community/const/resource.dart'; +import 'package:aku_community/extensions/widget_list_ext.dart'; + +class MyOrderCard extends StatefulWidget { + final MyOrderListModel model; + final VoidCallback callRefresh; + MyOrderCard({Key? key, required this.model, required this.callRefresh}) + : super(key: key); + + @override + _MyOrderCardState createState() => _MyOrderCardState(); +} + +class _MyOrderCardState extends State { + @override + Widget build(BuildContext context) { + return Container( + width: double.infinity, + decoration: BoxDecoration( + color: Colors.white, + ), + padding: EdgeInsets.symmetric(vertical: 32.w, horizontal: 32.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + widget.model.goodsName.text + .size(32.sp) + .bold + .color(ktextPrimary) + .make(), + Spacer(), + widget.model.statusString.text + .size(30.sp) + .bold + .color(widget.model.statusColor) + .make(), + ], + ), + 16.w.heightBox, + BeeDivider.horizontal(), + 24.w.heightBox, + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(8.w), + clipBehavior: Clip.antiAlias, + child: FadeInImage.assetNetwork( + width: 160.w, + height: 160.w, + fit: BoxFit.cover, + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: + API.image(ImgModel.first(widget.model.goodsImgList))), + ), + Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.model.goodsName.text + .size(28.sp) + .color(ktextPrimary) + .maxLines(2) + .overflow(TextOverflow.ellipsis) + .bold + .make(), + Spacer(), + '¥${widget.model.sellingPrice}' + .text + .size(28.sp) + .bold + .color(Color(0xFFE60E0E)) + .make(), + ], + ), + //TODO: 缺少字段 居家生活等副标题及商品规格 + ...[ + _rowTile('下单时间', widget.model.arrivlaTimeString), + _rowTile('到达地点', '人才公寓小区北侧门口'), + _rowTile('发货时间', widget.model.arrivlaTimeString), + ].sepWidget(separate: 16.w.heightBox), + ], + ) + ], + ), + _bottomWidget(), + ], + ), + ); + } + + Widget _bottomWidget() { + List _buttons = _getBottomButton(widget.model.status); + + return _buttons.isEmpty + ? SizedBox() + : Row( + children: [Spacer(), ..._buttons], + ); + } + + List _getBottomButton(int status) { + switch (status) { + case 1: + return [ + CardBottomButton.white( + text: '取消预约', + onPressed: () async { + await MyOrderFunc.cancelOrder(widget.model.id); + widget.callRefresh(); + }), + CardBottomButton.yellow( + text: '确认收货', + onPressed: () async { + await MyOrderFunc.confirmReceive(widget.model.id); + widget.callRefresh(); + }), + ].sepWidget(separate: 24.w.widthBox); + case 2: + return [ + // CardBottomButton.white(text: '提醒商家', onPressed: () {}), + ].sepWidget(separate: 24.w.widthBox); + case 3: + return [ + // CardBottomButton.white(text: '商品投诉', onPressed: () {}), + CardBottomButton.white( + text: '申请退换', + onPressed: () async { + await MyOrderFunc.refundOrder(widget.model.id); + widget.callRefresh(); + }), + // CardBottomButton.yellow(text: '查看详情', onPressed: () {}), + ].sepWidget(separate: 24.w.widthBox); + case 4: + return [ + // CardBottomButton.white(text: '查看详情', onPressed: () {}), + // CardBottomButton.yellow(text: '完成退换', onPressed: () {}), + ].sepWidget(separate: 24.w.widthBox); + default: + return []; + } + } + + Widget _rowTile( + String title, + String content, + ) { + return Row( + children: [ + title.text.size(24.sp).color(ktextSubColor).make(), + Spacer(), + content.text.size(24.sp).color(ktextPrimary).make(), + ], + ); + } +} diff --git a/lib/ui/market/order/my_order_func.dart b/lib/ui/market/order/my_order_func.dart new file mode 100644 index 00000000..08c27960 --- /dev/null +++ b/lib/ui/market/order/my_order_func.dart @@ -0,0 +1,20 @@ +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/utils/network/base_model.dart'; +import 'package:aku_community/utils/network/net_util.dart'; + +class MyOrderFunc { + static Future confirmReceive(int goodsAppointmentId) async { + BaseModel baseModel = await NetUtil().get(API.market.confirmReceive, + params: {"goodsAppointmentId": goodsAppointmentId}, showMessage: true); + } + + static Future refundOrder(int goodsAppointmentId) async { + BaseModel baseModel = await NetUtil().get(API.market.confirmReceive, + params: {"goodsAppointmentId": goodsAppointmentId}, showMessage: true); + } + + static Future cancelOrder(int goodsAppointmentId) async { + BaseModel baseModel = await NetUtil().get(API.market.confirmReceive, + params: {"goodsAppointmentId": goodsAppointmentId}, showMessage: true); + } +} diff --git a/lib/ui/market/order/my_order_page.dart b/lib/ui/market/order/my_order_page.dart new file mode 100644 index 00000000..184b332a --- /dev/null +++ b/lib/ui/market/order/my_order_page.dart @@ -0,0 +1,50 @@ +import 'package:aku_community/ui/market/order/my_order_view.dart'; +import 'package:aku_community/widget/bee_scaffold.dart'; +import 'package:aku_community/widget/tab_bar/bee_tab_bar.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class MyOrderPage extends StatefulWidget { + MyOrderPage({Key? key}) : super(key: key); + + @override + _MyOrderPageState createState() => _MyOrderPageState(); +} + +class _MyOrderPageState extends State + with TickerProviderStateMixin { + late TabController _tabController; + List _tabs = [ + '待发货', + '已发货', + '已收货', + '退换/投诉', + ]; + + @override + void initState() { + _tabController = TabController(length: _tabs.length, vsync: this); + super.initState(); + } + + @override + void dispose() { + _tabController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '我的订单', + appBarBottom: PreferredSize( + preferredSize: Size.fromHeight(88.w), + child: BeeTabBar(controller: _tabController, tabs: _tabs), + ), + body: TabBarView( + controller: _tabController, + children: List.generate( + _tabs.length, (index) => MyOrderView(index: index))), + ); + } +} diff --git a/lib/ui/market/order/my_order_view.dart b/lib/ui/market/order/my_order_view.dart new file mode 100644 index 00000000..c506f568 --- /dev/null +++ b/lib/ui/market/order/my_order_view.dart @@ -0,0 +1,62 @@ +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/models/market/order/my_order_list_model.dart'; +import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; +import 'package:aku_community/ui/market/order/my_order_card.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class MyOrderView extends StatefulWidget { + final int index; + MyOrderView({Key? key, required this.index}) : super(key: key); + + @override + _MyOrderViewState createState() => _MyOrderViewState(); +} + +class _MyOrderViewState extends State { + late EasyRefreshController _refreshController; + @override + void initState() { + super.initState(); + _refreshController = EasyRefreshController(); + } + + @override + void dispose() { + _refreshController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BeeListView( + path: API.market.myOrderList, + controller: _refreshController, + extraParams: { + "orderStart":widget.index+1 + }, + convert: (models) { + return models.tableList! + .map((e) => MyOrderListModel.fromJson(e)) + .toList(); + }, + builder: (items) { + return ListView.separated( + padding: EdgeInsets.symmetric(vertical: 24.w,horizontal: 32.w), + itemBuilder: (context, index) { + return MyOrderCard( + model: items[index], + callRefresh: () { + _refreshController.callRefresh(); + }, + ); + }, + separatorBuilder: (_, __) { + return 24.w.heightBox; + }, + itemCount: items.length); + }); + } +} diff --git a/lib/utils/card_bottom_button.dart b/lib/utils/card_bottom_button.dart new file mode 100644 index 00000000..a83a1d13 --- /dev/null +++ b/lib/utils/card_bottom_button.dart @@ -0,0 +1,52 @@ +import 'package:aku_community/base/base_style.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class CardBottomButton extends StatelessWidget { + final String text; + final Color textColor; + final Color bgColor; + final bool hasBorder; + final VoidCallback onPressed; + const CardBottomButton( + {Key? key, + required this.text, + required this.textColor, + required this.bgColor, + this.hasBorder = false, + required this.onPressed}) + : super(key: key); + CardBottomButton.white( + {Key? key, + required this.text, + required this.onPressed, + }) : this.bgColor = Colors.white, + this.textColor = ktextPrimary, + this.hasBorder = true, + super(key: key); + CardBottomButton.yellow( + {Key? key, + required this.text, + required this.onPressed, + }) : this.bgColor = Color(0xFFFFC40C), + this.textColor = ktextPrimary, + this.hasBorder = false, + super(key: key); + @override + Widget build(BuildContext context) { + return MaterialButton( + onPressed: this.onPressed, + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(74.w), + side: this.hasBorder + ? BorderSide(color: Color(0xFF999999), width: 2.w) + : BorderSide.none), + child: text.text.size(26.sp).color(this.textColor).bold.make(), + color: this.bgColor, + padding: EdgeInsets.symmetric(vertical: 8.w, horizontal: 24.w), + height: 52.w, + ); + } +}