import { Apis } from '@/gen/Apis'
import useModel from './model'
import { useWeAppAuthStore } from '@/common'
import { getApiLoading } from '@/common/libraries/apiLoading'

const getList = () => {
  getApiLoading(Apis.HouseOrder.HousePrepayments.List, useModel?.formData?.value).then(res => {
    useModel.nonPrepayableHouses.value = res?.data?.nonPrepayableHouses || []
    useModel.prepayableHouses.value = res?.data?.prepayableHouses || []
    useModel.metaData.value = {
      current_page: 1,
      last_page: 1,
      per_page: 10,
      total: res?.data?.prepayableHouses?.length || res?.data?.nonPrepayableHouses?.length || 0
    }
    console.log(res)
  })
}

export default {
  getList,
  loadMore(page: number) {
    useModel.formData.value.page = page
    this.getList()
  },
  handleClickHelp() {
    uni.showModal({
      title: '提示',
      content: '开启后，您物业费预缴低于 100 元时，会收到小程序订阅号提醒，更省心。',
      showCancel: false,
      confirmColor: '#0082FA',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  goToPage(url: string) {
    uni.navigateTo({ url })
  }
}
