提交 8c870c25 authored 作者: yueweilu's avatar yueweilu

支付时选择优惠券界面

上级 0bbfc72e
...@@ -54,6 +54,46 @@ abstract class ShopAPI { ...@@ -54,6 +54,46 @@ abstract class ShopAPI {
}); });
} }
/// 4、获取使用积分
///
static Future <CreditPointModel> creditPoints({
required String price,
}) async {
final result = await HttpService.to.post(
'/v1/coupon/Coupon/getIntegral',
params: {
'price': price,
},
);
if (result.data is! Map ) return CreditPointModel();
return CreditPointModel.fromJson(result.data);
}
/// 5、优惠券和积分是否展示
///
static Future <ShowModel> show() async {
final result = await HttpService.to.post(
'/v1/orders/Orders/getSetting',
params: {},
);
if (result.data is! Map ) return ShowModel();
return ShowModel.fromJson(result.data);
}
/// 6、 支付时选的优惠券列表
static Future<CouponListModel> coupon({
int page = 1,
int limit = 10,
required String type,
required String price
}) async {
final result = await HttpService.to.post(
'/v1/coupon/Coupon/getCouponAll',
params: {'page': page, 'page_size': limit, 'type': type,'price':price},
);
if (result.data is! Map ) return CouponListModel();
return CouponListModel.fromJson(result.data);
}
} }
\ No newline at end of file
...@@ -11,4 +11,5 @@ part 'user_model.dart'; ...@@ -11,4 +11,5 @@ part 'user_model.dart';
part 'msg.dart'; part 'msg.dart';
part 'study_history.dart'; part 'study_history.dart';
part 'library.dart'; part 'library.dart';
part 'mine.dart'; part 'mine.dart';
\ No newline at end of file part 'shop.dart';
\ No newline at end of file
...@@ -71,7 +71,7 @@ class RecordModel { ...@@ -71,7 +71,7 @@ class RecordModel {
class CouponModel { class CouponModel {
CouponModel({ CouponModel({
this.couponRecId, this.couponRecId,
this.endTime, // this.endTime,
this.couponId, this.couponId,
this.useStatus, this.useStatus,
this.couponName, this.couponName,
...@@ -81,7 +81,7 @@ class CouponModel { ...@@ -81,7 +81,7 @@ class CouponModel {
CouponModel.fromJson(dynamic json) { CouponModel.fromJson(dynamic json) {
couponRecId = json['coupon_rec_id']; couponRecId = json['coupon_rec_id'];
endTime = json['end_time']; // endTime = json['end_time'];
couponId = json['coupon_id']; couponId = json['coupon_id'];
useStatus = json['use_status']; useStatus = json['use_status'];
couponName = json['coupon_name']; couponName = json['coupon_name'];
...@@ -90,7 +90,7 @@ class CouponModel { ...@@ -90,7 +90,7 @@ class CouponModel {
} }
num? couponRecId; num? couponRecId;
String? endTime; // String? endTime;
num? couponId; num? couponId;
num? useStatus; num? useStatus;
String? couponName; String? couponName;
...@@ -108,7 +108,7 @@ class CouponModel { ...@@ -108,7 +108,7 @@ class CouponModel {
}) => }) =>
CouponModel( CouponModel(
couponRecId: couponRecId ?? this.couponRecId, couponRecId: couponRecId ?? this.couponRecId,
endTime: endTime ?? this.endTime, // endTime: endTime ?? this.endTime,
couponId: couponId ?? this.couponId, couponId: couponId ?? this.couponId,
useStatus: useStatus ?? this.useStatus, useStatus: useStatus ?? this.useStatus,
couponName: couponName ?? this.couponName, couponName: couponName ?? this.couponName,
...@@ -119,7 +119,7 @@ class CouponModel { ...@@ -119,7 +119,7 @@ class CouponModel {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final map = <String, dynamic>{}; final map = <String, dynamic>{};
map['coupon_rec_id'] = couponRecId; map['coupon_rec_id'] = couponRecId;
map['end_time'] = endTime; // map['end_time'] = endTime;
map['coupon_id'] = couponId; map['coupon_id'] = couponId;
map['use_status'] = useStatus; map['use_status'] = useStatus;
map['coupon_name'] = couponName; map['coupon_name'] = couponName;
......
part of models;
class PayModel { class PayModel {
PayModel({ PayModel({
required this.type, required this.type,
...@@ -12,4 +14,112 @@ class PayModel { ...@@ -12,4 +14,112 @@ class PayModel {
String icon; String icon;
bool selected; bool selected;
}
/// 可使用积分模型
class CreditPointModel {
CreditPointModel({
this.integral,
this.onePointDeductionAmount,
this.integralUseLimit,
this.integralSwitch,
this.deductibleAmount,
this.deductibleIntegral,});
CreditPointModel.fromJson(dynamic json) {
integral = json['integral'];
onePointDeductionAmount = json['one_point_deduction_amount'];
integralUseLimit = json['integral_use_limit'];
integralSwitch = json['integral_switch'];
deductibleAmount = json['deductible_amount'];
deductibleIntegral = json['deductible_integral'];
}
num? integral;
String? onePointDeductionAmount;
String? integralUseLimit;
String? integralSwitch;
String? deductibleAmount;
num? deductibleIntegral;
CreditPointModel copyWith({ num? integral,
String? onePointDeductionAmount,
String? integralUseLimit,
String? integralSwitch,
String? deductibleAmount,
num? deductibleIntegral,
}) => CreditPointModel( integral: integral ?? this.integral,
onePointDeductionAmount: onePointDeductionAmount ?? this.onePointDeductionAmount,
integralUseLimit: integralUseLimit ?? this.integralUseLimit,
integralSwitch: integralSwitch ?? this.integralSwitch,
deductibleAmount: deductibleAmount ?? this.deductibleAmount,
deductibleIntegral: deductibleIntegral ?? this.deductibleIntegral,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['integral'] = integral;
map['one_point_deduction_amount'] = onePointDeductionAmount;
map['integral_use_limit'] = integralUseLimit;
map['integral_switch'] = integralSwitch;
map['deductible_amount'] = deductibleAmount;
map['deductible_integral'] = deductibleIntegral;
return map;
}
}
/// 优惠券和 积分是否展示模型
class ShowModel {
ShowModel({
this.couponSwitch,
this.integralSwitch,});
ShowModel.fromJson(dynamic json) {
couponSwitch = json['coupon_switch'];
integralSwitch = json['integral_switch'];
}
String? couponSwitch;
String? integralSwitch;
ShowModel copyWith({ String? couponSwitch,
String? integralSwitch,
}) => ShowModel( couponSwitch: couponSwitch ?? this.couponSwitch,
integralSwitch: integralSwitch ?? this.integralSwitch,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['coupon_switch'] = couponSwitch;
map['integral_switch'] = integralSwitch;
return map;
}
}
class CouponListModel {
CouponListModel({
this.list,
this.total,});
CouponListModel.fromJson(dynamic json) {
if (json['list'] != null) {
list = [];
json['list'].forEach((v) {
list?.add(CouponModel.fromJson(v));
});
}
total = json['total'];
}
List<CouponModel>? list;
num? total;
CouponListModel copyWith({ List<CouponModel>? list,
num? total,
}) => CouponListModel( list: list ?? this.list,
total: total ?? this.total,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
if (list != null) {
map['list'] = list?.map((v) => v.toJson()).toList();
}
map['total'] = total;
return map;
}
} }
\ No newline at end of file
part of book_pay; part of book_pay;
class BookPayController extends GetxController { class BookPayController extends GetxController {
final List<CourseModel> buy; // 购物车选中的书籍列表
BookPayController(this.buy); final List<CourseModel>? buy;
BookPayController({this.buy});
// 积分模型
CreditPointModel creditPointModel = CreditPointModel();
// 是否展示优惠券和积分模型
ShowModel showModel = ShowModel();
// 是否使用积分
bool useCreditPoint = false;
// 支付方式 // 支付方式
List<PayModel> pays = Platform.isIOS ?[ List<PayModel> pays = Platform.isIOS ?[
...@@ -16,6 +24,18 @@ class BookPayController extends GetxController { ...@@ -16,6 +24,18 @@ class BookPayController extends GetxController {
// 时候展示底部视图 // 时候展示底部视图
bool showDetail = false; bool showDetail = false;
// 优惠前的原始价钱
late double originalPrice = getOriginalPrice();
late double finalPrice = 0.00;
@override
void onReady() {
_getCreditPoints(price: '100');
_getShow();
computeFinalPrice();
super.onReady();
}
// 支付方式 // 支付方式
late PayModel _payModel = pays.first; late PayModel _payModel = pays.first;
...@@ -39,19 +59,51 @@ class BookPayController extends GetxController { ...@@ -39,19 +59,51 @@ class BookPayController extends GetxController {
update(); update();
} }
void setUse(){
useCreditPoint = !useCreditPoint;
// 计算
computeFinalPrice();
update();
}
/// 获取积分
void _getCreditPoints({
required String price
}) async {
creditPointModel = await ShopAPI.creditPoints(price: price);
update();
}
void _getShow () async {
showModel = await ShopAPI.show();
update();
}
/// 获取优惠前的价钱
/// 总价钱
double getOriginalPrice(){
Decimal price = Decimal.zero;
for (CourseModel model in buy!) {
if (model.status == 1){
if (model.selected == true){
price = price + Decimal.parse(model.vipPrice??'0.00');
}
}
}
return price.toDouble();
}
/// 获取优惠后的价格
void computeFinalPrice(){
finalPrice = originalPrice;
if (useCreditPoint){
finalPrice = finalPrice - Decimal.parse(creditPointModel.deductibleAmount??'0.00').toDouble();
}
update();
}
// /// 获取总价
// ///总价格
// double get allPrice{
// Decimal price = Decimal.zero;
// for (CourseModel model in buy) {
// if (model.status == 1){
// if (model.selected == true){
// price = price + Decimal.parse(model.vipPrice??'0.00');
// }
// }
// }
// return price.toDouble();
// }
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ library book_pay; ...@@ -3,6 +3,7 @@ library book_pay;
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/apis/index.dart';
import 'package:flutter_book/theme.dart'; import 'package:flutter_book/theme.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_slidable/flutter_slidable.dart';
...@@ -10,7 +11,6 @@ import 'package:get/get.dart'; ...@@ -10,7 +11,6 @@ import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../models/index.dart'; import '../../models/index.dart';
import '../../models/shop.dart';
import '../../routes/index.dart'; import '../../routes/index.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
import '../../widgets/index.dart'; import '../../widgets/index.dart';
......
...@@ -16,7 +16,7 @@ class _BookPayPageState extends State<BookPayPage> { ...@@ -16,7 +16,7 @@ class _BookPayPageState extends State<BookPayPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GetBuilder<BookPayController>( return GetBuilder<BookPayController>(
init: BookPayController(widget.buy), init: BookPayController(buy: widget.buy),
builder: (controller) => Stack( builder: (controller) => Stack(
children: [ children: [
Scaffold( Scaffold(
...@@ -29,42 +29,44 @@ class _BookPayPageState extends State<BookPayPage> { ...@@ -29,42 +29,44 @@ class _BookPayPageState extends State<BookPayPage> {
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap:true, shrinkWrap:true,
itemBuilder: (BuildContext context, int index){ itemBuilder: (BuildContext context, int index){
return BuildItem(model: controller.buy[index],); return BuildItem(model: controller.buy![index],);
}, },
itemCount: controller.buy.length, itemCount: controller.buy!.length,
), ),
controller.showModel.couponSwitch =='0' && controller.showModel.integralSwitch =='0'?const SizedBox():SizedBox(height: 10.w,),
SizedBox(height: 10.w,), Visibility(
Container( visible: controller.showModel.couponSwitch =='0' && controller.showModel.integralSwitch =='0'?false:true,
margin: EdgeInsets.only(left: 10.w,right: 10.w), child: Container(
decoration: BoxDecoration( margin: EdgeInsets.only(left: 10.w,right: 10.w),
borderRadius:BorderRadius.circular(8.w), decoration: BoxDecoration(
color: Colors.white, borderRadius:BorderRadius.circular(8.w),
boxShadow: [ color: Colors.white,
BoxShadow( boxShadow: [
color: Colours.cC7.withOpacity(0.5), BoxShadow(
spreadRadius: 2.w, color: Colours.cC7.withOpacity(0.5),
blurRadius: 5.w, spreadRadius: 2.w,
offset: Offset(3.w, 0), // changes the position of the shadow blurRadius: 5.w,
offset: Offset(3.w, 0), // changes the position of the shadow
),
]
),
child: Column(
children: [
controller.showModel.couponSwitch =='0'?const SizedBox():GestureDetector(
child: _buildCouponWidget(controller,title: '优惠券',icon: 'assets/images/pay_coupon.png',),
onTap: (){
context.pushNamed(Routes.payCoupon);
},
), ),
] Container(height: 0.5.w,color: Colours.cF0,margin: EdgeInsets.only(left: 10.w),),
), controller.showModel.integralSwitch =='0'?const SizedBox(): GestureDetector(
child: Column( child: _buildPointWidget(controller,title: '积分抵扣',icon: 'assets/images/pay_point.png',),
children: [ onTap: (){
GestureDetector( context.pushNamed(Routes.creditPoints);
child: _buildWidget(title: '优惠券',icon: 'assets/images/pay_coupon.png',), },
onTap: (){ ),
context.pushNamed(Routes.payCoupon); ],
}, ),
),
Container(height: 0.5.w,color: Colours.cF0,margin: EdgeInsets.only(left: 10.w),),
GestureDetector(
child: _buildWidget(title: '积分抵扣',icon: 'assets/images/pay_point.png',),
onTap: (){
context.pushNamed(Routes.creditPoints);
},
),
],
), ),
), ),
Container( Container(
...@@ -206,7 +208,8 @@ class _BookPayPageState extends State<BookPayPage> { ...@@ -206,7 +208,8 @@ class _BookPayPageState extends State<BookPayPage> {
); );
} }
Widget _buildWidget({ // 优惠券选择
Widget _buildCouponWidget(BookPayController controller,{
required String title, required String title,
required String icon, required String icon,
}){ }){
...@@ -240,4 +243,48 @@ class _BookPayPageState extends State<BookPayPage> { ...@@ -240,4 +243,48 @@ class _BookPayPageState extends State<BookPayPage> {
); );
} }
// 积分选择
Widget _buildPointWidget(BookPayController controller,{
required String title,
required String icon,
}){
return Container(
margin: EdgeInsets.only(left: 13.w,right: 13.w),
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
margin: EdgeInsets.symmetric(vertical: 12.w),
// color: Colors.cyan,
width:20.w,
height:20.w,
child: Image.asset(icon),
),
SizedBox(width: 7.w,),
Text(title,style: TextStyle(fontSize: 14.w,color: Colours.c3,height: 1.1)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
controller.useCreditPoint?Text('-¥${controller.creditPointModel.deductibleAmount}',style: TextStyle(fontSize:13.w,color: AppTheme.primary,height:1.4),)
: Text('去选择',style: TextStyle(fontSize:13.w,color: Colours.c9,height:1.4)),
Gaps.hGaps10,
SizedBox(
// color: Colors.cyan,
width:5.w,
height:8.w,
child: Image.asset('assets/images/right_arrow.png'),
),
],
)
],
),
);
}
} }
...@@ -6,48 +6,51 @@ class BuildPayCount extends StatelessWidget { ...@@ -6,48 +6,51 @@ class BuildPayCount extends StatelessWidget {
const BuildPayCount({ const BuildPayCount({
Key? key, Key? key,
required this.payTap, required this.payTap,
required this.showTap required this.showTap,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return GetBuilder<BookPayController>(
padding: EdgeInsets.symmetric(horizontal: 15.w), init: BookPayController(),
height: 55.w, builder:(controller)=> Container(
color: Colors.white, padding: EdgeInsets.symmetric(horizontal: 15.w),
child: Row( height: 55.w,
mainAxisAlignment: MainAxisAlignment.spaceBetween, color: Colors.white,
crossAxisAlignment: CrossAxisAlignment.center, child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.spaceBetween,
GestureDetector( crossAxisAlignment: CrossAxisAlignment.center,
onTap: showTap, children: [
child: Row( GestureDetector(
crossAxisAlignment: CrossAxisAlignment.center, onTap: showTap,
children: [ child: Row(
Text('应付:',style: TextStyle(fontSize:14.w,color: Colours.c3 ,height: 1.1),), crossAxisAlignment: CrossAxisAlignment.center,
Text('¥98.9',style: TextStyle(fontSize:15.w,color:AppTheme.primary,fontWeight: Fonts.medium ,height: 1.1),), children: [
SizedBox( Text('应付:',style: TextStyle(fontSize:14.w,color: Colours.c3 ,height: 1.1),),
// color: Colors.cyan, Text('¥${controller.finalPrice}',style: TextStyle(fontSize:15.w,color:AppTheme.primary,fontWeight: Fonts.medium ,height: 1.1),),
width: 20.w, SizedBox(
height: 20.w, // color: Colors.cyan,
child: Image.asset('assets/images/pay_up.png') width: 20.w,
) height: 20.w,
], child: Image.asset('assets/images/pay_up.png')
), )
), ],
GestureDetector(
onTap: payTap,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.w),
color: AppTheme.primary
), ),
padding: EdgeInsets.symmetric(horizontal:13.5.w,vertical: 8.w),
child: Text('确认支付',style: TextStyle(fontSize: 14.w,fontWeight: Fonts.medium,color: Colors.white),),
), ),
) GestureDetector(
], onTap: payTap,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.w),
color: AppTheme.primary
),
padding: EdgeInsets.symmetric(horizontal:13.5.w,vertical: 8.w),
child: Text('确认支付',style: TextStyle(fontSize: 14.w,fontWeight: Fonts.medium,color: Colors.white),),
),
)
],
),
), ),
); );
} }
......
...@@ -186,7 +186,7 @@ class BookshopController extends GetxController { ...@@ -186,7 +186,7 @@ class BookshopController extends GetxController {
List<CourseModel> _test(){ List<CourseModel> _test(){
return [ return [
CourseModel(bookName: '哈1',bookId: 111,vipPrice: '12.33',authors: 'John',status: 1), CourseModel(bookName: '哈1',bookId: 111,vipPrice: '100.33',authors: 'John',status: 1),
CourseModel(bookName: '哈2',bookId: 123,vipPrice: '12.00',authors: 'json',status: 1), CourseModel(bookName: '哈2',bookId: 123,vipPrice: '12.00',authors: 'json',status: 1),
CourseModel(bookName: '哈3',bookId: 11,vipPrice: '12.43',authors: 'hash',status: 1), CourseModel(bookName: '哈3',bookId: 11,vipPrice: '12.43',authors: 'hash',status: 1),
CourseModel(bookName: '哈3',bookId: 11,vipPrice: '12.43',authors: 'hash',status: 1), CourseModel(bookName: '哈3',bookId: 11,vipPrice: '12.43',authors: 'hash',status: 1),
......
part of credit_points;
class CreditPointController extends GetxController {
final String price;
CreditPointController(this.price);
CreditPointModel creditPointModel = CreditPointModel();
bool use = false;
@override
void onReady() {
_getCreditPoints(price: price);
super.onReady();
}
void setUse(){
use = !use;
update();
}
void _getCreditPoints({
required String price
}) async {
creditPointModel = await ShopAPI.creditPoints(price: price);
update();
}
}
...@@ -6,6 +6,12 @@ import 'package:flutter/material.dart'; ...@@ -6,6 +6,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_book/theme.dart'; import 'package:flutter_book/theme.dart';
import 'package:flutter_book/utils/index.dart'; import 'package:flutter_book/utils/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
part 'view.dart'; import '../../apis/index.dart';
\ No newline at end of file import '../../models/index.dart';
import '../book_pay/index.dart';
part 'view.dart';
part 'controller.dart';
\ No newline at end of file
part of credit_points; part of credit_points;
class CreditPointsPage extends StatelessWidget { class CreditPointsPage extends StatelessWidget {
const CreditPointsPage({Key? key}) : super(key: key); const CreditPointsPage({
Key? key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -10,126 +12,140 @@ class CreditPointsPage extends StatelessWidget { ...@@ -10,126 +12,140 @@ class CreditPointsPage extends StatelessWidget {
context.pop('111111'); context.pop('111111');
return false; return false;
}, },
child: Scaffold( child: GetBuilder<BookPayController>(
extendBodyBehindAppBar: true, init: BookPayController(),
appBar: AppBar( builder:(controller)=> Scaffold(
centerTitle: true, extendBodyBehindAppBar: true,
title: const Text('积分'), appBar: AppBar(
backgroundColor: Colors.transparent, centerTitle: true,
), title: const Text('积分'),
body:Stack( backgroundColor: Colors.transparent,
children: [ ),
Image.asset( body:Stack(
'assets/images/point_bg.png',
fit: BoxFit.contain,
width: double.infinity,
),
SafeArea(
top: true,
child: Column(
children: [ children: [
// 积分卡片 Image.asset(
Container( 'assets/images/point_bg.png',
padding: EdgeInsets.symmetric(horizontal: 10.w), fit: BoxFit.contain,
child: Container( width: double.infinity,
padding: EdgeInsets.only(left: 17.w,top: 18.w,bottom: 24.w,right: 17.w), ),
decoration: BoxDecoration( SafeArea(
color: Colors.white.withOpacity(0.58), top: true,
borderRadius: BorderRadius.circular(8.w), child: Column(
border: Border.all(width: 2.w,color: Colors.white) children: [
), // 积分卡片
height: 175.w, Container(
child: Column( padding: EdgeInsets.symmetric(horizontal: 10.w),
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: Container(
crossAxisAlignment: CrossAxisAlignment.start, padding: EdgeInsets.only(left: 17.w,top: 18.w,bottom: 24.w,right: 17.w),
children: [ decoration: BoxDecoration(
Column( color: Colors.white.withOpacity(0.58),
crossAxisAlignment: CrossAxisAlignment.start, borderRadius: BorderRadius.circular(8.w),
children: [ border: Border.all(width: 2.w,color: Colors.white)
Text('可用积分',style: TextStyle(fontSize: 16.w,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),), ),
Gaps.vGaps13, height: 175.w,
Text('999',style: TextStyle(fontSize: 25.w,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),), child: Column(
], mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('可用积分',style: TextStyle(fontSize: 16.w,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),),
Gaps.vGaps13,
Text(controller.creditPointModel.integral.toString(),style: TextStyle(fontSize: 25.w,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),),
],
),
Row(
children: [
Expanded(
child: Container(
height: 0.5.w,
color: Colours.cE7,
),
),
Gaps.hGaps15,
Text('积分支付不能超过每笔订单的${controller.creditPointModel.integralUseLimit}%',style: TextStyle(fontSize: 12.w,height: 1.4,color: Colours.c9),),
Gaps.hGaps15,
Expanded(
child: Container(
height: 0.5.w,
color: Colours.cE7,
),
),
],
)
],
),
), ),
Row( ),
children: [ // 使用积分
Expanded( Container(
child: Container( // height: 105,
height: 0.5.w, margin: EdgeInsets.symmetric(horizontal: 10.w),
color: Colours.cE7, padding: EdgeInsets.only(left: 20.w,right: 20.w,top: 20.w),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colours.cC7.withOpacity(0.5),
offset: Offset(3.w, 0.w),
blurRadius: 4.w,
spreadRadius: 0,
), ),
],
borderRadius: BorderRadius.circular(8.w)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('积分抵扣',style: TextStyle(fontSize: 16.w,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),),
Gaps.vGaps10,
Container(
height: 0.5.w,
color: Colours.cE7,
// color: Colors.red,
), ),
Gaps.hGaps15, GestureDetector(
Text('积分支付不能超过每笔订单的20%',style: TextStyle(fontSize: 12.w,height: 1.4,color: Colours.c9),), onTap: (){
Gaps.hGaps15, controller.setUse();
Expanded( if (controller.useCreditPoint) {
context.pop();
}
},
child: Container( child: Container(
height: 0.5.w, color: Colors.white,
color: Colours.cE7, height: 54,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(text: TextSpan(
children: [
TextSpan(text: '抵扣',style: TextStyle(color: Colours.c9,fontSize: 13.w,height: 1.4)),
TextSpan(text: '¥${controller.creditPointModel.deductibleAmount}',style: TextStyle(color: AppTheme.primary,fontSize: 13.w,height: 1.4,fontWeight: Fonts.medium)),
TextSpan(text: '使用${controller.creditPointModel.deductibleIntegral}积分',style: TextStyle(color: Colours.c9,fontSize: 13.w,height: 1.4)),
]
)),
SizedBox(
width: 15.w,
height: 15.w,
child: Image.asset(
controller.useCreditPoint?'assets/images/check.png':'assets/images/uncheck.png',
),
)
],
),
), ),
), )
], ],
)
],
),
),
),
// 使用积分
Container(
// height: 105,
margin: EdgeInsets.symmetric(horizontal: 10.w),
padding: EdgeInsets.all(20.w),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colours.cC7.withOpacity(0.5),
offset: Offset(3.w, 0.w),
blurRadius: 4.w,
spreadRadius: 0,
), ),
],
borderRadius: BorderRadius.circular(8.w)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('可用积分',style: TextStyle(fontSize: 16.w,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),),
Gaps.vGaps10,
Container(
height: 0.5.w,
color: Colours.cE7,
// color: Colors.red,
),
Gaps.vGaps15,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(text: TextSpan(
children: [
TextSpan(text: '抵扣',style: TextStyle(color: Colours.c9,fontSize: 13.w,height: 1.4)),
TextSpan(text: '¥9.90',style: TextStyle(color: AppTheme.primary,fontSize: 13.w,height: 1.4,fontWeight: Fonts.medium)),
TextSpan(text: '使用9900积分',style: TextStyle(color: Colours.c9,fontSize: 13.w,height: 1.4)),
]
)),
SizedBox(
width: 15.w,
height: 15.w,
child: Image.asset(
'assets/images/uncheck.png',
),
)
],
) )
], ],
), ),
) ),
], ],
), )
), ),
],
)
), ),
); );
} }
} }
part of pay_coupon; part of pay_coupon;
class PayCouponController extends GetxController { class PayCouponController extends GetxController with GetSingleTickerProviderStateMixin{
final String tag;
PayCouponController(this.tag);
late TabController tabController;
List <Widget>tabs = [ List <Widget>tabs = [
const Tab(text: '可用',), const Tab(text: '可用',),
const Tab(text: '不可用',), const Tab(text: '不可用',),
]; ];
late TabController tabController = TabController(length:tabs.length, vsync: this);
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
CouponListModel couponListModel = CouponListModel();
// 优惠券
List <CouponModel> coupons = [];
final int _limit = 10;
int _page = 1;
bool _noMore = false;
final String price = '200';
Future<void> _getCoupon([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await ShopAPI.coupon(
page: _page,
limit: _limit,
type: tag,
price: price
);
tabs = [
Tab(text: '可用(${tag =='0'?result.list!.length:''})',),
Tab(text: '不可用(${tag =='1'?result.list!.length:''})',),
];
// 如果是刷新 清理数据
if (isRefresh) coupons.clear();
coupons.addAll(result.list!);
_page ++;
_noMore = result.list!.length < _limit;
update();
}
void onRefresh() async {
try {
await _getCoupon(true);
refreshController.finishRefresh(IndicatorResult.success);
refreshController.resetFooter();
} catch (error) {
print('--------------------------------$error');
refreshController.finishRefresh(IndicatorResult.fail);
}
}
void onLoading() async {
if (_noMore) {
refreshController.finishLoad(IndicatorResult.noMore);
return;
}
try {
await _getCoupon();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
} }
\ No newline at end of file
library pay_coupon; library pay_coupon;
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/pages/user_coupon/index.dart'; import 'package:flutter_book/pages/user_coupon/index.dart';
import 'package:flutter_book/widgets/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../apis/index.dart';
import '../../models/index.dart';
import '../../theme.dart'; import '../../theme.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
part 'view.dart'; part 'view.dart';
part 'controller.dart'; part 'controller.dart';
\ No newline at end of file part 'widgets/item.dart';
...@@ -13,7 +13,7 @@ class _PayCouponPageState extends State<PayCouponPage> { ...@@ -13,7 +13,7 @@ class _PayCouponPageState extends State<PayCouponPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GetBuilder<PayCouponController>( return GetBuilder<PayCouponController>(
init: PayCouponController(), init: PayCouponController('main'),
builder: (controller) =>Scaffold( builder: (controller) =>Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
...@@ -22,8 +22,7 @@ class _PayCouponPageState extends State<PayCouponPage> { ...@@ -22,8 +22,7 @@ class _PayCouponPageState extends State<PayCouponPage> {
body: Column( body: Column(
children: [ children: [
TabBar( TabBar(
labelColor: AppTheme.primary, labelColor: Colours.c3,
// isScrollable: true,
labelStyle: TextStyle(fontSize: 15.w,height: 1.4,fontWeight: Fonts.medium), labelStyle: TextStyle(fontSize: 15.w,height: 1.4,fontWeight: Fonts.medium),
unselectedLabelColor: Colours.c9, unselectedLabelColor: Colours.c9,
unselectedLabelStyle: TextStyle(fontSize: 15.w,height: 1.4), unselectedLabelStyle: TextStyle(fontSize: 15.w,height: 1.4),
...@@ -36,9 +35,9 @@ class _PayCouponPageState extends State<PayCouponPage> { ...@@ -36,9 +35,9 @@ class _PayCouponPageState extends State<PayCouponPage> {
Expanded( Expanded(
child: TabBarView( child: TabBarView(
controller: controller.tabController, controller: controller.tabController,
children: [ children: List.generate(controller.tabs.length, (index){
return CouponPage(tag:'$index');
], })
), ),
), ),
], ],
...@@ -49,7 +48,11 @@ class _PayCouponPageState extends State<PayCouponPage> { ...@@ -49,7 +48,11 @@ class _PayCouponPageState extends State<PayCouponPage> {
} }
class CouponPage extends StatefulWidget { class CouponPage extends StatefulWidget {
const CouponPage({Key? key}) : super(key: key); final String tag;
const CouponPage({
Key? key,
required this.tag
}) : super(key: key);
@override @override
State<CouponPage> createState() => _CouponPageState(); State<CouponPage> createState() => _CouponPageState();
...@@ -58,13 +61,25 @@ class CouponPage extends StatefulWidget { ...@@ -58,13 +61,25 @@ class CouponPage extends StatefulWidget {
class _CouponPageState extends State<CouponPage> { class _CouponPageState extends State<CouponPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView.builder( return GetBuilder<PayCouponController>(
itemBuilder: (BuildContext context, int index){ init: PayCouponController(widget.tag),
// return BuildItem(model: ,); builder: (controller) =>CustomPullScrollView(
}, controller: controller.refreshController,
itemCount: 2, onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: ListView.builder(
itemBuilder: (BuildContext context, int index){
CouponModel model = controller.coupons[index];
return BuildItem(model:model,);
},
itemCount: controller.coupons.length,
),
),
); );
} }
} }
part of pay_coupon;
class BuildItem extends StatelessWidget {
final CouponModel model;
const BuildItem({
Key? key,
required this.model
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(left: 10.w,top: 10.w,right: 10.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.w),
color: Colors.white,
boxShadow: [
BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5),
offset: Offset(3.w, 0),
blurRadius: 10.w,
spreadRadius: 0.w,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(
children: [
Image.asset('assets/images/coupon_yes.png'),
Positioned(
left: 0.w,
right: 0.w,
bottom: 0.w,
top: 0.w,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: '¥',
style: TextStyle(fontSize: 15.w,fontWeight: Fonts.boldSemi,height: 1.5,color: Colors.white)
),
TextSpan(
text: '5',
style: TextStyle(fontSize: 40.w,fontWeight: Fonts.boldSemi,height: 1.5,color: Colors.white)
),
]
),
),
Text('满${model.normPrice}可用',style: TextStyle(fontSize: 11.w,height: 1.5,color: Colors.white),)
],
),
)
],
),
Expanded(
child: Container(
margin: EdgeInsets.only(left:15.w,right: 15.w ),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(model.couponName??'',style: TextStyle(fontSize: 16.w,fontWeight: Fonts.medium,height: 1.5,color: Colours.c3),),
Gaps.vGaps5,
Text('满${model.normPrice}${model.reducedPrice}元',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
Gaps.vGaps5,
Text('有效期',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
],
),
Container(
width: 65.w,
height: 24.w,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.w),
color: Colors.white,
border: Border.all(width: 1.w,color: AppTheme.primary)
),
child: Text('立即使用',style: TextStyle(fontSize: 12.w,fontWeight: Fonts.medium,color: AppTheme.primary),),
)
],
),
),
)
],
)
);
}
}
...@@ -10,7 +10,6 @@ import 'package:get/get.dart'; ...@@ -10,7 +10,6 @@ import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart'; import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../models/shop.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
import '../../widgets/index.dart'; import '../../widgets/index.dart';
import '../book_pay/index.dart'; import '../book_pay/index.dart';
......
...@@ -31,7 +31,7 @@ class UserCouponController extends GetxController { ...@@ -31,7 +31,7 @@ class UserCouponController extends GetxController {
_getCoupon(); _getCoupon();
} }
/// 获取课程内图书列表 /// 获取我的优惠券
Future<void> _getCoupon([bool isRefresh = false]) async { Future<void> _getCoupon([bool isRefresh = false]) async {
if (isRefresh) _page = 1; if (isRefresh) _page = 1;
// 网路请求 // 网路请求
......
...@@ -65,7 +65,7 @@ class BuildItem extends StatelessWidget { ...@@ -65,7 +65,7 @@ class BuildItem extends StatelessWidget {
Gaps.vGaps5, Gaps.vGaps5,
Text('满${model.normPrice}${model.reducedPrice}元',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),), Text('满${model.normPrice}${model.reducedPrice}元',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
Gaps.vGaps5, Gaps.vGaps5,
Text(model.endTime??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),), // Text(model.endTime??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
], ],
), ),
Container( Container(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论