<template>
  <div class="distribution-recruit-set gray-box top-redius border-bottom-gray">
    <div class="title">{{$t('user.pointsFreezingSetting')}}</div>
    <el-form
      ref="dataForm"
      label-width="180px"
      size="mini"
      class="set-form"
      label-position="left"
      :rules="dataRule"
      :model="dataForm"
    >
      <el-form-item
        label="积分释放时间"
        style="width:440px"
        prop="scoreReleaseTime"
      >
        <el-time-select
          v-model="dataForm.scoreReleaseTime"
          format="HH:mm:ss"
          value-format="HH:mm:ss"
          :picker-options="{
            format: 'HH:mm',
            start: '00:00',
            step: '00:30',
            end: '23:30'
          }"
          placeholder="请选择每天积分释放时间">
        </el-time-select>
      </el-form-item>
      <!--<el-form-item
        label="积分释放周期T+"
        style="width:440px"
        prop="scoreReleaseCycle"
        v-if="dataForm.scoreReleaseCycle"
      >
        <el-input v-model="dataForm.scoreReleaseCycle" @change="setShopGetScore">
          <template slot="append">{{$t('coupon.yuan')}}{{$t('user.getOneGrowth')}}</template>
        </el-input>
      </el-form-item>-->
      <el-form-item label="积分释放周期T+" style="width:440px" prop="scoreReleaseCycle">
        <el-input-number autosize v-model="dataForm.scoreReleaseCycle" width="330" :min="1" :max="100" @change="cycleChange"></el-input-number>（至少大于1）
      </el-form-item>

      <el-form-item
        label="积分释放初始比例（%）"
        prop="scoreReleaseFirstPercent"
      >
        <el-input-number
          v-model="dataForm.scoreReleaseFirstPercent"
          controls-position="right"
          :min="1"
          :step="1"
          :max="100"
          size="small"
          type="number"
        ></el-input-number>
      </el-form-item>

      <el-form-item
        label="最小可释放积分"
        prop="scoreReleaseMin"
      >
        <el-input-number
          v-model="dataForm.scoreReleaseMin"
          controls-position="right"
          :min="1"
          :step="1"
          :max="100"
          size="small"
          type="number"
        ></el-input-number>
      </el-form-item>


      <el-descriptions title="普通会员释放比例" :column="2" :border="true">
        <el-descriptions-item v-for="item in ordinaryLevel" :key="item.id" :label="item.levelName + '(%)'">
          <el-input-number
            v-model="dataForm['levelId_'+item.id]"
            controls-position="right"
            :min="1"
            :step="1"
            :max="100"
            size="small"
            type="number"
          ></el-input-number>
        </el-descriptions-item>
      </el-descriptions>

      <el-descriptions title="付费会员释放比例" :column="2" :border="true">
        <el-descriptions-item v-for="item in vipLevel" :key="item.id" :label="item.levelName + '(%)'">
          <el-input-number
            v-model="dataForm['levelId_'+item.id]"
            controls-position="right"
            :min="1"
            :step="1"
            :max="100"
            size="small"
            type="number"
          ></el-input-number>
        </el-descriptions-item>
      </el-descriptions>



    </el-form>
    <div class="default-btn" @click="dataFormSubmit()">{{$t('sysManagement.save')}}</div>
  </div>
</template>

<script>
import TinyMce from '@/components/tiny-mce'

export default {
  components: {
    TinyMce
  },
  created () {
    this.getData()
    this.getUserLevel()
  },
  methods: {
    getUserLevel () {
      this.$http({
        url: this.$http.adornUrl('/user/userLevel/list'),
        method: 'get',
        params: this.$http.adornParams({
          userLevelType: 0
        })
      }).then(({ data }) => {
        this.ordinaryLevel = data
      })
      this.$http({
        url: this.$http.adornUrl('/user/userLevel/list'),
        method: 'get',
        params: this.$http.adornParams({
          userLevelType: 1
        })
      }).then(({ data }) => {
        this.vipLevel = data
      })
    },
    cycleChange (e) {
      if (String(e).length > 8) this.dataForm.scoreReleaseCycle = 1
    },
    // 获取数据
    getData () {
      this.$nextTick(() => {
        this.$http({
          url: this.$http.adornUrl('/user/scoreRelease/info/' + 'SCORE_RELEASE'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({ data }) => {
          if (data != null && data !== '') {
            this.dataForm = data
          }
        })
        this.$refs['dataForm'].resetFields()
      })
    },
    // 设置数据
    setDate (data) {
      this.dataForm = data
    },
    // 提交表单
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/user/scoreRelease/`),
            method: 'post',
            // data: this.$http.adornData({paramsValue: JSON.stringify(this.dataForm)})
            data: this.$http.adornParams({paramsValue: JSON.stringify(this.dataForm)})
          }).then(({ data }) => {
            this.getData()
            this.$message({
              message: this.$i18n.t('publics.operation'),
              type: 'success',
              duration: 1500
            })
          }).catch(() => {

          })
        }
      })
    }
  },
  data () {
    return {
      ordinaryLevel: [],
      vipLevel: [],
      addOrUpdateVisible: false,
      dataForm: {
        expireYear: 1,
        scoreReleaseMin: 1,
        scoreReleaseCycle: 1,
        scoreReleaseFirstPercent: 1,
        scoreReleaseTime: ''
      },
      dataRule: {
        expireYear: [
          { required: true, message: this.$i18n.t('publics.enterExpiration'), trigger: 'brue' }
        ]
      }
    }
  }
}
</script>
<style lang="scss">
.distribution-withdraw-cash-set {
  .input-tips {
    font-size: 12px;
  }
}
</style>
