/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2023-10-27 10:25:00
 * @LastEditTime: 2023-12-12 15:42:52
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../api/asset_bill.dart';
import '../models/prefee_detail.dart';

class PreFeeIndexStore extends GetxController {
  // 定义一个全局键，用于WisScrollView的状态管理
  final scrollViewKey = GlobalKey<WisScrollViewState>();

  // 定义一些可能为空的字符串，用于存储资产的id、类型和名称
  String? assetId;
  String? assetType;
  String? assetName;

  // 定义一个观察对象，用于存储预存款详情
  var detail = PrefeeDetailModel().obs;

  // 定义一个观察对象，用于存储费用列表
  var feeList = [].obs;

  // 初始化数据
  Future<void> onInitData() async {
    assetId = Get.arguments['id'];
    assetType = Get.arguments['type'];
    assetName = Get.arguments['name'];
    await getDetail();
  }

  // 获取预付费的详细信息
  Future<void> getDetail() async {
    var res = await AssetBillApi.getPreFeeDetail({
      "id": assetId,
      "treeSelection": assetType,
    });
    detail.value = res.data ?? PrefeeDetailModel();
    feeList.value = res.data?.item ?? [];
    feeList.refresh();
  }

  // 跳转到收支记录页面
  void toRecord(billType) {
    Get.toNamed(
      'pay_record/index',
      arguments: {
        'appBarTitle': '收支记录',
        'billType': billType,
        'payWayCodesFirst': ['2'],
        'assetId': assetId,
        'assetType': assetType,
      },
    );
  }

  // 跳转到预存款录单页面
  toSubmit() async {
    await Get.toNamed('receipt/submit', arguments: {
      'assetId': assetId,
      'chargeSubject': assetType,
      'type': 'prePay',
      'assetName': assetName,
    })!
        .then((value) => {
              getDetail(),
            });
  }
}
