| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- import '../../core/theme/app_colors.dart';
- import '../shell/nav_bar_config.dart';
- import '../../core/utils/responsive.dart';
- import '../../shared/widgets/form_section.dart';
- import '../../shared/widgets/action_bar.dart';
- import '../../core/i18n/app_localizations.dart';
- class OutingLogCreatePage extends ConsumerStatefulWidget {
- const OutingLogCreatePage({super.key});
- @override
- ConsumerState<OutingLogCreatePage> createState() =>
- _OutingLogCreatePageState();
- }
- class _OutingLogCreatePageState extends ConsumerState<OutingLogCreatePage> {
- final _customerCtrl = TextEditingController();
- final _summaryCtrl = TextEditingController();
- final _planCtrl = TextEditingController();
- // GPS 模拟
- String _gpsAddress = '深圳市南山区科技园南路88号';
- final double _gpsLat = 22.5431;
- final double _gpsLng = 113.9532;
- double _gpsAccuracy = 15.0;
- bool _gpsFailed = false;
- // 客户联想
- final List<String> _mockCustomers = [
- '华软科技',
- '云创数据',
- '数据引力',
- '天诚科技',
- '博思软件',
- '智云科技',
- '恒通信息',
- '创新无限',
- ];
- List<String> _customerSuggestions = [];
- bool _showCustomerSuggestions = false;
- String? _selectedCustomer;
- // 客户联系人
- final Map<String, List<Map<String, String>>> _mockContacts = {
- '华软科技': [
- {'name': '赵经理', 'phone': '13800138001', 'position': 'IT经理'},
- {'name': '李主管', 'phone': '13800138002', 'position': '采购主管'},
- ],
- '云创数据': [
- {'name': '陈经理', 'phone': '13800138003', 'position': '技术总监'},
- ],
- '数据引力': [
- {'name': '孙总', 'phone': '13800138004', 'position': '总经理'},
- ],
- '天诚科技': [
- {'name': '周主任', 'phone': '13800138005', 'position': '办公室主任'},
- ],
- };
- Map<String, String>? _selectedContact;
- // 照片
- final List<String> _photos = [];
- static const int _maxPhotos = 9;
- @override
- void dispose() {
- _customerCtrl.dispose();
- _summaryCtrl.dispose();
- _planCtrl.dispose();
- super.dispose();
- }
- void _onCustomerChanged(String value) {
- setState(() {
- _selectedCustomer = null;
- _selectedContact = null;
- if (value.isEmpty) {
- _customerSuggestions = [];
- _showCustomerSuggestions = false;
- } else {
- _customerSuggestions = _mockCustomers
- .where((c) => c.contains(value))
- .toList();
- _showCustomerSuggestions = _customerSuggestions.isNotEmpty;
- }
- });
- }
- void _selectCustomer(String customer) {
- setState(() {
- _selectedCustomer = customer;
- _customerCtrl.text = customer;
- _showCustomerSuggestions = false;
- _selectedContact = null;
- });
- }
- Future<void> _pickContact() async {
- if (_selectedCustomer == null) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('请先选择客户名称')),
- );
- return;
- }
- final contacts = _mockContacts[_selectedCustomer];
- if (contacts == null || contacts.isEmpty) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('该客户暂无联系人')),
- );
- return;
- }
- final result = await showDialog<Map<String, String>>(
- context: context,
- builder: (ctx) => SimpleDialog(
- title: const Text('选择联系人'),
- children: contacts
- .map(
- (c) => SimpleDialogOption(
- onPressed: () => Navigator.pop(ctx, c),
- child: Text('${c['name']} ${c['position']} ${c['phone']}'),
- ),
- )
- .toList(),
- ),
- );
- if (result != null) {
- setState(() => _selectedContact = result);
- }
- }
- Future<void> _takePhoto() async {
- if (_photos.length >= _maxPhotos) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('最多拍摄9张照片')),
- );
- return;
- }
- final idx = _photos.length + 1;
- setState(() {
- _photos.add('photo_placeholder_$idx');
- });
- if (context.mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(
- '模拟拍照:已拍摄第 $idx 张照片(含水印:${DateTime.now().toString().substring(0, 19)} | $_gpsLat°N, $_gpsLng°E)',
- ),
- ),
- );
- }
- }
- void _removePhoto(int index) {
- setState(() => _photos.removeAt(index));
- }
- Future<void> _simulateGps() async {
- setState(() {
- _gpsFailed = false;
- _gpsAddress = '深圳市南山区科技园南路88号';
- _gpsAccuracy = 15.0;
- });
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('GPS定位成功')),
- );
- }
- Future<void> _saveDraft() async {
- if (context.mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('已保存为草稿')),
- );
- }
- }
- Future<void> _submit() async {
- if (_gpsFailed) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('无法获取GPS定位,请检查位置权限')),
- );
- return;
- }
- if (_gpsAddress.isEmpty) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('GPS定位中,请稍后')),
- );
- return;
- }
- if (_photos.isEmpty) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('请至少拍摄一张现场照片')),
- );
- return;
- }
- if (_summaryCtrl.text.trim().isEmpty) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('请填写工作总结')),
- );
- return;
- }
- if (context.mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('外勤日志提交成功')),
- );
- context.pop();
- }
- }
- @override
- Widget build(BuildContext context) {
- final r = ResponsiveHelper.of(context);
- final l10n = AppLocalizations.of(context);
- ref
- .read(navBarConfigProvider.notifier)
- .update(
- NavBarConfig(
- title: l10n.get('outingLogCreate'),
- showBack: true,
- onBack: () => context.pop(),
- ),
- );
- return Column(
- children: [
- Expanded(
- child: Align(
- alignment: Alignment.topCenter,
- child: ConstrainedBox(
- constraints: BoxConstraints(maxWidth: r.formMaxWidth),
- child: SingleChildScrollView(
- padding: const EdgeInsets.symmetric(vertical: 8),
- child: Column(
- children: [
- _buildGpsSection(),
- const SizedBox(height: 8),
- FormSection(
- title: l10n.get('customerInfo'),
- children: [
- Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 10, vertical: 4),
- decoration: BoxDecoration(
- color: AppColors.bgPage,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- TextField(
- controller: _customerCtrl,
- decoration: InputDecoration(
- hintText: l10n.get('searchCustomer'),
- hintStyle: TextStyle(
- fontSize: 14,
- color: AppColors.textPlaceholder,
- ),
- border: InputBorder.none,
- contentPadding:
- EdgeInsets.symmetric(vertical: 10),
- isDense: true,
- ),
- style: const TextStyle(
- fontSize: 14,
- color: AppColors.textPrimary,
- ),
- onChanged: _onCustomerChanged,
- ),
- if (_showCustomerSuggestions)
- ..._customerSuggestions.map(
- (s) => GestureDetector(
- onTap: () => _selectCustomer(s),
- child: Container(
- padding: const EdgeInsets.symmetric(
- vertical: 8, horizontal: 4),
- decoration: const BoxDecoration(
- border: Border(
- top: BorderSide(
- color: AppColors.border),
- ),
- ),
- child: Text(
- s,
- style: const TextStyle(
- fontSize: 14,
- color: AppColors.textPrimary,
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- const SizedBox(height: 12),
- GestureDetector(
- onTap: _pickContact,
- child: Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 10, vertical: 12),
- decoration: BoxDecoration(
- color: AppColors.bgPage,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- _selectedContact != null
- ? '${_selectedContact!['name']} ${_selectedContact!['phone']}'
- : l10n.get('selectContactHint'),
- style: TextStyle(
- fontSize: 14,
- color: _selectedContact != null
- ? AppColors.textPrimary
- : AppColors.textPlaceholder,
- ),
- ),
- const Icon(Icons.chevron_right,
- size: 14,
- color: AppColors.textPlaceholder),
- ],
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- FormSection(
- title: l10n.get('workSummary'),
- children: [
- Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: AppColors.bgPage,
- borderRadius: BorderRadius.circular(4),
- ),
- child: TextField(
- controller: _summaryCtrl,
- maxLines: 5,
- decoration: const InputDecoration(
- hintText: '请填写本次外勤工作总结(必填)',
- hintStyle: TextStyle(
- fontSize: 14,
- color: AppColors.textPlaceholder,
- ),
- border: InputBorder.none,
- contentPadding: EdgeInsets.zero,
- isDense: true,
- ),
- style: const TextStyle(
- fontSize: 14,
- color: AppColors.textPrimary,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- FormSection(
- title: l10n.get('followUp'),
- children: [
- Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 10, vertical: 4),
- decoration: BoxDecoration(
- color: AppColors.bgPage,
- borderRadius: BorderRadius.circular(4),
- ),
- child: TextField(
- controller: _planCtrl,
- decoration: const InputDecoration(
- hintText: '后续推进计划(选填)',
- hintStyle: TextStyle(
- fontSize: 14,
- color: AppColors.textPlaceholder,
- ),
- border: InputBorder.none,
- contentPadding:
- EdgeInsets.symmetric(vertical: 10),
- isDense: true,
- ),
- style: const TextStyle(
- fontSize: 14,
- color: AppColors.textPrimary,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- FormSection(
- title: l10n.get('sitePhotos'),
- actionText:
- _photos.length >= _maxPhotos ? l10n.get('limitReached') : l10n.get('takePhoto'),
- showAction: _photos.length < _maxPhotos,
- actionIcon: Icons.camera_alt_outlined,
- onActionTap:
- _photos.length >= _maxPhotos ? null : _takePhoto,
- children: [
- if (_photos.isEmpty)
- GestureDetector(
- onTap: _takePhoto,
- child: Container(
- height: 100,
- decoration: BoxDecoration(
- color: AppColors.bgPage,
- borderRadius: BorderRadius.circular(4),
- border: Border.all(
- color: AppColors.border, width: 1),
- ),
- child: const Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Icon(Icons.camera_alt_outlined,
- size: 32, color: AppColors.primary),
- SizedBox(height: 4),
- Text(
- '点击拍照(至少1张)',
- style: TextStyle(
- fontSize: 12,
- color: AppColors.textPlaceholder,
- ),
- ),
- ],
- ),
- ),
- ),
- )
- else
- Wrap(
- spacing: 8,
- runSpacing: 8,
- children: [
- ..._photos.asMap().entries.map(
- (entry) =>
- _buildPhotoThumbnail(
- entry.key, entry.value),
- ),
- if (_photos.length < _maxPhotos)
- GestureDetector(
- onTap: _takePhoto,
- child: Container(
- width: 80,
- height: 80,
- decoration: BoxDecoration(
- color: AppColors.bgPage,
- borderRadius: BorderRadius.circular(4),
- border: Border.all(
- color: AppColors.border),
- ),
- child: const Icon(Icons.add,
- size: 28, color: AppColors.primary),
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- Container(
- padding: const EdgeInsets.all(8),
- decoration: BoxDecoration(
- color: AppColors.primaryLight,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Row(
- children: [
- const Icon(Icons.info_outline,
- size: 14, color: AppColors.primary),
- const SizedBox(width: 6),
- Expanded(
- child: Text(
- '照片将自动添加水印:服务器授时 + GPS经纬度(${_gpsLat.toStringAsFixed(4)}°N, ${_gpsLng.toStringAsFixed(4)}°E)',
- style: const TextStyle(
- fontSize: 11,
- color: AppColors.textSecondary,
- ),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- const SizedBox(height: 80),
- ],
- ),
- ),
- ),
- ),
- ),
- ActionBar(
- centerLabel: l10n.get('saveDraft'),
- rightLabel: l10n.get('submit'),
- showLeft: false,
- onCenterTap: _saveDraft,
- onRightTap: _submit,
- ),
- ],
- );
- }
- Widget _buildGpsSection() {
- if (_gpsFailed) {
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: AppColors.bgCard,
- borderRadius: BorderRadius.circular(8),
- ),
- child: Row(
- children: [
- const Icon(Icons.location_off,
- size: 22, color: AppColors.statusGray),
- const SizedBox(width: 10),
- const Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text('无法获取当前位置',
- style: TextStyle(
- fontSize: 14, color: AppColors.textPrimary)),
- SizedBox(height: 4),
- Text('请检查位置权限设置',
- style: TextStyle(
- fontSize: 12, color: AppColors.textSecondary)),
- ],
- ),
- ),
- GestureDetector(
- onTap: _simulateGps,
- child: Container(
- padding:
- const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
- decoration: BoxDecoration(
- color: AppColors.primaryLight,
- borderRadius: BorderRadius.circular(4),
- ),
- child: const Text('重试',
- style:
- TextStyle(fontSize: 12, color: AppColors.primary)),
- ),
- ),
- ],
- ),
- );
- }
- final isWarning = _gpsAccuracy > 100;
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: AppColors.bgCard,
- borderRadius: BorderRadius.circular(8),
- ),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Icon(
- Icons.shield_outlined,
- size: 22,
- color: isWarning ? AppColors.warning : AppColors.success,
- ),
- const SizedBox(width: 10),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(_gpsAddress,
- style: const TextStyle(
- fontSize: 14, color: AppColors.textPrimary)),
- const SizedBox(height: 4),
- Row(
- children: [
- Text(
- '${_gpsLat.toStringAsFixed(4)}°N, ${_gpsLng.toStringAsFixed(4)}°E · 精度 ${_gpsAccuracy.toStringAsFixed(0)}m',
- style: TextStyle(
- fontSize: 12,
- color: isWarning
- ? AppColors.warning
- : AppColors.textSecondary,
- ),
- ),
- if (isWarning) ...[
- const SizedBox(width: 6),
- const Icon(Icons.warning_amber_rounded,
- size: 14, color: AppColors.warning),
- ],
- ],
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildPhotoThumbnail(int index, String photo) {
- return Stack(
- children: [
- Container(
- width: 80,
- height: 80,
- decoration: BoxDecoration(
- color: const Color(0xFFD0E8F8),
- borderRadius: BorderRadius.circular(4),
- ),
- child: const Center(
- child: Icon(Icons.image_outlined,
- size: 32, color: AppColors.primary),
- ),
- ),
- Positioned(
- top: -4,
- right: -4,
- child: GestureDetector(
- onTap: () => _removePhoto(index),
- child: Container(
- padding: const EdgeInsets.all(2),
- decoration: const BoxDecoration(
- color: AppColors.danger,
- shape: BoxShape.circle,
- ),
- child:
- const Icon(Icons.close, size: 14, color: Colors.white),
- ),
- ),
- ),
- Positioned(
- bottom: 2,
- left: 2,
- right: 2,
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 2),
- color: Colors.black54,
- child: Text(
- '${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')} ${_gpsLat.toStringAsFixed(2)},${_gpsLng.toStringAsFixed(2)}',
- style: const TextStyle(fontSize: 8, color: Colors.white),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ),
- ],
- );
- }
- }
|