/*
 * @Author: XianKaiQun
 * @LastEditors: ChenYaJin
 * @Date: 2020-11-09 12:00:52
 * @LastEditTime: 2023-04-06 09:46:49
 */
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:service_package/src/assets.gen.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'store.dart';
//part 'components/list.dart';

class SuccessPageView extends StatelessWidget {
  const SuccessPageView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<SuccessPageStore>(context);

    Map<String, Color> tagColors = {
      'complaint': colorScheme.danger,
      'praise': colorScheme.success,
      'advice': colorScheme.notice,
      'suggest': colorScheme.warning,
    };
    return Observer(builder: (context) {
      return Scaffold(
        appBar: WAppBar(
          iconTheme: IconThemeData(
            color: colorScheme.mainTitle,
            size: 14.pt,
          ),
          backgroundColor: Colors.white,
          brightness: Brightness.light,
          title: WisText('客服工作台',
              size: 19.pt,
              weight: FontWeight.w600,
              color: colorScheme.mainTitle),
        ),
        body: WisScrollView(
          onInit: () => store.getData(),
          onRefresh: () => store.getData(),
          slivers: <Widget>[
            if (store.detail != null)
              WisCard(
                padding: EdgeInsets.all(15.pt),
                margin:
                    EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: ListTile.divideTiles(
                    context: context,
                    tiles: [
                      Row(
                        children: [
                          Image(
                            image: AssetList.$success_png_image,
                            width: 50.pt,
                            height: 50.pt,
                          ),
                          SizedBox(width: 15.pt),
                          Wisdom.column(
                            padding: EdgeInsets.symmetric(vertical: 15.pt),
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                '受理成功',
                                style: TextStyle(
                                  color: colorScheme.green,
                                  fontSize: 16.pt,
                                ),
                              ),
                              SizedBox(height: 10.pt),
                              Text(
                                '单号:${store.detail?.id}',
                                style: TextStyle(
                                  fontSize: 15.pt,
                                ),
                              ),
                            ],
                          ).nestExpanded(),
                        ],
                      ),
                      Row(
                        children: [
                          Image(
                            image: AssetList.$user_png_image,
                            width: 50.pt,
                            height: 50.pt,
                          ),
                          SizedBox(width: 15.pt),
                          Wisdom.column(
                            padding: EdgeInsets.symmetric(vertical: 15.pt),
                            crossAxisAlignment: CrossAxisAlignment.stretch,
                            children: [
                              Row(
                                children: [
                                  Text(
                                    '${store.detail?.name}',
                                    style: TextStyle(
                                      fontSize: 15.pt,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                  Text(
                                    '  ${store.detail?.mobile}',
                                    style: TextStyle(
                                      fontSize: 15.pt,
                                      color: colorScheme.primary,
                                    ),
                                  ),
                                  Spacer(),
                                  Text(
                                    '${store.status?.name}',
                                    style: TextStyle(
                                      color: colorScheme.warning,
                                    ),
                                  ),
                                ],
                              ),
                              SizedBox(height: 10.pt),
                              Row(
                                children: [
                                  Text(
                                    '房号：${store.detail?.houseName ?? '--'}',
                                    style: TextStyle(
                                      fontSize: 15.pt,
                                    ),
                                  ),
                                  Spacer(),
                                  Wisdom(
                                    color: tagColors[store.report?.code!] ??
                                        colorScheme.primary,
                                    padding: EdgeInsets.symmetric(
                                      horizontal: 5.pt,
                                      vertical: 2.pt,
                                    ),
                                    borderRadius: BorderRadius.circular(3.pt),
                                    child: Text(
                                      store.isRepair ? '报修' : '报事',
                                      style: TextStyle(
                                        color: Colors.white,
                                        height: 1.1,
                                        fontSize: 12.pt,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ],
                          ).nestExpanded(),
                        ],
                      ),
                      SizedBox(height: 15.pt),
                      Wisdom(
                        borderRadius: BorderRadius.circular(4.pt),
                        color: colorScheme.background,
                        padding: EdgeInsets.all(15.pt),
                        child: Text(
                          '${store.detail?.description}',
                          style: TextStyle(
                            fontSize: 15.pt,
                          ),
                        ),
                      )
                    ],
                  ).toList(),
                ),
              ).nestSliverToBoxAdapter(),
            if (store.qr != null)
              Wisdom.column(
                padding: EdgeInsets.fromLTRB(15.pt, 10.pt, 15.pt, 15.pt),
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Container(
                    width: 130.pt,
                    height: 130.pt,
                    alignment: Alignment.center,
                    child: QrImageView(data: '${store.qr?.qrCodeUrl}'),
                  ),
                  SizedBox(height: 25.pt),
                  Text(
                    '微信扫描此二维码跟进服务',
                    textAlign: TextAlign.center,
                  ),
                  Text(
                    '二维码将于${store.qr?.qrCodeExpires}失效',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: colorScheme.minor,
                    ),
                  ),
                  SizedBox(height: 25.pt),
                  WButton(
                    height: 44.pt,
                    onPressed: () => store.pop2mainPage(),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(25.pt),
                    ),
                    child: Text('返回首页'),
                  ),
                ],
              ).nestSliverToBoxAdapter(),
          ],
        ),
      );
    });
  }
}
