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

        <el-card shadow="never">
            <user-search @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 producetask from '@/api/technology/production';
import userSearch from '@/views/technology/production/components/user-search.vue'
export default {
    components: {
        userSearch
    },
    data() {
        return {
            visible: false,
            title: '选择工序',

            // 表格列配置
            columns: [
                {
                    columnKey: 'selection',
                    type: 'selection',
                    width: 45,
                    align: 'center',
                    selectable: (row, index) => {
                        return !this.processData.some((it) => it.id == row.id);
                    },
                    reserveSelection: true,
                    fixed: 'left'
                },

                {
                    prop: 'code',
                    label: '工序编码',
                    // sortable: 'custom',
                    showOverflowTooltip: true,
                    align: 'center',
                    minWidth: 110
                },
                {
                    prop: 'name',
                    label: '工序名称',
                    showOverflowTooltip: true,
                    align: 'center',
                    minWidth: 110
                },
                {
                    align: 'center',
                    prop: 'controlName',
                    label: '工序控制码',
                    showOverflowTooltip: true,
                    minWidth: 110
                },
                {
                    prop: 'workCenterName',
                    label: '所属工作中心',
                    align: 'center',
                    showOverflowTooltip: true,
                    minWidth: 110
                },





            ],

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

            processData: []

        }
    },

    watch: {

    },
    methods: {


        /* 表格数据源 */
        async datasource({ page, limit, where, order }) {
            const res = await parameter.list({
                ...where,
                ...order,
                pageNum: page,
                size: limit
            });
            return res;
        },

        open(item) {
            if (item) {
                this.processData = item

            }
            this.visible = true
        },

        /* 表格数据源 */
        async datasource({ page, limit, where, order }) {
            const res = await producetask.list({
                ...where,
                ...order,
                pageNum: page,
                size: limit
            });
            return res;
        },

        /* 刷新表格 */
        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('chooseProcess', this.selection)
            this.handleClose()
        },
    }
}
</script>
  
<style lang="scss" scoped>
.btns {
    text-align: center;
    padding: 10px 0;
}
</style>
  