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

const getList = () => {
  getApiLoading(Apis.WorkOrder.HouseWorkOrders.List, useModel?.formData?.value).then(res => {
    useModel.listData.value = [...useModel.listData.value, ...res?.data]
    useModel.metaData.value = res?.meta
  })
}
const handleSearch = () => {
  useModel.formData.value.page = 1
  useModel.listData.value = []
  getList()
}
export default {
  getList,
  handleChangeTabs(idx: number, e: any) {
    useModel.currentTabs.value = idx
    useModel.formData.value.status = e?.value
    handleSearch()
  },
  handleLoad(page: number) {
    useModel.formData.value.page = page
    getList()
  },
  handleCopyPhone(e: any) {
    // if (e?.company_employee) {
    //   uni.makePhoneCall({
    //     phoneNumber: e?.company_employee?.phone
    //   })
    //   return
    // }
    // if (e?.customer) {
    //   uni.makePhoneCall({
    //     phoneNumber: e?.customer?.phone
    //   })
    //   return
    // }
    if (e?.contact_phone) {
      //备用联系人
      uni.makePhoneCall({
        phoneNumber: e?.contact_phone
      })
      return
    }
    if (e?.reporter_phone) {
      uni.makePhoneCall({
        phoneNumber: e?.reporter_phone
      })
      return
    }
    uni.showToast({
      title: '暂无电话号码',
      icon: 'none'
    })
  },
   handleUpdateSetp(e: any) {
    if (e?.type === 'SecurityInspection') {
      //安全检查工单-前往完成
      uni.navigateTo({
        url: `/WORKORDER/show_patrol_task_locations/index?id=${e?.id}`
      })
      return
    }
    if (e?.type === 'RenovationInspection' || e?.type === 'RenovationAcceptance') {
      //装修工单-更新/验收
      uni.navigateTo({
        url: `/WORKORDER/patrol_update/index?id=${e?.id}&type=${e?.type}`
      })
      return
    }
    uni.navigateTo({
      url: `/WORKORDER/update/index?id=${e?.id}&projects_id=${e?.asset_projects_id}&location=${e?.location}`
    })
  },
  handleToDetail(e: { id: string }) {
    uni.navigateTo({
      url: `/WORKORDER/show/index?id=${e?.id}`
    })
  },
    handlePendingPaymentQrCode(e: any) {
    uni.navigateTo({
      url: `/WORKORDER/poster/index?id=${e?.id}&full_name=${e?.asset_house?.full_name}&amount=${e?.amount}`
    })
  }
}
