import { getApiLoading } from '@/common/libraries/apiLoading'
import { Apis } from '@/gen/Apis'
import useModel from './model'
export default {
  getShow(id: string) {
    getApiLoading(Apis.WorkOrder.HouseWorkOrders.Show, { id }).then(res => {
      useModel.dataShow.value = res?.data
    })
  },
  getHouseWorkLogs(id: number) {
    getApiLoading(Apis.WorkOrder.HouseWorkLogs.List, { house_work_orders_id: id }).then(res => {
      useModel.logsData.value = res?.data
    })
  },
  toPageAddLogs() {
    if (useModel?.dataShow?.value?.type === 'SecurityInspection') {
      //安全检查工单-前往完成
      uni.navigateTo({
        url: `/WORKORDER/show_patrol_task_locations/index?id=${useModel?.dataShow?.value?.id}`
      })
      return
    }
    if (
      useModel?.dataShow?.value?.type === 'RenovationInspection' ||
      useModel?.dataShow?.value?.type === 'RenovationAcceptance'
    ) {
      //装修工单-更新/验收
      uni.navigateTo({
        url: `/WORKORDER/patrol_update/index?id=${useModel?.dataShow?.value?.id}&type=${useModel?.dataShow?.value?.type}`
      })
      return false
    }

    if (useModel?.dataShow?.value?.status === 'PendingPayment') {
      //收款码
      uni.navigateTo({
        url: `/WORKORDER/poster/index?id=${useModel?.dataShow?.value?.id}&full_name=${useModel?.dataShow?.value?.asset_house?.full_name}&amount=${useModel?.dataShow?.value?.amount}`
      })
      return
    }
    if (useModel?.dataShow?.value?.status === 'Processing') {
      //更新进度
      uni.navigateTo({
        url: `/WORKORDER/update/index?id=${useModel?.dataShow?.value?.id}&projects_id=${useModel?.dataShow?.value?.asset_projects_id}&location=${useModel?.dataShow?.value?.location}`
      })
    }
  },
  handlePreviewImage(idx: number) {
    let urlList = useModel?.dataShow?.value?.attachments?.map((item: any) => item?.url) || []
    uni.previewImage({
      urls: urlList,
      current: idx
    })
  },
  handlePendingPaymentQrCode(e: any) {},
  handleCopyPhone() {
    // if (useModel?.dataShow?.value?.company_employee) {
    //   //员工提交
    //   uni.makePhoneCall({
    //     phoneNumber: useModel?.dataShow?.value?.company_employee?.phone
    //   })
    //   return
    // }
    // if (useModel?.dataShow?.value?.customer) {
    //   //客户提交
    //   uni.makePhoneCall({
    //     phoneNumber: useModel?.dataShow?.value?.customer?.phone
    //   })
    //   return
    // }
    if (useModel?.dataShow?.value?.contact_phone) {
      //备用联系人
      uni.makePhoneCall({
        phoneNumber: useModel?.dataShow?.value?.contact_phone
      })
      return
    }
    if (useModel?.dataShow?.value?.reporter_phone) {
      uni.makePhoneCall({
        phoneNumber: useModel?.dataShow?.value?.reporter_phone
      })
      return
    }
    uni.showToast({
      title: '暂无电话号码',
      icon: 'none'
    })
  }
}
