import { getApiLoading } from '@/common/libraries/apiLoading'
import useModel from './model'
import { Apis } from '@/gen/Apis'
import { useWeAppAuthStore } from '@/common'
const auth = useWeAppAuthStore()

const getOwnerAuditList = () => {
  getApiLoading(Apis.Archive.HouseRegisters.OwnerAuditList, useModel?.formData?.value).then(res => {
    useModel.dataList.value = [...useModel.dataList.value, ...res?.data]
    useModel.meta.value = res?.meta
    console.log(res)
  })
}

const handleSrarch = () => {
  useModel.dataList.value = []
  useModel.formData.value.page = 1
  getOwnerAuditList()
}
export default {
  getOwnerAuditList,
  handleSrarch,
  handleLoadMore(page: number) {
    useModel.formData.value.page = page
    getOwnerAuditList()
  },
  getHouseKeeper() {
    //联系物业
    if (auth?.data?.selected_house?.id) {
      getApiLoading(Apis.Grid.Grids.GetHousekeeper, {
        asset_houses_id: auth?.data?.selected_house?.id
      }).then(res => {
        useModel.houseKeeperData.value = res?.data
        console.log(res)
      })
    }
  },
  getCountHouse() {
    getApiLoading(Apis.Customer.Customers.GetCountHouse, {}).then(res => {
      useModel.countHouseData.value = res?.data
      console.log(res)
    })
  },
  handleAudit(e: { id: string }) {
    uni.showModal({
      title: '提示',
      content: '请仔细确认好注册用户信息！',
      confirmText: '通过',
      confirmColor: '#2A7EFB',
      success: function (res) {
        if (res.confirm) {
          getApiLoading(Apis.Archive.HouseRegisters.Audit, {
            status: 'Approved',
            id: e?.id
          }).then(res => {
            handleSrarch()
            console.log(res)
          })
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
}
