<template>
    <el-container class="aminui-main-container">
		<el-header class="aminui-main-container__query-header">
            <el-form :model="params">
                <el-row :gutter="15">
					<el-col :md="6" :xs="24">
						<el-form-item label="所属业务:">
                            <el-select v-model="params.refType" clearable filterable placeholder="请选择所属业务">
                                <el-option v-for="(label, key) in refTypeDic" :key="key" :label="label" :value="key"></el-option>
                            </el-select>
                        </el-form-item>
					</el-col>
                    <el-col :md="10" :xs="24">
                        <el-form-item label="发送时间:">
                            <el-date-picker v-model="createDate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD"></el-date-picker>
                        </el-form-item>
					</el-col>
                    <el-col :md="8" :xs="24">
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" @click="reloadTable">查询</el-button>
                            <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
                        </el-form-item>
					</el-col>
                </el-row>
            </el-form>
        </el-header>

        <el-container class="aminui-main-container__table-main">
            <el-main class="nopadding">
                <scTable class="scTable" ref="table" row-key="id" :apiObj="api" :params="params" :column="column" tableName="messageTable" pageParams="current">
                    <el-table-column label="序号" type="index" align="center" width="60"></el-table-column>
                    <template #refType="scope">{{ formatType(scope.row.refType) }}</template>
                </scTable>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
import { column, refTypeDic } from "./main";

export default {
    data() {
        return {
            column, refTypeDic,

            api: this.$API.message.message,
            params: {
                orderBy: "createTime_desc",
                receiveUserId: this.$TOOL.data.get("USER_INFO").id
            },
            createDate: []
        }
    },

    methods: {
        formatType(value) {
            return refTypeDic[value] || "";
        },

        reloadTable() {
            this.params["createTimeBegin"] = this.createDate && this.createDate[0] && this.createDate[0] + " 00:00:00" || null;
            this.params["createTimeEnd"] = this.createDate && this.createDate[1] && this.createDate[1] + " 23:59:59" || null;
            this.$refs.table.reload(this.params, 1);
        },
        
        reset() {
            this.createDate = [];
            this.params = {
                orderBy: "createTime_desc",
                receiveUserId: this.$TOOL.data.get("USER_INFO").id
            }

            this.reloadTable();
        }
    }
}
</script>