index.vue 9.34 KB
<!-- 秒杀活动 -->
<template>
    <div class="ctnr">
      <div class="menu-wrap">
        <Menu ref="menuRef" class="menu"></Menu>
      </div>
        <div class="list">
          <GLCombiForm class="search-wrap" ref="searchRef" labelWidth="154px" defaultWidth="432px" @handleOk="handleSearch" @handleRest="handleReset" :formObj="searchFormObj" :formData="searchFormData">
          </GLCombiForm>
          <div class="operate-wrap">
              <span class="table-title">内容列表</span>
              <div class="operate-btn">
                <el-button :size="size" type="primary">新增<i class="el-icon-arrow-down arrow-icon"></i></el-button>
                <div class="dropdown-wrap">
                  <ul>
                    <li class="dropdown-item" @click="addContent(item)" v-for="item in contentTypeList" :key="item.id">{{ item.name }}</li>
                  </ul>
                </div>
              </div>           
          </div>
          <GLTable  @setTableFinishFun="setTableFinishFun" ref="tableRef" :pageConf="pageConf" :searchForm="searchObj" :tableParams="tableParams" :getListApi="getListApi" :beforeSearchFn="beforeSearchFn">
            <div slot="coverImageSlot" slot-scope="scope">
              <el-image 
                class="cover-img"
                :src="scope.scope.prodImg" 
                :preview-src-list="[scope.scope.prodImg]">
              </el-image>
            </div>  
            <div slot="auth-button" slot-scope="scope">
                <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
            </div>
          </GLTable>
        </div>
        <AddImage  v-if="contentObj.imageDialogVisible" :contentObj="contentObj"  :visible="contentObj.imageDialogVisible"></AddImage>
        <AddVideo  v-if="contentObj.videoDialogVisible" :contentObj="contentObj"  :visible="contentObj.videoDialogVisible"></AddVideo>
    </div>
</template>
  
<script>
const CONTENT_LIST = [
    {
      id: '1',
      name: '特色方案'
    },
    {
      id: '2',
      name: '案例视频'
    },
    {
      id: '3',
      name: '营销海报'
    },
    {
      id: '4',
      name: '操作指引'
    },
    {
      id: '5',
      name: 'banner'
    }
  ]
import Menu from './components/Menu'
import AddVideo from './components/AddVideo'
import AddImage from './components/AddImage'

