import { Apis } from '@/gen/Apis'
import { getApiLoading } from '@/common/libraries/apiLoading'
import useModel from './model'
import { showToast } from '@/common/libraries/naviHelper'
import { isDatePassed } from '@/common/libraries/day'
const getShow = (data: { id: string }) => {
  getApiLoading(Apis.GoodsReleases.GoodsReleases.Show, data).then(res => {
    useModel.showData.value = res?.data
    if (res?.data?.passed_time) {
      useModel.isExpired.value = isDatePassed(res?.data?.passed_time)
    }
    console.log(res)
  })
}

export default {
  getShow,
  handleSubmit() {
    uni.showModal({
      title: '提示',
      content: '确定放行？',
      success: function (res) {
        if (res.confirm) {
          getApiLoading(Apis.GoodsReleases.GoodsReleases.ScanRelease, {
            code: useModel.showData.value?.code
          }).then(res => {
            showToast('放行成功！')
            getShow(useModel?.showData?.value)
            console.log(res)
          })
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
}
