<template>
    <el-dialog :title="title" v-if="visible" :visible.sync="visible" :before-close="handleClose"
        :close-on-click-modal="true" :close-on-press-escape="false" append-to-body width="70%">

        <el-card shadow="never">
            <planSearch @search="reload" />

            <!-- 数据表格 -->
            <ele-pro-table ref="table" :columns="columns" :datasource="datasource" :selection.sync="selection" row-key="id">

            </ele-pro-table>


        </el-card>

        <div class="btns">
            <el-button type="primary" size="small" @click="selected">选择</el-button>
            <el-button size="small" @click="handleClose">关闭</el-button>
        </div>
    </el-dialog>
</template>

<script>
import planSearch from './planSearch.vue'
import { getList } from '@/api/productionPlan';
import dictMixins from '@/mixins/dictMixins';
export default {
    components: { planSearch },
    mixins: [dictMixins],
    data() {
        return {
            visible: false,
            title: '生产订单',

            // 表格列配置
            columns: [
              {
                width: 45,
                type: 'selection',
                columnKey: 'selection',
                align: 'center',
                slot: 'selection'
              },
              {
                columnKey: 'index',
                label: '序号',
                type: 'index',
                width: 55,
                align: 'center',
                showOverflowTooltip: true
              },

              {
                slot: 'batchNo',
                prop: 'batchNo',
                label: '批次号',
                align: 'center',
                minWidth: 140,
                sortable: true
              },

              {
                slot: 'code',
                prop: 'code',
                action: 'code',
                label: '计划编号',
                align: 'center',

                minWidth: 160,
                sortable: true
              },

              {
                prop: 'salesCode',
                action: 'salesCode',
                label: '销售订单号',
                align: 'center',
                minWidth: 160
              },

              {
                prop: 'productCode',
                label: '编码',
                align: 'center',

                minWidth: 140
              },
              {
                prop: 'productName',
                label: '名称',
                align: 'center',

                minWidth: 140
              },

              {
                prop: 'brandNo',
                label: '牌号',
                align: 'center',
                showOverflowTooltip: true
              },

              {
                prop: 'specification',
                label: '规格',
                align: 'center',
                minWidth: 150,

                showOverflowTooltip: true
              },
              {
                prop: 'model',
                label: '型号',
                align: 'center',
                showOverflowTooltip: true
              },

              {
                prop: 'priority',
                label: '优先级',
                align: 'center',
                minWidth: 120,
                slot: 'priority',
                sortable: 'custom'
              },

              {
                prop: 'produceRoutingName',
                label: '工艺路线',
                align: 'center',
                width: 140,
                showOverflowTooltip: true
              },

              {
                prop: 'productNum',
                label: '计划数量',
                align: 'center',

                slot: 'productNum'
              },
              {
                prop: 'productWeight',
                label: '计划重量',
                align: 'center',

                slot: 'productWeight'
              },
              {
                prop: 'requiredFormingNum',
                label: '要求生产数量',
                align: 'center',

                slot: 'requiredFormingNum'
              },

              {
                prop: 'newSumOrderWeight',
                label: '要求生产重量',
                align: 'center',

                slot: 'newSumOrderWeight'
              },

              {
                prop: 'scheduleStatusName',
                label: '进度状态',
                align: 'center',
                minWidth: 100
              },

              {
                prop: '',
                label: '已排产数量',
                align: 'center',
                showOverflowTooltip: true
              },

              {
                prop: '',
                label: '未排产数量',
                align: 'center',
                showOverflowTooltip: true
              },
              {
                prop: '',
                label: '已生产数量',
                align: 'center',
                showOverflowTooltip: true
              },

              {
                prop: '',
                label: '未生产数量',
                align: 'center',
                showOverflowTooltip: true
              },


            ],

            // 表格选中数据
            selection: [],

            tableData: [],
            current: null

        }
    },

    watch: {

    },
    created() {
        this.requestDict('生产状态');
    },
    methods: {

        open(item) {
            if (item) {
                this.tableData = item
            }

            this.visible = true

        },


        /* 表格数据源 */
        async datasource({ page, limit, where }) {
            where.status = [1, 2, 3, 4, 7, 8]
            const data = await getList({
                ...where,
                pageNum: page,
                size: limit
            });

            return data;
        },

        /* 刷新表格 */
        reload(where) {
            this.$refs.table.reload({ page: 1, where: where });
        },






        handleClose() {
            this.visible = false
            this.$refs.table.setSelectedRows([]);
            this.selection = []

        },
        selected() {

            if (!this.selection.length) {
                this.$message.error('请至少选择一条数据');
                return;
            }
            this.$emit('selectPlan', this.selection)
            this.handleClose()
        },
    }
}
</script>

<style lang="scss" scoped>
.btns {
    text-align: center;
    padding: 10px 0;
}
</style>
