<template>
  <div></div>
</template>

<script>
import CONFIG from '@/config'
import { mapGetters, mapActions } from 'vuex'
import { CUSTOM_SOURCE_TYPE } from '@/utils/constant'

export default {
  name: 'ComplaintsDeal',
  computed: {
    ...mapGetters({
      isLogin: 'users/isLogin'
    })
  },
  mounted() {
    this.init()
  },
  methods: {
    ...mapActions({ jumpToLogin: 'users/jumpToLogin' }),
    init() {
      const { uin, id } = this.$route.query
      if (typeof complaintsDeal === 'undefined') {
        return null
      }
      // eslint-disable-next-line no-undef
      complaintsDeal({
        target: document.body,
        props: {
          // rootFontSize: '.62667rem',
          defaultEntryStyle: {
            width: '0.62667rem',
            height: '0.62667rem',
            right: '0.13333rem',
            bottom: '0.13333rem',
            zIndex: 6,
            background: '#fff',
            iconColor: '#80411a'
          },
          zIndex: 999,
          uin,
          url: window.location.href,
          company: '管理员',
          pageId: id,
          pageType: CUSTOM_SOURCE_TYPE.vote,
          env: CONFIG.env,
          beforeShow: next => {
            if (this.isLogin) {
              next()
            } else {
              const self = this
              this.$toast({
                message: '请先登录',
                duration: 1500,
                onClose() {
                  if (process.client && window.self !== window.top) return
                  self.jumpToLogin()
                }
              })
            }
          },
          afterSuccessSub: next => {
            this.$toast('提交成功，感谢您的反馈')
            next()
          },
          afterFailSub: res => {
            res.statusText && this.$toast(res.statusText)
          }
        }
      })
    }
  }
}
</script>

<style lang='less' scoped>
</style>
