<template>
  <div style="padding-top: 15px">
    <!-- <x-button type="primary" @click.native="handleUploadImage">上传图片</x-button> -->
    <!-- <group label-width="5em" title="图片列表">
      <cell primary="content" :title="`图片${index}`" v-for="(item, index) of fileList" :key="`image_${index}`">
        {{ item.objectKey }}
        <a href="javascript:" @click="handleDeleteImage(item.objectKey, index)">删除</a>
      </cell>
    </group> -->
    <upload-image :img-list="fileList" :able-delete="true" :oss-base-config="ossBaseConfig" @upLoadSucc="upLoadSuccEmit" @deleteImageSucc="deleteImageSuccEmit"></upload-image>
  </div>
</template>

<script>
import { XButton, Group, Cell } from 'vux'
import ossHandle from '@/assets/ossHandle'
import UploadImage from '@/common/uploadImage/UploadImage'
export default {
    name: 'OssText',
    components: {
        XButton,
        Group,
        Cell,
        UploadImage
    },
    data () {
        return {
            fileList: [],
            currentImageIndex: 0,
            ossBaseConfig: {
                limit: 9,
                ossCof: {
                    endpoint: 'oss-cn-shenzhen.aliyuncs.com',
                    bucket: 'vschool-solution',
                    region: 'oss-cn-shenzhen.aliyuncs.com'
                },
                filePath: '10086/TestUpload',
                sourceType: 2
            },
            fileDomain: ''
        }
    },
    methods: {
    // 上传图片
        handleUploadImage () {
            ossHandle.businessParams.limit = 3
            setTimeout(() => {
                ossHandle.getWxConfig(this.upLoadSucc)
            }, 0)
        },
        upLoadSucc (obj) {
            this.fileList.push(obj)
        },
        // 删除图片
        handleDeleteImage (objectKey, index) {
            this.currentImageIndex = index
            ossHandle.handleDelete(this.handleDeleteImageSucc, objectKey)
        },
        handleDeleteImageSucc () {
            let index = this.currentImageIndex
            this.fileList.splice(index, 1)
        },

        // 组件部分使用
        upLoadSuccEmit (obj) {
            this.fileList.push(obj)
        },
        deleteImageSuccEmit (index) {
            this.fileList.splice(index, 1)
        }
    }
}
</script>

<style></style>
