team_auth_upload_page.dart 8.3 KB

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