team_auth_page.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. import 'package:liftmanager/widgets/text_field_item.dart';
  18. class TeamAuthPage extends StatefulWidget {
  19. @override
  20. State<StatefulWidget> createState() {
  21. return TeamCardPageState();
  22. }
  23. }
  24. class TeamCardPageState extends State<TeamAuthPage> {
  25. final FocusNode _nodeText1 = FocusNode();
  26. final FocusNode _nodeText2 = FocusNode();
  27. final FocusNode _nodeText3 = FocusNode();
  28. TeamAuthItem item = TeamAuthItem();
  29. List<File> images = [];
  30. File headerImg;
  31. @override
  32. void initState() {
  33. super.initState();
  34. getTeamAuthInfo();
  35. }
  36. getTeamAuthInfo() {
  37. ApiService(context: context).teamAuth(onSuccess: (res) {
  38. if (res != null) {
  39. item = res;
  40. setState(() {});
  41. }
  42. }, onError: (code, msg) {
  43. toasts(msg);
  44. });
  45. }
  46. ///选择图片
  47. void selectPicker(int index) {
  48. showDialog(
  49. context: context,
  50. builder: (BuildContext context) {
  51. return SimpleDialog(
  52. title: Text("选择方式"),
  53. children: ["拍照", '从手机相册选择'].map((String value) {
  54. print("$value");
  55. return SimpleDialogOption(
  56. child: Text(
  57. "${value}",
  58. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  59. ),
  60. onPressed: () {
  61. if (index == -1) {
  62. _getHeaderImage(value == '拍照' ? 1 : 0);
  63. } else {
  64. _getImage(value == '拍照' ? 1 : 0, index);
  65. }
  66. Navigator.of(context).pop();
  67. },
  68. );
  69. }).toList());
  70. });
  71. }
  72. void _getHeaderImage(int key) async {
  73. try {
  74. var _imageFile = await ImagePicker.pickImage(
  75. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  76. maxWidth: 800,
  77. imageQuality: 95);
  78. if (_imageFile != null) {
  79. headerImg = _imageFile;
  80. setState(() {});
  81. }
  82. } catch (e) {
  83. toasts("没有权限,无法打开相册!");
  84. }
  85. }
  86. void _getImage(int key, int index) async {
  87. try {
  88. var _imageFile = await ImagePicker.pickImage(
  89. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  90. maxWidth: 800,
  91. imageQuality: 95);
  92. if (_imageFile != null) {
  93. if (images.length > index) {
  94. images[index] = _imageFile;
  95. } else {
  96. images.add(_imageFile);
  97. }
  98. setState(() {});
  99. }
  100. } catch (e) {
  101. toasts("没有权限,无法打开相册!");
  102. }
  103. }
  104. /**
  105. * 提交认证信息
  106. */
  107. uploadAuthData() {
  108. if (item.attestationName.length == 0) {
  109. toasts("请输入团队名称");
  110. return;
  111. }
  112. if (item.contactsName.length == 0) {
  113. toasts("请输入联系人");
  114. return;
  115. }
  116. if (item.contactsTel.length == 0) {
  117. toasts("请输入联系人电话");
  118. return;
  119. }
  120. if (images.length != 2) {
  121. toasts("请上传营业执照/资质证书");
  122. return;
  123. }
  124. if(headerImg !=null){
  125. images.add(headerImg);
  126. }
  127. showLoading(context, "正在提交");
  128. ApiService(context: context).uploadMore(images, 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.dark_text,
  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. }