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

const auth = useWeAppAuthStore()

const getCompanyEmployeeBacklogs = () => {
  getApiLoading(Apis.Company.CompanyEmployeeBacklogs.List, useModel?.formData?.value).then(res => {
    useModel.listData.value = [...useModel?.listData?.value, ...res?.data]
    useModel.metaData.value = res?.meta
    console.log(useModel.metaData.value, 'useModel.metaData.value')
  })
}

export default {
  getCountGridHouse() {
    getApiLoading(Apis.Grid.Grids.CountGridHouse, {}).then(res => {
      useModel.userData.value = res.data
      console.log(res)
    })
  },
  getCompanyEmployeeBacklogs,
  loadMore(res: any) {
    useModel.formData.value.page = res?.page
    getCompanyEmployeeBacklogs()
  },
  async uploadMedia(data: any) {
    let res = await Apis.Customer.CustomerMoments.UploadMedia(data)
    return res?.data
  },
  getIndexCount() {
    getApiLoading(Apis.Count.CommonCount.IndexCount, {}).then(res => {
      useModel.IndexCount.value = res.data
      console.log(res)
    })
  },
  getPageRole() {
    useModel.loadingPage.value = true
    useModel.pageRole.value =
      auth?.data?.permissions?.find((item: any) => item?.key === 'home')?.children || []
    console.log(useModel.pageRole.value, 'useModel.pageRole.value')
  }
}
