import { useWeAppAuthStore } from '@/common'
import { getApiLoading } from '@/common/libraries/apiLoading'
import useModel from './model'
import { Apis } from '@/gen/Apis'
import getUserLogin from '@/common/libraries/userUserLogin'
const auth = useWeAppAuthStore()
const previewPdf = () => {
  uni.showLoading({
    title: '加载中...',
    mask: true
  })
  uni.downloadFile({
    url: 'https://pay-test-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K44N5AP6T246WQWHNB2ERQ9M.pdf',
    success: function (e) {
      const filePath = e.tempFilePath
      uni.hideLoading()
      // 预览pdf
      uni.openDocument({
        filePath: filePath as string,
        showMenu: true
      })
    }
  })
}
export default {
  init() {
    useModel.userData.value = auth?.data?.user || undefined
  },
  getCountGridHouse() {
    getApiLoading(Apis.Grid.Grids.CountGridHouse, {}).then(res => {
      useModel.gridHouseData.value = res.data
      console.log(res)
    })
  },
  handleJinGang(e: any) {
    if (e?.url) {
      uni.navigateTo({
        url: !getUserLogin?.getLoginStatus() ? '/pages/login' : e?.url || ''
      })
      return
    }
    if (e?.icon === 'Permission') {
      uni.openSetting()
    }
    if (e?.icon === 'Feedback') {
      previewPdf()
    }
    console.log(e, 'e')
  }
}
