|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:huixiang/data/activity.dart';
|
|
|
|
import 'package:huixiang/data/base_data.dart';
|
|
|
|
import 'package:huixiang/data/store_info.dart';
|
|
|
|
import 'package:huixiang/data/user_entity.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/union/union_view/store_activity.dart';
|
|
|
|
import 'package:huixiang/union/union_view/store_info.dart';
|
|
|
|
import 'package:huixiang/union/union_view/union_coupon.dart';
|
|
|
|
import 'package:huixiang/union/union_view/vip.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/utils/shared_preference.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_appbar.dart';
|
|
|
|
import 'package:huixiang/view_widget/receive_success.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class UnionDetailsPage extends StatefulWidget {
|
|
|
|
final Map<String, dynamic>? arguments;
|
|
|
|
|
|
|
|
UnionDetailsPage({this.arguments});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _UnionDetailsPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UnionDetailsPage extends State<UnionDetailsPage> {
|
|
|
|
ApiService? apiService;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
refreshController.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
StoreInfo? storeInfo;
|
|
|
|
List<Activity>? activitys;
|
|
|
|
|
|
|
|
queryStoreInfo() async {
|
|
|
|
apiService = ApiService(Dio(), context: context, token: SharedInstance.instance.token);
|
|
|
|
BaseData? baseData = await apiService
|
|
|
|
?.queryStoreInfo(widget.arguments?["id"])
|
|
|
|
.catchError((error) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
storeInfo = StoreInfo.fromJson(baseData!.data);
|
|
|
|
activitys = storeInfo?.informationVOPageVO?.list
|
|
|
|
?.map((e) => Activity.fromJson(e))
|
|
|
|
.toList();
|
|
|
|
} else {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
|
|
|
future: queryStoreInfo(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: MyAppBar(
|
|
|
|
background: Color(0xFFF7F7F7),
|
|
|
|
title: storeInfo == null
|
|
|
|
? (widget.arguments?["storeName"] ?? "")
|
|
|
|
: storeInfo!.storeName,
|
|
|
|
titleColor: Colors.black87,
|
|
|
|
titleSize: 18.sp,
|
|
|
|
leadingColor: Colors.black,
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: SmartRefresher(
|
|
|
|
controller: refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: false,
|
|
|
|
header: MyHeader(),
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
onRefresh: () {
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
///门店信息
|
|
|
|
StoreInfos(storeInfo),
|
|
|
|
|
|
|
|
///门店对应VIP信息
|
|
|
|
Vip(storeInfo, _receiveVip, isReceive),
|
|
|
|
|
|
|
|
///门店对应优惠券
|
|
|
|
UnionCoupon(storeInfo, _receiveCoupon),
|
|
|
|
|
|
|
|
/// 门店对应的活动
|
|
|
|
StoreActivity(widget.arguments, activitys),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
flex: 1,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: _loginMin,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(top: 16.h, bottom: 16.h),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: isEnable() ? Color(0xFF32A060) : Color(0xFFD8D8D8),
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
top: Radius.circular(4),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
isEnable()
|
|
|
|
? S.of(context).jinrushangdian
|
|
|
|
: S.of(context).zanwuxianshangjindian,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.sp,
|
|
|
|
color: isEnable() ? Colors.white : Color(0xFFA0A0A0),
|
|
|
|
fontWeight: MyFontWeight.semi_bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEnable() {
|
|
|
|
String? miniAppId = storeInfo?.mini?.miniAppId;
|
|
|
|
if ((miniAppId?.isEmpty ?? true) ||
|
|
|
|
(storeInfo?.mini?.miniVersion?.isEmpty ?? true) ||
|
|
|
|
(storeInfo?.mini?.miniDownloadUrl?.isEmpty ?? true)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///领取优惠券
|
|
|
|
_receiveCoupon(couponId) async {
|
|
|
|
BaseData? baseData =
|
|
|
|
await apiService?.receiveCoupon(couponId).catchError((onError) {});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
queryStoreInfo();
|
|
|
|
showAlertDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 领取成功弹窗
|
|
|
|
showAlertDialog() {
|
|
|
|
//显示对话框
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ReceiveSuccess();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isReceive = true;
|
|
|
|
|
|
|
|
///领取VIP
|
|
|
|
_receiveVip() async {
|
|
|
|
if (storeInfo == null || (storeInfo?.id?.isEmpty ?? true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseData? baseData =
|
|
|
|
await apiService?.minLogin(storeInfo!.id!).catchError((onError) {});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
SmartDialog.showToast(S.of(context).lingquchenggong,
|
|
|
|
alignment: Alignment.center);
|
|
|
|
setState(() {
|
|
|
|
isReceive = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// printMin() async {
|
|
|
|
// String? miniAppId = storeInfo?.mini?.miniAppId;
|
|
|
|
// debugPrint("print isExistsApp: ${await Min.isExistsApp(miniAppId)}");
|
|
|
|
// debugPrint("print getAppBasePath: ${await Min.getAppBasePath(miniAppId)}");
|
|
|
|
// debugPrint("print currentPageUrl: ${await Min.currentPageUrl()}");
|
|
|
|
// debugPrint("print runingAppid: ${await Min.runingAppid()}");
|
|
|
|
// }
|
|
|
|
|
|
|
|
_loginMin() async {
|
|
|
|
if (!isEnable()) {
|
|
|
|
SmartDialog.showToast(S.of(context).zanbuzhichixianshangdiancan,
|
|
|
|
alignment: Alignment.center);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (storeInfo == null || (storeInfo?.id?.isEmpty ?? true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseData? baseData =
|
|
|
|
await apiService?.minLogin(storeInfo!.id!).catchError((onError) {});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
UserEntity userEntity = UserEntity.fromJson(baseData!.data);
|
|
|
|
// startMin(userEntity.token, userEntity.userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// startMin(token, userId) async {
|
|
|
|
// if (storeInfo == null) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// if(Platform.isAndroid){
|
|
|
|
// if (!(await Min.isInitialize())) {
|
|
|
|
// // 小程序的微信支付和app的充值支付使用同一个WXPayEntryActivity回调,
|
|
|
|
// // 然而充值时小程序未初始化会导致回调内部代码调用getPackage空指针,
|
|
|
|
// // 故而在此初始化一下
|
|
|
|
// await Min.initialize();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// printMin();
|
|
|
|
// String? miniAppId = storeInfo!.mini?.miniAppId;
|
|
|
|
// if (miniAppId?.isEmpty ?? true) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// String filePath = "";
|
|
|
|
// if (Platform.isAndroid) {
|
|
|
|
// filePath = (await getExternalStorageDirectory())?.path ?? "";
|
|
|
|
// } else {
|
|
|
|
// filePath = (await getApplicationDocumentsDirectory()).path;
|
|
|
|
// }
|
|
|
|
// filePath = "$filePath/$miniAppId.wgt";
|
|
|
|
//
|
|
|
|
// if (!(await Min.isExistsApp(miniAppId))) {
|
|
|
|
// await downloadWgt(miniAppId, filePath);
|
|
|
|
// await Min.reloadWgt(miniAppId, filePath);
|
|
|
|
// } else {
|
|
|
|
// String version = await Min.getAppVersionInfo(storeInfo!.mini!.miniAppId!);
|
|
|
|
// if (version != storeInfo!.mini!.miniVersion!) {
|
|
|
|
// await downloadWgt(miniAppId, filePath);
|
|
|
|
// await Min.reloadWgt(miniAppId, filePath);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
|
|
|
|
// String? nickname = sharedPreferences.getString("nick");
|
|
|
|
// String? mobile = sharedPreferences.getString("mobile");
|
|
|
|
// String? user = sharedPreferences.getString('user');
|
|
|
|
// String? latitude = sharedPreferences.getString("latitude");
|
|
|
|
// String? longitude = sharedPreferences.getString("longitude");
|
|
|
|
// print(user);
|
|
|
|
// UserInfo? userInfo = UserInfo.fromJson(jsonDecode(user ?? ""));
|
|
|
|
// Min.startMin(miniAppId, {
|
|
|
|
// "token": "Bearer $token",
|
|
|
|
// "shopId": widget.arguments!["id"],
|
|
|
|
// "tenantCode": storeInfo!.tenantCode,
|
|
|
|
// "position": "$latitude,$longitude",
|
|
|
|
// "baseURL": "https://pos.api.lotus-wallet.com/app/",
|
|
|
|
// // "baseURL": "http://192.168.10.236:8765/app/",
|
|
|
|
// "uid": userId,
|
|
|
|
// "userInfo": {
|
|
|
|
// "nickname": nickname,
|
|
|
|
// "headimg": userInfo.headimg,
|
|
|
|
// "balance": userInfo.balance,
|
|
|
|
// "money": userInfo.money,
|
|
|
|
// "phone": mobile,
|
|
|
|
// "isBind": userInfo.isBind,
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
double progressValue = 0;
|
|
|
|
String downText = S.current.zhengzaixiazaizhong;
|
|
|
|
|
|
|
|
downloadWgt(appId, savePath) async {
|
|
|
|
downText = S.of(context).zhengzaixiazaizhong;
|
|
|
|
Response response = await Dio()
|
|
|
|
.download(storeInfo!.mini?.miniDownloadUrl ?? "", savePath,
|
|
|
|
onReceiveProgress: (progress, max) {
|
|
|
|
progressValue = progress.toDouble() / max.toDouble();
|
|
|
|
// SmartDialog.showLoading(progressValue, status: downText);
|
|
|
|
});
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
downText = S.of(context).xiazaiwancheng;
|
|
|
|
// SmartDialog.showProgress(progressValue, status: downText);
|
|
|
|
SharedInstance.instance.saveMiniAppId((SharedInstance.instance.miniAppids)..add(appId));
|
|
|
|
} else {
|
|
|
|
print("print 下载失败");
|
|
|
|
}
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
SmartDialog.dismiss();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|