<template>
    <div class="flex-container">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <!-- 搜索区域 -->
            <a-form layout="inline">
                <a-row :gutter="24">
                    <a-col :md="3" :sm="6">
                        <a-form-item label="姓名">
                            <a-input placeholder="姓名" v-model="queryParam.name" style="width: 8rem;"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="12">
                        <a-form-item label="月份">
                            <a-range-picker
                                    :placeholder="['开始月份', '结束月份']"
                                    format="YYYYMM"
                                    :value="queryParam.month"
                                    :mode="tempMode"
                                    @panelChange="handlePanelChange"
                                    style="width: 16rem;"
                            />
                        </a-form-item>
                    </a-col>
                    <span class="table-page-search-submitButtons" style="float: left; overflow: hidden;">
                        <a-col :md="6" :sm="24">
                             <a-button @click="search()" type="primary">查询</a-button>
                             <a-divider type="vertical"/>
                             <a-button @click="excelInto()" type="primary">导入总经理KPI数据</a-button>
                             <a-divider type="vertical"/>
                             <a-button @click="excelOut()" type="primary">导出所有数据</a-button>
                        </a-col>
                    </span>
                </a-row>
            </a-form>
        </div>

        <a-modal
                title="批量导入"
                :visible="zjlkpivisible"
                @ok="createfunctionOk"
                @cancel="createfunctionCancel"
                html-type="submit"
                width="400px"
        >
            <a-row :gutter="24">
                <a-col :md="24" :sm="12">
                    <p style="text-align:center">{{ importTile }}</p>
                </a-col>
            </a-row>
            <import-btn :url="importUrl" :responseFun="doPush">
                <a-tooltip placement="topLeft" title="导入文件" arrowPointAtCenter>
                    <a-row :gutter="24">
                        <a-col :md="24" :sm="12">
                            <p>
                                选择文件：
                                <a-button type="primary">选择文件</a-button>
                            </p>
                        </a-col>
                    </a-row>
                </a-tooltip>
            </import-btn>
            <a-row :gutter="24">
                <a-col :md="24" :sm="12">
                    <p v-show="zjlmoBan">
                        模板下载：
                        <a-button type="primary" @click="downloadMoBan">总经理KPI信息模板</a-button>
                    </p>
                </a-col>
            </a-row>
            <a-row :gutter="24" :v-show="KDmoBan">
                <a-col :md="24" :sm="12">
                    <p>说明：</p>
                    <p>1.批量导入请严格按照模版进行导入;</p>
                </a-col>
            </a-row>
        </a-modal>
        <!--列表-->
        <s-table :columns="columns" :data="rowdata" bordered ref="table" size="small" class="flex-filling" :locale="emptyText">
            <!--拦截器-->
            <template slot="productLastUpdateTime" slot-scope="text">
                {{ text | dayjs}}
            </template>
            <!--拦截器-->
            <template slot="productCreateTime" slot-scope="text">
                {{ text | dayjs}}
            </template>
            <template slot="productState" slot-scope="text">
                <p v-if="text=='0'">正常</p>
                <p v-else=""></p>
            </template>
            <!--<template slot="operation" slot-scope="text,record">
                <span>
                  <a v-show="false" @click="modifyfunction(record)">编辑</a>
                  <a-divider v-show="false" type="vertical"/>
                  <a-popconfirm title="确定删除吗?" @confirm="remove(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </span>
            </template>-->
        </s-table>
    </div>
</template>

