team_auth_page.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import 'dart:io';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:image_picker/image_picker.dart';
  5. import 'package:keyboard_actions/keyboard_actions.dart';
  6. import 'package:liftmanager/internal/team/model/team_auth_item.dart';
  7. import 'package:liftmanager/internal/team/team_router.dart';
  8. import 'package:liftmanager/net/api_service.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/image_utils.dart';
  12. import 'package:liftmanager/utils/theme_utils.dart';
  13. import 'package:liftmanager/utils/toast.dart';
  14. import 'package:liftmanager/widgets/app_bar.dart';
  15. import 'package:liftmanager/widgets/click_item.dart';
  16. import 'package:liftmanager/widgets/selected_image.dart';
  17. class TeamAuthPage extends StatefulWidget {
  18. @override
  19. State<StatefulWidget> createState() {
  20. return TeamCardPageState();
  21. }
  22. }
  23. class TeamCardPageState extends State<TeamAuthPage> {
  24. final FocusNode _nodeText1 = FocusNode();
  25. final FocusNode _nodeText2 = FocusNode();
  26. final FocusNode _nodeText3 = FocusNode();
  27. TeamAuthItem item = TeamAuthItem();
  28. List<File> images = [];
  29. File headerImg;
  30. @override
  31. void initState() {
  32. super.initState();
  33. getTeamAuthInfo();
  34. }
  35. getTeamAuthInfo() {
  36. ApiService(context: context).teamAuth(onSuccess: (res) {
  37. if (res != null) {
  38. item = res;
  39. setState(() {});
  40. }
  41. }, onError: (code, msg) {
  42. toasts(msg);
  43. });
  44. }
  45. ///选择图片
  46. void selectPicker(int index) {
  47. showDialog(
  48. context: context,
  49. builder: (BuildContext context) {
  50. return SimpleDialog(
  51. title: Text("选择方式"),
  52. children: ["拍照", '从手机相册选择'].map((String value) {
  53. print("$value");
  54. return SimpleDialogOption(
  55. child: Text(
  56. "${value}",
  57. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  58. ),
  59. onPressed: () {
  60. if (index == -1) {
  61. _getHeaderImage(value == '拍照' ? 1 : 0);
  62. } else {
  63. _getImage(value == '拍照' ? 1 : 0, index);
  64. }
  65. Navigator.of(context).pop();
  66. },
  67. );
  68. }).toList());
  69. });
  70. }
  71. void _getHeaderImage(int key) async {
  72. try {
  73. var _imageFile = await ImagePicker.pickImage(
  74. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  75. maxWidth: 800,
  76. imageQuality: 95);
  77. if (_imageFile != null) {
  78. headerImg = _imageFile;
  79. setState(() {});
  80. }
  81. } catch (e) {
  82. toasts("没有权限,无法打开相册!");
  83. }
  84. }
  85. void _getImage(int key, int index) async {
  86. try {
  87. var _imageFile = await ImagePicker.pickImage(
  88. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  89. maxWidth: 800,
  90. imageQuality: 95);
  91. if (_imageFile != null) {
  92. if (images.length > index) {
  93. images[index] = _imageFile;
  94. } else {
  95. images.add(_imageFile);
  96. }
  97. setState(() {});
  98. }
  99. } catch (e) {
  100. toasts("没有权限,无法打开相册!");
  101. }
  102. }
  103. /**
  104. * 提交认证信息
  105. */
  106. uploadAuthData() {
  107. if (item.attestationName.length == 0) {
  108. toasts("请输入团队名称");
  109. return;
  110. }
  111. if (item.contactsName.length == 0) {
  112. toasts("请输入联系人");
  113. return;
  114. }
  115. if (item.contactsTel.length == 0) {
  116. toasts("请输入联系人电话");
  117. return;
  118. }
  119. if (images.length != 2) {
  120. toasts("请上传营业执照/资质证书");
  121. return;
  122. }
  123. if (headerImg != null) {
  124. images.add(headerImg);
  125. }
  126. showLoading(context, "正在提交");
  127. ApiService(context: context).uploadMore(images,
  128. onSuccess: (List<String> list) {
  129. ApiService(context: context).teamUploadAuth(
  130. item.id,
  131. item.attestationName,
  132. item.contactsName,
  133. item.contactsTel,
  134. list[0],
  135. list[1],
  136. list.length == 3 ? list[2] : "", onSuccess: (res) {
  137. dismissLoading(context);
  138. showAlert(context, "", res.message, "确定", () {
  139. NavigatorUtils.goBack(context);
  140. NavigatorUtils.goBack(context);
  141. });
  142. }, onError: (code, msg) {
  143. dismissLoading(context);
  144. toasts(msg);
  145. });
  146. }, onError: (code, msg) {
  147. dismissLoading(context);
  148. toasts(msg);
  149. });
  150. }
  151. @override
  152. Widget build(BuildContext context) {
  153. // TODO: implement build
  154. return Scaffold(
  155. appBar: MyAppBar(
  156. centerTitle: "我的团队",
  157. actions: <Widget>[
  158. FlatButton(
  159. child: Text("去认证"),
  160. textColor: Colours.tip_text_black,
  161. highlightColor: Colors.transparent,
  162. onPressed: () {
  163. // uploadAuthData();
  164. NavigatorUtils.push(context, TeamRouter.teamAuthUploadPage);
  165. },
  166. )
  167. ],
  168. ),
  169. body: SafeArea(
  170. child: Column(
  171. children: <Widget>[
  172. Expanded(
  173. flex: 1,
  174. child: defaultTargetPlatform == TargetPlatform.iOS
  175. ? FormKeyboardActions(child: _buildBody())
  176. : SingleChildScrollView(child: _buildBody()),
  177. )
  178. ],
  179. ),
  180. ));
  181. }
  182. _buildBody() {
  183. return Column(
  184. crossAxisAlignment: CrossAxisAlignment.start,
  185. children: _listWidgets(),
  186. );
  187. }
  188. _listWidgets() {
  189. return [
  190. Container(
  191. padding: EdgeInsets.only(top: 10, bottom: 20),
  192. color: ThemeUtils.getTabsBg(context),
  193. child: GestureDetector(
  194. onTap: () {
  195. selectPicker(-1);
  196. },
  197. child: Center(
  198. child: CircleAvatar(
  199. radius: 30,
  200. backgroundColor: Colors.transparent,
  201. backgroundImage: ImageUtils.getImageProvider(item.logoImg)),
  202. )),
  203. ),
  204. Container(
  205. padding: EdgeInsets.only(bottom: 20),
  206. color: ThemeUtils.getTabsBg(context),
  207. child: Center(
  208. child: Container(
  209. padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
  210. decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
  211. child: Text("logo",
  212. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
  213. )),
  214. ),
  215. Gaps.vGap10,
  216. ClickItem(
  217. title: "状态",
  218. content:
  219. "${item.isCertificated == 1 ? '已认证' : item.isCertificated == 2 ? '审核中' : item.isCertificated == 3 ? '认证失败' : '未认证'}",
  220. ),
  221. ClickItem(
  222. title: "团队名称",
  223. content: "${item.attestationName}",
  224. ),
  225. ClickItem(
  226. title: "联系人",
  227. content: "${item.contactsName}",
  228. ),
  229. ClickItem(
  230. title: "联系人电话",
  231. content: "${item.contactsTel}",
  232. ),
  233. Gaps.vGap10,
  234. ClickItem(
  235. title: "企业营业执照/资质证书",
  236. content: "",
  237. hideDiv: true,
  238. ),
  239. Container(
  240. color: ThemeUtils.getTabsBg(context),
  241. child: GridView.builder(
  242. shrinkWrap: true,
  243. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  244. physics: NeverScrollableScrollPhysics(),
  245. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  246. crossAxisCount: 3, childAspectRatio: 1.18),
  247. itemCount: 2,
  248. itemBuilder: (_, index) {
  249. return Stack(
  250. children: <Widget>[
  251. Center(
  252. child: imageWidget(index),
  253. )
  254. ],
  255. );
  256. },
  257. ))
  258. ];
  259. }
  260. Widget imageWidget(int index) {
  261. if (index == 0 && item.businessLicenseAnnex.length > 0) {
  262. return Image.network(
  263. "${item.businessLicenseAnnex}",
  264. width: 150,
  265. height: 150,
  266. fit: BoxFit.fill,
  267. );
  268. }
  269. if (index == 1 && item.taxRegistration.length > 0) {
  270. return Image.network(
  271. "${item.taxRegistration}",
  272. width: 150,
  273. height: 150,
  274. fit: BoxFit.fill,
  275. );
  276. }
  277. return SelectedImage(
  278. image: index < images.length ? images[index] : null,
  279. onTap: () {
  280. selectPicker(index);
  281. });
  282. }
  283. }