/**
 *
 * @author BOGON
 * @version 1.0
 */
var submitFlag = 0
var benchmarksComm = {
    dictCodes: [],
    necessaryExt: [],
    defaultColumns: [],
    bidFileGrid: {}, initTenderDetailDataGrid: function (fieldArray, id, readOnly, templateId) {
        var toolbars = [{
            text: '分数导出', iconCls: 'icon-coins', hidden: true, handler: function () {
                //需要导出分数然后再导入
                const fields = [
                    {
                        field: "bidId",
                        title: "",
                        width: 0
                    },
                    {
                        field: "id",
                        title: "",
                        width: 0
                    },
                    {
                        field: "rowNo",
                        title: "招标行"
                    },
                    {
                        field: "supplierCode",
                        title: "供应商编码"
                    },
                    {
                        field: "supplierName",
                        title: "供应商名称"
                    },
                    {
                        field: "materialCode",
                        title: "物料编码"
                    },
                    {
                        field: "materialName",
                        title: "物料名称"
                    },
                    {
                        field: "dcTouch",
                        title: "技术分"
                    },
                    {
                        field: "dcBusiness",
                        title: "商务分"
                    }
                ]
                exportFixedGrid('pc/tender/benchmarks/rest/exportScore', fields, {tenderId: id});
            }
        }, "-", {
            text: '分数导入', iconCls: 'icon-coins', hidden: true, handler: function () {
                var rows = benchmarksComm.tenderDetailDataGrid.datagrid("getRows");
                var notOk = rows.filter(function (row) {
                    return row.ok === 0;
                });
                if (notOk.length > 0) {
                    topWin.layer.alert("明细价格与总价格不一致，请议价调整!", {icon: 2});
                    return;
                }
                $("#scoreUpload .filebox-label").click();
            }
        }, "-", {
            text: '议价', iconCls: 'icon-coins-add', hidden: true, handler: function () {
                var rows = benchmarksComm.tenderDetailDataGrid.datagrid("getChecked");
                if (rows.length <= 0) {
                    topWin.layer.msg("请选择一条数据!");
                    return;
                }
                $.ajax({
                    url: g.ctx + 'pc/tender/benchmarks/rest/submitBargaining',
                    type: "POST",
                    contentType: 'application/json',
                    data: JSON.stringify(rows),
                    success: function () {
                        topWin.layer.alert("操作成功", {
                            icon: 1, closeBtn: 0, yes: function (index) {
                                topWin.layer.close(index);
                                benchmarksComm.tenderDetailDataGrid.datagrid("reload");
                            }
                        });
                    }, error: function () {
                        topWin.layer.alert(data.responseJSON.message, {icon: 2});
                    }
                });
            }
        }, '-', {
            text: '截止议价', iconCls: 'icon-coins-add', hidden: true, handler: function () {
                var rows = benchmarksComm.tenderDetailDataGrid.datagrid("getRows");
                const ids = rows.filter(a => a.bargainingStatus == 1 || a.bargainingStatus == 2).map(row => row.id);
                if (ids.length <= 0) {
                    topWin.layer.msg("当前没有议价中的数据!");
                    return;
                }

                topWin.layer.confirm('确定截止议价吗？', {icon: 3, title: '提示'}, function (index) {
                    $.ajax({
                        url: g.ctx + 'pc/tender/benchmarks/rest/stopBargaining',
                        type: "POST",
                        contentType: 'application/json',
                        data: JSON.stringify(ids),
                        success: function () {
                            topWin.layer.alert("操作成功", {
                                icon: 1, closeBtn: 0, yes: function (iindex) {
                                    topWin.layer.close(index);
                                    topWin.layer.close(iindex);
                                    benchmarksComm.tenderDetailDataGrid.datagrid("reload");
                                }
                            });
                        }, error: function () {
                            topWin.layer.alert(data.responseJSON.message, {icon: 2});
                        }
                    });
                })
            }
        }, "-", {
            text: '导出', iconCls: 'icon-download', handler: function () {
                openExportDialog('pc/tender/benchmarks/rest/exportBidDetail', 'project_table', {tenderId: id});
            }
        }, "-", {
            text: '导入', iconCls: 'icon-import', handler: function () {
                $('#project_table').edatagrid("saveRow")
                $("#detailUpload .filebox-label").click();
            }
        }, "-", {
            text: '标记分项最优', iconCls: 'icon-coins-add', hidden: true, handler: function () {
                var rows = benchmarksComm.tenderDetailDataGrid.datagrid("getRows");
                var loading = topWin.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                $.each(rows, function (idx, itm) {
                    let rowIndex = benchmarksComm.tenderDetailDataGrid.datagrid("getRowIndex", itm)
                    if (itm.benchmarksRank === 1) {
                        benchmarksComm.tenderDetailDataGrid.datagrid("updateRow", {
                            index: rowIndex,
                            row: {status: 1}
                        })
                    } else {
                        benchmarksComm.tenderDetailDataGrid.datagrid("updateRow", {
                            index: rowIndex,
                            row: {status: 0}
                        })
                    }
                })
                topWin.layer.close(loading)
            }
        }, '-', {
            text: '标记排名最优', iconCls: 'icon-coins-add', hidden: true, handler: function () {
                var rows = benchmarksComm.tenderDetailDataGrid.datagrid("getRows");
                var loading = topWin.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                $.each(rows, function (idx, itm) {
                    let rowIndex = benchmarksComm.tenderDetailDataGrid.datagrid("getRowIndex", itm)
                    if (itm.ranking === 1) {
                        benchmarksComm.tenderDetailDataGrid.datagrid("updateRow", {
                            index: rowIndex,
                            row: {status: 1}
                        })
                    } else {
                        benchmarksComm.tenderDetailDataGrid.datagrid("updateRow", {
                            index: rowIndex,
                            row: {status: 0}
                        })
                    }
                })
                topWin.layer.close(loading)
            }
        }, '-', {
            text: '计算配额', iconCls: 'icon-coins-add', handler: function () {
                if (submitFlag === 1) {
                    return
                }
                var postData = {
                    id: id
                }
                postData.bidDetails = benchmarksComm.tenderDetailDataGrid.datagrid("getRows");
                var filteredRows = postData.bidDetails.filter(function (row) {
                    return row.bargainingStatus === 1;
                });
                if (filteredRows.length > 0) {
                    topWin.layer.alert("请先截止议价再定标!", {icon: 2});
                    return;
                }
                var notOk = postData.bidDetails.filter(function (row) {
                    return row.ok === 0;
                });
                if (notOk.length > 0) {
                    topWin.layer.alert("明细价格与总价格不一致，请议价调整!", {icon: 2});
                    return;
                }
                //需要判断是否选中了中标供应商
                let bidedRows = postData.bidDetails.filter(a => (a.status + "") === "1");
                if (bidedRows.length === 0) {
                    topWin.layer.alert("请选择中标供应商再定标!", {icon: 2});
                    return;
                }
                postData.bidDetails = bidedRows
                submitFlag = 1
                var index = topWin.layer.load(0, {
                    shade: [0.6, '#eee'] //0.1透明度的白色背景
                });
                $.ajax({
                    url: g.ctx + 'pc/tender/benchmarks/rest/calculateQuotas',
                    type: "POST", contentType: 'application/json',
                    data: JSON.stringify(postData),
                    complete: function () {
                        submitFlag = 0
                        topWin.layer.close(index)
                    },
                    success: function (data) {
                        topWin.layer.alert("操作成功", {icon: 1}, function (idx) {
                            topWin.layer.close(idx);
                            benchmarksComm.tenderDetailDataGrid.datagrid("reload");
                        });
                    },
                    error: function (data) {
                        topWin.layer.alert(data.responseJSON.message, {icon: 2});
                    }
                });
            }
        }, {
            text: '数据补充导入',
            iconCls: 'icon-import',
            handler: function () {
                var importDialog = openQueryImportExcelDialog('pc/tender/benchmarks/rest/exportMaterial?tenderId=' + id, {}, '数据补充导入', function (file) {
                    let formData = new FormData();
                    formData.append("file", file);
                    var loading = topWin.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                    $.ajax({
                        url: g.ctx + 'pc/tender/benchmarks/rest/importMaterial',
                        method: "POST",
                        data: formData,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                            topWin.layer.alert("导入成功", {icon: 1}, function (idx) {
                                topWin.layer.close(idx);
                                $(el.tb).datagrid('reload');
                                importDialog.dialog('close');
                            });
                        },
                        complete: function (data) {
                            topWin.layer.close(loading);
                        },
                        error: function (data) {
                            topWin.layer.alert(JSON.parse(data.responseText).message, {
                                icon: 2,
                                shadeClose: true,
                                title: '温馨提示'
                            });
                        }
                    });
                });
            }
        }];
        var scoreColumns = [];
        if (fieldArray.dc.length !== 1) {
            $.each(fieldArray.dc, function (index, item) {
                scoreColumns.push({
                    field: toCamelCase(item.code),
                    title: item.name,
                    width: 80,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value
                    }
                });
            });
        }
        var frozenColumns = [{
            field: 'ck', checkbox: true, width: 50,
        }, {
            field: 'benchmarksRank', title: '排名', width: 50, align: 'center'
        }, {
            field: 'bargainingStatus', title: '议价状态', width: 70,
            exportEnum: [
                {code: 0, codeWithDesc: '未议价'},
                {code: 1, codeWithDesc: '议价中'},
                {code: 2, codeWithDesc: '议价已回复'},
                {code: 3, codeWithDesc: '议价截止'},
            ],
            align: 'center', formatter: function (val) {
                if (val == 1) {
                    return '<span style="color: red">' + "议价中" + '</span>'
                } else if (val == 2) {
                    return '<span style="color: green">' + "议价已回复" + '</span>'
                } else if (val == 0) {
                    return '<span style="color: black">' + "未议价" + '</span>'
                } else if (val == 3) {
                    return '<span style="color: darkgrey">' + "议价截止" + '</span>'
                }

            }
        }, {
            field: 'materialCode', title: '物料编码', align: 'center', width: 105
        }, {
            field: 'materialName', title: '物料名称', align: 'left', width: 230, formatter: function (value, row) {
                if (value == '') {
                    return '';
                }
                return '<span title="' + value + '">' + value + '</span>';
            }
        }, {
            field: 'supplierCode', title: '供应商编码', align: 'center'
        }, {
            field: 'supplierName',
            width: 230,
            title: '供应商名称',
            align: 'center',
            formatter: function (value, row, index) {
                return '<span class="inli¬ne-block text-middle">' + value + '</span>';
            }
        }, {
            field: 'status', title: '是否中标',
            exportEnum: [{code: 1, codeWithDesc: '是'}, {code: 0, codeWithDesc: '否'}],
            align: 'center', formatter: function (value, row, index) {
                if (value == 1) {
                    return '是';
                } else {
                    return '否';
                }
            },
            styler: function (value, row, index) {
                if (value == 1) {
                    return 'background-color:#f4b084;';
                }
            },
            editor: {
                type: 'combobox', options: {
                    prompt: "请输入",
                    valueField: 'value',
                    editable: false,
                    panelHeight: 'auto',
                    textField: 'label',
                    data: [{
                        label: '是', value: 1
                    }, {
                        label: '否', value: 0
                    }]
                }
            },
        }, {
            field: 'currency',
            width: 100,
            title: '报价币种',
            align: 'center',
            function(value, row, index) {
                return getDicName("currency", value)
            }
        }
        ];
        benchmarksComm.dictCodes.push("currency")
        var defaultCol = [
            {
                field: 'finalCnyAmount',
                title: '换算后未税单价(CNY)',
                width: 135,
                align: 'center',
                rowspan: 2,
                styler: function (value, row, index) {
                    return 'background-color:#f4b084;';
                }
            },
            {
                field: 'detailSumAmount',
                title: '含税金额(原币)',
                width: 100,
                align: 'center',
                rowspan: 2
            }, {
                field: 'detailTotalAmount',
                title: '未税金额(CNY)',
                width: 100,
                align: 'center',
                rowspan: 2
            },
             {
                field: 'quota', title: '定标配额', width: 100, align: 'center', rowspan: 2, editor: {
                    type: 'numberbox', options: {
                        prompt: "请输入", min: 0, max: 100, precision: 2
                    }
                }, formatter: function (val, row, index) {
                    if (val || val === 0) {
                        return (val) + "%";
                    } else {
                        return '';
                    }
                }

            }, {
                field: 'bidNum', title: '定标数量', width: 80, align: 'center', rowspan: 2, editor: {
                    type: 'numberbox', options: {
                        min: 0, // prompt: "请输入",
                        precision: 2
                    }
                }
            }, {
                field: 'bidRemark', title: '定标备注', width: 100, align: 'center', rowspan: 2, editor: {
                    type: 'textbox', options: {
                        prompt: "请输入"
                    }
                }
            }, {
                field: 'bargaining', title: '期望含税单价(原币)', width: 100, align: 'center', rowspan: 2, editor: {
                    type: 'numberbox', options: {
                        min: 0, precision: priceHandle.precision
                    }
                }
            }, {
                field: 'bargainingRemark', title: '议价备注', width: 100, align: 'center', rowspan: 2, editor: {
                    type: 'textbox', prompt: "请输入", options: {}
                }
            }, {
                field: 'finalPrice',
                title: '最终含税单价(原币)',
                width: 120,
                align: 'center',
                rowspan: 2,
                styler: function (value, row, index) {
                    return 'background-color:#f4b084;';
                }
            },
            {
                field: 'historyPrice',
                title: '历史未税单价(CNY)',
                width: 125,
                align: 'center',
                rowspan: 2
            },
            {
                field: 'decline',
                title: '涨降幅',
                width: 65,
                align: 'center',
                rowspan: 2,
                formatter: function (value, row, index) {
                    if (value) {
                        if (value.indexOf("-")) {
                            return '<span style="color: red;">' + value + '</span>';
                        } else {
                            return value;
                        }
                    }
                    return value
                }
            },
            {
                field: 'bargainingSupplierRemark', title: '回复议价备注', width: 100, align: 'center', rowspan: 2
            },{
                field: 'sumAmount',
                title: '含税总价(原币)',
                width: 100,
                align: 'center',
                rowspan: 2
            }, {
                field: 'totalAmount',
                title: '未税总价(CNY)',
                width: 100,
                align: 'center',
                rowspan: 2
            }, {
                field: 'materialName',
                title: '报价物料名称',
                width: 100,
                align: 'center',
                rowspan: 2
            }, {
                field: 'materialBrand',
                title: '报价品牌',
                width: 100,
                align: 'center',
                rowspan: 2
            }, {
                field: 'materialDesc',
                title: '报价详细规格参数',
                width: 100,
                align: 'center',
                rowspan: 2
            }];
        if (page.scoreFlag === 1) {
            defaultCol.unshift({
                field: '1', title: '评标分项', align: 'center', colspan: fieldArray.dc.length
            });
        }
        debugger
        var tenderFieldClum = []
        $.each(fieldArray.fields, function (index, item) {
            if (item.fieldName === 'material_code'
                || item.fieldName === 'material_name'
                || item.fieldName === 'currency') {
                return true;
            }
            if (item.fieldName === 'tax_price') {
                item.fieldAlias = '最初含税单价(原币)'
            }
            debugger
            let col = {
                field: toCamelCase(item.fieldName),
                title: item.fieldAlias === '' ? item.labelName : item.fieldAlias,
                width: 100,
                align: 'center',
                rowspan: 2
            }
            if (item.fieldType === 'numeric') {
                col.formatter = function (value) {
                    return formatterPrice(value)
                }
            } else if (item.fieldType === 'date') {
                col.formatter = function (value, row, index) {
                    if (value === '') {
                        return '';
                    }
                    return moment(value).format("YYYY-MM-DD");
                }
            } else if (item.fieldType === 'dict') {
                benchmarksComm.dictCodes.push(item.extVal)
                col.formatter = function (value, row, index) {
                    return getDicName(item.extVal, value)
                }
            } else if (item.fieldType === 'data') {
                benchmarksComm.necessaryExt.push(item.extVal)
                col.formatter = function (value, row, index) {
                    return getNecessaryDataName(item.extVal, value)
                }
            }
            tenderFieldClum.push(col)
        });
        debugger
        if (readOnly) {
            toolbars = []
            //只读需要把editor给删掉
            $.each(frozenColumns, function (idx, itm) {
                if (itm.editor) {
                    delete itm.editor
                }
            })
            //只读需要把editor给删掉
            $.each(defaultCol, function (idx, itm) {
                if (itm.editor) {
                    delete itm.editor
                }
            })
            $.each(tenderFieldClum, function (idx, itm) {
                if (itm.editor) {
                    delete itm.editor
                }
            })
        }
        debugger
        // var columns = []
        if (page.mroFlag) {
            if (page.scoreFlag === 0) {
                tenderFieldClum.push(...defaultCol)
                benchmarksComm.defaultColumns = [tenderFieldClum, scoreColumns];
            } else {
                defaultCol.splice(1, 0, ...tenderFieldClum)
                benchmarksComm.defaultColumns = [defaultCol, scoreColumns];
            }
        } else {
            defaultCol.push(...tenderFieldClum)
            benchmarksComm.defaultColumns = [defaultCol, scoreColumns];
        }
        if (page.scoreFlag === 0) {
            toolbars = toolbars.slice(4);
            //需要把评分项去掉
            $.each(defaultCol, function () {
                delete this.rowspan
            })
            benchmarksComm.defaultColumns = [defaultCol];
        }

        if (benchmarksComm.dictCodes.length > 0) {
            initDict(benchmarksComm.dictCodes.join(","))
        }
        if (benchmarksComm.necessaryExt.length > 0) {
            initNecessaryDatas(benchmarksComm.necessaryExt.join(","))
        }
        //通过编码查询数据库列排序
        //需要删除评分列
        let first = benchmarksComm.defaultColumns[0][0]
        let colums = []
        if (first.title === '评标分项') {
            colums = benchmarksComm.defaultColumns[0].slice(1)
        } else {
            colums = benchmarksComm.defaultColumns[0]
        }
        let column = getRemoteColumnSort(columnSortCodeEnum.BID_DETAIL + templateId, colums);
        let clm = []
        if (benchmarksComm.defaultColumns[1] != undefined && benchmarksComm.defaultColumns[1].length > 0) {
            column.splice(0, 0, {
                field: '1', title: '评标分项', align: 'center', colspan: fieldArray.dc.length
            });
            clm.push(column, benchmarksComm.defaultColumns[1])
        } else {
            clm.push(column)
        }
        toolbars.push({
            text: '列设置',
            iconCls: 'icon-anchor',
            id: 'btn_column_sort',
            handler: function () {
                let first = benchmarksComm.defaultColumns[0][0]
                let colums = []
                if (first.title === '评标分项') {
                    colums = benchmarksComm.defaultColumns[0].slice(1)
                } else {
                    colums = benchmarksComm.defaultColumns[0]
                }
                openSortDialog({
                    //唯一编码
                    code: columnSortCodeEnum.BID_DETAIL + templateId,
                    //初始列（每次新增或删除列需要手动删除sys_column_sort表中对应code数据）
                    columns: colums,
                    callBack: function (newColumns) {
                        benchmarksComm.initTenderDetailDataGrid(fieldArray, id, readOnly, templateId);
                    },
                });
            }
        })
        toolbars.push({
            text: '查询选中',
            iconCls: 'icon-ok',
            id: 'btn_column_sort',
            handler: function () {
                topWin.layer.prompt({title: '请输入供应商编码', formType: 2, maxlength: 255}, function (text, index) {
                    text= text.replace(/(\r\n|\n|\r)/gm, " ")
                    var arr = text.split(' ');
                    var rows = benchmarksComm.tenderDetailDataGrid.datagrid("getRows");
                    var loading = topWin.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                    $.each(rows, function (idx, itm) {
                        let rowIndex = benchmarksComm.tenderDetailDataGrid.datagrid("getRowIndex", itm)
                        $.each(arr, function (idx1, itm1) {
                            //如果供应商编码包含输入的itm1
                            if (itm1&&itm.supplierCode.indexOf(itm1) > -1) {
                                benchmarksComm.tenderDetailDataGrid.datagrid('selectRow', rowIndex);
                            }
                        })
                    })
                    topWin.layer.close(loading)
                    topWin.layer.close(index);
                });

            }
        })
        benchmarksComm.tenderDetailDataGrid = $('#project_table').edatagrid({
            width: '100%',
            height: '520px',
            url: g.ctx + 'pc/tender/benchmarks/rest/getQuoteDetails?id=' + id,
            loadMsg: "数据加载中......",
            method: "GET",
            nowrap: true,
            singleSelect: false,
            collapsible: false,
            frozenColumns: [frozenColumns],
            columns: clm,
            view: mygroupview,
            autoSave: true,
            groupField: 'rowNo',
            rowStyler: function (index, row) {
                if (row.ok === 0) {
                    return "background-color:#eea2a4"
                }
                return ''
            },
            groupFormatter: function (value, rows) {
                var materialName;
                if (rows.length > 0) {
                    var row = rows[0];
                    materialName = row.materialName;
                }
                return '<span class="inline-block text-middle" style="color: blue;">' + materialName + '（ ' + value + ' ）</span>';
            },
            toolbar: toolbars,
        });
    },
    initBidFileTable: function (id) {
        var toolbar = [{
            text: '下载全部附件', iconCls: 'icon-download', handler: () => {
                window.open(g.ctx + 'pc/tender/benchmarks/rest/downloadZip?tenderId=' + id);
            }
        }];
        var columns = [{
            field: 'supplierCode', title: '供应商编号', width: 140, align: 'center'

        }, {
            field: 'supplierName', title: '供应商名称', width: 250

        }, {
            field: 'fileName', title: '文件名', width: 250

        }, {
            field: 'fileId', title: '下载', width: 410, formatter: function (value, row, index) {
                return '<a href="' + g.ctx + 'pc/sys/file/rest/download/' + value + '">下载</a>';
            }
        }];
        benchmarksComm.bidFileGrid = $('#bid_file_table').datagrid({
            width: '100%',
            height: '400px',
            pagination: false,
            url: g.ctx + 'pc/tender/benchmarks/rest/getBidFileList',
            queryParams: {tenderId: id},
            loadMsg: "数据加载中......",
            method: "GET",
            nowrap: true,
            singleSelect: true,
            collapsible: false,
            columns: [columns],
            toolbar: toolbar,
            onLoadSuccess: function (data) {
                //需要合并相同供应商的附件
                let rows = data.rows
                let mm = {}
                for (var i = 0; i < rows.length; i++) {
                    if (mm[rows[i].supplierCode] == undefined) {
                        mm[rows[i].supplierCode] = {idx: i, rowspan: 1}
                    } else {
                        let tmp = mm[rows[i].supplierCode]
                        tmp.rowspan += 1
                        mm[rows[i].supplierCode] = tmp
                    }
                }
                $.each(mm, function (iii, tttt) {
                    benchmarksComm.bidFileGrid.datagrid("mergeCells", {
                        index: tttt.idx, field: "supplierCode", rowspan: tttt.rowspan
                    })
                    benchmarksComm.bidFileGrid.datagrid("mergeCells", {
                        index: tttt.idx, field: "supplierName", rowspan: tttt.rowspan
                    })
                })

            }
        });
    }
    ,
    loadField: function (id, readOnly, templateId) {
        $.ajax({
            url: g.ctx + 'pc/tender/benchmarks/rest/getFields', data: {id: id}, success: function (d) {
                benchmarksComm.initTenderDetailDataGrid(d, id, readOnly, templateId);
            }
        })
    }
    ,
    loadApproverLog: function (id) {
        $("#approverLogTb").datagrid({
            loadMsg: '数据加载中, 请耐心等待......',
            method: "GET",
            height: window.innerHeight - 55,
            url: g.ctx + 'pc/tender/benchmarks/rest/approvelList?id=' + id,
            singleSelect: false,
            rownumbers: true,
            remoteSort: false,
            pagination: false,
            columns: [
                [
                    {
                        field: 'approveNode',
                        title: '审批节点描述',
                        width: 120,
                        formatter: function (value) {
                            if (Number(value) === 1) {
                                return '主管确认';
                            } else {
                                return '总监审批';
                            }
                        }
                    },
                    {
                        field: 'approveResult',
                        title: '审批结果',
                        width: 120,
                        formatter: function (value) {
                            switch (Number(value)) {
                                case 0:
                                    return '<span style="color: red;">拒绝</span>';
                                case 1:
                                    return '<span style="color: green;">同意</span>';
                                default:
                                    return '';
                            }
                        }
                    },
                    {
                        field: 'approveOpinion',
                        title: '审批意见',
                        width: 300
                    },
                    {
                        field: 'approveUserName',
                        title: '审批用户姓名',
                        width: 130
                    },
                    {
                        field: 'approveTime',
                        title: '审批时间',
                        width: 140,
                        sortable: true
                    }
                ]
            ]
        });
    },
    isReadOnly: function () {
        if (type === 0 || type === 2) {
            return true;
        }
        return false;
    }
    ,
    scoreImport: function () {
        var filebox = $("#scoreFileInput").filebox("files");
        if (filebox.length == 1) {
            var formData = new FormData();
            formData.append("file", filebox[0]);
            var index = topWin.layer.load(1, {
                shade: [0.1, '#eee'] //0.1透明度的白色背景
            });
            $.ajax({
                url: g.ctx + 'pc/tender/benchmarks/rest/importScore/' + id,
                data: formData,
                type: 'post',
                contentType: false,
                processData: false,
                complete: function () {
                    $("#scoreFileInput").filebox("clear");
                    topWin.layer.close(index);
                },
                success: function (d) {
                    benchmarksComm.tenderDetailDataGrid.datagrid("reload");
                },
                error: function (data) {
                    topWin.layer.alert(data.responseJSON.message, {icon: 2});
                }
            })
        }
    },
    detailImport: function () {
        var filebox = $("#detailFileInput").filebox("files");
        if (filebox.length == 1) {
            var formData = new FormData();
            formData.append("file", filebox[0]);
            var index = topWin.layer.load(1, {
                shade: [0.1, '#eee'] //0.1透明度的白色背景
            });
            $.ajax({
                url: g.ctx + 'pc/tender/benchmarks/rest/importItem',
                data: formData,
                type: 'post',
                contentType: false,
                processData: false,
                complete: function () {
                    $("#detailFileInput").filebox("clear");
                },
                success: function (d) {
                    //需要更新数据
                    let cache = d.reduce((acc, item) => {
                        acc[item.id] = item;
                        return acc;
                    }, {});
                    let rows = $('#project_table').datagrid("getRows");
                    $.each(rows, function (index, item) {
                        let rowIndex = $('#project_table').datagrid("getRowIndex", item)
                        let element = cache[item.id];
                        $('#project_table').datagrid("updateRow", {
                            index: rowIndex, row: {
                                status: element.status === '是' ? 1 : 0,
                                quota: element.quota,
                                bidNum: element.bidNum,
                                bidRemark: element.bidRemark,
                                bargaining:element.bargaining,
                                bargainingRemark:element.bargainingRemark
                            }
                        })
                    })
                    topWin.layer.close(index);
                },
                error: function (data) {
                    topWin.layer.close(index);
                    topWin.layer.alert(data.responseJSON.message, {icon: 2});
                }
            })
        }
    },
    initRankingTable: function (id,templateId) {
        $("#supplierRankTb").datagrid({
            loadMsg: '数据加载中, 请耐心等待......',
            method: "GET",
            height: '200px',
            url: g.ctx + 'pc/tender/benchmarks/rest/supplierRankList?id=' + id,
            singleSelect: false,
            remoteSort: false,
            pagination: false,
            columns: [
                [
                    {
                        field: 'ranking',
                        title: '排名',
                        align: 'center',
                        width: 60,
                        formatter: function (value, row, index) {
                            return '<span style="color: red;">' + value + '</span>'
                        }
                    },
                    {
                        field: 'supplierCode',
                        title: '供应商编码',
                        align: 'center',
                        width: 120
                    },
                    {
                        field: 'supplierName',
                        title: '供应商名称',
                        width: 200
                    },
                    {
                        field: 'finalCnyAmount',
                        title: '未税总价(CNY)',
                        width: 100,
                        align: 'center'
                    },
                    {
                        field: 'finalAmount',
                        title: '含税总价(原币)',
                        width: 100,
                        align: 'center'
                    }
                ]
            ],
            onLoadSuccess: function () {
                // 动态切换列可见性（确保覆盖初始化状态）
                if (templateId === '412') { //412:MRO招标模板
                    $(this).datagrid('showColumn', 'finalAmount');
                } else {
                    $(this).datagrid('hideColumn', 'finalAmount');
                }
            }
        });
    }
}