<template>

    <basic-container v-loading="loading">
      <el-form
        label-position="left"
        inline size="small"
        :rules="rules"
        :model="form"
        ref="normalForm"
        label-width="200px"
        class="layout_v">
        <div class="layout_h_v_c">
          <span>商家提现时需要收取</span>
          <el-form-item style="margin: 0;margin-right: 10px;margin-left: 10px;">
            <el-input-number v-model="form.merchantRate" :min="0" :max="100" autocomplete="off" :precision="2" :step="1"></el-input-number>
          </el-form-item>
          <span>%的手续费</span>
        </div>
        <div class="layout_h_v_c" style="margin-top: 16px;">
          <span>任务员提现时需要收取</span>
          <el-form-item style="margin: 0;margin-right: 10px;margin-left: 10px;">
            <el-input-number v-model="form.taskRate" :min="0" :max="100" autocomplete="off" :precision="2" :step="1"></el-input-number>
          </el-form-item>
          <span>%的手续费</span>
        </div>
        <div class="layout_h_v_c" style="margin-top: 16px;">
          <span>推广员提现时需要收取</span>
          <el-form-item style="margin: 0;margin-right: 10px;margin-left: 10px;">
            <el-input-number v-model="form.promoteRate" :min="0" :max="100" autocomplete="off" :precision="2" :step="1"></el-input-number>
          </el-form-item>
          <span>%的手续费</span>
        </div>
        <div class="layout_h_v_c" style="margin-top: 16px;">
          <span>普通用户提现时需要收取</span>
          <el-form-item style="margin: 0;margin-right: 10px;margin-left: 10px;">
            <el-input-number v-model="form.normalRate" :min="0" :max="100" autocomplete="off" :precision="2" :step="1"></el-input-number>
          </el-form-item>
          <span>%的手续费</span>
        </div>
        <div class="layout_h_v_c" style="margin-top: 16px;">
          <span>VIP用户提现时需要收取</span>
          <el-form-item style="margin: 0;margin-right: 10px;margin-left: 10px;">
            <el-input-number v-model="form.vipRate" :min="0" :max="100" autocomplete="off" :precision="2" :step="1"></el-input-number>
          </el-form-item>
          <span>%的手续费</span>
        </div>
        <div class="layout_h_v_c" style="margin-top: 16px;">
          <span>1B币可提现</span>
          <el-form-item style="margin: 0;margin-right: 10px;margin-left: 10px;">
            <el-input-number v-model="form.rate" :min="0" :max="100" autocomplete="off" :precision="2" :step="1"></el-input-number>
          </el-form-item>
        </div>
      </el-form>
      <div class="layout_v" style="width: 100%;">
        <el-button class="self_center" type="primary" :loading="saving" @click="submitForm">保存</el-button>
      </div>
    </basic-container>

</template>

<script>

  import { getSystemSet, configSystemSet } from '@/api/systemSet/systemSet.js'
  import { ZmMixin } from '@/mixins/ZmMixin.js'

  export default {
    mixins: [ZmMixin],
    data() {
      return {
        key: 'SYSTEM_SET_WITHDRAW_SET',
        loading: false,
        saving: false,
        rules: {

        },
        form: {
          merchantRate: '',
          taskRate: '',
          promoteRate: '',
          normalRate: '',
          vipRate: '',
          rate: ''
        }
      }
    },
    created() {
      this.load()
    },
    methods: {
      load() {
        this.loading = true
        getSystemSet({key: this.key})
        .then(r => {
          this.loading = false
          let z = this.zmRes(r)
          if(z) {
            this.form = {
              merchantRate: z.merchantRate * 100,
              taskRate: z.taskRate * 100,
              promoteRate: z.promoteRate * 100,
              normalRate: z.normalRate * 100,
              vipRate: z.vipRate * 100,
              rate: z.rate
            }
          }
        })
        .catch(e => {
          this.loading = false
        })
      },
      submitForm() {
        this.saving = true
        configSystemSet({
          key: this.key,
          data: JSON.stringify({
            merchantRate: this.form.merchantRate / 100,
            taskRate: this.form.taskRate / 100,
            promoteRate: this.form.promoteRate / 100,
            normalRate: this.form.normalRate / 100,
            vipRate: this.form.vipRate / 100,
            rate: this.form.rate
          })
        })
        .then(r => {
          this.saving = false
          this.success("保存成功！")
        })
        .catch(e => {
          this.saving = false
        })
      }
    }
  }

</script>

<style scoped>


</style>
