You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
17 KiB

import 'dart:convert';
4 years ago
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
4 years ago
4 years ago
class ExchangeOrderPage extends StatefulWidget {
final Map<String, dynamic> arguments;
4 years ago
///兑换订单
ExchangeOrderPage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _ExchangeOrderPage();
}
}
class _ExchangeOrderPage extends State<ExchangeOrderPage> {
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
4 years ago
apiService = ApiService(Dio(), context: context, token: value.getString("token")),
points =
UserInfo.fromJson(jsonDecode(value.getString('user'))).points,
});
}
String points;
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
S.of(context).dingdanqueren,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
centerTitle: false,
backgroundColor: Color(0xFFFAFAFA),
elevation: 0,
leading: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
titleSpacing: 2,
leadingWidth: 56,
),
body: Column(
children: [
Expanded(
child: Column(
children: [
Container(
margin:
EdgeInsets.only(left: 16, right: 16, top: 26, bottom: 8),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
4 years ago
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
4 years ago
],
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: Column(
children: [
Row(
children: [
Image.asset(
"assets/image/icon_order_exchange_info.png",
width: 24,
height: 24,
),
SizedBox(width: 4),
Text(
S.of(context).duihuanxinxi,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Color(0xFF353535)),
),
],
),
SizedBox(
height: 18,
),
Row(
children: [
Text(
S.of(context).lingqufangshi,
style: TextStyle(
fontSize: 14,
color: Color(0xFF353535),
),
4 years ago
),
SizedBox(
width: 12,
),
Text(
widget.arguments["useTyped"] == 1
? S.of(context).ziti
: widget.arguments["useTyped"] == 2
? S.of(context).peisong
: S.of(context).xianshangfafang,
style: TextStyle(
fontSize: 14,
color: Color(0xFF353535),
),
4 years ago
),
],
),
Visibility(
child: SizedBox(
height: 13,
),
visible: widget.arguments["useTyped"] != 3,
4 years ago
),
Visibility(
child: Row(
children: [
Text(
S.of(context).zitidizhi,
4 years ago
style: TextStyle(
fontSize: 14,
color: Color(0xFF353535),
),
4 years ago
),
SizedBox(
width: 12,
),
4 years ago
Expanded(
child: GestureDetector(
onTap: () {
toAddressPicker();
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Text(
(address != null && address != "")
? address
: widget.arguments["useTyped"] == 1
? S.of(context).qingxuanzhemendian
4 years ago
: widget.arguments["useTyped"] ==
2
? S
.of(context)
.qingxuanzeshouhuodizhi
4 years ago
: S.of(context).xuni,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
color: Color(0xFF32A060),
),
),
flex: 1,
),
Icon(
Icons.keyboard_arrow_right,
size: 16,
color: Color(0xFF32A060),
),
],
),
),
4 years ago
flex: 1,
),
],
),
visible: widget.arguments["useTyped"] != 3,
4 years ago
),
SizedBox(
height: 12,
),
Row(
children: [
Visibility(
visible: widget.arguments["useTyped"] != 3,
child: Text(
S.of(context).zitishijian,
style: TextStyle(
fontSize: 14, color: Color(0xFF353535)),
),
4 years ago
),
Visibility(
visible: widget.arguments["useTyped"] != 3,
child: SizedBox(
width: 12,
),
4 years ago
),
Text(
widget.arguments["useTyped"] == 1
? S.of(context).duihuanhouwugegongzuori
: widget.arguments["useTyped"] == 2
? S.of(context).duihuanhoufahuo
: S.of(context).feishiwushangpin,
style: TextStyle(
fontSize: 14,
color: widget.arguments["useTyped"] == 3
? Color(0xFF32A060)
: Color(0xFF353535)),
4 years ago
),
],
),
],
),
),
Container(
margin:
EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 16),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
4 years ago
],
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: Column(
children: [
Row(
children: [
Image.asset(
"assets/image/icon_order_commodity_info.png",
width: 24,
height: 24,
),
SizedBox(width: 4),
Text(
S.of(context).duihuanshangpinxiangqing,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Color(0xFF353535),
),
4 years ago
),
],
),
SizedBox(
height: 18,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
mainAxisSize: MainAxisSize.max,
4 years ago
children: [
Image.network(
widget.arguments["image"],
4 years ago
fit: BoxFit.cover,
4 years ago
width: 80.w,
height: 80.h,
4 years ago
),
4 years ago
Expanded(
child: Container(
height: 80.h,
margin: EdgeInsets.only(left: 16.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
widget.arguments["name"],
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xFF353535)),
),
SizedBox(
height: 4,
),
Text(
"x1",
style: TextStyle(
fontSize: 12, color: Color(0xFF727272)),
),
],
4 years ago
),
4 years ago
),
flex: 1,
4 years ago
)
],
),
SizedBox(
height: 12,
),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Text(
// "商品积分",
// style:
// TextStyle(fontSize: 14, color: Color(0xFF353535)),
// ),
// SizedBox(
// width: 12,
// ),
// Text(
// S.of(context).jifen_(widget.arguments["price"]),
// style: TextStyle(
// fontSize: 12,
// color: Colors.black,
// ),
// ),
// ],
// ),
// SizedBox(
// height: 12,
// ),
4 years ago
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"实付积分",
style:
TextStyle(fontSize: 14, color: Color(0xFF353535)),
),
SizedBox(
width: 12,
),
Text(
S.of(context).jifen_(widget.arguments["price"]),
4 years ago
style:
TextStyle(fontSize: 12, color: Color(0xFF32A060)),
),
],
),
],
),
),
],
)),
GestureDetector(
onTap: () {
if (!storeIsSelected) return;
creditOrder();
4 years ago
},
child: Container(
padding: EdgeInsets.only(top: 16, bottom: 16),
decoration: BoxDecoration(
color: MaterialStateColor.resolveWith((states) =>
storeIsSelected ? Color(0xFF32A060) : Color(0xFFD8D8D8)),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
topRight: Radius.circular(4))),
alignment: Alignment.center,
child: Text(
S.of(context).querenduihuan,
style: TextStyle(
fontSize: 16,
color: MaterialStateColor.resolveWith((states) =>
storeIsSelected ? Colors.white : Color(0xFFA0A0A0)),
fontWeight: FontWeight.bold),
),
),
),
],
),
);
}
var storeIsSelected = true;
4 years ago
String storeId;
String address;
String userAddressId;
4 years ago
toAddressPicker() async {
4 years ago
if (widget.arguments["useTyped"] == 1) {
dynamic result =
await Navigator.of(context).pushNamed('/router/store_selector_page');
if (result == null) return;
storeId = result["id"];
address = result["address"];
} else if (widget.arguments["useTyped"] == 2) {
dynamic result = await Navigator.of(context).pushNamed(
'/router/manage_address_page',
arguments: {"isSelector": true});
if (result == null) return;
userAddressId = result["id"];
address = result["address"];
4 years ago
}
4 years ago
setState(() {});
4 years ago
}
creditOrder() async {
4 years ago
if (widget.arguments["useTyped"] == 1 &&
(storeId == null || storeId == "")) {
SmartDialog.showToast("请选择一个门店");
4 years ago
return;
}
4 years ago
if (widget.arguments["useTyped"] == 2 &&
(userAddressId == null || userAddressId == "")) {
SmartDialog.showToast("请选择一个收货地址");
4 years ago
return;
}
4 years ago
BaseData baseDate = await apiService.creditOrder({
"goodsId": widget.arguments["goodsId"],
"number": 1,
"useTyped": widget.arguments["useTyped"],
4 years ago
if (widget.arguments["useTyped"] == 1) "storeId": storeId,
if (widget.arguments["useTyped"] == 2) "userAddressId": userAddressId,
});
if (baseDate.isSuccess) {
await Navigator.of(context).pushNamed(
'/router/exchange_order_success_page',
4 years ago
arguments: {"price": widget.arguments["price"], "points": points, "id": baseDate.data});
points =
"${int.tryParse(points) - int.tryParse(widget.arguments["price"])}";
Navigator.of(context).pop();
} else {
SmartDialog.showToast(baseDate.msg);
}
}
4 years ago
}