team_auth_page.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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, onSuccess: (List<String> list) {
  128. ApiService(context: context).teamUploadAuth(
  129. item.id,
  130. item.attestationName,
  131. item.contactsName,
  132. item.contactsTel,
  133. list[0],
  134. list[1],
  135. list.length==3?list[2]:"", onSuccess: (res) {
  136. dismissLoading(context);
  137. showAlert(context, "", res.message, "确定", () {
  138. NavigatorUtils.goBack(context);
  139. NavigatorUtils.goBack(context);
  140. });
  141. }, onError: (code, msg) {
  142. dismissLoading(context);
  143. toasts(msg);
  144. });
  145. }, onError: (code, msg) {
  146. dismissLoading(context);
  147. toasts(msg);
  148. });
  149. }
  150. @override
  151. Widget build(BuildContext context) {
  152. // TODO: implement build
  153. return Scaffold(
  154. appBar: MyAppBar(
  155. centerTitle: "我的团队",
  156. actions: <Widget>[
  157. FlatButton(
  158. child: Text("去认证"),
  159. textColor: Colours.dark_text,
  160. highlightColor: Colors.transparent,
  161. onPressed: () {
  162. // uploadAuthData();
  163. NavigatorUtils.push(context, TeamRouter.teamAuthUploadPage);
  164. },
  165. )
  166. ],
  167. ),
  168. body: SafeArea(
  169. child: Column(
  170. children: <Widget>[
  171. Expanded(
  172. flex: 1,
  173. child: defaultTargetPlatform == TargetPlatform.iOS
  174. ? FormKeyboardActions(child: _buildBody())
  175. : SingleChildScrollView(child: _buildBody()),
  176. )
  177. ],
  178. ),
  179. ));
  180. }
  181. _buildBody() {
  182. return Column(
  183. crossAxisAlignment: CrossAxisAlignment.start,
  184. children: _listWidgets(),
  185. );
  186. }
  187. _listWidgets() {
  188. return [
  189. Container(
  190. padding: EdgeInsets.only(top: 10, bottom: 20),
  191. color: ThemeUtils.getTabsBg(context),
  192. child: GestureDetector(
  193. onTap: () {
  194. selectPicker(-1);
  195. },
  196. child: Center(
  197. child: CircleAvatar(
  198. radius: 30,
  199. backgroundColor: Colors.transparent,
  200. backgroundImage: ImageUtils.getImageProvider(item.logoImg)),
  201. )),
  202. ),
  203. Container(
  204. padding: EdgeInsets.only(bottom: 20),
  205. color: ThemeUtils.getTabsBg(context),
  206. child: Center(
  207. child: Container(
  208. padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
  209. decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
  210. child: Text("logo",
  211. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
  212. )),
  213. ),
  214. Gaps.vGap10,
  215. ClickItem(
  216. title: "状态",
  217. content:
  218. "${item.isCertificated == 1 ? '已认证' : item.isCertificated == 2 ? '审核中' : item.isCertificated == 3 ? '认证失败' : '未认证'}",
  219. ),
  220. ClickItem(
  221. title: "团队名称",
  222. content: "${item.attestationName}",
  223. ),
  224. ClickItem(
  225. title: "联系人",
  226. content: "${item.contactsName}",
  227. ),
  228. ClickItem(
  229. title: "联系人电话",
  230. content: "${item.contactsTel}",
  231. ),
  232. Gaps.vGap10,
  233. ClickItem(
  234. title: "企业营业执照/资质证书",
  235. content: "",
  236. hideDiv: true,
  237. ),
  238. Container(
  239. color: ThemeUtils.getTabsBg(context),
  240. child: GridView.builder(
  241. shrinkWrap: true,
  242. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  243. physics: NeverScrollableScrollPhysics(),
  244. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  245. crossAxisCount: 3, childAspectRatio: 1.18),
  246. itemCount: 2,
  247. itemBuilder: (_, index) {
  248. return Stack(
  249. children: <Widget>[
  250. Center(
  251. child: imageWidget(index),
  252. )
  253. ],
  254. );
  255. },
  256. ))
  257. ];
  258. }
  259. Widget imageWidget(int index){
  260. if(index == 0 && item.businessLicenseAnnex.length>0){
  261. return Image.network(
  262. "${item.businessLicenseAnnex}",
  263. width: 150,
  264. height: 150,
  265. fit: BoxFit.fill,
  266. );
  267. }
  268. if(index == 1 && item.taxRegistration.length>0){
  269. return Image.network(
  270. "${item.taxRegistration}",
  271. width: 150,
  272. height: 150,
  273. fit: BoxFit.fill,
  274. );
  275. }
  276. return SelectedImage(
  277. image: index < images.length ? images[index] : null,
  278. onTap: () {
  279. selectPicker(index);
  280. });
  281. }
  282. }