<template>
  <div class="addRechargeScheme">
    <div class="form-box" style="margin-top: 0">
      <div>
        <span style="color: rgb(64, 158, 255);cursor: pointer;margin-left: 20px" @click="cancel">充值管理</span>
        <span style="margin: 0 5px;color: #C0C4CC;">/</span>
        <span>充值编辑</span>
      </div>
    </div>

    <div class="form-box">
      <el-form :model="msg" style="padding:0 50px;" :rules="rules" ref="msg" label-width="120px">
        <el-form-item label="充值名称" class="is-required"  prop="Name">
          <el-tooltip class="item" effect="dark" content="在充值管理显示" placement="top"
                      style="position: absolute;left: -10px;top:13px">
            <i class="el-tooltip el-icon-info"></i>
          </el-tooltip>

          <el-input v-model="msg.Name" class="inputM_l"/>
        </el-form-item>

        <el-form-item label="支付金额" class="is-required"  prop="Name">
          <el-tooltip class="item" effect="dark" content="用户支付多少就充值多少" placement="top"
                      style="position: absolute;left: -10px;top:13px">
            <i class="el-tooltip el-icon-info"></i>
          </el-tooltip>

          <el-input v-model="msg.Money" class="inputM_l" step="1"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"/>
        </el-form-item>

        <el-form-item label="赠送金额" >
          <el-tooltip class="item" effect="dark" content="用户充值时，赠送的金额，默认为0" placement="top"
                      style="position: absolute;left: -10px;top:13px">
            <i class="el-tooltip el-icon-info"></i>
          </el-tooltip>

          <el-input v-model="msg.GiveMoney" class="inputM_l" step="1"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"/>
        </el-form-item>

        <el-form-item label="赠送积分"  >
          <el-tooltip class="item" effect="dark" content="用户充值时，赠送的积分，默认为0" placement="top"
                      style="position: absolute;left: -10px;top:13px">
            <i class="el-tooltip el-icon-info"></i>
          </el-tooltip>

          <el-input v-model="msg.GiveIntegral" class="inputM_l" step="1"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"/>
        </el-form-item>
      </el-form>
    </div>
    <el-button type="primary" style="margin: 12px 0 " @click="preserve('msg')" :loading="loading">保存</el-button>
  </div>
</template>

<script>
    export default {
        name: "addRechargeScheme",
      data(){
          return{
            msg:{
              Name:'',
              Money:'',
              GiveMoney:'',
              GiveIntegral:'',
            },
            loading:false,
            rules:{
              Name: [
                {required: true, message: "充值名称不能为空", trigger: "blur"}
              ],
              Money: [
                {required: true, message: "支付金额不能为空", trigger: "blur"}
              ],
            }
          }
      },
      created(){
        if(this.$route.query.ID){
          this.getRechargeRules(this.$route.query.ID)
        }
      },
      methods:{
        getRechargeRules(ID){
          this.apipost("/api/Recharge/GetRechargeRules",{'ID':ID} , res => {
            if (res.data.resultCode == 1) {
              this.msg =res.data.data
            } else {
              this.Info(res.data.message);
            }
          })
        },
        cancel(){
          this.$router.go(-1)
        },
        preserve(formName){

          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.msg.Money =parseInt(this.msg.Money)
              if(this.msg.GiveMoney!=''){
                this.msg.GiveMoney =parseInt(this.msg.GiveMoney)
              }else {
                this.msg.GiveMoney=0
              }
              if(this.msg.GiveIntegral!=''){
                this.msg.GiveIntegral =parseInt(this.msg.GiveIntegral)
              }else {
                this.msg.GiveIntegral=0

              }
              this.loading = true
              this.apipost("/api/Recharge/AddOrUpdateRechargeRules",this.msg , res => {
                this.loading = false

                if (res.data.resultCode == 1) {
                  this.Success(res.data.message);
                  this.$router.go(-1);//返回上一层
                } else {
                  this.Info(res.data.message);
                }
              })
            } else {
              return false;
            }
          });
        }
      }
    }
</script>

<style scoped>
  .addRechargeScheme .form-box{
    padding: 20px 0;
    background-color: #fff;
    margin-bottom: 20px;
    padding-right: 50%;
  }
  .addRechargeScheme .el-input__inner{
    height: 32px;
    line-height: 32px
  }
  .addRechargeScheme .inputM_l{
    margin-left: 10px;
  }
</style>
