view.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/data/bean/payment_way.dart';
  3. import 'package:electronic_assistant/resource/assets.gen.dart';
  4. import 'package:electronic_assistant/resource/colors.gen.dart';
  5. import 'package:electronic_assistant/router/app_pages.dart';
  6. import 'package:electronic_assistant/utils/expand.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_screenutil/flutter_screenutil.dart';
  9. import 'package:get/get.dart';
  10. import '../../data/bean/store_item.dart';
  11. import '../../data/consts/Constants.dart';
  12. import '../../widget/shimmer_effect.dart';
  13. import 'controller.dart';
  14. enum StoreFromType { home, mine, analyse, record }
  15. class StorePage extends BasePage<StoreController> {
  16. const StorePage({super.key});
  17. static start({StoreFromType? fromType}) {
  18. Get.toNamed(RoutePath.store, arguments: {'fromType': fromType});
  19. }
  20. @override
  21. Color backgroundColor() {
  22. return "#071935".color;
  23. }
  24. @override
  25. Color navigationBarColor() {
  26. return "#283B58".color;
  27. }
  28. @override
  29. bool statusBarDarkFont() {
  30. return false;
  31. }
  32. @override
  33. bool immersive() {
  34. return true;
  35. }
  36. //47.67
  37. @override
  38. Widget buildBody(BuildContext context) {
  39. return Stack(
  40. children: [
  41. SingleChildScrollView(
  42. child: _buildStoreContent(),
  43. ),
  44. Align(
  45. alignment: Alignment.bottomCenter,
  46. child: _buildBottomButton(),
  47. ),
  48. Positioned(
  49. left: 0,
  50. right: 0,
  51. child: AppBar(
  52. backgroundColor: Colors.transparent,
  53. scrolledUnderElevation: 0,
  54. leading: IconButton(
  55. color: Colors.white,
  56. icon: const Icon(Icons.arrow_back_ios_new_rounded),
  57. onPressed: () {
  58. Get.back();
  59. },
  60. ),
  61. actions: [_buildElectricBalance()],
  62. ),
  63. ),
  64. ],
  65. );
  66. }
  67. _buildElectricBalance() {
  68. return Container(
  69. padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.w),
  70. margin: EdgeInsets.only(right: 12.w),
  71. decoration: BoxDecoration(
  72. borderRadius: BorderRadius.circular(100.w),
  73. border: Border.all(
  74. color: "#7688B1".toColor(),
  75. width: 1.w,
  76. )),
  77. child: Row(
  78. children: [
  79. Assets.images.iconStoreLogo.image(width: 20.w, height: 20.w),
  80. Container(
  81. margin: EdgeInsets.symmetric(horizontal: 3.w),
  82. child: Text("电量",
  83. style: TextStyle(color: Colors.white, fontSize: 12.w)),
  84. ),
  85. Obx(() {
  86. return Text('${controller.userInfo?.memberInfo?.electric ?? '0'}',
  87. style: TextStyle(color: Colors.white, fontSize: 12.w));
  88. }),
  89. ],
  90. ),
  91. );
  92. }
  93. _buildStoreContent() {
  94. return Stack(
  95. children: [
  96. _buildTopBanner(),
  97. Column(
  98. children: [
  99. Container(
  100. margin: EdgeInsets.only(top: 315.w),
  101. height: 154.w,
  102. child: Obx(() => ListView.builder(
  103. itemBuilder: _buildStoreItem,
  104. itemCount: controller.storeItems.length,
  105. scrollDirection: Axis.horizontal,
  106. )),
  107. ),
  108. Container(
  109. margin: EdgeInsets.only(left: 12.w, right: 12.w, top: 18.w),
  110. alignment: Alignment.centerLeft,
  111. child: Obx(() => Text(
  112. " · ${controller.currentSelectedStoreItem.value?.itemDesc}",
  113. style: TextStyle(
  114. fontSize: 10.sp,
  115. color: "#AFAFAF".color,
  116. fontWeight: FontWeight.bold))),
  117. ),
  118. _buildPaymentWays(),
  119. _buildService(),
  120. _buildRule(),
  121. SizedBox(height: 80.w)
  122. ],
  123. ),
  124. ],
  125. );
  126. }
  127. _buildTopBanner() {
  128. return Stack(alignment: AlignmentDirectional.bottomStart, children: [
  129. Assets.images.bgStoreTop.image(),
  130. Container(
  131. margin: EdgeInsets.only(left: 12.w, bottom: 73.33.w),
  132. child: Assets.images.iconStoreDescripe.image(width: 268.w))
  133. ]);
  134. }
  135. Widget _buildStoreItem(BuildContext context, int index) {
  136. StoreItem storeItem = controller.storeItems[index];
  137. return GestureDetector(
  138. onTap: () => controller.onStoreItemClick(storeItem),
  139. child: Container(
  140. margin: EdgeInsets.only(
  141. left: index == 0 ? 12.w : 10.w,
  142. right: index == controller.storeItems.length - 1 ? 12.w : 0),
  143. child: Stack(
  144. children: [
  145. Obx(() =>
  146. controller.currentSelectedStoreItem.value?.id == storeItem.id
  147. ? _buildSelectedItemContent(storeItem)
  148. : _buildUnselectedItemContent(storeItem)),
  149. Visibility(
  150. visible: storeItem.popular,
  151. child: Container(
  152. padding: EdgeInsets.only(
  153. left: 8.w, right: 8.w, top: 2.w, bottom: 10.w),
  154. decoration: BoxDecoration(
  155. image: DecorationImage(
  156. image: Assets.images.iconStoreGoodTag.provider(),
  157. fit: BoxFit.fill,
  158. ),
  159. ),
  160. child: Text("最多人购买",
  161. style: TextStyle(
  162. color: "#703D27".color,
  163. fontSize: 12.sp,
  164. fontWeight: FontWeight.bold)),
  165. ),
  166. ),
  167. ],
  168. ),
  169. ),
  170. );
  171. }
  172. Widget _buildSelectedItemContent(StoreItem storeItem) {
  173. return Container(
  174. width: 132.w,
  175. margin: EdgeInsets.only(top: 9.w),
  176. decoration: BoxDecoration(
  177. borderRadius: BorderRadius.circular(12.w),
  178. gradient: LinearGradient(
  179. colors: ['#9075FF'.color, '#4366FF'.color],
  180. begin: Alignment.centerLeft,
  181. end: Alignment.centerRight,
  182. stops: const [0.0, 1.0],
  183. ),
  184. ),
  185. child: Container(
  186. margin: EdgeInsets.all(2.w),
  187. decoration: BoxDecoration(
  188. gradient: LinearGradient(
  189. colors: ['#DADBFF'.color, '#FFF3F6'.color],
  190. begin: Alignment.centerLeft,
  191. end: Alignment.centerRight,
  192. stops: const [0.0, 1.0],
  193. ),
  194. borderRadius: BorderRadius.circular(12.w),
  195. ),
  196. child: _buildItemContent(storeItem, true),
  197. ),
  198. );
  199. }
  200. Widget _buildUnselectedItemContent(StoreItem storeItem) {
  201. return Container(
  202. width: 132.w,
  203. margin: EdgeInsets.only(top: 9.w),
  204. padding: EdgeInsets.all(2.w),
  205. decoration: BoxDecoration(
  206. borderRadius: BorderRadius.circular(12.w), color: "#40567D".color),
  207. child: _buildItemContent(storeItem, false),
  208. );
  209. }
  210. Widget _buildItemContent(StoreItem storeItem, bool isSelect) {
  211. return Column(
  212. children: [
  213. Container(
  214. margin: EdgeInsets.only(top: 14.w),
  215. child: Text(storeItem.name,
  216. style: TextStyle(
  217. color: isSelect ? "#6177F2".color : Colors.white,
  218. fontSize: 13.sp,
  219. fontWeight: FontWeight.bold)),
  220. ),
  221. Container(
  222. margin: EdgeInsets.only(top: 10.w),
  223. child: RichText(
  224. text: TextSpan(
  225. children: [
  226. TextSpan(
  227. text: "¥",
  228. style: TextStyle(
  229. color: isSelect ? "#6177F2".color : Colors.white,
  230. fontSize: 16.sp,
  231. ),
  232. ),
  233. TextSpan(
  234. text: storeItem.amountText,
  235. style: TextStyle(
  236. color: isSelect ? "#6177F2".color : Colors.white,
  237. fontSize: 39.sp,
  238. fontWeight: FontWeight.bold,
  239. ),
  240. ),
  241. ],
  242. )),
  243. ),
  244. Text("¥${storeItem.originalAmountText}",
  245. style: TextStyle(
  246. color: "#AFAFAF".color,
  247. fontSize: 14.sp,
  248. decoration: TextDecoration.lineThrough,
  249. decorationColor: "#AFAFAF".color)),
  250. Container(
  251. padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 2.w),
  252. decoration: isSelect
  253. ? BoxDecoration(
  254. gradient: LinearGradient(
  255. colors: ['#9075FF'.color, '#4366FF'.color],
  256. begin: Alignment.topCenter,
  257. end: Alignment.bottomCenter,
  258. stops: const [0.0, 1.0],
  259. ),
  260. borderRadius: BorderRadius.circular(12.w),
  261. )
  262. : BoxDecoration(
  263. color: "#7688B1".toColor(),
  264. borderRadius: BorderRadius.circular(12.w),
  265. ),
  266. child: Row(
  267. mainAxisSize: MainAxisSize.min,
  268. children: [
  269. SizedBox(
  270. width: 16.w,
  271. height: 16.w,
  272. child: Assets.images.iconStoreGoodFlash.image(),
  273. ),
  274. Text(
  275. "${storeItem.authValue}电量",
  276. style: TextStyle(
  277. color: Colors.white,
  278. fontSize: 13.sp,
  279. fontWeight: FontWeight.bold,
  280. ),
  281. ),
  282. ],
  283. ),
  284. ),
  285. ],
  286. );
  287. }
  288. Widget _buildPaymentWays() {
  289. return Container(
  290. margin: EdgeInsets.only(top: 10.w),
  291. child: ExpansionTile(
  292. initiallyExpanded: true,
  293. onExpansionChanged: (value) {
  294. controller.isPaymentWayExpanded.value = value;
  295. },
  296. title: Padding(
  297. padding: EdgeInsets.symmetric(horizontal: 12.w),
  298. child: Row(
  299. children: [
  300. Text("支付方式",
  301. style: TextStyle(color: Colors.white, fontSize: 14.sp)),
  302. const Spacer(),
  303. Obx(() =>
  304. controller.currentSelectedPaymentWay.value?._icon ??
  305. Container()),
  306. Container(
  307. margin: EdgeInsets.only(left: 6.w, right: 4.w),
  308. child: Obx(() => Text(
  309. controller.currentSelectedPaymentWay.value?.title ?? "",
  310. style: TextStyle(color: Colors.white, fontSize: 14.sp))),
  311. ),
  312. Obx(() => controller.isPaymentWayExpanded.value
  313. ? Assets.images.iconArrowUpWhite
  314. .image(width: 16.w, height: 16.w)
  315. : Assets.images.iconArrowDownWhite
  316. .image(width: 16.w, height: 16.w)),
  317. ],
  318. ),
  319. ),
  320. showTrailingIcon: false,
  321. shape: const RoundedRectangleBorder(
  322. side: BorderSide(color: Colors.transparent),
  323. ),
  324. collapsedShape: const RoundedRectangleBorder(
  325. side: BorderSide(color: Colors.transparent),
  326. ),
  327. minTileHeight: 15.w,
  328. tilePadding: EdgeInsets.zero,
  329. children: [
  330. Obx(() => ListView.builder(
  331. shrinkWrap: true,
  332. physics: const NeverScrollableScrollPhysics(),
  333. padding: EdgeInsets.symmetric(horizontal: 12.w),
  334. itemBuilder: _buildPaymentWayItem,
  335. itemCount: controller.paymentWays.length,
  336. scrollDirection: Axis.vertical,
  337. )),
  338. ],
  339. ),
  340. );
  341. }
  342. Widget _buildPaymentWayItem(BuildContext context, int index) {
  343. PaymentWay paymentWay = controller.paymentWays[index];
  344. return GestureDetector(
  345. onTap: () => controller.onPaymentWayItemClick(paymentWay),
  346. child: Padding(
  347. padding: EdgeInsets.symmetric(vertical: 6.w),
  348. child: Row(
  349. children: [
  350. paymentWay._icon,
  351. Expanded(
  352. child: Container(
  353. margin: EdgeInsets.only(left: 8.w),
  354. child: Text(controller.paymentWays[index].title,
  355. style: TextStyle(color: Colors.white, fontSize: 14.sp)),
  356. ),
  357. ),
  358. Obx(() => SizedBox(
  359. width: 20.w,
  360. height: 20.w,
  361. child: controller.currentSelectedPaymentWay.value?.id ==
  362. paymentWay.id
  363. ? Assets.images.iconSelectTrue.image()
  364. : Assets.images.iconSelectFalse.image())),
  365. ],
  366. ),
  367. ),
  368. );
  369. }
  370. Widget _buildService() {
  371. return Container(
  372. margin: EdgeInsets.only(left: 12.w, right: 12.w, top: 30.w),
  373. child: Column(
  374. children: [
  375. Row(
  376. children: [
  377. Container(
  378. width: 4.w,
  379. height: 16.h,
  380. decoration: BoxDecoration(
  381. color: Colors.white,
  382. borderRadius: BorderRadius.circular(2),
  383. gradient: LinearGradient(
  384. colors: [
  385. '#357AFF'.toColor(),
  386. '#E389FF'.toColor(),
  387. '#ffffff'.toColor()
  388. ],
  389. begin: Alignment.topCenter,
  390. end: Alignment.bottomCenter,
  391. stops: const [0.0, 0.5, 1.0],
  392. ),
  393. ),
  394. ),
  395. SizedBox(
  396. width: 6.w,
  397. ),
  398. Text(
  399. "多种专属服务·高效辅助办公",
  400. style: TextStyle(
  401. fontSize: 15.sp,
  402. color: Colors.white,
  403. fontWeight: FontWeight.w500,
  404. ),
  405. ),
  406. ],
  407. ),
  408. Container(
  409. margin: EdgeInsets.only(top: 16.w),
  410. child: Row(
  411. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  412. children: [
  413. _buildServiceItem(
  414. Assets.images.iconStoreServiceSum.image(),
  415. "智能谈话总结",
  416. ),
  417. _buildServiceItem(
  418. Assets.images.iconStoreServiceRemain.image(),
  419. "待办任务处理",
  420. ),
  421. _buildServiceItem(
  422. Assets.images.iconStoreServiceAdvice.image(),
  423. "专业工作建议",
  424. ),
  425. _buildServiceItem(
  426. Assets.images.iconStoreServiceDeal.image(),
  427. "处理交代事宜",
  428. ),
  429. ],
  430. ),
  431. )
  432. ],
  433. ),
  434. );
  435. }
  436. Widget _buildServiceItem(Image icon, String title) {
  437. return Column(
  438. children: [
  439. SizedBox(
  440. width: 32.w,
  441. child: icon,
  442. ),
  443. SizedBox(
  444. height: 2.h,
  445. ),
  446. Text(
  447. title,
  448. style: TextStyle(
  449. color: ColorName.white.withOpacity(0.8),
  450. fontSize: 11.sp,
  451. ),
  452. ),
  453. ],
  454. );
  455. }
  456. Container _buildRule() {
  457. return Container(
  458. margin: EdgeInsets.only(top: 26.w, left: 12.w, right: 12.w),
  459. width: double.infinity,
  460. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
  461. decoration: BoxDecoration(
  462. color: "#40567D".toColor().withOpacity(0.2),
  463. borderRadius: BorderRadius.circular(8),
  464. ),
  465. child: Column(
  466. crossAxisAlignment: CrossAxisAlignment.start,
  467. children: [
  468. Text(
  469. "扣电规则",
  470. style: TextStyle(
  471. fontSize: 12,
  472. fontWeight: FontWeight.w500,
  473. color: Colors.white.withOpacity(0.6),
  474. ),
  475. ),
  476. SizedBox(
  477. height: 6.h,
  478. ),
  479. Text(
  480. "1、小听每听5分钟扣1电量,不满5分钟按5分钟算。",
  481. style: TextStyle(
  482. fontSize: 12,
  483. color: Colors.white.withOpacity(0.6),
  484. ),
  485. ),
  486. Text(
  487. "2、大文件、超大文件生成新的总结,每次扣1电量。",
  488. style: TextStyle(
  489. fontSize: 12,
  490. fontWeight: FontWeight.w500,
  491. color: Colors.white.withOpacity(0.6),
  492. ),
  493. ),
  494. Text(
  495. "3、用大文件和小听对话,每次对话扣1电量。",
  496. style: TextStyle(
  497. fontSize: 12,
  498. fontWeight: FontWeight.w500,
  499. color: Colors.white.withOpacity(0.6),
  500. ),
  501. ),
  502. ],
  503. ),
  504. );
  505. }
  506. Widget _buildBottomButton() {
  507. return Container(
  508. width: double.infinity,
  509. padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
  510. decoration: BoxDecoration(
  511. color: "#283B58".color,
  512. borderRadius: BorderRadius.only(
  513. topLeft: Radius.circular(12.w),
  514. topRight: Radius.circular(12.w),
  515. ),
  516. ),
  517. child: GestureDetector(
  518. onTap: () => controller.onBuyClick(),
  519. child: ShimmerEffect(
  520. child: Container(
  521. height: 48.w,
  522. alignment: Alignment.center,
  523. decoration: BoxDecoration(
  524. gradient: LinearGradient(
  525. colors: ['#9075FF'.color, '#4366FF'.color],
  526. begin: Alignment.centerLeft,
  527. end: Alignment.centerRight,
  528. stops: const [0.0, 1.0],
  529. ),
  530. borderRadius: BorderRadius.circular(8.w),
  531. ),
  532. child: _buildBuyButton(),
  533. ),
  534. ),
  535. ),
  536. );
  537. }
  538. Widget _buildBuyButton() {
  539. return Obx(() => Text(
  540. "立即购买 ¥${controller.currentSelectedStoreItem.value?.amountText ?? ''}",
  541. style: TextStyle(
  542. fontWeight: FontWeight.bold,
  543. fontSize: 16.sp,
  544. color: Colors.white),
  545. ));
  546. }
  547. }
  548. extension on PaymentWay {
  549. get _icon {
  550. switch (payMethod) {
  551. case PayMethod.alipay:
  552. return Assets.images.iconStoreAlipay.image(width: 20.w, height: 20.w);
  553. case PayMethod.wechat:
  554. return Assets.images.iconStoreWechatPay
  555. .image(width: 20.w, height: 20.w);
  556. default:
  557. return Container();
  558. }
  559. }
  560. }