import { Apis } from '@/gen/Apis'
import useModel from './model'
import { getApiLoading } from '@/common/libraries/apiLoading'
import { showToastBack, showToast } from '@/common/libraries/naviHelper'
export default {
  getList() {
    let total_amount = 0
    getApiLoading(Apis.Bill.HouseBills.MyBillYearList, useModel?.formData?.value).then(res => {
      if (res?.data?.length) {
        res?.data?.map((i: { bills: { amount: string }[] }) => {
          i?.bills?.map((k: { amount: string }) => {
            total_amount += parseFloat(k?.amount)
          })
        })
        useModel.total_amount.value = total_amount
      }
      useModel.listData.value = res?.data
      useModel.metaData.value = res?.meta
      console.log('onPay', res?.data)
    })
  },
  handleSubmitOrder() {
    if (!useModel?.total_amount?.value) {
      return showToast('没有可支付金额！')
    }
    getApiLoading(Apis.HouseOrder.HouseOrders.Store, {
      bill_ids: useModel?.formData?.value?.bill_ids,
      amount: useModel?.total_amount?.value,
      total_payable_amount: useModel?.total_amount?.value
    }).then(res => {
      uni.redirectTo({
        url: `/INDEX/pay/index?id=${res?.data?.id}`
      })
    })
  }
}
