<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="180px">
      <el-form-item label="每日首充赠送比例（%）" prop="firstSend">
        <el-input v-model="form.firstSend" type="number" placeholder="请输入当日首充" />
      </el-form-item>
      <el-form-item label="非每日首充赠送比例（%）" prop="send" label-width="180px">
        <el-input v-model="form.send" type="number" placeholder="请输入非每日首充" />
      </el-form-item>
      <el-form-item label="每日赠送封顶" prop="maxSend" label-width="180px">
        <el-input v-model="form.maxSend" type="number" placeholder="请输入每日赠送封顶" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import {
  listConfig,
  getConfig,
  delConfig,
  addConfig,
  updateConfig,
  refreshCache,
  getConfigKey,
  updateByKey
} from "@/api/system/config";

export default {
  name: "Channel",
  dicts: ['app_status_enable', 'app_recharge_withdraw_type', 'app_account_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      typeMap:{},
      typeList:[],
      configKey:"app_recharge_config",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        currencyId: null,
        icon: null,
        name: null,
        key: null,
        account: null,
        accountName: null,
        staus: null,
        rechargeRate: null,
        withdrawRate: null,
        showType:0,
        otherName:null,
        otherKey:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
      this.getList();
  },
  methods: {
    /** 查询充提渠道列表 */
    getList() {
      this.loading = true;
      this.reset();
      getConfigKey(this.configKey).then(response => {
        let data= response.data;
        if(data != undefined && data != null){
          let arr = data.split(",");
          this.form = {
            firstSend: arr[0],
            send: arr[1],
            maxSend: arr[2],
            configKey: this.configKey
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        firstSend: '',
        send: '',
        maxSend: ''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加充提渠道";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getChannel(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改充提渠道";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$confirm('是否确认修改?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            const loading = this.$loading({
              lock: true,
              text: 'Loading',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            });
            this.form["configValue"] = this.form.firstSend + "," + this.form.send + "," + this.form.maxSend;
            this.form["configName"] = "充值赠送设置";
            this.form["remark"] = "充值赠送设置逗号隔开，今日首充（%）,非今日首充（%）,赠送上限";
            updateByKey(this.form).then(response=>{
              this.$message({
                type: 'success',
                message: '修改成功!'
              });
              this.getList();
              loading.close();
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消修改'
            });
          });
        }
      });
    }
  }
};
</script>
