<template>
<div>

  <el-form ref="newTaskForm"  @submit.native.prevent style="padding-top:30px;">
    <el-form-item v-for="(val,index) in config_list" :key="index" v-if="val.type=='checkbox'" :label="val.label" label-width="100px">

  <el-checkbox-group v-model="val.value">
    <el-checkbox v-for="item in val.list" :label="item.key" :key="item.key">{{item.name}}</el-checkbox>
  </el-checkbox-group>

  </el-form-item>


    <el-form-item v-for="(item, index) in config_list" :key="index" v-if="item.type == 'text'" :label="item.label" label-width="100px">
      <el-input v-model="item.value" :value="config_list[index].value" auto-complete="off"></el-input>
    </el-form-item>

    <el-form-item v-for="(item, index) in config_list" :key="index" v-if="item.type == 'number'" :label="item.label" label-width="100px">


      <el-tooltip class="item" effect="dark" :content="item.remark" v-show="item.remark != ''" placement="right">
      <el-input-number size="medium" v-model="item.value"></el-input-number>
      </el-tooltip>

      <el-input-number v-show="item.remark == ''" size="medium" v-model="item.value"></el-input-number>

    </el-form-item>




    <el-form-item label-width="100px" style="padding-top:15px;">
      <el-button type="primary" :loading="send_site_info_loading" @click="send_site_setting">保存设置</el-button>
      <el-button @click="send_site_setting_default" :loading="send_site_info_default_loading">恢复默认</el-button>
    </el-form-item>

  </el-form>





  </div>





</template>

<script>
  import qs from 'qs'
  export default {
    data() {
      console.log(this.$store.getters.system_setting)
      return {
        config_list:[],
        send_site_info_loading:false,
        send_site_info_default_loading:false,
      };
    },
    methods: {
      loadSetting(){
        let self = this
        this.$http('/integral.php/ajax_request_common/get_site_setting', {
        }).then((ret) => {
          if(ret.status == '200'){
            let data = ret.data.data
            self.config_list = data
            console.log(data)
          }
        })
      },

      send_site_setting_default(){
        let self = this
        self.send_site_info_default_loading = true
        this.$http('/integral.php/ajax_request_common/set_site_setting_default', {
        }).then((ret) => {
          if(ret.status == '200'){
            let data = ret.data.data
            self.config_list = data
            self.send_site_info_default_loading = false
          }
        })
      },

      send_site_setting(){
        var form = this.$refs['newTaskForm']
        var self = this
        self.send_site_info_loading = true
        if (true) {
          if (form) {
            self.$http('post','/integral.php/ajax_request_common/set_site_setting',qs.stringify({row:self.config_list}),
              // headers: {
              //   'Content-Type': 'application/x-www-form-urlencoded'
              // }
            ).then((ret)=>{

              self.send_site_info_loading = false

              if(ret.status != '200'){
                self.$message({
                  message: '网络错误',
                  type: 'error'
                })
              }else{
                if(ret.data.code == 1){

                  form.clearValidate()

                  self.$message({
                    message: ret.data.msg,
                    type: 'success'
                  })
                }else{
                  self.$message({
                    message: ret.data.msg,
                    type: 'error'
                  })
                }
              }


            })
          }
        } else {
          return false
        }
      }
    },
    created(){
      this.loadSetting()
    }
  };
</script>
