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.
420 lines
14 KiB
420 lines
14 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
|
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; |
|
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; |
|
import 'package:flutter_svg/flutter_svg.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/store/scan.dart'; |
|
import 'package:huixiang/utils/location.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/store.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/border_text.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:huixiang/view_widget/item_title.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/request_permission.dart'; |
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
import 'package:permission_handler/permission_handler.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
class QuickOrder extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _QuickOrder(); |
|
} |
|
} |
|
|
|
class _QuickOrder extends State<QuickOrder> { |
|
ApiService apiService; |
|
List<Store> storeList; |
|
BMFCoordinate latLng; |
|
|
|
BMFMapController _mapController; |
|
final TextEditingController editingController = TextEditingController(); |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
getLatLng(); |
|
startLocation(); |
|
} |
|
|
|
///门店列表 |
|
queryStore(latitude, longitude, province, city, district, searchKey) async { |
|
BaseData<List<Store>> baseData = await apiService.queryStore({ |
|
// "city": city, |
|
// "district": district, |
|
// "province": province, |
|
"latitude": latitude, |
|
"longitude": longitude, |
|
"searchKey": searchKey |
|
}).catchError((error) {}); |
|
if (baseData != null && baseData.isSuccess) { |
|
storeList = baseData.data; |
|
} |
|
setState(() {}); |
|
} |
|
|
|
getLatLng() async { |
|
SharedPreferences.getInstance().then( |
|
(value) => { |
|
apiService = ApiService(Dio(), |
|
context: context, |
|
token: value.getString('token'), |
|
showLoading: false), |
|
if (value.containsKey("latitude") && |
|
value.containsKey("longitude") && |
|
value.containsKey("province") && |
|
value.containsKey("city") && |
|
value.containsKey("district")) |
|
{ |
|
latLng = BMFCoordinate(double.tryParse(value.getString("latitude")), |
|
double.tryParse(value.getString("longitude"))), |
|
queryStore( |
|
value.getString("latitude"), |
|
value.getString("longitude"), |
|
value.getString("province"), |
|
value.getString("city"), |
|
value.getString("district"), |
|
editingController.text, |
|
), |
|
setState(() { |
|
if (_mapController != null) { |
|
_mapController.updateMapOptions(BMFMapOptions( |
|
center: latLng, |
|
zoomLevel: 15, |
|
)); |
|
} |
|
}) |
|
} |
|
else |
|
{ |
|
queryStore("", "", "", "", "", editingController.text), |
|
} |
|
}, |
|
); |
|
} |
|
|
|
startLocation() async { |
|
Location.getInstance() |
|
.aMapFlutterLocation |
|
.onResultCallback() |
|
.listen((event) { |
|
if (event != null && |
|
event["latitude"] != null && |
|
event["longitude"] != null) { |
|
print("location: $event"); |
|
if (event["latitude"] is String && event["longitude"] is String) { |
|
latLng = BMFCoordinate(double.tryParse(event["latitude"]), |
|
double.tryParse(event["longitude"])); |
|
} else { |
|
latLng = BMFCoordinate(event["latitude"], event["longitude"]); |
|
} |
|
BMFCalculateUtils.coordConvert( |
|
coordinate: latLng, |
|
fromType: BMF_COORD_TYPE.BD09LL, |
|
toType: BMF_COORD_TYPE.COMMON) |
|
.then((value) { |
|
this.latLng = value; |
|
saveLatLng( |
|
value, event["province"], event["city"], event["district"]); |
|
print("union: Location result ${value.latitude} " |
|
"${value.longitude}"); |
|
Location.getInstance().stopLocation(); |
|
queryStore( |
|
"${value.latitude}", |
|
"${value.longitude}", |
|
event["province"], |
|
event["city"], |
|
event["district"], |
|
editingController.text); |
|
if (_mapController != null) |
|
_mapController.updateMapOptions(BMFMapOptions( |
|
center: value, |
|
zoomLevel: 15, |
|
)); |
|
}); |
|
} |
|
}); |
|
|
|
Location.getInstance().prepareLoc(); |
|
Location.getInstance().startLocation(context).then((value) {}); |
|
} |
|
|
|
saveLatLng(BMFCoordinate latLng, province, city, district) async { |
|
SharedPreferences prefs = await SharedPreferences.getInstance(); |
|
await prefs.setString("latitude", "${latLng.latitude}"); |
|
await prefs.setString("longitude", "${latLng.longitude}"); |
|
if (province != null) await prefs.setString("province", province); |
|
if (city != null) await prefs.setString("city", city); |
|
if (district != null) await prefs.setString("district", district); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Column( |
|
children: [ |
|
ItemTitle( |
|
text: "店铺推荐", |
|
imgPath: "assets/image/icon_shop.png", |
|
), |
|
Container( |
|
height: 170, |
|
margin: EdgeInsets.only(top: 10), |
|
child: ListView.builder( |
|
scrollDirection: Axis.horizontal, |
|
physics: BouncingScrollPhysics(), |
|
padding: EdgeInsets.symmetric(horizontal: 10), |
|
itemCount: storeList == null ? 0 : storeList.length, |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
if (storeList[position].posType.code == "NORMALSTORE") { |
|
showDeleteDialog(); |
|
} else { |
|
Navigator.of(context).pushNamed( |
|
'/router/store_order', |
|
arguments: { |
|
"id": storeList[position].id, |
|
"tenant": storeList[position].tenantCode, |
|
"storeName": storeList[position].storeName |
|
}, |
|
); |
|
} |
|
}, |
|
child: storeItem(storeList[position], position), |
|
); |
|
}, |
|
), |
|
), |
|
], |
|
); |
|
} |
|
|
|
Widget storeItem(Store store, position) { |
|
return Container( |
|
width: 160, |
|
height: 160, |
|
margin: EdgeInsets.symmetric( |
|
horizontal: 6.w, |
|
vertical: 3, |
|
), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(4.w), |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Color(0x08000000), |
|
offset: Offset(0, 3), |
|
blurRadius: 14, |
|
spreadRadius: 0, |
|
), |
|
], |
|
), |
|
child: Stack( |
|
children: [ |
|
Positioned( |
|
top: 0, |
|
left: 0, |
|
right: 0, |
|
child: ClipRRect( |
|
child: MImage( |
|
store.facade, |
|
width: double.infinity, |
|
height: 100, |
|
fit: BoxFit.cover, |
|
errorSrc: "assets/image/default_1.png", |
|
fadeSrc: "assets/image/default_1.png", |
|
), |
|
borderRadius: BorderRadius.vertical( |
|
top: Radius.circular(4), |
|
), |
|
), |
|
), |
|
Positioned( |
|
bottom: 0, |
|
left: 0, |
|
right: 0, |
|
child: SvgPicture.asset( |
|
"assets/svg/kuaijiexiadan_bg.svg", |
|
width: double.infinity, |
|
height: 85, |
|
fit: BoxFit.fill, |
|
), |
|
), |
|
Positioned( |
|
bottom: 0, |
|
left: 0, |
|
right: 0, |
|
child: Container( |
|
height: 95, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
MImage( |
|
store.logo, |
|
width: 32, |
|
height: 32, |
|
fit: BoxFit.cover, |
|
errorSrc: "assets/image/default_1.png", |
|
fadeSrc: "assets/image/default_1.png", |
|
), |
|
Padding( |
|
padding: EdgeInsets.only(left: 10, right: 10), |
|
child: Text( |
|
store.storeName, |
|
textAlign: TextAlign.center, |
|
style: TextStyle( |
|
fontSize: 13.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
), |
|
), |
|
// Text( |
|
// store?.remark ??"", |
|
// style: TextStyle( |
|
// fontSize: 10.sp, |
|
// fontWeight: MyFontWeight.medium, |
|
// color: Color(0xFF868686), |
|
// ), |
|
// ), |
|
SizedBox( |
|
height: 5, |
|
), |
|
], |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
///扫码提示弹窗 |
|
showDeleteDialog() { |
|
showDialog( |
|
context: context, |
|
builder: (context) { |
|
return AlertDialog( |
|
content: Container( |
|
width: MediaQuery.of(context).size.width - 84, |
|
height: 110.h, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
"您即将进行扫码点餐", |
|
style: TextStyle( |
|
fontSize: 17.sp, |
|
fontWeight: FontWeight.bold, |
|
color: Colors.black, |
|
), |
|
), |
|
SizedBox( |
|
height: 30.h, |
|
), |
|
Row( |
|
children: [ |
|
Expanded( |
|
child: InkWell( |
|
child: BorderText( |
|
text: "取消", |
|
textColor: Color(0xFF32A060), |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
borderColor: Color(0xFF32A060), |
|
radius: 4, |
|
padding: EdgeInsets.all(12), |
|
borderWidth: 1, |
|
), |
|
onTap: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
), |
|
flex: 1, |
|
), |
|
SizedBox( |
|
width: 16.w, |
|
), |
|
Expanded( |
|
child: InkWell( |
|
child: RoundButton( |
|
text: "确定", |
|
textColor: Colors.white, |
|
radius: 4, |
|
padding: EdgeInsets.all(12), |
|
backgroup: Color(0xFF32A060), |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
), |
|
onTap: () { |
|
toScan(); |
|
Navigator.of(context).pop(); |
|
}, |
|
), |
|
flex: 1, |
|
), |
|
], |
|
) |
|
], |
|
), |
|
), |
|
); |
|
}, |
|
); |
|
} |
|
|
|
///扫码 |
|
toScan() async { |
|
if (await Permission.camera.isPermanentlyDenied) { |
|
showCupertinoDialog( |
|
context: context, |
|
builder: (context) { |
|
return RequestPermission( |
|
"assets/image/icon_camera_permission_tips.png", |
|
S.of(context).ninxiangjiquanxianweikaiqi, |
|
S.of(context).weilekaipaizhaoxuanzhetouxiang, |
|
S.of(context).kaiqiquanxian, |
|
(result) async { |
|
if (result) { |
|
await openAppSettings(); |
|
} |
|
}, |
|
heightRatioWithWidth: 0.82, |
|
); |
|
}); |
|
} else if (await Permission.camera.isGranted) { |
|
// http://pos.app.gznl.top/placeorder/?tableId=1315903669597634560&tenantCode=1166&shopId=1300372027722432512 |
|
var result = await Navigator.of(context).pushNamed('/router/qr_scan'); |
|
// String result = await scanner.scan(); |
|
Uri uri = Uri.parse(result); |
|
String tableId = uri.queryParameters["tableId"]; |
|
String tenantCode = uri.queryParameters["tenantCode"]; |
|
String shopId = uri.queryParameters["shopId"]; |
|
if (tableId != null && |
|
tableId != "" && |
|
tenantCode != null && |
|
tenantCode != "" && |
|
shopId != null && |
|
shopId != "") { |
|
Navigator.of(context).pushNamed( |
|
'/router/store_order', |
|
arguments: { |
|
"id": shopId, |
|
"tenant": tenantCode, |
|
"storeName": "", |
|
"tableId": int.tryParse(tableId), |
|
}, |
|
); |
|
} |
|
} else { |
|
await Permission.camera.request(); |
|
} |
|
} |
|
}
|
|
|