<template>
  <a-card :bordered="false" v-if="currUserInfo">
    <x-form-table
      title="收费查询"
      :queryParamsName="queryParamsName"
      :fixedQueryForm="fixedQueryForm"
      serviceName="af-revenue"
      @action="action"
      ref="xFormTable">
    </x-form-table>
    <bill-print serviceName="af-revenue" ref="bill-print" @ok="chargeOk"/>
  </a-card>
</template>

<script>
import { mapState } from 'vuex'
import { getConfigByName, getConfigByNameAsync } from '@vue2-client/services/api/common'

export default {
  name: 'UserChargeRecordQuery',
  components: {
    XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue'),
    BillPrint: () => import('@vue2-client/base-client/components/common/XPrint/index.vue')
  },
  data () {
    return {
      // 查询配置名称
      queryParamsName: '',
      // 查询表单固定值
      fixedQueryForm: {},
      // 是否显示详情抽屉
      detailVisible: false,
      // 当前记录
      record: {}
    }
  },
  props: {
    currUserInfo: {
      type: Object,
      default: () => undefined
    }
  },
  mounted () {
    if (this.currUserInfo.f_meter_type === '物联网表') {
      this.queryParamsName = 'WebUserChargeRecordQueryCRUD'
    } else {
      this.queryParamsName = 'UserChargeRecordQueryCRUD'
    }
    getConfigByName('revenueConfig', 'af-revenue', (res) => {
      const queryCondition = res.chargeQueryCondition ? res.chargeQueryCondition : res.queryCondition
      if (queryCondition === 'f_userfiles_id') {
        this.fixedQueryForm = { uc_f_userfiles_id: this.currUserInfo.f_userfiles_id }
      } else if (queryCondition === 'f_userinfo_id') {
        this.fixedQueryForm = { uc_f_userinfo_id: this.currUserInfo.f_userinfo_id }
      } else if (queryCondition === 'f_user_id') {
        this.fixedQueryForm = { uc_f_user_id: this.currUserInfo.f_user_id }
      }
      this.$refs.xFormTable.refresh(true)
    })
  },
  methods: {
    async getBillUrl (type) {
      const res = getConfigByNameAsync('票据类型Url映射Config')
      return res[type]
    },
    async action (record, id, actionType) {
      const billUrl = await this.getBillUrl(record.uc_type)
      this.$refs['bill-print'].print({
        id: record.uc_id,
        billUrl: billUrl,
        billType: record.uc_type,
        operator: this.currUser.name,
        billStyle: '普通票据'
      })
    },
    onClose () {
      this.detailVisible = false
      // 关闭详情之后重新查询表单
      this.$refs.xFormTable.refreshTable(true)
    },
    chargeOk () {
      this.$message.success('补打成功')
    }
  },
  computed: {
    ...mapState('account', { currUser: 'user' }),
    ...mapState('setting', { isMobile: 'isMobile' })
  },
}
</script>

<style scoped>

</style>
