<template>
  <div class="app-container">

    <div style="margin-bottom: 16px;">
      <el-button type="danger" icon="el-icon-delete" @click="handleResetRewardPool">重置奖池缓存</el-button>
    </div>

    <el-descriptions :column="1" border>
      <el-descriptions-item label="奖池总下注">{{ totalBet }}</el-descriptions-item>
      <el-descriptions-item label="奖池总返奖">{{ totalWin }}</el-descriptions-item>
      <el-descriptions-item label="系统盈利">{{ totalBet - totalWin }}</el-descriptions-item>
      <el-descriptions-item label="RTP">{{ totalBet > 0 ? totalWin / totalBet : 0 }}</el-descriptions-item>
    </el-descriptions>
    <br />
    <el-form :model="queryParams" ref="queryForm" label-width="200px">
      <el-form-item label="一次抽奖奖池保留比例" prop="minProfit">
        <el-input v-model="queryParams.minProfit" placeholder="" />
        <span>用户一次抽奖最大奖励不能超过奖池的保留比例</span>
      </el-form-item>

    </el-form>
    <el-row>
      <el-col :span="24">
        <el-button type="primary" style="width: 50%;display: block; margin: 0 auto;" @click="submitForm">保存</el-button>
      </el-col>
    </el-row>
    <br />

  </div>
</template>

<script>
import {
  getConfig, updateConfig
} from "@/api/game/sugar/config/api";
import { resetRewardPool } from "@/api/game/sugar/dailywin/api";
import { Descriptions } from "element-ui";

export default {
  name: "User",
  dicts: ["user_type", "user_status"],
  data() {
    return {
      // 查询参数
      queryParams: {
        "defaultAwardPool": 0.0,
        "jpPercent": [
          10,
          100
        ],
        "rtp": 0.8,
        "minProfit": 0.3
      },
      totalWin: 0,
      totalBet: 0
    };
  },
  created() {
    this.getConfig();
  },
  methods: {
    getConfig() {
      getConfig().then(response => {
        console.log(response)
        this.queryParams = response.data.config;
        this.totalBet = response.data.totalBet;
        this.totalWin = response.data.totalWin;
      });
    },

    submitForm() {
      updateConfig(this.queryParams).then(response => {
        if (response.code != 200) {
          this.$modal.msgError(response.msg);
          return;
        }
        this.$modal.msgSuccess("修改成功");
        this.getConfig();
      });
    },
    handleResetRewardPool() {
      this.$confirm("确定要重置极速永恒奖池缓存（总下注/总返奖归零）吗？", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        resetRewardPool().then(() => {
          this.$message.success("奖池缓存已重置");
          this.getConfig();
        });
      });
    }
  }
};
</script>
