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.

414 lines
14 KiB

3 years ago
import 'package:dio/dio.dart';
3 years ago
import 'package:flutter/cupertino.dart';
3 years ago
import 'package:flutter/material.dart';
3 years ago
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_bmflocation/flutter_bmflocation.dart';
3 years ago
import 'package:flutter_svg/flutter_svg.dart';
3 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/store/scan.dart';
3 years ago
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';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
3 years ago
import 'package:huixiang/view_widget/border_text.dart';
3 years ago
import 'package:huixiang/view_widget/custom_image.dart';
3 years ago
import 'package:huixiang/view_widget/item_title.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:huixiang/view_widget/request_permission.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:permission_handler/permission_handler.dart';
3 years ago
import 'package:shared_preferences/shared_preferences.dart';
3 years ago
class QuickOrder extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _QuickOrder();
}
}
class _QuickOrder extends State<QuickOrder> {
3 years ago
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) {});
3 years ago
if (baseData != null && baseData.isSuccess) {
storeList = baseData.data;
}
setState(() {});
}
getLatLng() async {
SharedPreferences.getInstance().then(
(value) => {
3 years ago
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().startLocation(context, (BaiduLocation result){
if (result != null &&
result.latitude != null &&
result.longitude != null) {
print("location: $result");
latLng = BMFCoordinate(result.latitude, result.longitude);
3 years ago
BMFCalculateUtils.coordConvert(
coordinate: latLng,
fromType: BMF_COORD_TYPE.BD09LL,
toType: BMF_COORD_TYPE.COMMON)
3 years ago
.then((value) {
this.latLng = value;
saveLatLng(
value, result.province, result.city, result.district);
3 years ago
print("union: Location result ${value.latitude} "
"${value.longitude}");
Location.getInstance().stopLocation();
queryStore(
"${value.latitude}",
"${value.longitude}",
result.province,
result.city,
result.district,
3 years ago
editingController.text);
if (_mapController != null)
_mapController.updateMapOptions(BMFMapOptions(
center: value,
zoomLevel: 15,
));
});
}
}).then((value) {});
3 years ago
}
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);
}
3 years ago
@override
Widget build(BuildContext context) {
return Column(
children: [
ItemTitle(
text: S.of(context).dianputuijian,
imgPath: "assets/image/icon_shop.webp",
3 years ago
),
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,
3 years ago
itemBuilder: (context, position) {
3 years ago
return GestureDetector(
onTap: () {
3 years ago
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
},
);
}
3 years ago
},
child: storeItem(storeList[position], position),
3 years ago
);
3 years ago
},
),
),
],
);
}
Widget storeItem(Store store, position) {
3 years ago
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(
3 years ago
child: MImage(
store.facade,
3 years ago
width: double.infinity,
height: 100,
3 years ago
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
3 years ago
),
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,
3 years ago
fit: BoxFit.fill,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 95,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
3 years ago
MImage(
store.logo,
3 years ago
width: 32,
height: 32,
3 years ago
fit: BoxFit.cover,
isCircle: true,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
3 years ago
),
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,
),
3 years ago
),
),
3 years ago
// Text(
// store?.remark ??"",
// style: TextStyle(
// fontSize: 10.sp,
// fontWeight: MyFontWeight.medium,
// color: Color(0xFF868686),
// ),
// ),
3 years ago
SizedBox(
height: 5,
),
],
),
),
),
],
),
);
}
3 years ago
///扫码提示弹窗
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(
S.of(context).saomadiancan,
3 years ago
style: TextStyle(
fontSize: 17.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(
height: 30.h,
),
Row(
children: [
Expanded(
child: InkWell(
child: BorderText(
text: S.of(context).quxiao,
3 years ago
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: S.of(context).queren,
3 years ago
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.webp",
3 years ago
S.of(context).ninxiangjiquanxianweikaiqi,
S.of(context).weilekaipaizhaoxuanzhetouxiang,
S.of(context).kaiqiquanxian,
(result) async {
3 years ago
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
// 新版桌子码跳转
// http://miniscan.lotus-wallet.com/placeorder?tenant_code=1194&table_id=1669609340031467520&store_id=1637659387134738432
3 years ago
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"] ?? uri.queryParameters["table_id"];
String tenantCode = uri.queryParameters["tenantCode"] ?? uri.queryParameters["tenant_code"];
String shopId = uri.queryParameters["shopId"] ?? uri.queryParameters["store_id"];
if (tableId != null &&
tableId != "" &&
tenantCode != null &&
tenantCode != "" &&
shopId != null &&
shopId != "") {
3 years ago
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": shopId,
"tenant": tenantCode,
"storeName": "",
"tableId": int.tryParse(tableId),
},
);
}
} else {
await Permission.camera.request();
}
}
3 years ago
}