<template>
  <div class="app-container" v-loading="loading">
    <el-tabs tab-position="left">
      <el-tab-pane label="充值/提现配置" lazy>
        <h3>充值</h3>
        <config-item :config="getConfig(ConfigKey.SERVICE_FEE_RATE)"/>
        <config-item :config="getConfig(ConfigKey.RECHARGE_MIN_SERVICE)"/>
        <config-item :config="getConfig(ConfigKey.ORDER_AUTO_CLOSE_CD)"/>
        <config-item :config="getConfig(ConfigKey.ARRIVAL_DELAY)"/>
        <h3>提现</h3>
        <config-item :config="getConfig(ConfigKey.DAILY_WITHDRAW_AMOUNT)"/>
        <config-item :config="getConfig(ConfigKey.DAILY_WITHDRAW_COUNT)"/>
        <config-item :config="getConfig(ConfigKey.NOVERIFY_WITHDRAW_SINGLE)"/>
        <h3>风控</h3>
        <config-item :config="getConfig(ConfigKey.RISK_WITHDRAW_ENABLED)" type="switch"/>
        <config-item :config="getConfig(ConfigKey.RISK_WITHDRAW_TIME)"/>
        <config-item :config="getConfig(ConfigKey.RISK_WITHDRAW_COUNT)"/>
      </el-tab-pane>
      <el-tab-pane label="文章配置" lazy>
        <config-item :config="getConfig(ConfigKey.SS_LICENCE_USER_ID)">
          <article-input slot-scope="d" v-model="d.row.configValue"/>
        </config-item>
        <config-item :config="getConfig(ConfigKey.SS_LICENCE_PRIVACY_ID)">
          <article-input slot-scope="d" v-model="d.row.configValue"/>
        </config-item>
        <config-item :config="getConfig(ConfigKey.SS_LICENCE_ABOUT_ID)">
          <article-input slot-scope="d" v-model="d.row.configValue"/>
        </config-item>
        <config-item :config="getConfig(ConfigKey.SS_LICENCE_COLLECTION_ID)">
          <article-input slot-scope="d" v-model="d.row.configValue"/>
        </config-item>
        <config-item :config="getConfig(ConfigKey.SS_LICENCE_MCH_ID)">
          <article-input slot-scope="d" v-model="d.row.configValue"/>
        </config-item>
      </el-tab-pane>
      <el-tab-pane label="其他" lazy>
        <config-item :config="getConfig(ConfigKey.WECHAT_APPROVAL)" type="switch"/>
        <config-item :config="getConfig(ConfigKey.LOGIN_WITH_PHONE)" type="switch"/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>

import { getConfigKeys } from '@/api/system/config'
import { ConfigKey } from '@/utils/constants'
import ConfigItem from '@/views/system/config/components/ConfigItem.vue'
import ArticleInput from '@/components/Business/Article/ArticleInput.vue'

export default {
  name: "GroupConfig",
  components: { ArticleInput, ConfigItem },
  data() {
    return {
      ConfigKey,
      keys: Object.values(ConfigKey),
      map: {},
      loading: false,
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getConfig(key) {
      let config = this.map[key];
      if (config == null) {
        return {
          configName: '加载中'
        }
      }
      return config;
    },
    getList() {
      this.loading = true;
      getConfigKeys(this.keys).then(res => {
        let list = res.data;
        let map = {};
        list.forEach(item => {
          map[item.configKey] = item;
        })
        this.map = map;
        console.log(this.map)
      }).finally(() => {
        this.loading = false;
      })
    },
  }
}
</script>

<style>
.el-tabs__content {
  padding: 1em 2em;
}
</style>