<script>
    import STable from '@/components/table';
    import ImportBtn from "../../../components/sysmanage/ImportBtn";
    import { zjlKpiList, uploadExcel, downloadMoBan } from "@/api/school-center/managerKpiAPI"
    import {cloneObject, exportFile} from '@/utils/util';
    import ConstantActivity from "@/constant/ConstantActivity";
    import Vue from 'vue';
    import moment from "moment";
    import {DatetimePicker} from 'vant';

    Vue.use(DatetimePicker);

    export default {
        name: "managerKpiAPI",
        components: {
            STable, ImportBtn
        },
        data() {
            return {
                emptyText: {emptyText: '暂无数据'},
                title: ConstantActivity.title,
                queryParam: {
                    name: '',
                    month: ['', ''],
                },
                modelData: {
                    month: '',
                    county: '',
                    name: '',
                    totalPerformance: '',
                    performanceBase: '',
                    yfPerformance: '',
                    kpi: '',
                    rwKpi: '',
                    wxKpi: '',
                    yyKpi: '',
                    workKpi: '',
                    totalBonus: '',
                    totalFund: '',
                    autumnBonus: '',
                    yfBonus: '',
                },
                columns: [
                    {dataIndex: 'month', width: 20, title: '月份 '},
                    {dataIndex: 'county', width: 20, title: '县分'},
                    {dataIndex: 'name', width: 25, title: '督导'},
                    {dataIndex: 'totalPerformance', width: 30, title: '绩效奖金合计'},
                    {dataIndex: 'performanceBase', width: 25, title: '绩效基数'},
                    {dataIndex: 'yfPerformance', width: 25, title: '应发绩效'},
                    {dataIndex: 'kpi', width: 20, title: 'kpi总分'},
                    {dataIndex: 'rwKpi', width: 25, title: '移动入网'},
                    {dataIndex: 'wxKpi', width: 30, title: '存量维系'},
                    {dataIndex: 'yyKpi', width: 25, title: '团队运营'},
                    {dataIndex: 'workKpi', width: 25, title: '每月工作'},
                    {dataIndex: 'totalBonus', width: 25, title: '累计佣金'},
                    {dataIndex: 'totalFund', width: 25, title: '累计分成'},
                    {dataIndex: 'autumnBonus', width: 25, title: '秋营达标奖'},
                    {dataIndex: 'yfBonus', width: 25, title: '应发提成'}
                ],
                rowdata: parameter => {
                    let params = {
                        pageNo: parameter.pageNo,
                        pageSize: parameter.pageSize
                    }
                    let obj = cloneObject(this.queryParam)

                    return zjlKpiList(Object.assign(params, obj)).then(res => {
                        let data = {}
                        if (res.state !== 'success') {
                            this.$message.error("查询失败！", 5);
                            this.emptyText.emptyText = '查询失败！'
                            data = {
                                data: [],
                                pageSize: parameter.pageSize,
                                pageNo: 1,
                                totalCount: 0
                            }
                        } else {
                            data = {
                                data: res.data.records,
                                pageSize: parameter.pageSize,
                                pageNo: parameter.pageNo,
                                totalCount: res.data.total
                            }
                        }
                        return data
                    })
                },
                importTile: "",
                importUrl: "",
                zjlmoBan: true,
                KDmoBan: true,
                zjlkpivisible: false,
                tempMode:['month', 'month'],
            }
        },
        methods: {
            moment,
            handlePanelChange(value, mode) {
                this.queryParam.month = value;
                this.tempMode = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]];
                //console.log("this.tempMode=================="+this.tempMode);
            },
            excelOut() {
                let params = {
                    pageNo: 1,
                    pageSize: 10
                }
                let obj = cloneObject(this.queryParam)
                let nowdate = moment().format("YYYY-MM-DD");
                //导出
                exportFile(
                    uploadExcel(Object.assign(params, obj)),
                    "总经理KPI信息" + nowdate + ".xlsx",
                );

            },
            excelInto() {
                this.importTile = "批量导入总经理KPI信息";
                this.importUrl = "manager/ciop/managerKpi/importDate";
                this.zjlmoBan = true;
                this.zjlkpivisible = true
            },
            downloadMoBan: function () {
                exportFile(downloadMoBan(), "总经理KPI信息.xlsx");
            },
            doPush(res) {
                console.log(res);
                if (!res || !res.response) {
                    this.$message.error("上传文件出错！", 10);
                    return false;
                }
                const response = res.response;
                if (response.state !== "success") {
                    this.$message.error(response.msg ? response.msg : "上传文件出错！", 10);
                    return false;
                }
                this.$message.success("上传成功！" + response.data, 5);
            },

            createfunctionOk() {
                this.zjlkpivisible = false;
                this.clearmodel();
            },
            createfunctionCancel() {
                this.zjlkpivisible = false;
                this.clearmodel0();
            },
            clearmodel() {
                this.importTile = "";
                this.zjlmoBan = false;
                this.importUrl = "";
            },
            search() {
                console.log("queryParam.month=================="+this.queryParam);
                this.$refs.table.refresh({search: true})
            },

        },
        mounted() {

        }
    }
</script>

<style scoped>

</style>