<template>
  <div>
    <Dec :content="content" />

    <div class="setdata">
      <div class="setlv">
        <span style="float:left;line-height:65px;">成绩等级设置：</span>
        <Slider :data="data" width="600" style="margin-left:120px" bgcolor="#56c68d" @change="change" />
        <p class="dec">请按正确率划分成绩等级区间</p>
      </div>
      <div class="setinfo">
        <span style="float:left;">自定义配置：</span>
        <div class="viewbox" style="margin-left:120px;overflow:hidden">
          <div class="infobox" style="float:left;">
            <p>云平台显示名字</p>
            <el-input
              v-model="text"
              type="text"
              placeholder="请输入内容"
              maxlength="10"
              style="width:210px"
              show-word-limit
            />
            <p>云平台主页logo布局</p>
            <el-switch
              v-model="layoutSwitch"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="switchChange"
            />
            <p>上传LOGO</p>
            <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <p>图片规格：100*100 </p>
            <p>文件大小：小于200K</p>

          </div>
          <div class="pcview" style="float:left;margin:0 20px">
            <div class="login-pc">
              <img :src="require('@/assets/images/logo.png')" class="login-logo" alt="">
              <div class="login-title">{{ text }}</div>
            </div>
            <h2 class="viewtitle">云平台</h2>
          </div>
          <div class="nativeview" style="float:left;">
            <div class="login-pc">
              <img :src="require('@/assets/images/logo.png')" class="login-logo" alt="">
              <div class="login-title">{{ text }}</div>
            </div>
            <h2 class="viewtitle">客户端</h2>
          </div>
        </div>
      </div>
      <div class="testtip" style="overflow:hidden;margin-top:20px;">
        <span style="float:left;line-height:40px;">考试提示语：</span>
        <div class="inputtip" style="float:left;">
          <el-input
            v-model="text"
            type="text"
            placeholder="请输入内容"
            maxlength="15"
            style="width:310px"
            show-word-limit
          />
        </div>
        <div class="tipview" style="float:left;margin-left:20px;">
          <div class="login-pc">
            <img :src="require('@/assets/images/logo.png')" class="login-logo" alt="">
            <div class="login-title">{{ text }}</div>
          </div>
        </div>
      </div>
      <el-button type="primary" style="display:block;margin:0 auto;margin-top:40px;">保存</el-button>
    </div>
  </div>
</template>
<script>

import { getLogoLayout } from '@/utils/auth'
import Dec from '@/components/Dec'
import Slider from './complate/slider'
export default {
  name: 'Setdata',
  components: {
    Dec,
    Slider
  },
  data() {
    return {
      content: '',
      layoutSwitch: getLogoLayout() === 'topBottom',
      text: '',
      data: [
        {
          name: '不合格',
          color: '#374c41',
          bl: '50%'
        },
        {
          name: '合格',
          color: '#3c8574',
          bl: '70%'
        },
        {
          name: '良好',
          color: '#45a472',
          bl: '80%'
        }
      ],

      imageUrl: ''
    }
  },
  methods: {
    switchChange() {
      if (this.layoutSwitch) {
        this.$store.commit('user/SET_LOGOLAYOUT', 'topBottom')
      } else {
        this.$store.commit('user/SET_LOGOLAYOUT', 'leftRight')
      }
    },
    change(data) {
      this.data = data
    },

    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw)
    },
    beforeAvatarUpload(file) {
      const isSize = new Promise(function(resolve, reject) {
        const width = 100
        const height = 100
        const _URL = window.URL || window.webkitURL
        const img = new Image()
        img.onload = function() {
          const valid = img.width <= width && img.height <= height
          valid ? resolve() : reject()
        }
        img.src = _URL.createObjectURL(file)
      }).then(() => {
        return file
      }, () => {
        this.$message.error('上传的icon必须是等于或大于100*100!')
        return Promise.reject()
      })
      return isSize
    }

  }
}
</script>
<style >
.setdata{
    max-width: 1100px;
    height: calc(100% - 65px);
    background: #fff;
    margin:0 auto;
    padding:20px;
    margin-top:15px;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
  }
  .avatar {
    width: 100px;
    height: 100px;
    display: block;
  }
  .login-pc{
    width:590px;
    height:800px;
    overflow: hidden;
    background: url("../../../assets/images/login.jpg") no-repeat;
    background-size:cover;
    zoom:0.5;
  }
  .login-pc .login-logo{
    width:140px;
    display: block;
    margin: 0 auto;
    margin-top:48px;
  }
  .login-pc .login-title{
    font-size: 24px;
    color:#000;
    font-weight:bold;
    text-align: center;
    margin-top:190px;
  }
  .setlv{
    overflow: hidden;
  }
  .setlv .dec{
    font-size: 12px;
    color:#bbb
  }
  .viewtitle{
    text-align: center
  }

</style>
