<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="MES_WORKORDER_INFO"
                @search="doSearchClick"
                @reset="doResetClick">
            </Search>
            <div class="float-left">
                <el-button
                    size="small"
                    type="primary"
                    @click="doImportClick">
                    导入
                </el-button>
            </div>
        </div>
        <div class="general-list-main-pack pl-15 pr-15 pb-15">
            <div>
                <PreviewTable
                    :tableConfig="tableConfig"
                    @onPageSizeChange="onPageSizeChange"
                    @onCurrentPageChange="onCurrentPageChange">
                </PreviewTable>
            </div>
        </div>

        <!-- 导入生产计划对话框 -->
        <ImportPlan
            ref="ImportPlan"
            @onUploadSuccess="importPlanUploadSuccess">
        </ImportPlan>
    </div>
</template>

<script>
    import PreviewTable from '@/components/PreviewTable'
    import Search from '@/components/Search'
    import ImportPlan from './components/ImportPlan'

    export default {
        name: 'ProductionPlanIndex',
        components: {
            PreviewTable,
            Search,
            ImportPlan
        },
        data () {
            return {
                // 精准搜索关键字列表
                searchList: {},
                // 表格配置项
                tableConfig: {
                    height: 0,
                    data: [],
                    fieldList: [],
                    paginationToggle: true,
                    paginationConfig: {
                        total: 0,
                        currentPage: 1,
                        pageSize: 20
                    }
                }
            }
        },
        methods: {
            // 点击刷新按钮
            doRefreshClick () {
                this.getTableData().then(response => {
                    this.$message.success('刷新成功！')
                })
            },
            // 点击搜索按钮
            doSearchClick (searchValue) {
                this.searchList = _.cloneDeep(searchValue)
                this.tableConfig.paginationConfig.currentPage = 1
                // 获取列表数据
                this.getTableData()
            },
            // 点击重置按钮
            doResetClick (searchValue) {
                this.searchList = { ...searchValue, filters: [] }
                this.tableConfig.paginationConfig.currentPage = 1
                this.tableConfig.paginationConfig.pageSize = 20
                // 获取表格数据
                this.getTableData()
            },
            // 点击导入按钮
            doImportClick () {
                this.$refs.ImportPlan.dialogToggle = true
            },
            // 表格组件分页数量改变事件
            onPageSizeChange (pageSize) {
                this.tableConfig.paginationConfig.currentPage = 1
                this.tableConfig.paginationConfig.pageSize = pageSize
                // 获取列表数据
                this.getTableData()
            },
            // 表格组件分页页数改变事件
            onCurrentPageChange (currentPage) {
                this.tableConfig.paginationConfig.currentPage = currentPage
                // 获取列表数据
                this.getTableData()
            },
            // 获取列表数据
            getTableData () {
                let queryParams = {
                    searchCode: this.searchList.searchCode || 'MES_WORKORDER_INFO',
                    filters: this.searchList.filters || [],
                    pageSize: this.tableConfig.paginationConfig.pageSize,
                    pageNum: this.tableConfig.paginationConfig.currentPage
                }
                return new Promise((resolve, reject) => {
                    this.$fetch('basic-info-controller/workOrder-post', queryParams).then(response => {
                        this.tableConfig.data = _.cloneDeep(response.list)
                        this.tableConfig.paginationConfig.total = _.cloneDeep(response.total)
                        resolve()
                    })
                })
            },
            // 获取列表表头
            getTableLabel () {
                let queryParams = { searchCode: 'MES_WORKORDER_INFO' }
                this.$fetch('show-field-controller/showField-get', queryParams).then(response => {
                    this.tableConfig.fieldList = _.cloneDeep(response)
                })
            },
            // 计划导入成功
            importPlanUploadSuccess () {
                // 获取列表数据
                this.getTableData()
            }
        },
        mounted () {
            setTimeout(() => {
                this.tableConfig.height = document.querySelector('.page-pack').offsetHeight - 210
                // 获取列表数据
                this.getTableData()
                // 获取列表表头
                this.getTableLabel()
            }, 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>
