<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form ref="config" :model="config" label-width="200px" class="demo-config">
        <el-form-item label="惠民积分：">
          <el-radio-group v-model.number="config.quota_integral_switch">
            <el-radio :label="0">关闭</el-radio>
            <el-radio :label="1">开启</el-radio>
          </el-radio-group>
        </el-form-item>
        <div v-show="config.quota_integral_switch == 1">
          <el-form-item label="积分赠送比例：">
            <el-input v-model="config.quota_integral_rate" :precision="2" :step="0.01" :min="0" type="number" class="selWidth">
              <template slot="append">倍</template>
            </el-input>
            <div class="tips">会员在中小型餐厅消费获得的积分倍数，以实际支付金额为准。</div>
          </el-form-item>
          <el-form-item label="补差支付比例：">
            <el-input v-model="config.quota_integral_diff_rate" :precision="2" :step="0.01" :min="0" type="number" class="selWidth">
              <template slot="append">%</template>
            </el-input>
            <div class="tips">会员使用积分兑换酒水时，超出积分抵扣部分的金额支付比例。</div>
          </el-form-item>
          <el-form-item label="会员升级">
            <el-input v-model="config.quota_integral_give_money" :precision="2" :step="0.01" :min="0" type="number" style="width:500px!important;">
              <template slot="prepend">补差实际支付金额达到</template>
              <template slot="append">元，赠送</template>
            </el-input>
            <el-select v-model.number="config.quota_integral_give_card" placeholder="请选择" class="filter-item selWidth mr20">
              <el-option v-for="(item,index) in level_list" :key="index" :label="item.svip_name" :value="item.group_data_id" v-if="item.status == 1">
                {{ item.svip_name }}
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="共创股东">
            <el-input v-model="config.quota_integral_shareholder_money" :precision="2" :step="0.01" :min="0" type="number" style="width:500px!important;">
              <template slot="prepend">单个商户补差实际支付金额达到</template>
              <template slot="append">元，成为</template>
            </el-input>
            <el-select v-model.number="config.quota_integral_shareholder_level_id" placeholder="请选择" class="filter-item selWidth mr20">
              <el-option v-for="(item,index) in shareholder_level_list" :key="index" :label="item.title" :value="item.id">
                {{ item.title }}
              </el-option>
            </el-select>
          </el-form-item>


        </div>
        <!-- 提交按钮 -->
        <el-form-item>
          <el-button type="primary" @click="setConfig()">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { exchangeQuotaConfigGet, exchangeQuotaConfigSet } from "@/api/marketing";
import {levelListApi} from "@/api/user";
import {merShareholderList} from "@/api/merchant";

export default {
  name: 'Index',
  data() {
    return {
      level_list: [],
      shareholder_level_list: [],
      // 配置信息
      config: {
        quota_integral_switch: 0,
        quota_integral_rate: 0.00,
        quota_integral_diff_rate: 0.00,
        quota_integral_give_money: 0.00,
        quota_integral_give_card: '',
        quota_integral_shareholder_money: 0.00,
        quota_integral_shareholder_level_id: '',
      },
    }
  },
  mounted() {
    this.getLevelList();
    this.getShareholder();
    this.getConfig();
  },
  methods: {
    // 获取全部会员卡等级
    getLevelList(){
      let _this = this;
      levelListApi().then(res => {
        _this.level_list = res.data.list || {};
      }).catch((res) => {
        console.log('获取失败',res)
      })
    },
    // 获取全部共创股东等级
    getShareholder(){
      let _this = this;
      let params = {
        page: 1,
        limit: 20,
        merchant_type: 1,
      };
      merShareholderList(params).then(res => {
        _this.shareholder_level_list = res.data.list || {};
      }).catch((res) => {
        console.log('获取失败',res)
      })
    },
    // 提交配置信息
    setConfig(){
      let _this = this;
      // 信息处理
      let config = Object.assign({}, _this.config);
      // 提交配置信息
      exchangeQuotaConfigSet(config).then((res) => {
        _this.$message.success(res.message);
        _this.getConfig();
      }).catch((res) => {
        _this.$message.error(res.message);
      });
    },
    // 获取配置信息
    getConfig(){
      let _this = this;
      exchangeQuotaConfigGet().then((res) => {
        _this.config = res.data || {};
      }).catch((res) => {
        _this.$message.error(res.message);
      });
    },


  }
}
</script>

<style scoped lang="scss">
.selWidth{
  margin-bottom: 10px!important;
}
.tips{
  padding-bottom: 5px;
  font-size: 12px;
  color: #999;
}
</style>
