import { useWeAppAuthStore } from '@/common'
import useModel from './model'
import { Apis } from '@/gen/Apis'
import { getApiLoading } from '@/common/libraries/apiLoading'
const auth = useWeAppAuthStore()
import { showToastBack, showToast } from '@/common/libraries/naviHelper'
export default {
  init(data: any) {
    useModel.HouseWorkOrdersStatusItemEnum.value = {
      Processing0: { text: '不合格', value: '0' },
      Processing1: { text: '合格', value: '1' }
    }
    useModel.formData.value = {
      ...data,
      house_work_orders_id: data?.id
    }
  },
  handleSubmit() {
    console.log('handleSubmit', useModel.formData.value)
    if (
      useModel?.formData?.value?.type === 'RenovationInspection' &&
      !useModel?.formData?.value?.attachments?.length
    ) {
      return showToast('请上传巡检图片！')
    }
    if (useModel?.formData?.value?.type === 'RenovationAcceptance') {
      if (!useModel?.formData?.value?.is_passed) {
        return showToast('请选择验收结果！')
      }
      if (!useModel?.formData?.value?.description) {
        return showToast('请输入验收说明！')
      }
      if (!useModel?.formData?.value?.attachments?.length) {
        return showToast('请上传验收图片！')
      }
    }
    console.log('useModel.formData.value', useModel.formData.value)
    getApiLoading(Apis.WorkOrder.HouseWorkLogs.Store, {
      ...useModel.formData.value,
      status: 'Completed'
    }).then(res => {
      showToastBack('提交成功！', 1, true)
      console.log(res)
    })
  }
}
