<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
            
            <el-form-item label="生产工单" prop="workorderCode">
                <el-input
                v-model="queryParams.workorderCode"
                placeholder="请输入生产工单"
                clearable
                @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="物料编码" prop="sapItemCode">
                <el-input
                v-model="queryParams.sapItemCode"
                placeholder="请输入物料编码"
                clearable
                @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="物料名称" prop="itemName">
                <el-input
                v-model="queryParams.itemName"
                placeholder="请输入物料名称"
                clearable
                @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="工艺编码" prop="seRouteCode">
                <el-input
                v-model="queryParams.seRouteCode"
                placeholder="请输入工艺编码"
                clearable
                @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            
            <el-form-item label="状态" prop="statusList">
                <el-select v-model="queryParams.statusList" multiple placeholder="请选择状态" clearable>
                    <el-option
                        v-for="dict in dict.type.se_issue_table_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                        ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button
            type="success"
            plain
            size="mini"
            :disabled="multiple"
            @click="handleSubmit"
            >完成</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="组合单号" align="center" prop="combinationCode" />
        <el-table-column label="生产工单" align="center" prop="workorderCode" />
        <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
            <dict-tag :options="dict.type.se_issue_table_status" :value="scope.row.status"/>
            </template>
        </el-table-column>
        <el-table-column label="物料编码" align="center" prop="sapItemCode" />
        <el-table-column label="物料名称" align="center" prop="itemName" />
        <el-table-column label="数量" align="center" prop="quantity" />
        <el-table-column label="工艺编码" align="center" prop="seRouteCode" />
        <el-table-column label="工艺描述" align="center" prop="seRouteDesc" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleSend(scope.row)"
            >发料</el-button>
            <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleSubmit(scope.row)"
            >完成</el-button>
            </template>
        </el-table-column>
        </el-table>

        <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        />
    </div>
</template>
<script>
import { listSecrecyissue, putSecrecyissue } from "@/api/mes/pro/secretSend";
export default {
    dicts: ['se_issue_table_status'],
    name: "secretSend",
    data() {
        return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 异常信息表格数据
        informationList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
            pageNum: 1,
            pageSize: 10,
            itemName: null,
            statusList: [],
            seRouteCode: null,
            sapItemCode: null,
            abnormalType: null,        workorderCode: null,      },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        getList() {
            this.loading = true;
            listSecrecyissue(this.queryParams).then(response => {
                this.informationList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 表单重置
        reset() {
            this.form = {
                abnormalId: null,
                abnormalType: null,
                userId: null,
                userName: null,
                nickName: null,
                workorderCode: null,
                remark: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null      };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        handleSend(row) {
            const ids = row.id ? [row.id] : this.ids;
            this.$modal.confirm('是否发料？').then(function() {
                return putSecrecyissue({
                status: 0,
                ids: ids
            });
            }).then((res) => {
                if(res.code === 200) {
                    this.getList()
                }
            })
        },
        handleSubmit(row) {
            const ids = row.id ? [row.id] : this.ids;
            this.$modal.confirm('是否完成发料申请？').then(function() {
                return putSecrecyissue({
                status: 1,
                ids: ids
            });
            }).then((res) => {
                if(res.code === 200) {
                    this.getList()
                }
            })
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length!==1
            this.multiple = !selection.length
        }
    }
}
</script>