<template>
  <div v-loading="loading" class="addActivity">
    <div class="head-title">
      <span @click="CommonJump('activityList')" 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="Title" class="is-required" size="small">
          <el-input v-model="addMsg.Title" placeholder="请输入标题" class="w400"/>
        </el-form-item>
        <el-form-item label="问卷调查份数" prop="SurveyNum" class="is-required" size="small">
          <el-input v-model="addMsg.SurveyNum" placeholder="请输入问卷调查份数" type="number" :min="0" class="w400"/>
        </el-form-item>
        <el-form-item label="活动时间" class="is-required">
          <el-date-picker v-model="dateList"  size="small" type="datetimerange"
                          range-separator="至" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领奖方式" size="small" class="is-required">
          <el-radio-group v-model="addMsg.PrizeType">
            <el-radio :label="x.Id" v-for="(x,y) in platList" :key="y">{{x.Name}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="奖品地址" prop="PrizeAddress" class="is-required" size="small">
          <el-input v-model="addMsg.PrizeAddress" placeholder="请输入奖品地址" class="w400"/>
        </el-form-item>
        <el-form-item label="活动说明" prop="Description" class="is-required" size="small">
          <el-input v-model="addMsg.Description" placeholder="请输入奖品说明" type="textarea" class="w400"/>
        </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,
          Title:'',
          StartDate:'',
          EndDate:"",
          SurveyNum:0,
          Description:'',
          PrizeAddress:'',
          PrizeType:'0',

        },
        rules: {
          Title: [{
            required: true,
            message: '请输入标题',
            trigger: 'blur'
          }],
          SurveyNum: [{
            required: true,
            message: '请输入问卷调查份数',
            trigger: 'blur'
          }],
          Description: [{
            required: true,
            message: '请输入奖品说明',
            trigger: 'blur'
          }],
          PrizeAddress: [{
            required: true,
            message: '请输入奖品地址',
            trigger: 'blur'
          }],

        },
        platList:[],
        dateList:[],
        loading: false,
      };
    },
    created() {

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

    },
    methods: {
      Save(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.addMsg.PrizeType==0 ){
              this.Error('请选择奖品领取类型')
              return false
            }

            if (this.dateList && this.dateList.length > 0) {
              this.addMsg.StartDate = this.dateList[0];
              this.addMsg.EndDate = this.dateList[1];
            } else {
              this.Error('请选择活动时间')
              return false
            }

            this.apipost("/api/Survey/SetActivitySurvey", this.addMsg, res => {
              if (res.data.resultCode == 1) {
                this.CommonJump('activityList');
                this.Success(res.data.message);
              } else {
                this.Error(res.data.message);
              }
            })
          } else {
            return false;
          }
        });
      },
      GetPrizeTypeEnumList(){
        this.apipost("/api/Survey/GetPrizeTypeEnumList", {}, res => {
          if(res.data.resultCode==1){
            this.platList = res.data.data
          }else {
            this.Info(res.data.message);
          }

        })
      },




      getData(ID) {
        this.loading = true;
        this.apipost("/api/Survey/GetActivitySurvey", {
          ID: ID
        }, res => {
          this.loading = false;
          this.addMsg = res.data.data;
          this.addMsg.PrizeType = this.addMsg.PrizeType.toString()
          this.dateList = [this.addMsg.StartDate,this.addMsg.EndDate]
        })
      },


    },
    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;
  }



  .addActivity .blue {
    color: #409EFF;

  }

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

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

</style>
