bind_alipay_page.dart 14 KB

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