<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="100px">
      
        <el-form-item label="藏品名称:" prop="collectionName">
          <el-input v-model="message.collectionName" style="width: 550px" 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="imageUrl" :src="imageUrl" class="avatar" />
          <i
            v-else
            class="el-icon-plus avatar-uploader-icon"
          ></i> </el-upload>
        </el-form-item> 

        <el-form-item label="3D模板:" prop="">
          <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"
          ></i> </el-upload>
        </el-form-item> 
        <el-form-item label="藏品价格:" prop="collectionPrice">
          <el-input v-model="message.collectionPrice" style="width: 550px" placeholder="请输入藏品价格"></el-input>
        </el-form-item> 
        <el-form-item label="藏品数量:" prop="collectionCount">
          <el-input v-model="message.collectionCount" style="width: 550px" placeholder="请输入藏品数量"></el-input>
        </el-form-item> 
        <el-form-item label="发行方:" prop="collectionPublisher">
          <el-input v-model="message.collectionPublisher" style="width: 550px" placeholder="请输入发行方"></el-input>
        </el-form-item> 
        
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
        <el-form-item label="藏品故事:" prop="collectionHistory">
            <el-upload
          action="#"
          list-type="picture-card"
          :auto-upload="false">
            <i slot="default" class="el-icon-plus"></i>
            <div slot="file" slot-scope="{file}">
              <img
                class="el-upload-list__item-thumbnail"
                :src="file.url" alt=""
              >
              <span class="el-upload-list__item-actions">
                <span
                  class="el-upload-list__item-preview"
                  @click="handlePictureCardPreview(file)"
                >
                  <i class="el-icon-zoom-in"></i>
                </span>
                <span
                  v-if="!disabled"
                  class="el-upload-list__item-delete"
                  @click="handleDownload(file)"
                >
                  <i class="el-icon-download"></i>
                </span>
                <span
                  v-if="!disabled"
                  class="el-upload-list__item-delete"
                  @click="handleRemove(file)"
                >
                  <i class="el-icon-delete"></i>
                </span>
              </span>
            </div>
        </el-upload>
          <label for="">点击查看</label>
        </el-form-item> 
        <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 {
        message: {
          collectionName:'',
          imageUrl: '',
          collectionPrice:'' , 
          collectionCount:'' ,
          collectionPublisher:'' , 
          collectionHistory:'',
        },
        rules:{
          collectionName: [
            { required: true, message: '请输入藏品名称', trigger: 'blur' }
          ],
          imageUrl: [
            { required: true, message: '请导入藏品图片', trigger: 'blur' }
          ],
          collectionPrice: [
            { required: true, message: '请输入藏品价格', trigger: 'blur' }
          ],
          collectionCount: [
            { required: true, message: '请输入藏品数量', trigger: 'blur' }
          ],
          collectionPublisher: [
            { required: true, message: '请输入发布人', trigger: 'blur' }
          ],
          collectionHistory: [
            { 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.collectionPrice);
        console.log( "-****" , this.message.collectionCount);
        console.log( "-****" , this.message.collectionPublisher);
        console.log( "-****" , this.message.collectionHistory);
        addCollection(this.collectionName) .then((res)=>{
          console.log(res);
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      // importForm(formName) {
        
      // }
    }
}
</script>

<style>
.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: 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>