export default {
    name: 'discover',
    components: {
      Menu,
      AddVideo,
      AddImage
    },
    data() {
      return {
        contentObj: {
          imageDialogVisible: false,
          videoDialogVisible: false,
          type: ''
        },
        contentTypeList: CONTENT_LIST.slice(0, 4),
        operateList:[
          {
            name: '新增子集'
          },
          {
            name: '重命名'
          }
        ],
        getListApi: this.$apis.discover.getListApi,
        pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
        searchFormObj: {
          type: '',
          status: '',
          subMenuId: '4'
        },
        searchObj: {},
        searchFormData: [
            {
                label: '所属内容专区',
                name: 'type',
                type: 'select',
                optionList: [{id: '',name: '全部'}, ...CONTENT_LIST],
                optionId: 'id',
                optionLabel: 'name',
                isClear: true
            },
            {
                label: '状态',
                name: 'status',
                type: 'select',
                optionList: [
                  {
                    id: '',
                    name: '全部'
                  },
                  {
                    id: '1',
                    name: '已上架'
                  },
                  {
                    id: '2',
                    name: '已下架'
                  }
                ],
                optionId: 'id',
                optionLabel: 'name',
                isClear: true
            },
        ],
        buttonList: [
          {
            type: 'el-button',
            name: '编辑',
            attrs: {
              type: 'text',
              fn: '编辑'
            },
            listeners: {
              click: row => this.addContent(row.scope, 1)
            }
          },
          {
            type: 'el-button',
            name: '上架',
            attrs: {
              type: 'text',
              fn: '上架'
            },
            condition: row => {
              return row.scope.type != 5 && row.scope.status != 1
            },
            listeners: {
              click: row => this.updateStatus(row.scope.id, 1)
            }
          },
          {
            type: 'el-button',
            name: '下架',
            attrs: {
              type: 'text',
              fn: '下架'
            },
            condition: row => {
              return row.scope.type != 5 && row.scope.status == 1
            },
            listeners: {
              click: row =>  this.updateStatus(row.scope.id, 2)
            }
          }
        ],
        tableParams: {
            listName: 'list',
            tableOption: {
              width: 150
            },
            tableColumns: [
                {
                    label: '所属内容专区',
                    formatter: (cell) => {
                      return CONTENT_LIST.find(item => item.id == cell.type).name
                    }
                },
                {
                    label: '封面图片',
                    prop: 'coverImage',
                    addHtml: 'coverImageSlot'
                },
                {
                    label: '内容封面标题',
                    prop: 'proName',
                },
                {
                    label: '状态',
                    prop: 'status',
                    formatter: (cell) => {
                      return (cell.status == 1 || cell.type == 5) ? '已上架' : '已下架'
                    }
                },
            ]
        },
      }
    },
    created() {
    },
    mounted() {

    },
  
    methods:{
      addContent(item, isEdit){
        let type = isEdit ? item.type : item.id
        if(type != 1){
          this.contentObj = {
            imageDialogVisible: type==3 || type==5,
            videoDialogVisible: type==2 || type==4,
            ...this.$refs.menuRef.curModuleInfo,
            type,
          }
          if(isEdit) this.contentObj.id = item.id
        }else{
          let params = {
            ...this.$refs.menuRef.curModuleInfo,
          }
          if(isEdit) params.id = item.id
          const queryStr = encodeURIComponent(JSON.stringify(params))
          this.$router.push({ path: `/discoverManager/addProd/`+queryStr,query: { $title: isEdit ? '编辑特色方案' : '新增特色方案' }})
        }
      },
      updateStatus(id, status) {
        if(status==2){
          this.$confirm('请确认是否下架', '提示', {
            confirmButtonText: '下架',
            cancelButtonText: '否',
            type: 'warning',
            callback: action => {
              if (action == 'confirm') {
                this.toShelfProd(id, status)
              }
            }
          })
        }else{
          this.toShelfProd(id, status)
        }
      },
      toShelfProd(id, status){
        this.$apis.discover.updateStatusApi({id, status}).then(res => {
          if(res){
            this.$message.success(`${status == 2 ? '下架成功' : '上架成功'}`)
            this.handleSearch()
          }
        })
      },
      handleSearch(){
        this.$refs.tableRef.refreshTable()
      },
      handleReset(){
        this.searchFormObj = {
          type: '',
          status: '',
          subMenuId: ''
        },
        this.handleSearch()
      },
      getParams() {
        var params = JSON.parse(JSON.stringify(this.searchFormObj))
        const { secondaryMenuId, thirdMenuId } = this.$refs.menuRef.curModuleInfo
        params.subMenuId = thirdMenuId || secondaryMenuId
        return params
      },
      beforeSearchFn() {
        return new Promise(resolve => {
          this.searchObj = this.getParams()
          resolve()
        })
      },
    }
  }
</script>
  
<style scoped lang="scss">
.ctnr{
  position: relative;
  .search-wrap{
    /deep/ .el-form-item {
      &, .search-item{
        width: 312px;
      }
    }
  }
  .operate-btn{
    position: relative;
    &:hover{
      .dropdown-wrap {
        display: block;
      }
    }
    .arrow-icon{
      margin-left: 8px;
    }
    .dropdown-wrap{
      display: none;
      position: absolute;
      background-color: #fff;
      top: 100%;
      width: 96px;
      left: 0;
      box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px 0 #00000014, 0 9px 28px 8px #0000000d;
      z-index: 50;
      .dropdown-item{
        height: 36px;
        line-height: 36px;
        padding: 0 20px;
        font-size: 14px;
        color: #666666;
        list-style: none;
        cursor: default;
        &:hover{
          background: #F2F1FF;
          color: #5850FF;
        }
      }
    }
  }
  .cover-img{
    height: 36px;
    width: 36px;
  }
  .list{
    background-color: #fff;
    padding: 20px;
    margin-left: 276px;
  }
  .menu-wrap{
    overflow-y: auto;
    position: absolute;
    height: -webkit-fill-available;
    background-color: #fff;
    min-height: calc(100vh - 125px);
    &::-webkit-scrollbar{
      width: 4px;
    }
  }
}
</style>