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

const getUserHoueInfo = (phone?: string) => {
  getApiLoading(Apis.Archive.HouseOccupants.GetHouseOccupantsByPhone, { phone }).then(res => {
    useModel.userHouse.value = res?.data
    console.log(res)
  })
}
const getOccupantArrearageHouses = (phone?: string) => {
  getApiLoading(Apis.Bill.HouseBills.GetOccupantArrearageHouses, { phone }).then(res => {
    useModel.arrearageHouses.value = res?.data
    console.log(res)
  })
}

export default {
  handleMakePhoneCall() {
    if (useModel.showData.value?.phone) {
      uni.makePhoneCall({
        phoneNumber: useModel.showData.value?.phone //仅为示例，并非真实的电话号码
      })
    }
  },
  getShow(id: number) {
    getApiLoading(Apis.Archive.HouseOccupants.Show, { id }).then(res => {
      useModel.showData.value = res?.data
      getUserHoueInfo(res?.data?.phone)
      getOccupantArrearageHouses(res?.data?.phone)
      console.log(res)
    })
  },
  shareBill() {
    navigateToMiniProgram({
      path: '/pages/forward/index?source=OutstandingFeeList',
      envVersion: 'develop',
      extraData: { source: 'OutstandingFeeList' }
    })
  }
}
