bind_alipay_page.dart 15 KB

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