<template>
  <div class="message-add" :style="{height:height,width:width}"  >
    
    <!-- <el-page-header @back="goBack" content="创建消息"></el-page-header> -->
    <div class="message-add-box">
      <el-form :model="message" :rules="rules" ref="form" label-width="125px">
      
        <el-form-item label="藏品名称（套）:" prop="collectionName" style="width: 550px">
          <el-input v-model="message.collectionName" maxlength="20"
          show-word-limit placeholder="请输入藏品名称"></el-input>
        </el-form-item> 
        <el-form-item label="藏品头图:" prop="imageUrl">
          <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="message.imageUrl" :src="message.imageUrl" class="avatar" />
          <i
            v-else
            class="el-icon-plus avatar-uploader-icon"
          ></i> </el-upload>
        </el-form-item> 

        <div class="down">
            <div>
            <span class="demonstration">设置套系时间 ：</span>
            <el-date-picker
              v-model="value2"
              type="datetimerange"
              align="right"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['12:00:00', '08:00:00']">
            </el-date-picker>
          </div>

          <span class="demonstration">线下礼品兑换 ：</span>
            <el-radio v-model="radio" label="1">可兑换</el-radio>
            <el-radio v-model="radio" label="2">不可兑换</el-radio>
        </div>
        <el-form-item>
          <el-button type="primary" @click="addCollection('form')">提交</el-button>
          <!-- <el-button @click="resetForm('form')">重置</el-button>
          <el-button @click="importForm('form')">导入</el-button> -->
        </el-form-item>
      </el-form>
    </div>     
  </div>
</template>

<script>
import {addCollection} from '../../api/collection/collection.js'

 export default {
  
    data() {
      return {
        radio: '1',
        value2: '',
        message: {
          collectionName:'',
          imageUrl: '',
          collectionTime:'' , 
        },
        rules:{
          collectionName: [
            { required: true, message: '请输入藏品名称', trigger: 'blur' }
          ],
          imageUrl: [
            { required: true, message: '请按照规范上传尺寸为750px*750px的图片', trigger: 'blur' }
          ],
          collectionTime: [
            { required: true, message: '请输入套系时间', trigger: 'blur' }
          ],
        }
    }
  },
  mounted() {
    
  },
  methods: {
        handleAvatarSuccess(res, file) {
          this.imageUrl = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      addCollection() { 
        console.log( "-****" , this.message.collectionName);
        console.log( "-****" , this.message.imageUrl);
        console.log( "-****" , this.message.collectionTime);
        console.log( "-****" , this.radio);
        console.log( "-****" , this.value2);
        
        addCollection(this.collectionName) .then((res)=>{
          console.log(res);
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
    }
}
</script>

<style>
.down{
  margin-left: 15px;
}
.demonstration{
    text-align: right;
    vertical-align: middle;
    font-size: 14px;
    color: #606266;
    line-height: 40px;
    padding: 0 12px 0 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    text-align: right;
    vertical-align: middle;
    font-size: 14px;
    color: #606266;
    line-height: 40px;
    padding: 0 12px 0 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    font-weight: 700;
}
.el-icon-plus{
  margin-top: 85px;
}
.avatar-uploader .el-upload {
    width: 370px; 
    height: 370px;
    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: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
.message-add-box{
  width: 60%;
  height: 100%;
  margin: 50px auto;
  border: 1px solid #ccc;
  padding-top: 40px;
  padding-left: 100px;
  padding-right: 30px;
}

/* .users-input-box{
  color:aqua;
} */

.quill-editor /deep/ .ql-container {
    min-height: 220px;
  }

  .ql-container {
    min-height: 230px;
  }

.ql-toolbar.ql-snow {
  border: 1px solid #ccc;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  padding: 8px;
  width: 450px;
}
.ql-toolbar.ql-snow + .ql-container.ql-snow {
    border-top: 0px;
    width: 450px;
}
</style>