<template>
    <div style="margin-top: 10px">
        <el-table :data="dataList"  v-if="switchType === '1'" height="280">
            <el-table-column label="公众号" prop="name" align="center"/>
            <el-table-column label="accountId" prop="accountId" align="center"/>
            <el-table-column label="投手" prop="pitcher" align="center"/>
            <el-table-column label="开始时间" prop="startTime" align="center"/>
            <el-table-column label="结束时间" prop="endTime" align="center"/>
        </el-table>
        <el-table :data="dataList"  v-else-if="switchType === '2'" height="280">
            <el-table-column label="公众号" prop="name" align="center"/>
            <el-table-column label="accountId" prop="accountId" align="center"/>
            <el-table-column label="书名" prop="book" align="center"/>
            <el-table-column label="开始时间" prop="startTime" align="center"/>
            <el-table-column label="结束时间" prop="endTime" align="center"/>
        </el-table>
        <el-table :data="dataList"  v-else-if="switchType === '3'" height="280">
            <el-table-column label="公众号" prop="name" align="center"/>
            <el-table-column label="accountId" prop="accountId" align="center"/>
            <el-table-column label="投手" prop="pitcher" align="center"/>
            <el-table-column label="开始时间" prop="startTime" align="center"/>
            <el-table-column label="结束时间" prop="endTime" align="center"/>
        </el-table>
        <el-table :data="dataList"  v-else-if="switchType === '4'" height="280">
            <el-table-column label="公众号" prop="name" align="center"/>
            <el-table-column label="accountId" prop="accountId" align="center"/>
            <el-table-column label="现在小说平台" prop="currentPlatform" align="center"/>
            <el-table-column label="原始小说平台" prop="primaryPlatform" align="center"/>
            <el-table-column label="切换时间" prop="changeDate" align="center"/>
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            :page-sizes="[5, 10, 20]"
            @pagination="getList"
        />
    </div>
</template>

<script>
import { getSwitchAcc, getSwitchBook, getSwitchPitche, getSwitchPlatform } from "@/api/accounts/adApi";
export default {
    props: {
        accountId: {
            type: Number,
            default: null
        },
        switchType: {
            type: String,
            default: "1"   // 1 切号  2 切书  3 切投手  4 切平台
        }
    },
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 5,
                accountId: null,
            },
            dataList: [],
            total: 0
        }
    },
    watch: {
        accountId: {
            handler(newVal,oldVal) {
                this.queryParams.accountId = newVal
                this.getList()
            },
            immediate: true
        },
        switchType: {
            handler(newVal, oldVal) {
                this.queryParams = { ...this.queryParams, pageNum: 1 }
                this.getList()
            },
            immediate: true
        }
    },
    methods: {
        getList() {
            let request = null
            switch(this.switchType){
                case '1':
                    request = getSwitchAcc
                    break;
                case '2':
                    request = getSwitchBook
                    break;
                case '3':
                    request = getSwitchPitche
                    break;
                case '4':
                    request = getSwitchPlatform
                    break;
            }
            if(this.queryParams.accountId && request !== null){
                request(this.queryParams).then(res => {
                    this.total = res.data.total
                    console.log(this.total)
                    this.dataList = res.data.records
                })
            }
        }
    }
}
</script>