index.vue 7.3 KB
<!-- 秒杀活动 -->
<template>
    <div class="ctnr">
        <div class="operate-wrap">
            <span class="table-title">管理列表</span>
            <div class="operate-btn">
                <el-button :size="size" type="primary" plain @click="addStrategy(1)">新增</el-button>
            </div>           
        </div>
        <GLTable ref="tableRef" :pageConf="pageConf" :searchForm="searchFormObj" :tableParams="tableParams" :getListApi="getListApi" :beforeSearchFn="beforeSearchFn">
            <div slot="imgSlot" class="imgSlot" slot-scope="scope">
                <img :src="scope.scope.strategyImg" alt="">
            </div>
            <div slot="linkText" slot-scope="scope">
                <p
                    class="link-text"
                    @click="goBurialPointPage(scope)"
                >{{ scope.scope[scope.prop] || 0 }}</p>
            </div>
            <div class="showSlot" slot="showSlot" slot-scope="scope">
                <el-switch :value="scope.scope.mainFlag" @change="updateFlagFn($event, scope.scope)" :active-value="1" :inactive-value="0"></el-switch>
            </div>
            <div slot="auth-button" slot-scope="scope">
                <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
            </div>
        </GLTable>
    </div>
</template>
  
<script>
import { utils } from 'glsx-common'
export default {
    name: 'strategyIndex',
    data() {
      return {
        size: 'small',
        curEditId: '',
        searchFormObj: {},
        getListApi: this.$apis.strategy.getListApi,
        pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
        tableParams: {
            listName: 'list',
            tableOption: true,
            tableColumns: [
                {
                    label: '攻略名称',
                    prop: 'strategyName'
                },
                {
                    label: '攻略宣传图',
                    addHtml: 'imgSlot',
                },
                {
                    label: '分类名称',
                    prop: 'categoryName'
                },
                {
                    label: '浏览量/次',
                    prop: 'viewAmount',
                    addHtml: 'linkText'
                },
                {
                    label: '访客',
                    prop: 'fansAmount',
                    addHtml: 'linkText'
                },
                {
                    label: '分享',
                    prop: 'shareAmount',
                    addHtml: 'linkText'
                },
                {
                    label: '首页展示',
                    addHtml: 'showSlot'
                },
                {
                    label: '创建日期',
                    prop: 'createdDate',
                    width: 220
                },
                {
                    label: '更新日期',
                    prop: 'updatedDate',
                    width: 220
                },
                {
                    label: '操作人',
                    prop: 'updatedBy'
                }
            ]
        },
        buttonList: [
          {
            type: 'el-button',
            name: '编辑',
            attrs: {
              type: 'text',
              fn: '编辑'
            },
            listeners: {
              click: row => this.addStrategy(2, row.scope)
            }
          },
          {
            type: 'el-button',
            name: '删除',
            attrs: {
              type: 'text',
              fn: '删除'
            },
            listeners: {
              click: row => this.delStrategy(row.scope)
            }
          },
          {
            type: 'el-button',
            name: '置顶',
            attrs: {
              type: 'text',
              fn: '置顶'
            },
            listeners: {
              click: row => this.topStrategy(row.scope)
            }
          }
        ],
      }
    },
  
    components: {
    },
  
    mounted() {
    },
  
    methods: {
        updateFlagFn(e, {id}){
            this.$apis.strategy.updateMainFlagApi({id, mainFlag : e}).then(res => {
                if(res){
                    this.$message.success('操作成功')
                    this.handleSearch()
                }
            })
        },
        addStrategy(type, row) {
            const params = {
                type
            }
            if(type==2) params.id = row.id
            const queryStr = encodeURIComponent(JSON.stringify(params))
            this.$router.push({
                path: `/strategy/add/`+queryStr
            })
        },
        topStrategy({id}){
            this.$apis.strategy.topStrategyApi({id, topFlag: 1}).then(res => {
                if(res){
                    this.$message.success('操作成功')
                    this.handleSearch()
                }
            })
        },
        delStrategy({id}){
            this.$confirm('是否删除该攻略', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              callback: action => {
                if (action == 'confirm') {
                    this.$apis.strategy.delStrategyApi({id}).then(res => {
                        if(res){
                            this.$message.success('操作成功')
                            this.handleSearch()
                        }
                    })
                }
              }
            })
        },
        goBurialPointPage(scope){
            const recordType = {
                viewAmount: {
                    id: 1,
                    name: '浏览明细'
                },
                fansAmount: {
                    id: 3,
                    name: '访客明细'
                },
                shareAmount: {
                    id: 2,
                    name: '分享明细'
                }
            }[scope.prop]
            console.log(recordType.id)
            const params = {
                recordType : recordType.id,
                strategyName: scope.scope.strategyName,
                id: scope.scope.id
            }
            // 为了避免特殊符号encodeURIComponent多一次
            const queryStr = encodeURIComponent(encodeURIComponent(JSON.stringify(params)))
            this.$router.push({
                path: `/strategy/burialPointList/`+queryStr,
                query: { $title: recordType.name }
            })
        },
        handleReset(){
            this.searchFormObj = {}
            this.handleSearch()
        },
        handleSearch(){
            this.$refs.tableRef.refreshTable()
        },
        beforeSearchFn(){
            return new Promise((resolve, reject)=>{
                this.searchForm = utils.deepClone(this.searchFormObj)
                const { categoryCode  } = this.searchForm
                this.searchForm.categoryCode = categoryCode && categoryCode.length ? categoryCode.pop() : ''
                resolve()
            }) 
        }
    }
  }
</script>
  
<style scoped lang="scss">
.ctnr{
    background-color: #fff;
    padding: 20px;
    .imgSlot{
        img{
            width: 36px;
            height: 36px;
            vertical-align: middle;
        }
    }
    .link-text{
        color: #5850FF;
        cursor: pointer;
    }
}
</style>