<template>
    <div class="page-pack">
        <div class="title-pack clear-float pl-15 pr-15">
            <div class="float-left">
                <span class="page-title-text">前处理槽液日常检测报告</span>
            </div>
            <div class="float-right page-refresh">
                <span @click="doRefreshClick" class="pointer">
                    <svg-icon icon-class="refresh"></svg-icon>
                    <span class="ml-10">刷新</span>
                </span>
            </div>
        </div>
        <div class="tool-pack clear-float pl-15 pr-15">
            <Search
                searchCode="DAILY_CHECK_RECORD"
                @search="doSearchClick"
                @reset="doResetClick">
            </Search>
            <div class="float-left">
                <el-button
                    size="small"
                    type="primary"
                    @click="doAddClick">
                    新增报告
                </el-button>
            </div>
        </div>
        <div class="general-list-main-pack pl-15 pr-15 pb-15">
            <div>
                <Table
                    :tableConfig="tableConfig"
                    @onPageSizeChange="onPageSizeChange"
                    @onCurrentPageChange="onCurrentPageChange">
                    <template slot="createTime">
                        <el-table-column
                            label="检测日期"
                            width="150">
                            <template slot-scope="scope">
                                {{ formatTime(scope.row.createTime, 'YYYY-MM-DD') }}
                            </template>
                        </el-table-column>
                    </template>
                    <template slot="operationColumn">
                        <el-table-column
                            fixed="right"
                            width="100"
                            label="操作">
                            <template slot-scope="scope">
                                <el-button
                                    type="text"
                                    @click="doViewReportClick(scope.row.id)">
                                    查看报告
                                </el-button>
                            </template>
                        </el-table-column>
                    </template>
                </Table>
            </div>
        </div>

        <!-- 新增报告 -->
        <AddReport
            ref="AddReport"
            @doConfirmClick="doAddReportConfirmClick">
        </AddReport>

        <!-- 查看报告 -->
        <ViewReport
            ref="ViewReport"
            :checkRecordId="checkRecordId">
        </ViewReport>
    </div>
</template>

<script>
    import Moment from 'moment'
    import Table from '@/components/Table'
    import Search from '@/components/Search'
    import AddReport from './components/AddReport'
    import ViewReport from './components/ViewReport'

    export default {
        name: 'electrophoresisTank',
        components: {
            Table,
            Search,
            AddReport,
            ViewReport
        },
        data () {
            return {
                // 检测记录id
                checkRecordId: '',
                // 搜索组件关键字列表
                searchList: {},
                // 表格配置项
                tableConfig: {
                    height: 0,
                    data: [],
                    fieldList: [
                        { label: '序号', value: 'id', width: 55 },
                        { label: '版本状态/Rev', value: 'rev' },
                        { label: '记录编号/Sheet No.', value: 'sheetNo' },
                        { label: '流水码/No.', value: 'no' },
                        { label: '化验员', value: 'createBy' },
                        { label: '检测日期', value: 'createTime', slot: 'createTime' }
                    ],
                    paginationToggle: true,
                    paginationConfig: {
                        total: 0,
                        currentPage: 1,
                        pageSize: 20
                    }
                }
            }
        },
        methods: {
            // 时间日期格式化
            formatTime (time, format) {
                if (time === null) {
                    return '暂无'
                } else {
                    return Moment(time).format(format)
                }
            },
            // 点击刷新按钮
            doRefreshClick () {
                this.getCheckRecordList().then(() => {
                    this.$message.success('刷新成功！')
                })
            },
            // 点击搜索按钮
            doSearchClick (searchValue) {
                this.searchList = searchValue
                this.tableConfig.paginationConfig.currentPage = 1
                // 获取设备点检记录列表
                this.getCheckRecordList()
            },
            // 点击重置按钮
            doResetClick (searchValue) {
                this.searchList = { ...searchValue, filters: [] }
                this.tableConfig.paginationConfig.currentPage = 1
                this.tableConfig.paginationConfig.pageSize = 20
                // 获取设备点检记录列表
                this.getCheckRecordList()
            },
            // 触发列表分页数量改变事件
            onPageSizeChange (pageSize) {
                this.tableConfig.paginationConfig.currentPage = 1
                this.tableConfig.paginationConfig.pageSize = pageSize
                // 获取设备点检记录列表
                this.getCheckRecordList()
            },
            // 触发列表分页页数改变事件
            onCurrentPageChange (currentPage) {
                this.tableConfig.paginationConfig.currentPage = currentPage
                // 获取设备点检记录列表
                this.getCheckRecordList()
            },
            // 点击新增报告按钮
            doAddClick () {
                this.$refs.AddReport.dialogToggle = true
            },
            // 点击新增报告对话框确认按钮
            doAddReportConfirmClick () {
                // 获取设备点检记录列表
                this.getCheckRecordList()
            },
            // 点击查看报告按钮
            doViewReportClick (checkId) {
                this.checkRecordId = _.cloneDeep(checkId)
                this.$refs.ViewReport.dialogToggle = true
            },
            // 获取设备点检记录列表
            getCheckRecordList () {
                let queryParams = {
                    searchCode: 'DAILY_CHECK_RECORD',
                    filters: this.searchList.filters || [],
                    pageSize: this.tableConfig.paginationConfig.pageSize,
                    pageNum: this.tableConfig.paginationConfig.currentPage
                }
                return new Promise((resolve, reject) => {
                    this.$fetch('daily-check-controller/pretreatment-post', queryParams).then(response => {
                        this.tableConfig.data = _.cloneDeep(response.list)
                        this.tableConfig.paginationConfig.total = _.cloneDeep(response.total)
                        resolve()
                    })
                })
            }
        },
        mounted () {
            setTimeout(() => {
                this.tableConfig.height = document.querySelector('.page-pack').offsetHeight - 210
                // 获取设备点检记录列表
                this.getCheckRecordList()
            }, 0)
        }
    }
</script>

<style lang="scss" scoped>
    .page-pack {
        position: relative;
        min-height: 100%;
        width: 100%;
        border: 1px solid #d2d3d5;
        background-color: #fff;
        overflow-y: auto;

        .title-pack {
            height: 38px;
            line-height: 38px;
            border-bottom: 1px solid #d2d3d5;
        }

        .tool-pack {
            padding-top: 16px;
            padding-bottom: 16px;
            .tool-tag {
                height: 32px;
                line-height: 32px;
                font-size: 14px;
            }
        }

        .edit-button {
            color: #538FFD;
        }

        .status-circle {
            display: inline-block;
            width: 6px;
            height: 6px;
            border-radius: 6px;
            margin-right: 5px;
            vertical-align: middle;
        }
        .delete-button {
            color: #F47476;
        }

        .view-span {
            color: #1284fa;
            border-bottom: 1px solid #1284fa;
            &:hover {
                cursor: pointer;
            }
        }
        .el-dialog__body {
            padding: 30px 30px 10px 20px!important;
            .el-row {

                .el-col {
                    line-height: 35px;

                    .el-form-item {
                        width: 100%;

                        .el-form-item__content {
                            width: 100%;

                            .el-input {
                                font-size: 12px;
                                height: 32px;
                            }
                            .el-input__inner {
                                height: 32px;
                            }
                            .el-select {
                                width: 100%!important;
                                font-size: 12px;
                                height: 32px;
                            }
                            .el-date-editor {
                                width: 100%!important;
                            }
                        }
                    }
                }
            }
        }
    }
</style>