<template>
    <div class="app-container calendar-list-container">

        <!-- 查询和其他操作 -->
        <div class="filter-container">
            <el-select v-model="listQuery.companyType" clearable placeholder="请选择公司主体" style="top: -4px;width: 200px;">
                <el-option :key="item.type" v-for="item in companyTypeList" :label="item.name" :value="item.type">
                </el-option>
            </el-select>
            <el-select v-model="listQuery.depType" clearable placeholder="请选择部门" style="top: -4px;width: 200px;">
                <el-option :key="item.type" v-for="item in depTypeList" :label="item.name" :value="item.type">
                </el-option>
            </el-select>
            <el-input clearable class="filter-item" style="width: 200px;" placeholder="请输入员工姓名"
                v-model="listQuery.name"></el-input>
            <el-date-picker class="filter-item" v-model="listQuery.time" type="datetime" placeholder="选择生成时间">
            </el-date-picker>
            <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查找</el-button>
            <el-button class="filter-item" type="primary"  :loading="downloadLoading" v-waves icon="el-icon-download" @click="handleDownload">导出</el-button>

        </div>

        <!-- 查询结果 -->
        <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit
            highlight-current-row>
            <el-table-column type="index" label="序号" header-align="center" align="center">
            </el-table-column>

            <el-table-column align="center" min-width="100px" label="员工姓名" prop="name">
            </el-table-column>

            <el-table-column align="center" min-width="200px" label="公司主体" prop="companyName">
            </el-table-column>

            <el-table-column align="center" min-width="80px" label="部门" prop="depName">
            </el-table-column>
            <el-table-column align="center" min-width="80px" label="积分" prop="integral">
            </el-table-column>
            <el-table-column align="center" label="操作" width="240px" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="primary" size="small" @click="handleView(scope.row, false)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>

        <!-- 员工积分记录列表 -->
        <el-dialog title="员工积分记录" :visible.sync="dialogFormVisible" width="70%">
            <div class="filter-container">
                <el-select v-model="itemListQuery.type" clearable placeholder="请选择积分类型" style="top: -4px;width: 200px;">
                    <el-option :key="item.type" v-for="item in allTypeList" :label="item.name" :value="item.type">
                    </el-option>
                </el-select>
                <el-date-picker class="filter-item" v-model="itemListQuery.time" type="datetime" placeholder="选择生成时间">
                </el-date-picker>
                <el-button class="filter-item" type="primary" v-waves icon="el-icon-search"
                    @click="itemHandleFilter">查找</el-button>
                <el-button class="filter-item" type="primary" v-waves icon="el-icon-download">导出</el-button>

            </div>
            <!-- 查询结果 -->
            <el-table size="small" :data="itemList" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit
                highlight-current-row>
                <el-table-column type="index" label="序号" header-align="center" align="center">
                </el-table-column>

                <el-table-column align="center" min-width="100px" label="员工姓名" prop="name">
                </el-table-column>

                <el-table-column align="center" min-width="200px" label="积分类型" prop="integralCategory">
                </el-table-column>

                <el-table-column align="center" min-width="80px" label="积分名称" prop="integralName">
                </el-table-column>
                <el-table-column align="center" min-width="80px" label="积分" prop="integral">
                </el-table-column>
                <el-table-column align="center" min-width="80px" label="生成时间" prop="time">
                </el-table-column>
            </el-table>

            <!-- 分页 -->
            <div class="pagination-container">
                <el-pagination background @size-change="itemHandleSizeChange" @current-change="itemHandleCurrentChange"
                    :current-page="itemListQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="itemListQuery.limit"
                    layout="total, sizes, prev, pager, next, jumper" :total="itemTotal">
                </el-pagination>
            </div>
        </el-dialog>

    </div>
</template>
  
<style>
.demo-table-expand {
    font-size: 0;
}

.demo-table-expand label {
    width: 200px;
    color: #99a9bf;
}

.demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
}
</style>
  
<script>
import { getPointList, getItemPointList, pointRulesTypeList } from "@/api/pointManage";
import { companyTypeList, depTypeList } from "@/api/public";
import waves from "@/directive/waves"; // 水波纹指令
import Tinymce from '@/components/Tinymce'

