123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- import 'dart:io';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:image_picker/image_picker.dart';
- import 'package:keyboard_actions/keyboard_actions.dart';
- import 'package:liftmanager/internal/team/model/team_auth_item.dart';
- import 'package:liftmanager/internal/team/team_router.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/utils/image_utils.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/widgets/app_bar.dart';
- import 'package:liftmanager/widgets/click_item.dart';
- import 'package:liftmanager/widgets/selected_image.dart';
- class TeamAuthPage extends StatefulWidget {
- @override
- State<StatefulWidget> createState() {
- return TeamCardPageState();
- }
- }
- class TeamCardPageState extends State<TeamAuthPage> {
- final FocusNode _nodeText1 = FocusNode();
- final FocusNode _nodeText2 = FocusNode();
- final FocusNode _nodeText3 = FocusNode();
- TeamAuthItem item = TeamAuthItem();
- List<File> images = [];
- File headerImg;
- @override
- void initState() {
- super.initState();
- getTeamAuthInfo();
- }
- getTeamAuthInfo() {
- ApiService(context: context).teamAuth(onSuccess: (res) {
- if (res != null) {
- item = res;
- setState(() {});
- }
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- ///选择图片
- void selectPicker(int index) {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return SimpleDialog(
- title: Text("选择方式"),
- children: ["拍照", '从手机相册选择'].map((String value) {
- print("$value");
- return SimpleDialogOption(
- child: Text(
- "${value}",
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
- ),
- onPressed: () {
- if (index == -1) {
- _getHeaderImage(value == '拍照' ? 1 : 0);
- } else {
- _getImage(value == '拍照' ? 1 : 0, index);
- }
- Navigator.of(context).pop();
- },
- );
- }).toList());
- });
- }
- void _getHeaderImage(int key) async {
- try {
- var _imageFile = await ImagePicker.pickImage(
- source: key == 1 ? ImageSource.camera : ImageSource.gallery,
- maxWidth: 800,
- imageQuality: 95);
- if (_imageFile != null) {
- headerImg = _imageFile;
- setState(() {});
- }
- } catch (e) {
- toasts("没有权限,无法打开相册!");
- }
- }
- void _getImage(int key, int index) async {
- try {
- var _imageFile = await ImagePicker.pickImage(
- source: key == 1 ? ImageSource.camera : ImageSource.gallery,
- maxWidth: 800,
- imageQuality: 95);
- if (_imageFile != null) {
- if (images.length > index) {
- images[index] = _imageFile;
- } else {
- images.add(_imageFile);
- }
- setState(() {});
- }
- } catch (e) {
- toasts("没有权限,无法打开相册!");
- }
- }
- /**
- * 提交认证信息
- */
- uploadAuthData() {
- if (item.attestationName.length == 0) {
- toasts("请输入团队名称");
- return;
- }
- if (item.contactsName.length == 0) {
- toasts("请输入联系人");
- return;
- }
- if (item.contactsTel.length == 0) {
- toasts("请输入联系人电话");
- return;
- }
- if (images.length != 2) {
- toasts("请上传营业执照/资质证书");
- return;
- }
- if (headerImg != null) {
- images.add(headerImg);
- }
- showLoading(context, "正在提交");
- ApiService(context: context).uploadMore(images,
- onSuccess: (List<String> list) {
- ApiService(context: context).teamUploadAuth(
- item.id,
- item.attestationName,
- item.contactsName,
- item.contactsTel,
- list[0],
- list[1],
- list.length == 3 ? list[2] : "", onSuccess: (res) {
- dismissLoading(context);
- showAlert(context, "", res.message, "确定", () {
- NavigatorUtils.goBack(context);
- NavigatorUtils.goBack(context);
- });
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
- @override
- Widget build(BuildContext context) {
- // TODO: implement build
- return Scaffold(
- appBar: MyAppBar(
- centerTitle: "我的团队",
- actions: <Widget>[
- FlatButton(
- child: Text("去认证"),
- textColor: Colours.tip_text_black,
- highlightColor: Colors.transparent,
- onPressed: () {
-
- // uploadAuthData();
- NavigatorUtils.push(context, TeamRouter.teamAuthUploadPage);
- },
- )
- ],
- ),
- body: SafeArea(
- child: Column(
- children: <Widget>[
- Expanded(
- flex: 1,
- child: defaultTargetPlatform == TargetPlatform.iOS
- ? FormKeyboardActions(child: _buildBody())
- : SingleChildScrollView(child: _buildBody()),
- )
- ],
- ),
- ));
- }
- _buildBody() {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: _listWidgets(),
- );
- }
- _listWidgets() {
- return [
- Container(
- padding: EdgeInsets.only(top: 10, bottom: 20),
- color: ThemeUtils.getTabsBg(context),
- child: GestureDetector(
- onTap: () {
- selectPicker(-1);
- },
- child: Center(
- child: CircleAvatar(
- radius: 30,
- backgroundColor: Colors.transparent,
- backgroundImage: ImageUtils.getImageProvider(item.logoImg)),
- )),
- ),
- Container(
- padding: EdgeInsets.only(bottom: 20),
- color: ThemeUtils.getTabsBg(context),
- child: Center(
- child: Container(
- padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
- decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
- child: Text("logo",
- style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
- )),
- ),
- Gaps.vGap10,
- ClickItem(
- title: "状态",
- content:
- "${item.isCertificated == 1 ? '已认证' : item.isCertificated == 2 ? '审核中' : item.isCertificated == 3 ? '认证失败' : '未认证'}",
- ),
- ClickItem(
- title: "团队名称",
- content: "${item.attestationName}",
- ),
- ClickItem(
- title: "联系人",
- content: "${item.contactsName}",
- ),
- ClickItem(
- title: "联系人电话",
- content: "${item.contactsTel}",
- ),
- Gaps.vGap10,
- ClickItem(
- title: "企业营业执照/资质证书",
- content: "",
- hideDiv: true,
- ),
- Container(
- color: ThemeUtils.getTabsBg(context),
- child: GridView.builder(
- shrinkWrap: true,
- padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
- physics: NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3, childAspectRatio: 1.18),
- itemCount: 2,
- itemBuilder: (_, index) {
- return Stack(
- children: <Widget>[
- Center(
- child: imageWidget(index),
- )
- ],
- );
- },
- ))
- ];
- }
- Widget imageWidget(int index) {
- if (index == 0 && item.businessLicenseAnnex.length > 0) {
- return Image.network(
- "${item.businessLicenseAnnex}",
- width: 150,
- height: 150,
- fit: BoxFit.fill,
- );
- }
- if (index == 1 && item.taxRegistration.length > 0) {
- return Image.network(
- "${item.taxRegistration}",
- width: 150,
- height: 150,
- fit: BoxFit.fill,
- );
- }
- return SelectedImage(
- image: index < images.length ? images[index] : null,
- onTap: () {
- selectPicker(index);
- });
- }
- }
|