"use strict";
const common_vendor = require("../../common/vendor.js");
const gen_Apis = require("../../gen/Apis.js");
const INDEX_bill_order_model = require("./model.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const common_libraries_naviHelper = require("../../common/libraries/naviHelper.js");
const method = {
  getList() {
    var _a, _b;
    let total_amount = 0;
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Bill.HouseBills.MyBillYearList, (_b = (_a = INDEX_bill_order_model.useModel) == null ? void 0 : _a.formData) == null ? void 0 : _b.value).then((res) => {
      var _a2, _b2;
      if ((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.length) {
        (_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.map((i) => {
          var _a3;
          (_a3 = i == null ? void 0 : i.bills) == null ? void 0 : _a3.map((k) => {
            total_amount += parseFloat(k == null ? void 0 : k.amount);
          });
        });
        INDEX_bill_order_model.useModel.total_amount.value = total_amount;
      }
      INDEX_bill_order_model.useModel.listData.value = res == null ? void 0 : res.data;
      INDEX_bill_order_model.useModel.metaData.value = res == null ? void 0 : res.meta;
      console.log("onPay", res == null ? void 0 : res.data);
    });
  },
  handleSubmitOrder() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i;
    if (!((_b = (_a = INDEX_bill_order_model.useModel) == null ? void 0 : _a.total_amount) == null ? void 0 : _b.value)) {
      return common_libraries_naviHelper.showToast("没有可支付金额！");
    }
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.HouseOrder.HouseOrders.Store, {
      bill_ids: (_e = (_d = (_c = INDEX_bill_order_model.useModel) == null ? void 0 : _c.formData) == null ? void 0 : _d.value) == null ? void 0 : _e.bill_ids,
      amount: (_g = (_f = INDEX_bill_order_model.useModel) == null ? void 0 : _f.total_amount) == null ? void 0 : _g.value,
      total_payable_amount: (_i = (_h = INDEX_bill_order_model.useModel) == null ? void 0 : _h.total_amount) == null ? void 0 : _i.value
    }).then((res) => {
      var _a2;
      common_vendor.index.redirectTo({
        url: `/INDEX/pay/index?id=${(_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.id}`
      });
    });
  }
};
exports.method = method;
