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

const getList = () => {
  getApiLoading(Apis.WorkOrder.HouseWorkOrders.MySubmitList, useModel?.formData?.value).then(
    res => {
      useModel.dataList.value = [...useModel?.dataList?.value, ...res?.data]
      useModel.meta.value = res?.meta
    }
  )
}
const handleSearch = () => {
  useModel.formData.value.page = 1
  useModel.dataList.value = []
  getList()
}
export default {
  getList,
  handleToDetail(e: { id: string }) {
    uni.navigateTo({
      url: `/WORKORDER/show_log/index?id=${e?.id}`
    })
  },
  handleAdd() {
    uni.navigateTo({
      url: '/WORKORDER/add/index'
    })
  },
  handleChangeTabs(idx: number, e: any) {
    useModel.currentTabs.value = idx
    useModel.formData.value.type = e?.value
    handleSearch()
  },

  handleAssignEmployee(e: any) {
    if (e?.status === 'PendingAcceptance') {
      //去验收工单
      uni.navigateTo({
        url: `/WORKORDER/acceptance/index?id=${e?.id}`
      })
      return false
    }
    console.log(e, 'eee')
  },
  handleChangeStatus(e: { value: string }) {
    useModel.formData.value.status = e?.value
    handleSearch()
  },
  handleLoad(page: number) {
    useModel.formData.value.page = page
    getList()
  }
}