export default {
    name: 'pointList',
    components: { Tinymce },
    directives: { waves },
    data() {
        return {
            companyTypeList: [
                {
                    type: 'highTechnology',
                    name: '高科技'
                },
                {
                    type: 'fastExtinction',
                    name: '快销'
                },
                {
                    type: 'manufacturingIndustry',
                    name: '制造业'
                },
                {
                    type: 'all',
                    name: '全部'
                },
            ],
            depTypeList: [
                {
                    type: 1,
                    name: '启用'
                },
                {
                    type: 0,
                    name: '禁用'
                },
            ],
            allTypeList: [
                {
                    type: 'highTechnology',
                    name: '高科技'
                },
                {
                    type: 'fastExtinction',
                    name: '快销'
                },
                {
                    type: 'manufacturingIndustry',
                    name: '制造业'
                },
                {
                    type: 'all',
                    name: '全部'
                },
            ],
            list: [
                {
                    id: 1,
                    name: '类型1',
                    companyName: '名称1',
                    depName: '代码1',
                    integral: '100',
                    flag: 1
                },
                {
                    id: 2,
                    name: '类型2',
                    companyName: '名称2',
                    depName: '代码2',
                    integral: '200',
                    flag: 0
                },
                {
                    id: 3,
                    name: '类型3',
                    companyName: '名称3',
                    depName: '代码3',
                    integral: '300',
                    flag: 1
                },
            ],
            itemList: [
                {
                    id: 1,
                    name: '类型1',
                    integralCategory: '名称1',
                    integralName: '代码1',
                    integral: '100',
                    time: '2023-4-3'
                },
                {
                    id: 2,
                    name: '类型1',
                    integralCategory: '名称1',
                    integralName: '代码1',
                    integral: '100',
                    time: '2023-4-3'
                },
                {
                    id: 3,
                    name: '类型1',
                    integralCategory: '名称1',
                    integralName: '代码1',
                    integral: '100',
                    time: '2023-4-3'
                },
            ],
            total: 0,
            itemTotal: 0,
            listLoading: false,
            downloadLoading: false,
            listQuery: {
                page: 1,
                limit: 10,
                companyType: '',
                depType: '',
                name: '',
                time: '',
            },
            itemListQuery: {
                page: 1,
                limit: 10,
                id: '',
                type: '',
                time: '',
            },
            dialogFormVisible: false,
        }
    },
    created() {
        // this.getCompanyTypeList();
        // this.getDepTypeList(); 
        // this.getList();
    },
    methods: {
        handleDownload() {
            this.downloadLoading = true
            import('@/vendor/Export2Excel').then(excel => {
            const tHeader = ['员工姓名', '公司主体', '部门', '积分', ]
            const filterVal = ['name','companyName', 'depName', 'integral']
            excel.export_json_to_excel2(tHeader, this.list, filterVal, '积分列表')
            this.downloadLoading = false
            })
        },
        getCompanyTypeList() {
            companyTypeList().then(response => {
                this.companyTypeList = response.data.data;
            }).catch(() => {});
        },
        getDepTypeList() {
            depTypeList().then(response => {
                this.depTypeList = response.data.data;
            }).catch(() => {});
        },
        getPointRulesType() {
            pointRulesTypeList().then(response => {
                this.allTypeList = response.data.data;
            }).catch(() => {
                
            });
        },
        getList() {
            this.listLoading = true
            getPointList(this.listQuery).then(response => {
                this.list = response.data.data.items
                this.total = response.data.data.total
                this.listLoading = false
            }).catch(() => {
                
            })
        },
        getItemList() {
            this.listLoading = true
            getItemPointList(this.itemListQuery).then(response => {
                this.itemList = response.data.data.items
                this.itemLotal = response.data.data.total
                this.listLoading = false
            }).catch(() => {})
        },
        handleFilter() {
            this.listQuery.page = 1
            this.getList()
        },

        handleSizeChange(val) {
            this.listQuery.limit = val
            this.getList()
        },

        handleCurrentChange(val) {
            this.listQuery.page = val
            this.getList()
        },
        itemHandleFilter() {
            this.itemListQuery.page = 1
            this.getItemList()
        },

        itemHandleSizeChange(val) {
            this.itemListQuery.limit = val
            this.getItemList()
        },

        itemHandleCurrentChange(val) {
            this.itemListQuery.page = val
            this.getItemList()
        },

        handleView(row) {
            this.itemListQuery.id = row.id;
            // getPointRulesType()
            // this.getItemList()
            this.dialogFormVisible = true
        },
    }
}
</script>
<style>
.ad-avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.ad-avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.ad-avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.ad-avatar {
    display: block;
}
</style>
  