/**
 * 牧业金融生物资产：lfT（livestockFinance.lfNs）、lfCommon
 */
export default {
  methods: {
    lfT(key, values) {
      const ns = this.lfNs
      if (!ns) {
        return key
      }
      return this.$t(`livestockFinance.${ns}.${key}`, values)
    },
    lfCommon(key) {
      return this.$t(`livestockFinance.common.${key}`)
    },
    /** 第三方数据同步，带全局 loading */
    runSyncWithLoading(syncFn) {
      if (this.syncing) {
        return Promise.reject(new Error("syncing"))
      }
      let modalLoading = false
      this.syncing = true
      this.$modal.loading(this.lfCommon("syncLoading"))
      modalLoading = true
      return syncFn().finally(() => {
        this.syncing = false
        if (modalLoading) {
          this.$modal.closeLoading()
        }
      })
    }
  }
}
