team_auth_upload_page.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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/image_utils.dart';
  11. import 'package:liftmanager/utils/theme_utils.dart';
  12. import 'package:liftmanager/utils/toast.dart';
  13. import 'package:liftmanager/widgets/app_bar.dart';
  14. import 'package:liftmanager/widgets/click_item.dart';
  15. import 'package:liftmanager/widgets/selected_image.dart';
  16. import 'package:liftmanager/widgets/text_field_item.dart';
  17. class TeamAuthUploadPage extends StatefulWidget {
  18. @override
  19. State<StatefulWidget> createState() {
  20. return TeamCardUploadPageState();
  21. }
  22. }
  23. class TeamCardUploadPageState extends State<TeamAuthUploadPage> {
  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. // toasts("请上传团队logo");
  125. // return;
  126. // }
  127. showLoading(context, "正在提交");
  128. ApiService(context: context).uploadMore(images, onSuccess: (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. item.logoImg, onSuccess: (res) {
  137. dismissLoading(context);
  138. showAlert(context, "提示", "提交成功", "确定", () {
  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. },
  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: Center(
  193. child: SelectedImage(
  194. image: headerImg,
  195. onTap: () {
  196. selectPicker(-1);
  197. }),
  198. ),
  199. ),
  200. Container(
  201. padding: EdgeInsets.only(bottom: 20),
  202. color: ThemeUtils.getTabsBg(context),
  203. child: Center(
  204. child: Container(
  205. padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
  206. decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
  207. child: Text("logo",
  208. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
  209. )),
  210. ),
  211. Gaps.vGap10,
  212. ClickItem(
  213. title: "状态",
  214. content:
  215. "${item.isCertificated == 1 ? '已认证' : item.isCertificated == 2 ? '审核中' : item.isCertificated == 3 ? '认证失败' : '未认证'}",
  216. ),
  217. TextFieldItem(
  218. title: "团队名称",
  219. content: "${item.attestationName}",
  220. controller: TextEditingController(),
  221. hintText: "请填写团队名称",
  222. focusNode: _nodeText1,
  223. onChanged: (res) {
  224. item.attestationName = res;
  225. },
  226. ),
  227. TextFieldItem(
  228. title: "联系人",
  229. content: "${item.contactsName}",
  230. controller: TextEditingController(),
  231. hintText: "请填写联系人",
  232. focusNode: _nodeText2,
  233. onChanged: (res) {
  234. item.contactsName = res;
  235. },
  236. ),
  237. TextFieldItem(
  238. title: "联系人电话",
  239. content: "${item.contactsTel}",
  240. controller: TextEditingController(),
  241. hintText: "请填写联系人电话",
  242. focusNode: _nodeText3,
  243. onChanged: (res) {
  244. item.contactsTel = res;
  245. },
  246. ),
  247. Gaps.vGap10,
  248. ClickItem(
  249. title: "企业营业执照/资质证书",
  250. content: "",
  251. hideDiv: true,
  252. ),
  253. Container(
  254. color: ThemeUtils.getTabsBg(context),
  255. child: GridView.builder(
  256. shrinkWrap: true,
  257. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  258. physics: NeverScrollableScrollPhysics(),
  259. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  260. crossAxisCount: 3, childAspectRatio: 1.18),
  261. itemCount: 2,
  262. itemBuilder: (_, index) {
  263. return Stack(
  264. children: <Widget>[
  265. Center(
  266. child: SelectedImage(
  267. image: index < images.length ? images[index] : null,
  268. onTap: () {
  269. selectPicker(index);
  270. }),
  271. )
  272. ],
  273. );
  274. },
  275. ))
  276. ];
  277. }
  278. }