import { getApiLoading } from '@/common/libraries/apiLoading'
import { getTime } from '@/common/libraries/day'
import { showToast, showToastBack } from '@/common/libraries/naviHelper'
import { Apis } from '@/gen/Apis'
import useModel from './model'

export default {
  init(e:any) {
    useModel.formData.value = {house_meters_id: e?.id}
  },
  handleSubmit() {
    console.log('handleSubmit', useModel.formData.value)
    if (!useModel?.formData?.value?.current_reading) {
      return showToast('请设置本次读数！')
    }
    getApiLoading(Apis.Meter.HouseMeterReadings.Store, {
      ...useModel.formData.value,
      reading_time: getTime()
    }).then(res => {
      showToastBack('提交成功！', 1, true)
      console.log(res)
    })
  },
  handleToSelectHouse() {
    uni.navigateTo({
      url: '/pages/public/asset_houses/index?type=work_add'
    })
  },
  handleSwitchChange(e: any) {
    useModel.formData.value.is_anonymous = e?.detail?.value
    console.log(e, 'e')
  },
  getShow(e:any){
     getApiLoading(Apis.Meter.HouseMeters.Show,e).then(res => {
      useModel.showData.value = res?.data
      console.log(res)
    })
  }
}
