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

const getList = () => {
  Apis.Collection.HouseCollectionTasks.List(useModel?.formData?.value).then(res => {
    useModel.dataList.value = [...useModel.dataList.value, ...res?.data]
    useModel.meta.value = res?.meta
    console.log('登录', res?.data)
  })
}

const getTaskRecords = (id: string) => {
  getApiLoading(Apis.Collection.HouseCollectionRecords.GetTaskRecords, {
    collection_tasks_id: id
  }).then(res => {
    useModel.showDataTable.value = res?.data
  })
}
export default {
  getList,
  changeTab(idx: number, e: any) {
    useModel.tabCurrent.value = idx
    useModel.formData.value.status = e?.value
    useModel.formData.value.page = 1
    useModel.dataList.value = []
    getList()
  },
  load(e: { page: number }) {
    useModel.formData.value.page = e?.page
    getList()
  },
  goDetail(e: { id: string }) {
    uni.navigateTo({
      url: `/BILL/collection_record/show?id=${e?.id}`
    })
  },
  getShow(id: number) {
    getApiLoading(Apis.Collection.HouseCollectionTasks.Show, { id }).then(res => {
      useModel.showData.value = res?.data
      getTaskRecords(res?.data?.id)
    })
  },
  getTaskRecords,
  getShowChannel(list: string[]) {
    let enums = ''
    list?.map(key => {
      enums += key
        ? `${HouseCollectionTasksChannelEnum[key as keyof typeof HouseCollectionTasksChannelEnum]?.text} `
        : ''
    })
    return enums
  }
}
