<template>
  <div class="app-container">
    <div class="box">
      <el-form ref="form" :model="form" :rules="dataRule" class="demo-ruleForm" label-width="150px">
        <el-form-item label="订单积分抵扣比例" prop="cashToPointsRatio">
          <el-input-number v-model="form.cashToPointsRatio" controls-position="right" :min="0" :precision="2"></el-input-number>%
        </el-form-item>
        <!-- <el-form-item label="积分兑换比例" prop="pointsToCashRatio">
          <el-input-number v-model="form.pointsToCashRatio" controls-position="right" :min="0" :precision="2"></el-input-number> ( 多少积分可以兑换1元钱)
        </el-form-item> -->
        <!-- <el-form-item label="赠送积分比例" prop="giftPointRatio">
          <el-input-number v-model="form.giftPointRatio" controls-position="right" :min="0" :precision="2"></el-input-number>%
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" :loading="btnLoading" @click="onSubmit('form')">提 交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { businessSalesConfigAdd, businessSalesConfigInfo } from '@/api/operating'
export default {
  data () {
    return {
      form: {
        cashToPointsRatio: undefined,
        pointsToCashRatio: undefined
      },
      btnLoading: false,
      dataRule: {
        cashToPointsRatio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        pointsToCashRatio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
        giftPointRatio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur'
          }
        ],
      }
    }
  },
  mounted () {
    this.getInfo()
  },
  methods: {
    getInfo () {
      businessSalesConfigInfo().then((res) => {
        this.form = res.data || {}
      })
    },
    // 提交
    onSubmit (form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          this.form.giftPointRatio = 0;
          this.form.pointsToCashRatio = 1;
          businessSalesConfigAdd(this.form).then((res) => {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            this.getInfo()
          }).finally(() => {
            this.btnLoading = false
          })
        } else {
          console.log('error submit!!')
          this.$message.error('请完成必填输入！')
          return false
        }
      })
    }
  }
}
</script>

<style lang='scss' scoped>
</style>