index.vue 2.39 KB
<template>
    <GLDialog mode="mid" :close-on-click-modal="false" title="创建封面" :visible.sync="visible" :before-close="onCancel" @onOk="onOk" @onCancel="onCancel">
        <glsx-combi-form class="glsx-combi-form" ref="detailRef" labelWidth="154px" defaultWidth="432px" :isInline="false" :formObj.sync="detailFormObj" :formData="detailFormData" :formRules="detailRules">
            <div slot="coverSlot">
            <Upload  tip="建议尺寸:最大5M,176*120px" :formObj="detailFormObj" btnName="上传封面" attr="url"></Upload>
            </div>
        </glsx-combi-form>
    </GLDialog>
</template>
<script>
import Upload from '@/components/Upload'
import glsxCombiForm from '@/components/glsx-combi-form'
export default {
    name: 'AddVideo',
    components: {
        glsxCombiForm,
        Upload
    },
    props: {
        visible: {
            type: Boolean,
            default: false
        },
        formObj: {
            type: Object,
            default: ()=>{
                return {
                    title: '',
                    url: ''
                }
            }
        }
    },
    data(){
        return {
            detailFormObj: {
                title: '',
                url: ''
            },
            detailFormData: [
                {
                    label: '产品名称',
                    name: 'title',
                    type: 'input',
                    maxlength: 12,
                    showLimit: true
                },
                {
                    label: '产品封面',
                    name: 'url',
                    addHtml: 'coverSlot'
                }
            ],
            detailRules: {
                title: [{ required: true, message: '请输入产品名称', trigger: 'change' }],
                url: [{ required: true, message: '请上传产品封面', trigger: 'change' }]
            },
        }
    },
    created(){
        const {title, url } = this.formObj 
        this.detailFormObj = { title, url } 
    },
    methods: {
        onCancel(){
            this.$emit('closeDialog')
        },
        onOk() {
            this.$refs.detailRef.$refs.formRef.validate(valid => {
                if(valid){
                    const { title, url} = this.detailFormObj
                    this.$emit('confirmDialog',{ title, url })
                }
            })
        },
    }
}
</script>
<style lang="scss" scoped>
</style>