import 'package:farmer_client/utils/processStatus.dart';
import 'package:farmer_client/widgets/Bold.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../models/entities/OrderInfoModel.dart';
import 'package:intl/intl.dart';
import 'LinearGradientText.dart';

class TextCell extends StatelessWidget {
  String title;
  String? value;

  TextCell({Key? key, required this.title, this.value}):super(key: key);

  @override
  Widget build(BuildContext context) {
    return RichText(
      text: TextSpan(children: <InlineSpan>[
        TextSpan(
            text: title,
            style: const TextStyle(
                color: Color(0xff666666),
                fontSize: 16,
                fontWeight: FontWeight.bold)),
        TextSpan(
            text: value,
            style: const TextStyle(
                color: Color(0xff222222),
                fontSize: 16,
                fontWeight: FontWeight.bold)),
      ]),
    );
  }

}

class OrderListCard extends StatelessWidget {
  final OrderInfoModel item;
  late ProcessSign processSign;

  OrderListCard({Key? key, required this.item}) : super(key: key) {
    processSign = getProcessSign(getProcessStatus(item));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 375.w,
      height: 345.h,
      margin: const EdgeInsets.fromLTRB(0, 0, 0, 20),
      decoration: const BoxDecoration(color: Colors.white, boxShadow: [
        BoxShadow(
            color: Colors.black12,
            offset: Offset(0.0, 15.0), //阴影xy轴偏移量
            blurRadius: 15.0, //阴影模糊程度
            spreadRadius: 1.0 //阴影扩散程度
        )
      ]),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            margin: const EdgeInsets.fromLTRB(15, 20, 15, 0),
            width: 18.0,
            height: 275.h,
            child: const Image(
              image: AssetImage('images/ordersLeft.png'),
            ),
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: 320.w,
                  margin: const EdgeInsets.fromLTRB(0, 10, 0, 15),
                  padding: const EdgeInsets.fromLTRB(0, 0, 0, 20),
                  decoration: const BoxDecoration(
                      border: Border(
                          bottom:
                          BorderSide(width: 0.5, color: Color(0x20000000)
                            // 0x17000000
                          ))),
                  child: GestureDetector(
                    child:
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        TextCell(title: '订单编号：', value: item.orderNo),
                        Bold(text: "详情 >>", fontSize: 16.sp, color: const Color(0xff222222)),
                      ],
                    ),
                    onTap: () {
                      Get.toNamed('/orderPageInfo', arguments: {
                        'id': item.orderId,
                        'title': processSign.label,
                        'styleColor': processSign.color
                      });
                    },
                  ),
                ),
                Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Padding(
                          padding: const EdgeInsets.fromLTRB(0, 0, 0, 15),
                          child: TextCell(title: '农机名称：', value: item.machineryName),
                        ),
                        Padding(
                          padding: const EdgeInsets.fromLTRB(0, 0, 0, 15),
                          child: TextCell(title: '作业面积：', value: item.amount.toString()),
                        ),
                        Padding(
                          padding: const EdgeInsets.fromLTRB(0, 0, 0, 15),
                          child: TextCell(title: '需求时间：', value: DateFormat("yyyy-MM-dd").format(
                              DateTime.parse(item.appointmentDate.toString()))),
                        ),
                        Padding(
                          padding: const EdgeInsets.fromLTRB(0, 0, 0, 15),
                          child: TextCell(title: '需求时间：', value: DateFormat("yyyy-MM-dd").format(
                              DateTime.parse(item.createDate.toString()))),
                        ),
                      ],
                    )),
                Container(
                  margin: const EdgeInsets.fromLTRB(0, 0, 0, 30),
                  padding: const EdgeInsets.fromLTRB(0, 20, 0, 0),
                  decoration: const BoxDecoration(
                      border: Border(
                          top: BorderSide(
                              width: 0.5, color: Color(0x20000000)))),
                  width: 320.w,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      RichText(
                        text: TextSpan(children: <InlineSpan>[
                          const TextSpan(
                              text: '订单状态：',
                              style: TextStyle(
                                  color: Color(0xff666666),
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold)),
                          TextSpan(
                              text: processSign.label,
                              style: TextStyle(
                                  color: processSign.color,
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold)),
                        ]),
                      ),
                      Row(
                        children: [
                          const Text('费用：',
                              style: TextStyle(
                                  color: Color(0xff666666),
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold)),
                          LinearGradientText(
                            colors: const <Color>[
                              Color(0xFFFA7878),
                              Color(0xFFB61515),
                            ],
                            child: RichText(
                              text: TextSpan(children: <InlineSpan>[
                                TextSpan(
                                    text: ((item.charges ?? 0) / 100)
                                        .toString(),
                                    style: const TextStyle(
                                      fontSize: 16,
                                      fontWeight: FontWeight.bold,
                                    )),
                                const TextSpan(
                                    text: "元",
                                    style: TextStyle(
                                      fontSize: 16,
                                      fontWeight: FontWeight.bold,
                                    )),
                              ]),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
