<template>
  <div v-loading="loading" class="addpoint">
    <div class="head-title">
      <span @click="CommonJump('starsList')" class="blue point">星星数管理</span> / 编辑星星数管理
    </div>
    <div class="content">
      <el-form :model="addMsg" :rules="rules" ref="addMsg" label-width="150px" style="width:50%">
        <el-form-item label="充值名称" prop="GoodsName" class="is-required" size="small">
          <el-input v-model="addMsg.GoodsName" placeholder="请输入充值名称" class="w400"/>
        </el-form-item>
        <el-form-item label="售价" prop="SellingPrice" class="is-required" size="small">
          <el-input v-model="addMsg.SellingPrice" placeholder="请输入售价" class="w400" type="number" :min="0">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="星星数" prop="PonitNum" class="is-required" size="small">
          <el-input v-model="addMsg.PonitNum" placeholder="请输入星星数" class="w400" type="number" :min="0"/>
        </el-form-item>
        <el-form-item label="赠送星星数" prop="GivePoint" class="is-required" size="small">
          <el-input v-model="addMsg.GivePoint" placeholder="请输入赠送星星数" class="w400" type="number" :min="0"/>
        </el-form-item>
      </el-form>
    </div>
    <div style="margin-top:20px">
      <el-button size="small" type="primary" @click="Save('addMsg')">保存</el-button>
    </div>

  </div>

</template>
<script>


  export default {
    components: {

    },
    data() {
      return {
        addMsg: {
          ID: 0,
          GoodsName:'',
          PonitNum:0,
          GivePoint:0,
          SellingPrice:0,
        },
        rules: {
          GoodsName: [{
            required: true,
            message: '请输入充值名称',
            trigger: 'blur'
          }],
          PonitNum: [{
            required: true,
            message: '请输入星星数',
            trigger: 'blur'
          }],
          SellingPrice: [{
            required: true,
            message: '请输入售价',
            trigger: 'blur'
          }],
          GivePoint: [{
            required: true,
            message: '赠送星星数不能为空',
            trigger: 'blur'
          }],
        },
        loading: false,
      };
    },
    created() {

      if(this.$route.query.ID){
        this.getData(this.$route.query.ID)
      }


    },
    methods: {
      Save(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.addMsg.SellingPrice==0){
              this.Error('售价大于0')
              return false
            }
            if(this.addMsg.PonitNum==0){
              this.Error('星星数大于0')
              return false
            }
            this.apipost("/api/Point/SetPointGoods", this.addMsg, res => {
              if (res.data.resultCode == 1) {
                this.CommonJump('starsList');
                this.Success(res.data.message);
              } else {
                this.Error(res.data.message);
              }
            })
          } else {
            return false;
          }
        });
      },
      getData(ID) {
        this.loading = true;
        this.apipost("/api/Point/GetPointGoodsModel", {
          ID: ID
        }, res => {
          this.loading = false;
          var tempDate = res.data.data;
          this.addMsg.ID = tempDate.ID;
          this.addMsg.GoodsName = tempDate.GoodsName;
          this.addMsg.PonitNum = tempDate.PonitNum;
          this.addMsg.GivePoint = tempDate.GivePoint;
          this.addMsg.SellingPrice = tempDate.SellingPrice;
        })
      },
    },
    mounted() {
    }
  };
</script>
<style>
  .app-add-cat .el-checkbox-group {
    font-size: 14px !important;
  }

  .app-add-cat .el-checkbox {
    margin-right: 0;
  }

  .app-add-cat .el-dialog__body {
    padding: 10px 20px !important;
  }

  .app-add-cat .tag-box .tag-item {
    margin-right: 5px;
  }

  .app-add-cat .tag-box {
    margin: 20px 0;
  }

  .app-add-cat .app-goods-cat-list .active {
    background: #FAFAFA;
  }

  .app-add-cat .app-goods-cat-list .cat-item {
    cursor: pointer;
    padding: 5px 10px;
  }

  .app-add-cat .app-goods-cat-list {
    border: 1px solid #E8EAEE;
    border-radius: 5px;
    margin-top: -5px;
    padding: 10px 0;
    overflow: scroll;
    height: 400px;
  }



  .addpoint .blue {
    color: #409EFF;

  }

  .addpoint .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }
  .addpoint .gez_list{
    /*width: 650px;*/
    margin-bottom: 12px;
    padding: 20px;
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;

  }
  .addpoint .quyu{
    background-color: #f4f4f5;
    color: #909399;
    padding: 10px;
    line-height: 30px;
    height: 30px;
    font-size: 12px;
    border-radius: 4px;
    white-space: nowrap;
    margin: 5px;
  }
  .addpoint .el-tag + .el-tag {
    margin-left: 10px;
  }
  .addpoint .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .addpoint .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }

</style>
