index.vue 11.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 tip="建议尺寸:最大5M" :formObj="formObj" btnName="上传海报" attr="prodImg"></Upload>
            </div>
            <div slot="linkConfigSlot">
                <el-switch v-model="formObj.isLink" active-value="1" inactive-value="2"  active-color="#5850FF"  inactive-color="#E8E8EA"></el-switch>
                <div class="link-tip"> 默认链接内容为特色产品中第一个产品内容详情</div>
            </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: '',
                prodImg: '',
                isLink: '2',
            },
            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',
                    isHide: false,
                    type: 'input',
                    maxlength: 8,
                    showLimit: true
                },
                {
                    label: '海报图片',
                    name: 'prodImg',
                    isHide: false,
                    addHtml: 'mainVideoSlot'
                },
                {
                    label: '是否配置链接',
                    isHide: true,
                    name: 'isLink',
                    addHtml: 'linkConfigSlot'
                }
            ],
            rules: {
                isLink: [{required: true, validator: (rule, value, callback) => {return callback() }, trigger: 'change'}],
                proName: [{ 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'
                    }
                ],
                prodImg: [
                    {
                        required: true,
                        validator: (rule, value, callback) => {
                            if (!this.formObj.prodImg) {
                                return callback(new Error('请上传海报图片'))
                            } else {
                                return callback()
                            }
                        },
                        trigger: 'change'
                    }
                ]
            },
            menuList: []
        }
    },
    computed: {
        title(){
            return `${this.formObj.id ? '编辑': '新增'}${this.formObj.type==5 ? 'banner' : '内容'}`
        },
        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 => {
                if(type==5){
                    item.isHide = !(item.name == 'isLink' || item.name == 'prodImg')
                    if(item.name == 'prodImg') item.label == 'banner'
                }else{
                    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(){
            this.contentObj.imageDialogVisible = false
            // this.$emit('closeVideoDialog')
        },
        async getContentDetail(){
            this.$apis.discover.getContentDetailApi({id: this.contentObj.id}).then(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))
                    if(!this.contentObj.id) delete params.id
                    if(this.contentObj.type==3){
                        params.subMenuId = this.contentObj.thirdMenuId || this.contentObj.secondaryMenuId
                        delete params.isLink
                    }else{
                        params.subMenuId = this.contentObj.secondaryMenuId
                        delete params.proName
                    }
                    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;
        }
    }
}
.link-tip{
    height: 17px;
    line-height: 17px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    font-size: 12px;
    color: #999999;
}
</style>