import { getApiLoading } from '@/common/libraries/apiLoading'
import { Apis } from '@/gen/Apis'
import useModel from './model'
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 getHouseRegisters = () => {
  getApiLoading(Apis.Archive.HouseRegisters.List, 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
  if (useModel.currentTabs.value === 0) {
    getOwnerAuditList()
  }
  if (useModel.currentTabs.value === 1) {
    getHouseRegisters()
  }
}
export default {
  getOwnerAuditList,
  handleSrarch,
  getHouseRegisters,
  handleLoadMore(page: number) {
    useModel.formData.value.page = page
    if (useModel.currentTabs.value === 0) {
      getOwnerAuditList()
    }
    if (useModel.currentTabs.value === 1) {
      getHouseRegisters()
    }
  },
  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('用户点击取消')
        }
      }
    })
  }
}
