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) {
    uni.setNavigationBarTitle({
      title: data?.type
    })
    console.log('init', auth?.data)
    useModel.formData.value = {
      ...data,
      pageType: data?.type,
      assign_employees: auth?.data?.user,
      house_work_orders_id: data?.id
    }
  },
  handleSubmit() {
    console.log('handleSubmit', useModel.formData.value)
    let data = useModel?.formData?.value
    if (!data?.level) {
      return showToast('请先选择优先级！')
    }
    if (data?.pageType === '指派工单' && !data?.assign_employees_id) {
      return showToast('请先选择处理人！')
    }
    getApiLoading(
      data?.pageType === '指派工单'
        ? Apis.WorkOrder.HouseWorkOrders.Assign
        : Apis.WorkOrder.HouseWorkOrders.Receive,
      data
    ).then(res => {
      showToastBack(data?.pageType === '指派工单' ? '提交成功！' : '领取成功！', 1, true)
      console.log(res)
    })
  }
}
