index.vue 12.2 KB
<template>
    <GLDialog mode="mid" :close-on-click-modal="false" :title="title" :visible.sync="visible" @onOk="onOk" :before-close="onCancel" @onCancel="onCancel">
        <glsx-combi-form class="glsx-combi-form" ref="videoRef" labelWidth="154px" defaultWidth="432px" :isInline="false" :formObj.sync="formObj" :formData="formData" :formRules="rules">
            <div slot="moduleSlot" class="radio-slot">
                <el-radio-group  @change="menuRadioChange('firstMenu')" v-model="contentObj.menuId">
                    <el-radio v-for="item in menuList" :key="item.id" :label="item.id">{{item.name}}</el-radio>
                </el-radio-group>
            </div>
            <div slot="attrSlot" class="radio-slot">
                <el-radio-group @change="menuRadioChange()" v-model="contentObj.secondaryMenuId">
                    <el-radio v-for="item in secondaryMenuList" :key="item.id" :label="item.id">{{item.name}}</el-radio>
                </el-radio-group>
            </div>
            <div slot="sceneSlot" class="radio-slot">
                <el-radio-group v-model="contentObj.thirdMenuId">
                    <el-radio v-for="item in thirdMenuList" :key="item.id" :label="item.id">{{item.name}}</el-radio>
                </el-radio-group>
            </div>
            <div slot="contentSlot" class="radio-slot">
                <el-radio-group v-model="formObj.type">
                    <el-radio :label="formObj.type">{{contentType[contentObj.type]}}</el-radio>
                </el-radio-group>
            </div>
            <div slot="businessSlot" class="global-menu">
                <span class="module">{{contentObj.menuName}}</span>
                <i class="el-icon-arrow-right arrow-right"></i>
                <span class="module">{{contentObj.secondaryMenuName}}</span>
                <i class="el-icon-arrow-right arrow-right"></i>
                <template v-if="contentObj.thirdMenuId">
                    <span class="module">{{contentObj.thirdMenuName}}</span>
                    <i class="el-icon-arrow-right arrow-right"></i>
                </template>
                <span class="module active">{{contentType[contentObj.type]}}</span>
            </div>
            <div slot="mainVideoSlot" class="main-video-slot">
                <Upload fileType="video" :formObj="formObj" btnName="上传视频" attr="vedioUrl" coverAttr="prodImg"></Upload>
                <Upload tip="建议尺寸:最大5M,138*84px" :formObj="formObj" btnName="上传视频封面" attr="prodImg"></Upload>
            </div>
            <div slot="viewSlot" class="view-slot">
                <el-input placeholder="请输入观看人数" v-model="formObj.view"  onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"  type="text"></el-input>
            </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
        },
        contentObj: {
            type: Object,
            default: ()=>{
                return {}
            }
        }
    },
    data(){
        return {
            contentType: {
                1: '特色产品',
                2: '案例视频',
                3: '营销海报',
                4: '操作指引'
            },
            detailVisible: false,
            formObj: {
                id: '',
                menuId: '',
                subMenuId: '',
                type: '',
                proName: '',
                title: '',
                vedioUrl: '',
                prodImg: '',
                view: ''
            },
            formData:[
                {                    
                    label: '业务模块',
                    name: 'module',
                    isHide: true,
                    addHtml: 'moduleSlot'
                },
                {
                    label: '业务属性',
                    name: 'zone',
                    isHide: true,
                    addHtml: 'attrSlot'
                },
                {
                    label: '场景细分',
                    name: 'scene',
                    isHide: true,
                    addHtml: 'sceneSlot'
                },
                {
                    label: '内容专区',
                    name: 'contZone',
                    isHide: true,
                    addHtml: 'contentSlot'
                },
                {
                    label: '业务模块',
                    name: 'business',
                    isHide: false,
                    addHtml: 'businessSlot'
                },
                {
                    label: '封面标题',
                    name: 'proName',
                    type: 'input',
                    maxlength: 30,
                    showLimit: true
                },
                {
                    label: '内容标题',
                    name: 'title',
                    type: 'input',
                    maxlength: 30,
                    showLimit: true
                },
                {
                    label: '主视频',
                    name: 'mainVideo',
                    addHtml: 'mainVideoSlot'
                },
                {
                    label: '观看人数',
                    name: 'view',
                    addHtml: 'viewSlot'
                },
            ],
            rules: {
                proName: [
                    {
                        required: true,
                        validator: (rule, value, callback) => {
                            if (!value) {
                                return callback(new Error('请输入封面标题'))
                            } else if(value.length>30) {
                                return callback(new Error('封面标题不能大于30个字'))
                            }else {
                                return callback()
                            }
                        },
                        trigger: 'change'
                    }
                ],
                title: [
                    {
                        required: true,
                        validator: (rule, value, callback) => {
                            if (!value) {
                                return callback(new Error('请输入内容标题'))
                            } else if(value.length>30) {
                                return callback(new Error('内容标题不能大于30个字'))
                            }else {
                                return callback()
                            }
                        },
                        trigger: 'change'
                    }
                ],
                view: [{ required: true, message: '请输入观看人数', trigger: 'change' }],
                business: [{required: true, validator: (rule, value, callback) => {return callback() }, trigger: 'change'}],
                module: [{required: true, validator: (rule, value, callback) => {return callback() }, trigger: 'change'}],
                zone: [{
                        required: true,
                        validator: (rule, value, callback) => {
                            if (!this.contentObj.secondaryMenuId) {
                                return callback(new Error('请选择业务属性'))
                            }else {
                                return callback()
                            }
                        },
                        trigger: 'change'
                    }
                ],
                contZone: [{required: true, validator: (rule, value, callback) => {return callback() }, trigger: 'change'}],
                scene: [
                    {
                        required: true,
                        validator: (rule, value, callback) => {
                            if (this.thirdMenuList.length && !this.contentObj.thirdMenuId) {
                                return callback(new Error('请选择场景细分'))
                            }else {
                                return callback()
                            }
                        },
                        trigger: 'change'
                    }
                ],
                mainVideo: [
                    {
                        required: true,
                        validator: (rule, value, callback) => {
                            if (!this.formObj.vedioUrl) {
                                return callback(new Error('请上传主视频'))
                            } else if(!this.formObj.prodImg) {
                                return callback(new Error('请上传视频封面'))
                            }else {
                                return callback()
                            }
                        },
                        trigger: 'change'
                    }
                ]
            },
            menuList: []
        }
    },
    computed: {
        title(){
            return `${this.formObj.id ? '编辑': '新增'}${this.contentObj.type==2 ? '案例视频' : '操作指引'}`
        },
        secondaryMenuList(){
            const target = this.menuList.find(item => item.id == this.contentObj.menuId)
            return target?.subList || []
        },
        thirdMenuList(){
            const target = this.secondaryMenuList.find(item => item.id == this.contentObj.secondaryMenuId)
            return target?.subList || []
        }
    },
    created() {
        const { secondaryMenuId ,thirdMenuId , type} = this.contentObj
        this.formObj =  {...this.formObj, subMenuId: thirdMenuId || secondaryMenuId, type}
        if(this.contentObj.id) {
            this.formData.forEach(item => {
                const hideItemList = ['module', 'zone', 'contZone', 'scene']
                if(hideItemList.includes(item.name)){
                    item.isHide = false
                }
                if(item.name=='business')  item.isHide = true
            });
            this.getMenuList()
        }
    },
    methods: {
        menuRadioChange(level){
            this.contentObj.thirdMenuId = ''
            if(level=='firstMenu') this.contentObj.secondaryMenuId = ''
        },
        getMenuList() {
            this.$apis.discover.getMenuListApi({}).then(res => {
                this.getContentDetail()
                if(res?.length){
                    this.menuList = res
                }
            })
        },
        closeDetailDialog(){
            this.detailVisible = false
        },
        onCancel(){
            console.log(this.contentObj)
            this.contentObj.videoDialogVisible = false
            // this.$emit('closeVideoDialog')
        },
        async getContentDetail(){
            this.$apis.discover.getContentDetailApi({id: this.contentObj.id}).then(res => {
                console.log(res)
                if(res?.id){
                    for(const key in this.formObj){
                        this.formObj[key] = res[key]
                    }
                }
            })
        },
        onOk() {
            console.log(this.formObj)
            this.$refs.videoRef.$refs.formRef.validate(valid => {
                if(valid) {
                    const params = JSON.parse(JSON.stringify(this.formObj))
                    params.subMenuId = this.contentObj.thirdMenuId || this.contentObj.secondaryMenuId
                    if(!this.contentObj.id) delete params.id
                    this.$apis.discover.addContentApi(params).then(res => {
                        if(res) {
                            this.$message.success('操作成功')
                            this.onCancel()
                            this.$parent.handleSearch();
                        }
                    })
                }
            })
        },
    }
}
</script>
<style lang="scss" scoped>
.main-video-slot{
    display: flex;
    /deep/ .upload-ctnr{
        margin-right: 8px;
    }
}

.radio-slot{
    /deep/ .el-radio{
        margin-right: 20px;
        line-height: 25px;
        .el-radio__label{
            width: 100px;
            display: inline-block;
        }
    }
}

.view-slot{
    /deep/ .el-input{
        width: 136px;
    }
}
</style>