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

        <!-- 查询和其他操作 -->
        <div class="filter-container">
            <el-input clearable class="filter-item" style="width: 200px;" placeholder="员工姓名"
                v-model="listQuery.userName"></el-input>
            <el-select v-model="listQuery.companyId" clearable placeholder="公司主体" class="filter-item" style="width: 200px;">
                <el-option :key="item.companyId" v-for="item in companyTypeList" :label="item.companyName" :value="item.companyId">
                </el-option>
            </el-select>
            <el-select v-model="listQuery.deptId" clearable placeholder="部门名称" class="filter-item" style="width: 200px;">
                <el-option :key="item.type" v-for="item in depTypeList" :label="item.deptName" :value="item.deptId">
                </el-option>
            </el-select>
            <el-select v-model="listQuery.staffStatus" clearable placeholder="员工状态" class="filter-item" style="width: 200px;">
                <el-option :key="item.dictValue" v-for="item in staffStatusList" :label="item.dictLabel" :value="item.dictValue">
                </el-option>
            </el-select>
            <el-select v-model="listQuery.lockStatus" clearable placeholder="初始积分领取状态" class="filter-item" style="width: 200px;">
                <el-option :key="item.dictValue" v-for="item in lockStatusList" :label="item.dictLabel" :value="item.dictValue">
                </el-option>
            </el-select>
            <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="70px" label="员工姓名" prop="userName">
            </el-table-column>
            <el-table-column align="center" min-width="100px" label="员工账号" prop="loginId">
            </el-table-column>
            <el-table-column align="center" min-width="200px" label="公司主体" prop="companyName">
            </el-table-column>
            <el-table-column align="center" min-width="200px" label="部门" prop="deptName">
            </el-table-column>
            <el-table-column align="center" min-width="120px" label="入职时间" prop="realEntryDate">
            </el-table-column>
            
            <el-table-column align="center" min-width="80px" label="积分" prop="integral">
            </el-table-column>
            <el-table-column align="center" min-width="70px" label="员工状态" prop="staffStatusName">
            </el-table-column>
            <el-table-column align="center" min-width="120px" label="初始积分领取状态" prop="lockStatusName">
            </el-table-column>
            <el-table-column align="center" label="操作" min-width="100px" 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 :close-on-click-modal="false" 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.dictValue" v-for="item in allTypeList" :label="item.dictLabel" :value="item.dictValue">
                    </el-option>
                </el-select>
                <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" @click="handleItemDownload">导出</el-button>

            </div>
            <!-- 查询结果 -->
            <el-table size="small" :data="itemList" 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="integralTypeName">
                </el-table-column>
                <el-table-column align="center" min-width="200px" label="积分说明" prop="comment">
                </el-table-column>
                <el-table-column align="center" min-width="80px" label="积分" prop="integral">
                    <template slot-scope="scope">
                        <span style="color: #67C23A;font-weight: 600;font-size: 14px;" v-if="scope.row.pm == 0">
                            + {{ scope.row.integral }}
                        </span>
                        <span style="color: #F56C6C;font-weight: 600;font-size: 14px;" v-else>
                            - {{ scope.row.integral }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column align="center" min-width="80px" label="生成时间" prop="createTime">
                </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 } from "@/api/pointManage";
import { companyTypeList, depTypeList,dataTypeList } from "@/api/public";
import waves from "@/directive/waves"; // 水波纹指令
import Tinymce from '@/components/Tinymce'

export default {
    name: 'pointList',
    components: { Tinymce },
    directives: { waves },
    data() {
        return {
            lockStatusList:[],
            staffStatusList: [],
            companyTypeList: [
                
            ],
            depTypeList: [
                
            ],
            allTypeList: [
               
            ],
            list: [
                
            ],
            itemList: [
                
            ],
            total: 0,
            itemTotal: 0,
            listLoading: false,
            downloadLoading: false,
            listQuery: {
                page: 1,
                limit: 10,
                companyId: '',
                deptId: '',
                userName: '',
                staffStatus: '',
                lockStatus:'',
            },
            itemListQuery: {
                page: 1,
                limit: 10,
                type: '',
            },
            dialogFormVisible: false,
        }
    },
    created() {
        this.getCompanyTypeList();
        this.getDepTypeList(); 
        this.getStaffStatusList();
        this.getLockStatusListList();
        this.getList();
    },
    methods: {
        getLockStatusListList(){
            dataTypeList({dictType:'lock_status'}).then(response => {
                this.lockStatusList = response.data.data;
            })
        },
        getStaffStatusList(){
            dataTypeList({dictType:'staff_status'}).then(response => {
                this.staffStatusList = response.data.data;
            })
        },
        handleDownload() {
            window.location.href = process.env.BASE_API + '/mall-integral/export/user/page?companyId=' + this.listQuery.companyId + '&deptId=' + this.listQuery.deptId + '&userName=' + this.listQuery.userName + '&lockStatus=' + this.listQuery.lockStatus+ '&staffStatus=' + this.listQuery.staffStatus;
        },
        handleItemDownload() {
            window.location.href = process.env.BASE_API + '/mall-integral/export/user/log?type=' + this.itemListQuery.type;
        },
        getCompanyTypeList() {
            companyTypeList().then(response => {
                this.companyTypeList = response.data.data;
            }).catch(() => {});
        },
        getDepTypeList() {
            depTypeList().then(response => {
                this.depTypeList = response.data.data;
            }).catch(() => {});
        },
        getPointRulesType() {
            dataTypeList({dictType:'integral_rule_type'}).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() {
            getItemPointList(this.itemListQuery).then(response => {
                this.itemList = response.data.data.items
                this.itemTotal = response.data.data.total
            }).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.userId = row.loginId;
            this.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>
  