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
13 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';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:geolocator/geolocator.dart';
3 years ago
import 'package:huixiang/generated/l10n.dart';
3 years ago
import 'package:huixiang/utils/location.dart';
import 'package:huixiang/data/base_data.dart';
import 'package:huixiang/data/store.dart';
3 years ago
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' as PH;
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> {
ApiService? apiService;
List<Store>? storeList;
Position? latLng;
3 years ago
// BMFMapController? _mapController;
3 years ago
final TextEditingController editingController = TextEditingController();
@override
void initState() {
super.initState();
getLatLng();
startLocation();
}
///门店列表
queryStore(latitude, longitude, searchKey) async {
BaseData<List<Store>>? baseData = await apiService?.queryStore({
3 years ago
// "city": city,
// "district": district,
// "province": province,
"latitude": latitude,
"longitude": longitude,
"searchKey": searchKey
}).catchError((error) {
});
if (baseData?.isSuccess ?? false) {
storeList = baseData!.data;
3 years ago
}
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") )
3 years ago
{
latLng = Position(
latitude: double.tryParse(value.getString("latitude") ??"")!,
longitude: double.tryParse(value.getString("longitude") ?? "")!,
timestamp: DateTime.now(),
accuracy: 0,
altitude: 0,
heading: 0,
speed: 0,
speedAccuracy: 0
),
3 years ago
queryStore(
value.getString("latitude"),
value.getString("longitude"),
editingController.text,
),
setState(() {
// _mapController?.updateMapOptions(
// BMFMapOptions(
// center: latLng,
// zoomLevel: 15,
// ));
3 years ago
})
}
else
{
queryStore("", "", editingController.text),
3 years ago
}
},
);
}
startLocation() async {
LocationInstance.getInstance().startLocation(context, (Position? result){
if (result?.latitude != null &&
result?.longitude != null) {
print("location: $result");
latLng = Position(
latitude: result?.latitude??0,
longitude: result?.longitude ?? 0,
timestamp: DateTime.now(),
accuracy: 0,
altitude: 0,
heading: 0,
speed: 0,
speedAccuracy: 0
);
LocationInstance.getInstance().getAddress(latLng!.latitude, latLng!.longitude)?.then((r) {
if (r != null) {
saveLatLng(latLng!, r.province, r.city, r.area);
}
LocationInstance.getInstance().stopLocation();
3 years ago
queryStore(
"${latLng?.latitude}",
"${latLng?.longitude}",
3 years ago
editingController.text);
// _mapController?.updateMapOptions(BMFMapOptions(
// center: value,
// zoomLevel: 15,
// )
// );
return r;
3 years ago
});
}
}).then((value) {});
3 years ago
}
saveLatLng(Position latLng, province, city, district) async {
3 years ago
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?.length ?? 0,
3 years ago
itemBuilder: (context, position) {
3 years ago
return GestureDetector(
onTap: () {
if (storeList![position].posType?.code == "NORMALSTORE") {
3 years ago
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
},
);
}
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 PH.Permission.camera.isPermanentlyDenied) {
3 years ago
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 PH.openAppSettings();
3 years ago
}
},
heightRatioWithWidth: 0.82,
);
});
} else if (await PH.Permission.camera.isGranted) {
3 years ago
// 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');
if (result == null || result !is String || (result as String).isEmpty) {
return;
}
3 years ago
// 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 != "" &&
tenantCode != "" &&
shopId != "") {
3 years ago
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": shopId,
"tenant": tenantCode,
"storeName": "",
"tableId": int.tryParse(tableId),
},
);
}
} else {
await PH.Permission.camera.request();
3 years ago
}
}
3 years ago
}