/*
 * @Descripttion: 
 * @version: 
 * @Author: guanxiaoxin
 * @Date: 2023-10-13 10:54:37
 * @LastEditors: guanxiaoxin
 * @LastEditTime: 2023-10-18 17:20:37
 * @FilePath: \VNoteApp\lib\pages\contract\package_list\widgets\service_information.dart
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:vitalapp/components/cell.dart';
import 'package:vitalapp/components/dialog_date.dart';
import 'package:vitalapp/components/dialog_select.dart';
import 'package:vitalapp/components/panel.dart';
import 'package:vitalapp/pages/contract/package_list/controller.dart';
import 'package:vitalapp/store/store.dart';

class ServiceInformationPage extends GetView<ServicePackageContractController> {
  const ServiceInformationPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        VPanel(
          child: VListFormCellGroup(
            children: [
              VListFormCell(
                label: '签约医生',
                content: Store.user.principalName,
              ),
              VListFormCell(
                label: '医生电话',
                content: Store.user.principalPhone,
              ),
              Obx(
                () => VListFormCell(
                  label: '服务日期',
                  content: DateFormat('yyyy-MM-dd')
                      .format(controller.state.serviceStartDate),
                  onTap: () async {
                    final result = await VDialogDate(
                      minimumDate: DateTime.now(),
                      title: '服务日期',
                      initialValue: controller.state.serviceStartDate,
                    ).show();
                    controller.state.serviceStartDate = result;
                  },
                ),
              ),
              Obx(
                () => VListFormCell(
                  label: '服务年限',
                  content: '${controller.state.serviceTime}年',
                  onTap: () async {
                    String? result = await VDialogSelect<VSelectModel, String>(
                      source: [
                        VSelectModel(code: "1", name: "1年"),
                        VSelectModel(code: "2", name: "2年"),
                        VSelectModel(code: "3", name: "3年"),
                      ],
                      labelGetter: (data) => data.name,
                      valueGetter: (data) => data.code,
                    ).show();
                    controller.state.serviceTime = int.parse(result ?? '1');
                  },
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
