<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-form ref="form" :model="form" label-width="250px" class="form-page">
        <template v-for="item in configData">
          <div class="hr-tip" v-if="item.SORT==='1'"><span>会员相关</span></div>
          <div class="hr-tip" v-if="item.SORT==='13'"><span>前台相关</span></div>
          <div class="hr-tip" v-if="item.SORT==='16'"><span>提现相关</span></div>
          <div class="hr-tip" v-if="item.SORT==='41'"><span>其他</span></div>
          <el-form-item :label="item.TITLE" :key="item.CONFIG_NAME">
            <template v-if="(item.INPUT_TYPE).toString()==='2'">
              <el-select v-model="item.VALUE" placeholder="请选择">
                <el-option v-for="optionItem in item.OPTIONS" :label="optionItem.label" :value="optionItem.value"
                           :key="optionItem.label"></el-option>
              </el-select>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='3'">
              <el-checkbox-group v-model="item.VALUE">
                <el-checkbox v-for="optionItem in item.OPTIONS" :label="optionItem.label" :value="optionItem.value"
                             :key="optionItem.label"></el-checkbox>
              </el-checkbox-group>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='4'">
              <el-date-picker v-model="item.VALUE" type="year" placeholder="选择年">
              </el-date-picker>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='5'">
              <el-date-picker
                v-model="item.VALUE"
                type="datetime"
                placeholder="Select date">
              </el-date-picker>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='6'">
              <el-date-picker
                v-model="item.VALUE"
                type="date"
                placeholder="Select date">
              </el-date-picker>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='7'">
              <el-time-select v-model="item.VALUE"
                              :picker-options="{start: item.OPTIONS.start, end: item.OPTIONS.end, step: item.OPTIONS.step}"
                              placeholder="选择时间">
              </el-time-select>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='8'">
              <el-switch v-model="item.VALUE">
              </el-switch>
            </template>
            <template v-else-if="(item.INPUT_TYPE).toString()==='9'">
              <el-input
                        type="textarea"
                        :rows="4"
                        placeholder="请输入内容"
                        v-model="item.VALUE">
              </el-input>
            </template>
            <template v-else>
              <el-input v-model="item.VALUE" placeholder="请输入内容">
                <template v-if="!!item.UNIT" slot="append">{{item.UNIT}}</template>
              </el-input>
            </template>
          </el-form-item>
        </template>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">更新</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import network from './../../utils/network'

export default {
  name: 'config_other',
  mounted () {
    this.getData()
  },
  data () {
    return {
      loading: true,
      submitButtonStat: false,
      configData: null,
    }
  },
  computed: {
    form: function () {
      let result = {}
      for (let i in this.configData) {
        result[i] = this.configData[i].VALUE
      }
      return result
    }
  },
  methods: {
    onSubmit () {
      this.submitButtonStat = true
      network.postData('config/other', this.form).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
        this.submitButtonStat = false
        this.getData()
      }).catch(response => {
        this.submitButtonStat = false
        this.getData()
      })
    },
    getData () {
      network.getData('config/other').then(response => {
        this.configData = response
        this.loading = false
      })
    },
  }
}
</script>

<style scoped>
  .hr-tip {
    font-size: 12px;
    position: relative;
    text-align: center;
    height: 30px;
    line-height: 30px;
    color: #999;
    margin-bottom: 20px;
  }

  .hr-tip:before {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    top: 14px;
    border-bottom: 1px dashed #ddd;
    height: 1px;
  }

  .hr-tip span {
    display: inline-block;
    background: #fff;
    position: relative;
    padding: 0 10px;
  }
</style>
