bind_alipay_page.dart 16 KB

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