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

const getAssignPermission = (id: number) => {
  getApiLoading(Apis.WorkOrder.HouseWorkOrders.GetAssignPermission, {
    id: id
  }).then(res => {
    useModel.assignPermissionData.value = res?.data
  })
}

export default {
  getShow(id: string) {
    getApiLoading(Apis.WorkOrder.HouseWorkOrders.Show, { id }).then(res => {
      useModel.dataShow.value = res?.data
      getAssignPermission(res?.data?.id)
    })
  },
  getHouseWorkLogs(id: number) {
    getApiLoading(Apis.WorkOrder.HouseWorkLogs.List, { house_work_orders_id: id }).then(res => {
      useModel.logsData.value = res?.data
    })
  },
  toPageUpdate(type: string) {
    uni.navigateTo({
      url: `/INDEX/task/update/index?id=${useModel?.dataShow?.value?.id}&type=${type}`
    })
  },
  handlePreviewImage(idx: number | string) {
    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?.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'
    })
  }
}
