part of user_order_completed;

class UserOrderCompletedPage extends StatefulWidget {
  final String orderNum; // 订单编号
  const UserOrderCompletedPage({Key? key , required this.orderNum}) : super(key: key);

  @override
  State<UserOrderCompletedPage> createState() => _UserOrderCompletedState();
}

class _UserOrderCompletedState extends State<UserOrderCompletedPage> {
/*  late num? selectedGender ; // 选中的性别
  @override
  void initState() {
    super.initState();
    selectedGender = widget.userInfo.sex;
    // 在这里可以使用 localVariable 进行操作
  }*/

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        context.pop(true);
        return false;
      },
      child: GetBuilder<UserOrderCompletedController>(
          init: UserOrderCompletedController(widget.orderNum),
          builder: (controller) => Scaffold(
              appBar: CustomAppBar(
                title: const Text('已完成'),
                actions: [],
              ),
              body: Container(
                width: double.infinity,
                margin: EdgeInsets.symmetric(
                    horizontal: AppTheme.margin, vertical: AppTheme.margin),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8.w),
                  color: Colors.white,
                  boxShadow: [
                    BoxShadow(
                      color: Colours.cC7.withOpacity(0.5),
                      offset: Offset(3.w, 0),
                      blurRadius: 10.w,
                      spreadRadius: 0.w,
                    ),
                  ],
                ),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(8.w),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Padding(
                        padding: EdgeInsets.only(
                            left: 12.0.w, top: 12.0.w, bottom: 12.0.w),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Image.network(
                              controller.model.bookList==null?'http://zxts-book-file.zijingebook.com/2024-01/29/b91194564969b9151fa382807977282acdffa22d.jpg':
                              controller.model.bookList![0].img??'',
                              // 用实际图片链接替换
                              fit: BoxFit.cover, // 设置适应方式为充满
                              width: 72.0.w,
                              height: 86.0.w,
                            ),
                            Expanded(
                              child: Padding(
                                padding: EdgeInsets.only(
                                    left: 12.0.w, top: 5.5.w, right: 45.w),
                                child: Column(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  crossAxisAlignment:
                                      CrossAxisAlignment.start, // 下面的Text靠左
                                  children: [
                                    Container(
                                      height: 47.5.w,
                                      child: Text(
                                        controller.model.bookList==null?'':
                                        controller.model.bookList![0].name??'',
                                        style: TextStyle(
                                          color: Colours.c3,
                                          fontWeight: Fonts.bold,
                                          fontSize: 13.w,
                                        ),
                                        maxLines: 2,
                                        overflow:
                                        TextOverflow.ellipsis, // 超过部分显示省略号
                                      ),
                                    ),
                                    Text(
                                      "¥${controller.model.totalPrice}",
                                      style: TextStyle(
                                        color: Colours.cAB1941,
                                        fontWeight: Fonts.medium,
                                        fontSize: 14.w,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        color: Colours.cLine,
                        margin: EdgeInsets.only(
                            left: 10.w, right: 10.w, bottom: 12.w),
                        height: 1.w,
                      ),
                      Container(
                        padding: EdgeInsets.only(
                            left: 11.5.w, bottom: 8.w, right: 10.w),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: controller.orderCompleteds.map((model) {
                            return Padding(
                              padding: EdgeInsets.only(top: 12.w),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    model.name,
                                    style: TextStyle(
                                        fontSize: 13.w,
                                        height: 1.6.w,
                                        color: Colours.c9),
                                  ),
                                  controller.orderCompleteds.indexOf(model) == 0
                                      ? GestureDetector(
                                          onTap: () {
                                            showModalBottomSheet(
                                              context: context,
                                              shape: RoundedRectangleBorder(
                                                borderRadius: BorderRadius.vertical(top: Radius.circular(8.w)),
                                              ),
                                              builder: (BuildContext context) {
                                                return RefundedDetailsPage(totalPrice: controller.model.totalPrice.toString(),
                                                  couponPrice: controller.model.couponPrice.toString(),
                                                  integralPrice: controller.model.integralPrice.toString(),);
                                              },
                                            ).then((value) {
                                              print('点击了应付款后面');
                                            });
                                          },
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text(
                                                '共减 ¥ ${model.other.toString()}',
                                                style: TextStyle(
                                                  fontSize: 13.w,
                                                  height: 1.6,
                                                  color: AppTheme.primary,
                                                ),
                                              ),
                                              SizedBox(
                                                width: 8.w,
                                              ),
                                              Text(
                                                '合计${model.value.toString()}',
                                                style: TextStyle(
                                                  fontSize: 13.w,
                                                  height: 1.6,
                                                  color: Colours.c3,
                                                ),
                                              ),
                                              Gaps.hGaps8,
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(top: 4.w),
                                                child: Image.asset(
                                                  'assets/images/right_arrow.png',
                                                ),
                                              ),
                                            ],
                                          ))
                                      : Padding(
                                          padding:
                                              EdgeInsets.only(right: 12.5.w),
                                          child: Text(
                                            model.value.toString(),
                                            style: TextStyle(
                                                fontSize: 13.w,
                                                height: 1.6.w,
                                                color: Colours.c3),
                                          ),
                                        ),
                                ],
                              ),
                            );
                          }).toList(),
                        ),
                      ),
                      Container(
                        color: Colours.cLine,
                        margin: EdgeInsets.only(
                            left: 10.w, right: 10.w, top: 6.w, bottom: 13.w),
                        height: 1.w,
                      ),
                      Visibility(
                        visible: controller.judgeComments() ==0?false:true,
                        // visible: true,
                        child: Align(
                          alignment: Alignment.centerRight,
                          child: Padding(
                            padding: EdgeInsets.only(right: 15.2),
                            child: Container(
                              height: 23.w,
                              width: 60.w,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(10.w),
                                  border: Border.all(
                                      color: Colours.cC31F4C, width: 0.5.w)),
                              child: Center(
                                child: GestureDetector(
                                    onTap: () async {
                                      final result = await context.pushNamed(Routes.orderEvaluate,extra:controller.model,
                                          queryParameters: {'orderNum':controller.model.ordersnum});
                                      if (result == true) {
                                        controller.getOrderInfo();        }
                                    },
                                    child: Text(controller.judgeComments() ==1?'去评价':"继续评价",
                                      style: TextStyle(
                                          fontSize: 12.w, color: Colours.cC31F4C),
                                    )),
                              ),
                            ),
                          ),
                        ),
                      ),

                      SizedBox(
                        height: 14.5.w,
                      ),
                    ],
                  ),
                ),
              ))),
    );
  }
}
