/**
 *
 * @author BOGON
 * @version 1.0
 */

var page = {
    submitFlag: 0,
    initDatagrid: function () {
        $("#tb").datagrid({
            url: g.ctx + 'pc/spe/rectifiedNotice/rest/rectifiedSupplierList?planId=' + id,
            method: "GET",
            loadMsg: '数据远程载入中,请等待...',
            singleSelect: false,
            pagination: false,
            checkbox: true,
            rownumbers: true,
            height: document.documentElement.clientHeight - 20,
            columns: [[
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'status',
                    title: '状态',
                    width: 80,
                    formatter: function (value, row) {
                        if (value === 1) {
                            return '<span style="color: darkgreen">已提交整改</span>'
                        }
                        return '未提交整改'
                    }
                },
                {
                    field: 'supplierCode',
                    title: '供应商编码',
                    width: 110
                },
                {
                    field: 'supplierName',
                    title: '供应商名称',
                    width: 110
                },
                {
                    field: 'level',
                    title: '等级',
                    width: 200
                },
                {
                    field: 'remark1',
                    title: '备注1',
                    width: 300
                },
                {
                    field: 'remark2',
                    title: '备注2',
                    width: 300
                }
            ]]
        });
    },
    saveData: function (callback) {
        let datagrid = $("#tb").datagrid("getChecked");
        if (datagrid.length === 0) {
            topWin.layer.msg('请选择要提交的供应商', {icon: 2});
            return
        }
        if (page.submitFlag === 1) {
            return
        }
        page.submitFlag = 1
        var load = topWin.layer.load(2);
        let ids = datagrid.map(a => a.id).join(',')
        $.ajax({
            type: 'POST',
            url: g.ctx + 'pc/spe/rectifiedNotice/rest/saveBatchNotice',
            data: {ids: ids, id: id},
            complete: function () {
                topWin.layer.close(load)
                page.submitFlag = 0
            },
            success: function () {
                topWin.layer.msg('操作成功', {icon: 1, time: 500}, function () {
                    callback();
                });
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    }
}
$(function () {
    page.initDatagrid()
})