<template>
  <div class="app-container">
    <div class="box" v-loading="loading">
      <el-form :inline="true" ref="formRef" :model="form" :rules="rules" class="demo-form-inline">
        <h3>合伙人身份配置</h3>
        <div class="item" style=" width: 1100px;">
          *城市合伙人返豆
          <div>
            <el-form-item label="" prop="cityPartnerReturnPoint">
              <el-input-number v-model="form.cityPartnerReturnPoint" controls-position="right" :min="0" :precision="0"></el-input-number> 个
            </el-form-item>
          </div>
          线下支付合伙人金额后发放兑换豆数量。 手动直接增加兑换豆数量，不再根据支付金额计算。
        </div>
        <h3>城市合伙人下级商品消费提成比例</h3>
        <div class="item" style=" width: 1100px;">
          *分下级销售利润的
          <div>
            <el-form-item label="" prop="cityPartnerProfitRatio">
              <el-input-number v-model="form.cityPartnerProfitRatio" controls-position="right" :min="0" :precision="2"></el-input-number> %
            </el-form-item>
          </div>
          该倍数是销售金额的的利润 进行分润 N %
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *分润后金额的
          <div>
            <el-form-item label="" prop="cityPartnerProfitAmountMultiple">
              <el-input-number v-model="form.cityPartnerProfitAmountMultiple" controls-position="right" :min="0" :precision="2"></el-input-number> 倍
            </el-form-item>
          </div>
          分润的金额 乘 倍数 获得 兑换豆
        </div>
        <h3>商家下级商品消费提成比例</h3>
        <div class="item" style=" width: 1100px;">
          *分下级销售利润的
          <div>
            <el-form-item label="" prop="businessProfitRatio">
              <el-input-number v-model="form.businessProfitRatio" controls-position="right" :min="0" :precision="2"></el-input-number> %
            </el-form-item>
          </div>
          该倍数是销售金额的的利润 进行分润 N %
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *分润后金额的
          <div>
            <el-form-item label="" prop="businessProfitAmountMultiple">
              <el-input-number v-model="form.businessProfitAmountMultiple" controls-position="right" :min="0" :precision="2"></el-input-number> 倍
            </el-form-item>
          </div>
          分润的金额 乘 倍数 获得 兑换豆
        </div>
        <h3>广告提成比例</h3>
        <div class="item" style=" width: 1100px;">
          *省级合伙人
          <div>
            <el-form-item label="" prop="provincePartnerAdCommissionRatio">
              <el-input-number v-model="form.provincePartnerAdCommissionRatio" controls-position="right" :min="0" :precision="2"></el-input-number> %
            </el-form-item>
          </div>
          该倍数是广告金额的百分比
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *省级合伙人
          <div>
            <el-form-item label="" prop="provincePartnerAdCommissionMultiple">
              <el-input-number v-model="form.provincePartnerAdCommissionMultiple" controls-position="right" :min="0" :precision="2"></el-input-number> 倍
            </el-form-item>
          </div>
          该倍数是指赠送广告额 N倍的兑换豆
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *城市合伙人
          <div>
            <el-form-item label="" prop="cityPartnerAdCommissionRatio">
              <el-input-number v-model="form.cityPartnerAdCommissionRatio" controls-position="right" :min="0" :precision="2"></el-input-number> %
            </el-form-item>
          </div>
          该倍数是广告金额的百分比
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *城市合伙人
          <div>
            <el-form-item label="" prop="cityPartnerAdCommissionMultiple">
              <el-input-number v-model="form.cityPartnerAdCommissionMultiple" controls-position="right" :min="0" :precision="2"></el-input-number> 倍
            </el-form-item>
          </div>
          该倍数是指赠送广告额 N倍的兑换豆
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *C端用户
          <div>
            <el-form-item label="" prop="userAdCommissionRatio">
              <el-input-number v-model="form.userAdCommissionRatio" controls-position="right" :min="0" :precision="2"></el-input-number> %
            </el-form-item>
          </div>
          该倍数是广告金额的百分比
        </div>
        <br />
        <div class="item" style=" width: 1100px;">
          *C端用户
          <div>
            <el-form-item label="" prop="userAdCommissionMultiple">
              <el-input-number v-model="form.userAdCommissionMultiple" controls-position="right" :min="0" :precision="2"></el-input-number> 倍
            </el-form-item>
          </div>
          该倍数是指赠送广告额 N倍的兑换豆
        </div>
      </el-form>
      <div class="btnBox">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">保 存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { partnerRuleConfigSet, partnerRuleConfigInfo } from "@/api/partner"
export default {
  data () {
    return {
      buttonLoading: false,
      loading: false,
      form: {
        cityPartnerReturnPoint: undefined,
        cityPartnerProfitRatio: undefined,
        cityPartnerProfitAmountMultiple: undefined,
        businessProfitRatio: undefined,
        businessProfitAmountMultiple: undefined,
        provincePartnerAdCommissionRatio: undefined,
        provincePartnerAdCommissionMultiple: undefined,
        cityPartnerAdCommissionRatio: undefined,
        cityPartnerAdCommissionMultiple: undefined,
        userAdCommissionRatio: undefined,
        userAdCommissionMultiple: undefined
      },
      rules: {
        cityPartnerReturnPoint: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        cityPartnerProfitRatio: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        cityPartnerProfitAmountMultiple: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        businessProfitRatio: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        businessProfitAmountMultiple: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        provincePartnerAdCommissionRatio: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        provincePartnerAdCommissionMultiple: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        cityPartnerAdCommissionRatio: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        cityPartnerAdCommissionMultiple: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        userAdCommissionRatio: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
        userAdCommissionMultiple: [
          { required: true, message: "请输入", trigger: "blur" }
        ],
      }
    }
  },
  created () {
    this.getDetails()
  },
  methods: {
    getDetails () {
      this.loading = true
      partnerRuleConfigInfo().then(res => {
        if (res.data) {
          this.form = res.data
        }
      }).finally(() => {
        this.loading = false
      })
    },
    submitForm () {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          partnerRuleConfigSet(this.form).then(res => {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
          }).finally(() => {
            this.buttonLoading = false;
          })
        }
      })
    }
  }
}
</script>

<style lang='scss' scoped>
h3 {
  font-weight: 700;
}
.item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  font-size: 14px;
  > div {
    margin: 0 10px;
  }
}
.hint {
  font-size: 12px;
  color: red;
}
.btnBox {
  margin: 20px 0 0 100px;
}
.el-form-item {
  margin-bottom: 0;
}
</style>