Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
9a668166
提交
9a668166
authored
1月 15, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
购物车 逻辑
上级
a7cce90e
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
234 行增加
和
54 行删除
+234
-54
controller.dart
lib/pages/book_pay/controller.dart
+24
-3
index.dart
lib/pages/book_pay/index.dart
+2
-0
view.dart
lib/pages/book_pay/view.dart
+8
-4
item.dart
lib/pages/book_pay/widgets/item.dart
+5
-5
controller.dart
lib/pages/book_shop/controller.dart
+114
-3
index.dart
lib/pages/book_shop/index.dart
+5
-1
view.dart
lib/pages/book_shop/view.dart
+13
-13
book.dart
lib/pages/book_shop/widgets/book.dart
+11
-10
count.dart
lib/pages/book_shop/widgets/count.dart
+31
-13
index.dart
lib/routes/index.dart
+1
-0
routes.dart
lib/routes/routes.dart
+1
-1
pubspec.lock
pubspec.lock
+16
-0
pubspec.yaml
pubspec.yaml
+3
-1
没有找到文件。
lib/pages/book_pay/controller.dart
浏览文件 @
9a668166
part of
book_pay
;
class
BookPayController
extends
GetxController
{
List
<
PayModel
>
pays
=
[
final
List
<
CourseModel
>
buy
;
BookPayController
(
this
.
buy
);
// 支付方式
List
<
PayModel
>
pays
=
Platform
.
isIOS
?[
PayModel
(
type:
3
,
name:
'紫荆币'
,
icon:
'assets/images/pay_coin.png'
,
selected:
true
),
]:[
PayModel
(
type:
1
,
name:
'微信'
,
icon:
'assets/images/pay_wechat.png'
,
selected:
true
),
PayModel
(
type:
2
,
name:
'支付宝'
,
icon:
'assets/images/pay_ali.png'
,
selected:
false
),
PayModel
(
type:
3
,
name:
'紫荆币'
,
icon:
'assets/images/pay_coin.png'
,
selected:
false
),
...
...
@@ -9,7 +15,7 @@ class BookPayController extends GetxController {
// 支付方式
late
PayModel
_payModel
;
late
PayModel
_payModel
=
pays
.
first
;
PayModel
get
payModel
=>
_payModel
;
void
setPayModel
(
PayModel
payModel
){
...
...
@@ -22,8 +28,22 @@ class BookPayController extends GetxController {
model
.
selected
=
false
;
}
}
print
(
'--------------------------------
${_payModel.name}
'
);
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
lib/pages/book_pay/index.dart
浏览文件 @
9a668166
library
book_pay
;
import
'package:decimal/decimal.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_book/theme.dart'
;
import
'package:flutter_slidable/flutter_slidable.dart'
;
...
...
@@ -10,6 +11,7 @@ import '../../models/index.dart';
import
'../../models/shop.dart'
;
import
'../../utils/index.dart'
;
import
'../book_shop/index.dart'
;
import
'dart:io'
;
part
'controller.dart'
;
part
'view.dart'
;
...
...
lib/pages/book_pay/view.dart
浏览文件 @
9a668166
part of
book_pay
;
class
BookPayPage
extends
StatefulWidget
{
const
BookPayPage
({
Key
?
key
})
:
super
(
key:
key
);
final
List
<
CourseModel
>
buy
;
const
BookPayPage
({
Key
?
key
,
required
this
.
buy
})
:
super
(
key:
key
);
@override
State
<
BookPayPage
>
createState
()
=>
_BookPayPageState
();
...
...
@@ -12,7 +16,7 @@ class _BookPayPageState extends State<BookPayPage> {
@override
Widget
build
(
BuildContext
context
)
{
return
GetBuilder
<
BookPayController
>(
init:
BookPayController
(),
init:
BookPayController
(
widget
.
buy
),
builder:
(
controller
)
=>
Scaffold
(
backgroundColor:
Colours
.
cF9
,
appBar:
AppBar
(
title:
const
Text
(
'支付'
),),
...
...
@@ -23,9 +27,9 @@ class _BookPayPageState extends State<BookPayPage> {
physics:
const
NeverScrollableScrollPhysics
(),
shrinkWrap:
true
,
itemBuilder:
(
BuildContext
context
,
int
index
){
return
const
BuildItem
(
);
return
BuildItem
(
model:
controller
.
buy
[
index
],
);
},
itemCount:
2
,
itemCount:
controller
.
buy
.
length
,
),
const
SizedBox
(
height:
10
,),
...
...
lib/pages/book_pay/widgets/item.dart
浏览文件 @
9a668166
part of
book_pay
;
class
BuildItem
extends
StatelessWidget
{
final
CourseModel
?
model
;
final
CourseModel
model
;
const
BuildItem
({
super
.
key
,
this
.
model
,
required
this
.
model
,
});
@override
...
...
@@ -69,12 +69,12 @@ class BuildItem extends StatelessWidget {
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
model
!=
null
?
model
!.
bookName
.
toString
():
''
,
style:
const
TextStyle
(
fontSize:
13
,
fontWeight:
Fonts
.
medium
,
color:
Colours
.
c3
),
maxLines:
2
,
overflow:
TextOverflow
.
ellipsis
,),
Text
(
model
.
bookName
??
''
,
style:
const
TextStyle
(
fontSize:
13
,
fontWeight:
Fonts
.
medium
,
color:
Colours
.
c3
),
maxLines:
2
,
overflow:
TextOverflow
.
ellipsis
,),
const
SizedBox
(
height:
5
,),
Text
(
model
!=
null
?
model
!.
authors
.
toString
():
''
,
style:
const
TextStyle
(
fontSize:
11
,
color:
Colours
.
c9
)),
Text
(
model
.
authors
??
''
,
style:
const
TextStyle
(
fontSize:
11
,
color:
Colours
.
c9
)),
],
),
Text
(
'¥
${model
!= null?model!.authors.toString():
''}
'
,
style:
const
TextStyle
(
fontSize:
14
,
fontWeight:
FontWeight
.
w500
,
color:
AppTheme
.
primary
)),
Text
(
'¥
${model
.vipPrice??
''}
'
,
style:
const
TextStyle
(
fontSize:
14
,
fontWeight:
FontWeight
.
w500
,
color:
AppTheme
.
primary
)),
],
),
),
...
...
lib/pages/book_shop/controller.dart
浏览文件 @
9a668166
...
...
@@ -9,17 +9,128 @@ class BookshopController extends GetxController {
// 书架数组
List
<
CourseModel
>
carts
=
[];
// 是否全选
late
bool
all
=
false
;
final
int
_limit
=
10
;
int
_page
=
1
;
bool
_noMore
=
false
;
@override
void
onReady
()
{
onRefresh
();
super
.
onReady
();
}
@override
void
onClose
()
{
refreshController
.
dispose
();
super
.
onClose
();
}
// 选中 与 取消选中
void
select
(
CourseModel
courseModel
){
if
(
courseModel
.
status
==
1
){
courseModel
.
selected
=
!
courseModel
.
selected
;
}
bool
checkAll
=
true
;
for
(
CourseModel
model
in
carts
){
if
(
model
.
status
==
1
){
if
(
model
.
selected
==
false
){
checkAll
=
false
;
}
}
}
all
=
checkAll
;
update
();
}
// 获取选中数量
int
get
num
{
int
num
=
0
;
for
(
CourseModel
model
in
carts
){
if
(
model
.
selected
==
true
){
num
++;
}
}
return
num
;
}
// 获取总价
//总价格
double
get
allPrice
{
Decimal
price
=
Decimal
.
zero
;
for
(
CourseModel
model
in
carts
)
{
if
(
model
.
status
==
1
){
if
(
model
.
selected
==
true
){
price
=
price
+
Decimal
.
parse
(
model
.
vipPrice
??
'0.00'
);
}
}
}
return
price
.
toDouble
();
}
/* 另一种方式处理精度
* double get allPrice {
double price = 0;
for (CourseModel model in carts) {
if (model.status == 1 && model.selected == true) {
print('----------------11111----------------${model.vipPrice ?? '0.00'}');
price += double.parse(model.vipPrice ?? '0.00');
}
}
NumberFormat formatter = NumberFormat("0.00");
String formattedPrice = formatter.format(price);
print('-------------22222-------------------$formattedPrice');
return double.parse(formattedPrice);
}
* */
// 全选
void
selectAll
()
{
if
(
all
==
false
){
for
(
CourseModel
model
in
carts
)
{
if
(
model
.
status
==
1
){
model
.
selected
=
true
;
}
}
all
=
true
;
}
else
{
for
(
CourseModel
model
in
carts
)
{
if
(
model
.
status
==
1
){
model
.
selected
=
false
;
}
}
all
=
false
;
}
update
();
}
/// 购买的书籍
List
<
CourseModel
>
get
buy
{
List
<
CourseModel
>
temp
=
[];
for
(
CourseModel
model
in
carts
)
{
if
(
model
.
status
==
1
){
if
(
model
.
selected
==
true
){
temp
.
add
(
model
);
}
}
}
return
temp
;
}
/// 删除购物车 单个书籍
void
delCart
({
required
String
cartId
,
...
...
@@ -75,9 +186,9 @@ class BookshopController extends GetxController {
List
<
CourseModel
>
_test
(){
return
[
CourseModel
(),
CourseModel
(),
CourseModel
(),
CourseModel
(
bookName:
'哈1'
,
bookId:
111
,
vipPrice:
'12.33'
,
authors:
'John'
,
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
),
];
}
...
...
lib/pages/book_shop/index.dart
浏览文件 @
9a668166
library
book_shop
;
import
'dart:ffi'
;
import
'package:decimal/decimal.dart'
;
import
'package:easy_refresh/easy_refresh.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_book/utils/index.dart'
;
...
...
@@ -7,12 +10,13 @@ import 'package:flutter_book/widgets/index.dart';
import
'package:flutter_slidable/flutter_slidable.dart'
;
import
'package:get/get.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:intl/intl.dart'
;
import
'../../apis/index.dart'
;
import
'../../models/index.dart'
;
import
'../../routes/index.dart'
;
import
'../../theme.dart'
;
import
'dart:math'
;
part
'controller.dart'
;
part
'view.dart'
;
...
...
lib/pages/book_shop/view.dart
浏览文件 @
9a668166
...
...
@@ -19,22 +19,22 @@ class _BookShopPageState extends State<BookShopPage> {
body:
Column
(
children:
[
Expanded
(
child:
CustomPullScrollView
(
controller:
controller
.
refreshController
,
onRefresh:
controller
.
onRefresh
,
onLoading:
controller
.
onLoading
,
child:
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
){
CourseModel
model
=
controller
.
carts
[
index
];
return
BookCell
(
model:
model
,
on
Tap:
(){
child:
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
){
CourseModel
model
=
controller
.
carts
[
index
];
return
GestureDetector
(
onTap:
(){
controller
.
select
(
model
);
},
child:
BookCell
(
model:
model
,
del
Tap:
(){
controller
.
delCart
(
cartId:
model
.
cartId
.
toString
());
},)
;
},
itemCount:
controller
.
carts
.
length
,
)
,
},)
,
);
}
,
itemCount:
controller
.
carts
.
length
,
),
),
BuildCounter
()
BuildCounter
(
controller:
controller
,
)
],
),
),
...
...
lib/pages/book_shop/widgets/book.dart
浏览文件 @
9a668166
...
...
@@ -2,11 +2,11 @@ part of book_shop;
class
BookCell
extends
StatelessWidget
{
final
CourseModel
model
;
final
void
Function
()
on
Tap
;
final
void
Function
()
del
Tap
;
const
BookCell
({
super
.
key
,
required
this
.
model
,
required
this
.
on
Tap
required
this
.
del
Tap
});
@override
...
...
@@ -17,13 +17,13 @@ class BookCell extends StatelessWidget {
color:
Colors
.
white
,
boxShadow:
[
BoxShadow
(
color:
const
Color
(
0xFFC7C7C7
).
withOpacity
(
0.5
),
color:
model
.
selected
?
AppTheme
.
primary
.
withOpacity
(
0.21
):
const
Color
(
0xFFC7C7C7
).
withOpacity
(
0.5
),
spreadRadius:
0
,
blurRadius:
10
,
offset:
const
Offset
(
3
,
0
),
// changes the position of the shadow
),
],
border:
Border
.
all
(
width:
0.5
,
color:
AppTheme
.
primary
)
border:
model
.
selected
?
Border
.
all
(
width:
0.5
,
color:
AppTheme
.
primary
):
null
,
),
margin:
const
EdgeInsets
.
only
(
left:
10
,
right:
10
,
top:
10
),
height:
110
,
...
...
@@ -34,7 +34,7 @@ class BookCell extends StatelessWidget {
SlidableAction
(
// An action can be bigger than the others.
onPressed:
(
BuildContext
context
){
on
Tap
;
del
Tap
;
},
backgroundColor:
AppTheme
.
primary
,
foregroundColor:
Colors
.
white
,
...
...
@@ -50,10 +50,11 @@ class BookCell extends StatelessWidget {
margin:
const
EdgeInsets
.
only
(
left:
12
,
right:
11
),
child:
Row
(
children:
[
Container
(
SizedBox
(
height:
17
,
width:
17
,
color:
Colors
.
cyan
,
// color: Colors.cyan,
child:
Image
.
asset
(
model
.
selected
?
'assets/images/pay_check.png'
:
'assets/images/pay_uncheck.png'
),
),
const
SizedBox
(
width:
12
,),
Container
(
...
...
@@ -94,12 +95,12 @@ class BookCell extends StatelessWidget {
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
model
!=
null
?
model
!.
bookName
.
toString
():
''
,
style:
const
TextStyle
(
fontSize:
13
,
fontWeight:
Fonts
.
medium
,
color:
Colours
.
c3
),
maxLines:
2
,
overflow:
TextOverflow
.
ellipsis
,),
Text
(
model
.
bookName
??
''
,
style:
const
TextStyle
(
fontSize:
13
,
fontWeight:
Fonts
.
medium
,
color:
Colours
.
c3
),
maxLines:
2
,
overflow:
TextOverflow
.
ellipsis
,),
const
SizedBox
(
height:
5
,),
Text
(
model
!=
null
?
model
!.
authors
.
toString
():
''
,
style:
const
TextStyle
(
fontSize:
11
,
color:
Colours
.
c9
)),
Text
(
model
.
authors
??
''
,
style:
const
TextStyle
(
fontSize:
11
,
color:
Colours
.
c9
)),
],
),
Text
(
'¥
${model
!= null?model!.authors.toString():
''}
'
,
style:
const
TextStyle
(
fontSize:
14
,
fontWeight:
FontWeight
.
w500
,
color:
AppTheme
.
primary
)),
Text
(
'¥
${model
.vipPrice??
''}
'
,
style:
const
TextStyle
(
fontSize:
14
,
fontWeight:
FontWeight
.
w500
,
color:
AppTheme
.
primary
)),
],
),
),
...
...
lib/pages/book_shop/widgets/count.dart
浏览文件 @
9a668166
...
...
@@ -2,7 +2,11 @@ part of book_shop;
class
BuildCounter
extends
StatelessWidget
{
const
BuildCounter
({
Key
?
key
})
:
super
(
key:
key
);
final
BookshopController
controller
;
const
BuildCounter
({
Key
?
key
,
required
this
.
controller
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -16,26 +20,40 @@ class BuildCounter extends StatelessWidget {
children:
[
Row
(
children:
[
Container
(
height:
17
,
width:
17
,
color:
Colors
.
yellow
,
),
const
SizedBox
(
width:
11
),
const
Text
(
'全选'
,
style:
TextStyle
(
color:
Color
(
0xFF333333
),
fontSize:
12
,
fontWeight:
FontWeight
.
w500
)),
GestureDetector
(
onTap:
(){
controller
.
selectAll
();
},
child:
Container
(
color:
Colors
.
white
,
child:
Row
(
children:
[
SizedBox
(
height:
17
,
width:
17
,
child:
Image
.
asset
(
controller
.
all
?
'assets/images/pay_check.png'
:
'assets/images/pay_uncheck.png'
),
),
const
SizedBox
(
width:
11
),
const
Text
(
'全选'
,
style:
TextStyle
(
color:
Color
(
0xFF333333
),
fontSize:
12
,
fontWeight:
FontWeight
.
w500
)),
],
),
),
),
const
SizedBox
(
width:
15
,),
const
Column
(
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
'合计 ¥
98.9'
,
style:
TextStyle
(
color:
AppTheme
.
primary
,
fontSize:
12
,
fontWeight:
FontWeight
.
w500
)),
Text
(
'已选
2 件'
,
style:
TextStyle
(
color:
Color
(
0xFF999999
),
fontSize:
10
,))
Text
(
'合计 ¥
${controller.allPrice.toStringAsFixed(2)}
'
,
style:
const
TextStyle
(
color:
AppTheme
.
primary
,
fontSize:
12
,
fontWeight:
FontWeight
.
w500
)),
Text
(
'已选
${controller.num}
件'
,
style:
const
TextStyle
(
color:
Color
(
0xFF999999
),
fontSize:
10
,))
],
)
],
),
GestureDetector
(
onTap:
(){
context
.
pushNamed
(
Routes
.
bookPay
);
if
(
controller
.
num
>
0
){
context
.
pushNamed
(
Routes
.
bookPay
,
extra:
controller
.
buy
);
}
},
child:
Container
(
margin:
const
EdgeInsets
.
symmetric
(
vertical:
9
),
...
...
@@ -46,7 +64,7 @@ class BuildCounter extends StatelessWidget {
// height: 35,
alignment:
Alignment
.
center
,
padding:
const
EdgeInsets
.
symmetric
(
vertical:
8
,
horizontal:
20
),
child:
Text
(
'结算(
2)'
,
style:
TextStyle
(
fontSize:
14
,
color:
Colors
.
white
,
height:
1.1
,
fontWeight:
Fonts
.
medium
),),
child:
Text
(
'结算(
${controller.num}
)'
,
style:
const
TextStyle
(
fontSize:
14
,
color:
Colors
.
white
,
height:
1.1
,
fontWeight:
Fonts
.
medium
),),
),
)
],
...
...
lib/routes/index.dart
浏览文件 @
9a668166
...
...
@@ -29,6 +29,7 @@ import 'package:flutter_book/pages/user_wrong/index.dart';
import
'package:flutter_book/pages/web/index.dart'
;
import
'package:go_router/go_router.dart'
;
import
'../models/index.dart'
;
import
'../pages/user_terms/index.dart'
;
import
'../store/index.dart'
;
...
...
lib/routes/routes.dart
浏览文件 @
9a668166
...
...
@@ -168,7 +168,7 @@ abstract class Routes {
pageBuilder:
(
context
,
state
)
=>
CupertinoPage
(
name:
state
.
uri
.
toString
(),
key:
state
.
pageKey
,
child:
const
BookPayPage
(
)
child:
BookPayPage
(
buy:
state
.
extra
as
List
<
CourseModel
>,
)
)
),
GoRoute
(
...
...
pubspec.lock
浏览文件 @
9a668166
...
...
@@ -89,6 +89,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.6"
decimal:
dependency: "direct main"
description:
name: decimal
sha256: "24a261d5d5c87e86c7651c417a5dbdf8bcd7080dd592533910e8d0505a279f21"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.3"
dio:
dependency: "direct main"
description:
...
...
@@ -525,6 +533,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
rational:
dependency: transitive
description:
name: rational
sha256: ba58e9e18df9abde280e8b10051e4bce85091e41e8e7e411b6cde2e738d357cf
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.2"
recase:
dependency: transitive
description:
...
...
pubspec.yaml
浏览文件 @
9a668166
...
...
@@ -79,8 +79,10 @@ dependencies:
flutter_star
:
^1.2.0
# toast
oktoast
:
^3.0.0
#
策划
#
侧滑
flutter_slidable
:
^3.0.1
# 精度
decimal
:
^2.3.3
dev_dependencies
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论