<template>
  <wrapper
    fill
    margin
    padding
    background
  >
    <schema-table :schema="schema" />
    <credit-config-dialog ref="creditDialog" />
  </wrapper>
</template>

<script>
import { mapGetters } from 'vuex'
import { getTenantCredits } from './api'
import CreditConfigDialog from './components/CreditConfigDialog'

export default {
  name: 'AIStockGroup',
  components: {
    CreditConfigDialog
  },
  data () {
    return {
      schema: {
        condition: { auditType: void 0 },
        list: this.getTenantCredits,
        buttons: [
          { label: '阈值配置', on: this.onConfig }
        ],
        filters: [
          { key: 'auditType', type: 'select', placeholder: '全部类型', options: [
            { value: 1, label: '图片' },
            { value: 2, label: '视频' }
          ] }
        ],
        cols: [
          { label: '审核类型', render: this.transformAuditType },
          { prop: 'effectiveDate', label: '生效日期' },
          { prop: 'expiryDate', label: '结束日期' },
          { prop: 'initialAmount', label: '总次数' },
          { prop: 'remaining', label: '剩余次数' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters(['tenant'])
  },
  methods: {
    getTenantCredits (params) {
      return getTenantCredits({
        tenant: this.tenant,
        ...params
      })
    },
    transformAuditType (data) {
      return ['', '图片', '视频'][data.auditType]
    },
    onConfig () {
      this.$refs.creditDialog.show(this.tenant)
    }
  }
}
</script>
