228 lines
7.6 KiB
Dart
228 lines
7.6 KiB
Dart
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:forui/forui.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
import '../controller.dart';
|
|
import 'setting_components.dart';
|
|
|
|
Widget settingPay(BuildContext context) {
|
|
final controller = Get.find<SettingController>();
|
|
return Obx(() {
|
|
final sys = controller.sysSetting.value;
|
|
if (sys == null) return const SettingEmpty(message: '暂无支付设置');
|
|
final enabled = sys.usePayDisplayType ?? OrderPayDisplayType.values;
|
|
final defaultType = sys.defaultPayDisplayType ?? enabled.firstOrNull;
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
SettingGroup(
|
|
title: '使用支付方式',
|
|
child: Padding(
|
|
padding: EdgeInsets.all(16.w),
|
|
child: GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 4,
|
|
crossAxisSpacing: XfjDesignTokens.cardGap.w,
|
|
mainAxisSpacing: XfjDesignTokens.cardGap.h,
|
|
childAspectRatio: 2.35,
|
|
),
|
|
itemCount: OrderPayDisplayType.values.length,
|
|
itemBuilder: (context, index) {
|
|
final type = OrderPayDisplayType.values[index];
|
|
return _PayTypeCard(
|
|
type: type,
|
|
selected: enabled.contains(type),
|
|
onTap: () => controller.togglePayType(type),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: XfjDesignTokens.cardGap.h),
|
|
SettingGroup(
|
|
title: '默认支付方式',
|
|
child: Padding(
|
|
padding: EdgeInsets.all(16.w),
|
|
child: GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 4,
|
|
crossAxisSpacing: XfjDesignTokens.cardGap.w,
|
|
mainAxisSpacing: XfjDesignTokens.cardGap.h,
|
|
childAspectRatio: 3.3,
|
|
),
|
|
itemCount: enabled.length,
|
|
itemBuilder: (context, index) {
|
|
final type = enabled[index];
|
|
return _DefaultPayCard(
|
|
type: type,
|
|
selected: type == defaultType,
|
|
onTap: () => controller.setDefaultPayType(type),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: XfjDesignTokens.cardGap.h),
|
|
const SettingNotice(
|
|
text: '修改支付方式只影响收银端选择入口,不改变服务端权限、钱包范围和渠道支付能力。',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
class _PayTypeCard extends StatelessWidget {
|
|
const _PayTypeCard({
|
|
required this.type,
|
|
required this.selected,
|
|
required this.onTap,
|
|
});
|
|
|
|
final OrderPayDisplayType type;
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = FTheme.of(context);
|
|
return InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
child: Container(
|
|
padding: EdgeInsets.all(14.w),
|
|
decoration: BoxDecoration(
|
|
color:
|
|
selected ? XfjDesignTokens.primarySoft : XfjDesignTokens.surface,
|
|
border: Border.all(
|
|
color: selected ? XfjDesignTokens.primary : XfjDesignTokens.line,
|
|
),
|
|
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
FIcon(
|
|
_payIcon(type),
|
|
color: selected
|
|
? XfjDesignTokens.primary
|
|
: XfjDesignTokens.muted,
|
|
size: 24.sp,
|
|
),
|
|
SizedBox(width: 10.w),
|
|
Expanded(
|
|
child: Text(
|
|
_payLabel(type),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.typography.base.copyWith(
|
|
color: XfjDesignTokens.ink,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
width: 24.w,
|
|
height: 24.w,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color:
|
|
selected ? XfjDesignTokens.primary : Colors.transparent,
|
|
border: selected
|
|
? null
|
|
: Border.all(color: XfjDesignTokens.line),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: selected
|
|
? FIcon(FAssets.icons.check,
|
|
color: Colors.white, size: 14.sp)
|
|
: null,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 8.h),
|
|
Text(
|
|
selected ? '收银时可选择' : '当前已停用',
|
|
style: theme.typography.sm.copyWith(
|
|
color: XfjDesignTokens.muted,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DefaultPayCard extends StatelessWidget {
|
|
const _DefaultPayCard({
|
|
required this.type,
|
|
required this.selected,
|
|
required this.onTap,
|
|
});
|
|
|
|
final OrderPayDisplayType type;
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = FTheme.of(context);
|
|
return InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: selected ? XfjDesignTokens.primary : XfjDesignTokens.surface,
|
|
border: Border.all(
|
|
color: selected ? XfjDesignTokens.primary : XfjDesignTokens.line,
|
|
),
|
|
borderRadius: BorderRadius.circular(XfjDesignTokens.controlRadius),
|
|
),
|
|
child: Text(
|
|
_payLabel(type),
|
|
style: theme.typography.base.copyWith(
|
|
color: selected ? Colors.white : XfjDesignTokens.ink,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _payLabel(OrderPayDisplayType type) {
|
|
return switch (type) {
|
|
OrderPayDisplayType.walletCard => '饭卡',
|
|
OrderPayDisplayType.qrCode => '付款码',
|
|
OrderPayDisplayType.qrCodeScan => '扫一扫',
|
|
OrderPayDisplayType.face => '人脸',
|
|
OrderPayDisplayType.cash => '现金',
|
|
OrderPayDisplayType.zyy => '中医院',
|
|
OrderPayDisplayType.rmyy => '人民医院',
|
|
OrderPayDisplayType.csxfk => '超市消费卡',
|
|
};
|
|
}
|
|
|
|
SvgAsset _payIcon(OrderPayDisplayType type) {
|
|
return switch (type) {
|
|
OrderPayDisplayType.walletCard => FAssets.icons.idCard,
|
|
OrderPayDisplayType.qrCode => FAssets.icons.qrCode,
|
|
OrderPayDisplayType.qrCodeScan => FAssets.icons.scanLine,
|
|
OrderPayDisplayType.face => FAssets.icons.scanFace,
|
|
OrderPayDisplayType.cash => FAssets.icons.banknote,
|
|
_ => FAssets.icons.creditCard,
|
|
};
|
|
}
|