bind_alipay_page.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. import 'dart:convert';
  2. import 'dart:math';
  3. import 'package:bbyyy/beans/pay_way_bean_entity.dart';
  4. import 'package:bbyyy/beans/user_bean_entity.dart';
  5. import 'package:bbyyy/https/MyDio.dart';
  6. import 'package:bbyyy/my_tools/dims.dart';
  7. import 'package:bbyyy/my_tools/event_bus.dart';
  8. import 'package:bbyyy/my_tools/my_colors.dart';
  9. import 'package:bbyyy/my_tools/my_cookie.dart';
  10. import 'package:bbyyy/my_tools/my_tools.dart';
  11. import 'package:bbyyy/my_tools/my_views.dart';
  12. import 'package:bbyyy/paegs/mine_page/bind_alipay_page/set_alipay_page.dart';
  13. import 'package:bbyyy/paegs/mine_page/bind_alipay_page/withdraw_password_page.dart';
  14. import 'package:bbyyy/paegs/mine_page/coupon_page/coupon_view.dart';
  15. import 'package:bbyyy/pay/pay_tools.dart';
  16. import 'package:flutter/cupertino.dart';
  17. import 'package:flutter/material.dart';
  18. import 'package:flutter/services.dart';
  19. import 'package:flutter_svg/svg.dart';
  20. import 'package:fluwx/fluwx.dart';
  21. class BindAlipayPage extends StatefulWidget {
  22. @override
  23. _BindAlipayPageState createState() => _BindAlipayPageState();
  24. }
  25. class _BindAlipayPageState extends State<BindAlipayPage> {
  26. TextEditingController controller = TextEditingController();
  27. bool showInput = false;
  28. List<PayWayBeanData> payWays = [];
  29. bool showAlipay = false;
  30. bool showWeChat = false;
  31. @override
  32. void initState() {
  33. super.initState();
  34. Future.delayed(Duration.zero, () {
  35. checkPaymentMethod((response, hasError) {
  36. if (!hasError) {
  37. PayWayBeanEntity entity =
  38. PayWayBeanEntity.fromJson(json.decode(response.toString()));
  39. payWays = entity.data;
  40. showAlipay =
  41. payWays[payWays.indexWhere((element) => element.way == 1)]
  42. .withdraw;
  43. showWeChat =
  44. payWays[payWays.indexWhere((element) => element.way == 2)]
  45. .withdraw;
  46. setState(() {});
  47. }
  48. }, (e) {});
  49. });
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. return Scaffold(
  54. body: Container(
  55. decoration: BoxDecoration(
  56. gradient: LinearGradient(
  57. colors: MyColors.lg2,
  58. begin: Alignment.topCenter,
  59. end: Alignment.bottomCenter),
  60. ),
  61. child: Column(
  62. children: [
  63. SafeArea(
  64. bottom: false,
  65. child: Container(
  66. height: 45,
  67. width: double.infinity,
  68. child: Stack(
  69. children: [
  70. Text(
  71. '绑定',
  72. style: TextStyle(color: Colors.white, fontSize: 16),
  73. ),
  74. Positioned(
  75. left: 0,
  76. child: GestureDetector(
  77. onTap: () {
  78. Navigator.pop(context);
  79. },
  80. behavior: HitTestBehavior.translucent,
  81. child: Transform.rotate(
  82. angle: pi,
  83. child: Padding(
  84. padding: EdgeInsets.only(
  85. left: 16, right: 16, top: 8, bottom: 8),
  86. child: SvgPicture.asset(
  87. 'images/svg/箭头.svg',
  88. color: Colors.white,
  89. height: 14,
  90. ),
  91. ),
  92. ),
  93. ),
  94. ),
  95. Positioned(
  96. right: 0,
  97. child: GestureDetector(
  98. onTap: () {
  99. MyTools().toPage(
  100. context, WithdrawPasswordPage(), (then) {});
  101. },
  102. behavior: HitTestBehavior.translucent,
  103. child: Padding(
  104. padding: EdgeInsets.only(
  105. left: 16, right: 16, top: 8, bottom: 8),
  106. child: Text(
  107. '提现密码',
  108. style: TextStyle(color: Colors.white, fontSize: 12),
  109. ),
  110. ),
  111. ),
  112. ),
  113. ],
  114. alignment: Alignment.center,
  115. ),
  116. ),
  117. ),
  118. if (showAlipay)
  119. Container(
  120. height: 220,
  121. margin: EdgeInsets.fromLTRB(15, 60, 15, 0),
  122. width: double.infinity,
  123. child: ClipShadowPath(
  124. clipper: TicketClipPath2(),
  125. shadow: Shadow(blurRadius: 5, color: MyColors.c21333333),
  126. child: Scaffold(
  127. body: Stack(
  128. alignment: Alignment.bottomCenter,
  129. children: [
  130. Column(
  131. children: [
  132. Container(
  133. margin: EdgeInsets.only(top: 30),
  134. child: SvgPicture.asset(
  135. 'images/svg/支付宝.svg',
  136. height: 40,
  137. width: 40,
  138. ),
  139. ),
  140. Container(
  141. child: MyViews().myText(
  142. MyCookie()
  143. .userBean
  144. .aliPayAccount
  145. .isNotEmpty &&
  146. MyCookie().userBean.aliPayName.isEmpty
  147. ? '未绑定账号持有人真实姓名'
  148. : '当前绑定支付宝账号',
  149. MyCookie()
  150. .userBean
  151. .aliPayAccount
  152. .isNotEmpty &&
  153. MyCookie().userBean.aliPayName.isEmpty
  154. ? MyColors.cFF4233
  155. : MyColors.c333333,
  156. 13),
  157. margin: EdgeInsets.only(top: 11, bottom: 11),
  158. ),
  159. Container(
  160. decoration: BoxDecoration(
  161. borderRadius: BorderRadius.circular(22.5),
  162. color: MyColors.cFF4233),
  163. height: 45,
  164. margin: EdgeInsets.symmetric(horizontal: 22),
  165. child: MyViews().myText(
  166. MyCookie().userBean.aliPayAccount.isEmpty
  167. ? '暂未绑定'
  168. : MyCookie().userBean.aliPayAccount,
  169. Colors.white,
  170. 20),
  171. alignment: Alignment.center,
  172. )
  173. ],
  174. ),
  175. Container(
  176. child: CustomPaint(
  177. painter: DashedPainter(),
  178. size: Size(double.infinity, 1),
  179. ),
  180. margin:
  181. EdgeInsets.only(bottom: 38, right: 10, left: 10),
  182. ),
  183. Positioned(
  184. bottom: 0,
  185. child: GestureDetector(
  186. onTap: () {
  187. if (MyCookie().userBean.aliPayAccount.isEmpty) {
  188. MyTools().toPage(context, SetAlipayPage(),
  189. (then) {
  190. setState(() {});
  191. });
  192. } else {
  193. unbindAlipay();
  194. }
  195. },
  196. behavior: HitTestBehavior.translucent,
  197. child: Container(
  198. height: 39,
  199. child: Row(
  200. children: [
  201. MyViews().myText(
  202. MyCookie().userBean.aliPayAccount.isEmpty
  203. ? '去绑定'
  204. : '解除绑定',
  205. MyColors.c999999,
  206. 11),
  207. Container(
  208. margin: EdgeInsets.only(left: 5),
  209. child: SvgPicture.asset(
  210. 'images/svg/箭头.svg',
  211. color: MyColors.c999999,
  212. height: 8,
  213. width: 8,
  214. ),
  215. )
  216. ],
  217. mainAxisAlignment: MainAxisAlignment.center,
  218. crossAxisAlignment: CrossAxisAlignment.center,
  219. ),
  220. alignment: Alignment.center,
  221. ),
  222. ),
  223. ),
  224. ],
  225. ),
  226. ),
  227. ),
  228. ),
  229. // if (showWeChat)
  230. Container(
  231. height: 220,
  232. margin: EdgeInsets.fromLTRB(15, 20, 15, 50),
  233. width: double.infinity,
  234. child: ClipShadowPath(
  235. clipper: TicketClipPath2(),
  236. shadow: Shadow(blurRadius: 5, color: MyColors.c21333333),
  237. child: Scaffold(
  238. body: Stack(
  239. alignment: Alignment.bottomCenter,
  240. children: [
  241. Column(
  242. children: [
  243. Container(
  244. margin: EdgeInsets.only(top: 30),
  245. child: SvgPicture.asset(
  246. 'images/svg/微信.svg',
  247. height: 40,
  248. width: 40,
  249. ),
  250. ),
  251. Container(
  252. child: MyViews()
  253. .myText('当前绑定微信账号', MyColors.c333333, 13),
  254. margin: EdgeInsets.only(top: 11, bottom: 11),
  255. ),
  256. GestureDetector(
  257. onTap: () {
  258. Clipboard.setData(ClipboardData(
  259. text: '${MyCookie().userBean.wxOpenid}'));
  260. },
  261. behavior: HitTestBehavior.translucent,
  262. child: Container(
  263. decoration: BoxDecoration(
  264. borderRadius: BorderRadius.circular(22.5),
  265. color: MyColors.cFF4233),
  266. height: 45,
  267. margin: EdgeInsets.symmetric(horizontal: 22),
  268. child: MyCookie().userBean.wxOpenid.isEmpty
  269. ? MyViews().myText('暂未绑定', Colors.white, 20)
  270. : Row(
  271. children: [
  272. Container(
  273. margin: EdgeInsets.only(right: 10),
  274. child: ClipRRect(
  275. borderRadius:
  276. BorderRadius.circular(14),
  277. child: MyViews().netImg(
  278. MyCookie().userBean.wxPicture,
  279. 28,
  280. 28),
  281. ),
  282. ),
  283. MyViews().myText(
  284. MyCookie().userBean.wxName,
  285. Colors.white,
  286. 20)
  287. ],
  288. mainAxisAlignment:
  289. MainAxisAlignment.center,
  290. ),
  291. alignment: Alignment.center,
  292. ),
  293. )
  294. ],
  295. ),
  296. Container(
  297. child: CustomPaint(
  298. painter: DashedPainter(),
  299. size: Size(double.infinity, 1),
  300. ),
  301. margin:
  302. EdgeInsets.only(bottom: 38, right: 10, left: 10),
  303. ),
  304. Positioned(
  305. bottom: 0,
  306. child: GestureDetector(
  307. onTap: () {
  308. if (MyCookie().userBean.wxOpenid.isEmpty) {
  309. EventBus().on('bindToWeChat', (arg) {
  310. showToast('绑定成功');
  311. setState(() {});
  312. EventBus().off('bindToWeChat');
  313. });
  314. sendWeChatAuth(
  315. scope: "snsapi_userinfo",
  316. state: "wechat_sdk_demo_test");
  317. } else {
  318. unbindWeChat();
  319. }
  320. },
  321. behavior: HitTestBehavior.translucent,
  322. child: Container(
  323. height: 39,
  324. child: Row(
  325. children: [
  326. MyViews().myText(
  327. MyCookie().userBean.wxOpenid.isEmpty
  328. ? '去绑定'
  329. : '解除绑定',
  330. MyColors.c999999,
  331. 11),
  332. Container(
  333. margin: EdgeInsets.only(left: 5),
  334. child: SvgPicture.asset(
  335. 'images/svg/箭头.svg',
  336. color: MyColors.c999999,
  337. height: 8,
  338. width: 8,
  339. ),
  340. )
  341. ],
  342. mainAxisAlignment: MainAxisAlignment.center,
  343. crossAxisAlignment: CrossAxisAlignment.center,
  344. ),
  345. alignment: Alignment.center,
  346. ),
  347. ),
  348. ),
  349. ],
  350. ),
  351. ),
  352. ),
  353. )
  354. ],
  355. ),
  356. ),
  357. );
  358. }
  359. void queryPersonalInformation() {
  360. MyDio().query({
  361. "key": "user",
  362. "filters": {
  363. "conditions": ["uid == ${MyCookie().getUID()}"]
  364. },
  365. "dims": userDims,
  366. "paging": [1, 20]
  367. }, (response, hasError) {
  368. if (!hasError) {
  369. UserBeanEntity entity =
  370. UserBeanEntity.fromJson(json.decode(response.data.toString()));
  371. MyCookie().userBean = entity.data.data[0];
  372. EventBus().emit('userChange');
  373. setState(() {});
  374. }
  375. }, (error) {});
  376. }
  377. void unbindAlipay() {
  378. MyDio().update({
  379. "key": "user",
  380. "values": {
  381. "name": MyCookie().loginInformation.data.extra.name,
  382. "picture": MyCookie().loginInformation.data.extra.picture,
  383. "id": MyCookie().loginInformation.data.extra.id,
  384. "alipay_account": '',
  385. "alipay_name": ''
  386. }
  387. }, (response, hasError) {
  388. if (!hasError) {
  389. MyCookie().userBean.aliPayAccount = '';
  390. MyCookie().userBean.aliPayName = '';
  391. setState(() {});
  392. }
  393. }, (error) {});
  394. }
  395. void unbindWeChat() {
  396. MyDio().update({
  397. "key": "user",
  398. "values": {
  399. "id": MyCookie().loginInformation.data.extra.id,
  400. "wx_picture": '',
  401. "wx_name": '',
  402. "wx_openid": ''
  403. }
  404. }, (response, hasError) {
  405. if (!hasError) {
  406. MyCookie().userBean.wxOpenid = '';
  407. MyCookie().userBean.wxName = '';
  408. MyCookie().userBean.wxPicture = '';
  409. setState(() {});
  410. }
  411. }, (error) {});
  412. }
  413. }