var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    purchaseGroupCode: '#purchaseGroupCode',
    status: '#status',
    quotaStatus: '#quotaStatus',
    statusLists: '#statusLists',
    inquiryType: '#inquiryType',
    purchaseType: '#purchaseType',
    btn_add: '#btn_add',
    btn_edit: '#btn_edit',
    btn_copy: '#btn_copy',
    btn_publish: '#btn_publish',
    btn_end: '#btn_end',
    btn_remove: '#btn_remove',
    btn_cancel: '#btn_cancel',
    btn_add_supplier: '#btn_add_supplier',
    bodyHeight: document.documentElement.clientHeight
};

$(function () {
    initDict('inquiry_type');
    initNecessaryDatas('pc/sys/purchaseOrg/rest/listAll,pc/sys/purchaseGroup/rest/listAll,pc/sys/company/rest/listAll');
    initCombo();
    loadGrid();
});
/**
 * 初始化下拉框
 */
function initCombo() {

    $(el.purchaseGroupCode).combobox({
        valueField: 'purchaseGroupCode',
        textField: 'codeWithDesc',
        method: 'POST',
        // panelHeight: 200,
        // panelWidth: 240,
        prompt: '--- 请选择 ---',
        url: g.ctx + 'pc/sys/purchaseGroup/rest/listAll'
    });
    $(el.statusLists).combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        data: [
            {value: 0, label: '全部'},
            {value: 1, label: '新建'},
            {value: 2, label: '已发布'},
            // {value: 11, label: '报价完成'},
            {value: 3, label: '截止'},
            {value: 4, label: '取消'},
            {value: 6, label: '定价OA审批中'},
            {value: 7, label: '定价OA审批拒绝'},
            {value: 8, label: '定价OA审批驳回'},
            {value: 9, label: '待提交OA审批'},
            {value: 10, label: '待主管确认'},
            {value: 11, label: '待总监审批'},
            {value: 5, label: '定价审批中'},
            {value: 5, label: '定价完成'},

        ],
        multiple: true,
    });
    $(el.quotaStatus).combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        value:'',
        data: [
            {value: '', label: '全部'},
            {value: 1, label: '报价完成'}
        ],
        // multiple: true,
    });
    // // 初始化采购类别
    // $(el.inquiryType).combobox({
    //     url: g.ctx + 'pc/sys/dict/getDicByType?type=inquiry_type',
    //     panelHeight: 260,
    //     method: 'GET',
    //     valueField: 'code',
    //     textField: 'codeWithDesc',
    //     editable: false
    // });
    //采购类型
    $(el.purchaseType).combobox({
        valueField: 'code',
        textField: 'name',
        limitToList: 'true',
        data: [
            {'name': '标准', 'code': '0'},
            {'name': '委外', 'code': '3'}
        ],
        editable: false,
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
    });
}
function loadGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight, 37, 40);
    $(el.tb).datagrid({
        height: el.bodyHeight - searchHeight,
        url: g.ctx + 'pc/inquiry/rest/list',
        singleSelect: true,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        rownumbers: true,
        queryParams: {
             createUserName: userName,
            statusLists: $(el.statusLists).combobox("getValues").join(','),
            quotaStatus: $(el.quotaStatus).combobox("getValue")
        },
        frozenColumns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'status',
                    title: '询价单状态',
                    width: 90,
                    formatter: function (value) {
                        switch (Number(value)) {
                            case 1:
                                return '<span style="color:black;">新建</span>';
                            case 2:
                                return '<span style="color:blue;">已发布</span>';
                            case 3:
                                return '<span style="color:red;">截止</span>';
                            case 4:
                                return '<span style="color:grey;">取消</span>';
                            case 6:
                                return '<span style="color:orange;">定价OA审批中</span>';
                            case 7:
                                return '<span style="color:red;">定价OA审批拒绝</span>';
                            case 8:
                                return '<span style="color:grey;">定价OA审批驳回</span>';
                            case 9:
                                return '<span style="color:blue;">待提交OA审批</span>';
                            case 10:
                                return '<span style="color:blue;">待主管确认</span>';
                            case 11:
                                return '<span style="color:blue;">待总监审批</span>';
                            case 5:
                                return '<span style="color:green;">定价完成</span>';
                            default:
                                return '';
                        }
                    }
                },
                {
                    field: 'inquiryCode',
                    title: '询价单编号',
                    width: 140,
                    formatter: function (value) {
                        return '<u style="color: blue;">' + value + '</u>'
                    }
                },
            ]
        ],
        columns: [
            [
                // {
                //     field: 'inquiryType',
                //     title: '询价类别',
                //     width: 100,
                //     formatter: function (value) {
                //         return getDicName('inquiry_type',value)
                //     }
                // },
                {
                    field: 'inquiryTitle',
                    title: '主题',
                    width: 300

                },
                {
                    field: 'createUserName',
                    title: '创建人',
                    width: 90
                },
                {
                    field: 'dataSource',
                    title: '数据来源',
                    width: 100,
                    formatter: function (value) {
                        //数据来源；0-手动新增；1-采购申请；2-价格信息记录
                        switch (value) {
                            case 0:
                                return 'SRM手工创建';
                            case 1:
                                return '采购申请';
                            case 2:
                                return '价格信息记录';
                            default:
                                return 'SRM手工创建';
                        }
                    }
                },
                // {
                //     field: 'purchaseOrgCode',
                //     title: '采购组织',
                //     width: 150,
                //     formatter: function (value) {
                //         return getNecessaryDataName('pc/sys/purchaseOrg/rest/listAll',value)
                //     }
                // },
                {
                    field: 'companyCode',
                    title: '签约主体',
                    width: 150,
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/company/rest/listAll',value)
                    }
                },
                {
                    field: 'purchaseGroupCode',
                    title: '采购组',
                    width: 120,
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/purchaseGroup/rest/listAll',value)
                    }
                },
                {
                    field: 'quoteInfo',
                    title: '报价情况',
                    width: 90,
                    formatter: function (value, row) {

                        return "<a href='javascript:void(0)' onclick=\"lookSupplierQuoteInfo('" + row.id + "', 0," + row.outAssistFlag + ")\">" + value + "</a>";
                    }
                },
                {
                    field: 'stateTurnedInfo',
                    title: '转合同情况',
                    width: 90,
                    formatter: function (value, row) {

                        return "<a href='javascript:void(0)' onclick=\"lookSupplierContractInfo('" + row.id + "')\">" + value + "</a>";
                    }
                },
                {
                    field: 'beginTime',
                    title: '开始时间',
                    width: 140,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                },
                {
                    field: 'endTime',
                    title: '结束时间',
                    width: 140,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                },

                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 140,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                },
                {
                    field: 'finishTime',
                    title: '完成时间',
                    width: 140,
                    formatter: function (value) {
                        if (value) {
                            return moment(value).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    width: 300
                },
                {
                    field: 'cancelRemark',
                    title: '作废原因',
                    width: 300
                }
            ]
        ],
        toolbar: [
            {
                text: '新增',
                iconCls: 'icon-add',
                id: 'btn_add',
                handler: function () {
                    detail(otpTypeEnum.ADD);
                }
            }, "-",
            {
                text: '编辑',
                id: 'btn_edit',
                iconCls: 'icon-edit',
                handler: function () {
                    detail(otpTypeEnum.EDIT);
                }
            }, "-",
            {
                text: '复制',
                id: 'btn_copy',
                iconCls: 'icon-plan-copy',
                handler: function () {
                    detail(otpTypeEnum.COPY);
                }
            }, "-",
            {
                text: '发布',
                iconCls: 'icon-ok',
                id: 'btn_publish',
                handler: function () {
                    publish();
                }
            }, "-",
            {
                text: '截止',
                iconCls: 'icon-delete',
                id: 'btn_end',
                handler: function () {
                    end();
                }
            }, "-",
            {
                text: '删除',
                iconCls: 'icon-remove',
                id: 'btn_remove',
                handler: function () {
                    remove();
                }
            }, "-",
            {
                text: '作废',
                iconCls: 'icon-remove',
                id: 'btn_cancel',
                handler: function () {
                    cancel();
                }
            }, "-",
            {
                text: '查看',
                iconCls: 'icon-find',
                id: 'btn_look',
                handler: function () {
                    look();
                }
            }, "-",
            // {
            //     text: '添加供应商',
            //     iconCls: 'icon-add',
            //     id: "btn_add_supplier",
            //     handler: function () {
            //         var row = $(el.tb).datagrid('getSelected');
            //         if (row == null) {
            //             layer.msg("请选择需要添加供应商的询价单!");
            //             return;
            //         }
            //         openSupplierDialog(row.id,row.signing_subject);
            //     }
            // }
            // {
            //     text: '复制',
            //     iconCls: 'icon-plan-copy',
            //     id: 'icon_copy',
            //     handler: function () {
            //         copyXunJia();
            //     }
            // }, "-",
            // {
            //     text: '延期',
            //     iconCls: 'icon-edit',
            //     id: 'icon_delay',
            //     handler: function () {
            //         editTime();
            //     }
            // }, "-",
            // {
            //     text: '导出',
            //     iconCls: 'icon-print',
            //     id: 'icon_print',
            //     handler: function () {
            //         exportExcel();
            //     }
            // }, "-",
            // {
            //     text: '审批日志',
            //     iconCls: 'icon-tip',
            //     id: 'icon_tip',
            //     handler: function () {
            //         lookApprovalLog();
            //     }
            // },
            {
                text: '生成合同',
                iconCls: 'icon-sum',
                id: 'btn_contract',
                handler: function () {
                    var row = $(el.tb).datagrid('getSelected');
                    if (!row) {
                        topWin.layer.alert('请选中一条记录', {icon: 0});
                        return false;
                    }
                    if (row.status != 5 ) {
                        topWin.layer.msg("请选择一条已完成的询价单!");
                        return;
                    }
                    CREATE_CONTRACT_COMMON.lookCreateContract(CONTRACT_TYPE.ASSET, '#tb', BUSINESS_TYPE.INQUIRY, row.id);
                }
            },
            {
                text: '批量生成合同',
                iconCls: 'icon-sum',
                id: 'btn_contract',
                handler: function () {
                    CREATE_CONTRACT_COMMON.lookBatchCreateContract(CONTRACT_TYPE.ASSET, '#tb', BUSINESS_TYPE.INQUIRY);
                }
            },
            {
                text: '生成费用合同',
                iconCls: 'icon-sum',
                id: 'btn_cost_contract',
                handler: function () {

                    const row = $(el.tb).datagrid('getSelected');
                    if (row == null) {
                        topWin.layer.msg("请选择一条招标单!");
                        return;
                    }
                    if (row.purchaseRequestType !== "01") {
                        topWin.layer.msg("请选择费用合同类招投标的询价单！");
                        return;
                    }
                    if (row.status !== 5) {
                        topWin.layer.msg("请选择一条定价完成的询价单！");
                        return;
                    }
                    CREATE_CONTRACT_COMMON.lookCreateContract(CONTRACT_TYPE.COST, '#tb', BUSINESS_TYPE.INQUIRY, row.id);
                }
            },
            {
                text: '批量生成费用合同',
                iconCls: 'icon-sum',
                id: 'btn_batch_cost_contract',
                handler: function () {
                    CREATE_CONTRACT_COMMON.lookBatchCreateContract(CONTRACT_TYPE.COST, '#tb', BUSINESS_TYPE.INQUIRY);
                }
            }
            // {
            //     text: '查看',
            //     iconCls: 'icon-print',
            //     id: 'icon_contract',
            //     handler: function () {
            //         xbjOrderLook();
            //     }
            // }, '-',
        ],
        onLoadSuccess: function () {
            displayButtonByUserRole("xunjia.hall.index");
            $(el.tb).datagrid('clearSelections');
        },
        onDblClickRow: function () {
            look();
        },
        onCheck: function (rowIndex) {
            var rows = $(el.tb).datagrid('getRows');
            var status = rows[rowIndex].status;
            //1-新增；2-发布；3-截止；4-取消；5-完成
            switch (Number(status)) {
                case 1:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('enable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('enable');
                    $(el.btn_end).linkbutton('disable');
                    $(el.btn_remove).linkbutton('enable');
                    $(el.btn_cancel).linkbutton('enable');
                    $(el.btn_add_supplier).linkbutton('enable');
                    break;
                case 2:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('disable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('enable');
                    $(el.btn_end).linkbutton('enable');
                    $(el.btn_remove).linkbutton('enable');
                    $(el.btn_cancel).linkbutton('enable');
                    $(el.btn_add_supplier).linkbutton('enable');
                    break;
                case 3:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('disable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('disable');
                    $(el.btn_end).linkbutton('disable');
                    $(el.btn_remove).linkbutton('enable');
                    $(el.btn_cancel).linkbutton('enable');
                    $(el.btn_add_supplier).linkbutton('disable');
                    break;
                case 4:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('disable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('disable');
                    $(el.btn_end).linkbutton('disable');
                    $(el.btn_remove).linkbutton('enable');
                    $(el.btn_cancel).linkbutton('disable');
                    $(el.btn_add_supplier).linkbutton('disable');
                    break;
                case 5:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('disable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('disable');
                    $(el.btn_end).linkbutton('disable');
                    $(el.btn_remove).linkbutton('enable');
                    $(el.btn_cancel).linkbutton('disable');
                    $(el.btn_add_supplier).linkbutton('disable');
                    break;
                case 6:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('disable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('disable');
                    $(el.btn_end).linkbutton('disable');
                    $(el.btn_remove).linkbutton('disable');
                    $(el.btn_cancel).linkbutton('disable');
                    $(el.btn_add_supplier).linkbutton('disable');
                    break;
                case 7:
                    $(el.btn_add).linkbutton('enable');
                    $(el.btn_edit).linkbutton('disable');
                    $(el.btn_copy).linkbutton('enable');
                    $(el.btn_publish).linkbutton('disable');
                    $(el.btn_end).linkbutton('disable');
                    $(el.btn_remove).linkbutton('disable');
                    $(el.btn_cancel).linkbutton('disable');
                    $(el.btn_add_supplier).linkbutton('disable');
                    break;
                default:
                    break;
            }
        }
    });
}

function detail(optType){
    var id = '';
    if (optType===otpTypeEnum.EDIT||optType===otpTypeEnum.COPY){
        var row = $(el.tb).datagrid('getSelected'), userId = $(el.userId).val();
        if (!row) {
            topWin.layer.alert('请选中一条记录', {icon: 0});
            return false;
        }
        id = row.id;
    }
    var dialogElement = openDialog("editDialog", g.ctx + "pc/inquiry/hall/detail?id="+id+"&optType="+optType, {
        title: (optType === otpTypeEnum.ADD ? "创建询价单" :optType===otpTypeEnum.EDIT?"编辑询价单":"复制询价单"),
        width: '100%',
        height: '100%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            dialogElement.dialog('destroy');
        },
        buttons: [{
            text: '提交',
            iconCls: 'icon-save',
            handler: function () {
                topWin.frames['editDialog'].saveOrUpdate(function () {
                    topWin.layer.msg('数据保存成功', {icon: 1});
                    dialogElement.dialog('close');
                    $(el.tb).datagrid('reload');
                });
            }
        }, {
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                dialogElement.dialog('close');
            }
        }]
    });

}

function look(){
    var row = $(el.tb).datagrid('getSelected');
    if (!row) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return false;
    }
    var lookDialogElement = openDialog("lookDialog", g.ctx + "pc/inquiry/hall/look?id="+row.id, {
        title: "查看",
        width: '100%',
        height: '100%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            lookDialogElement.dialog('destroy');
        },
        buttons: [{
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                lookDialogElement.dialog('close');
            }
        }]
    });
}

/**
 * 发布
 */
function publish(){
    var row = $(el.tb).datagrid('getSelected');
    if (!row) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return false;
    }
    var id = row.id;
    parent.layer.confirm('是否确认发布？', function (index) {
        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/inquiry/rest/publish',
            method: "post",
            data: {id: id},
            success: function () {
                parent.layer.close(index);
                $(el.tb).datagrid('reload');
                $(el.tb).datagrid('clearSelections');
            },
            complete: function(data) {
                top.layer.close(loading);
            },
            error: function (data) {
                parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
            }
        });
    });
}

/**
 * 截止
 */
function end(){
    var row = $(el.tb).datagrid('getSelected');
    if (!row) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return false;
    }
    var id = row.id;
    lookQuoteInfo(id, 1);
}

/**
 * 删除
 */
function remove(){
    var row = $(el.tb).datagrid('getSelected');
    if (!row) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return false;
    }
    var id = row.id;
    parent.layer.confirm('是否确认删除？', function (index) {
        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/inquiry/rest/remove',
            method: "post",
            data: {id: id},
            success: function () {
                parent.layer.close(index);
                $(el.tb).datagrid('reload');
                $(el.tb).datagrid('clearSelections');
            },
            complete: function(data) {
                top.layer.close(loading);
            },
            error: function (data) {
                parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
            }
        });
    });
}


/**
 * 作废
 */
function cancel(){
    var row = $(el.tb).datagrid('getSelected');
    if (!row) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return false;
    }
    var id = row.id;
    topWin.layer.prompt({title: "请填写作废原因", formType: 2, value: '', maxlength: 500}, function(text, index){
        if(text ===''){
            topWin.layer.msg('请填写作废原因', {icon: 2});
            return;
        }
        var loading = topWin.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/inquiry/rest/cancel',
            method: "post",
            data: {id: id,cancelRemark:text},
            success: function () {
                topWin.layer.close(index);
                topWin.layer.msg('数据保存成功', {icon: 1});
                $(el.tb).datagrid('reload');
                $(el.tb).datagrid('clearSelections');
            },
            complete: function(data) {
                topWin.layer.close(loading);
            },
            error: function (data) {
                parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
            }
        });
    });
}

/**
 * 查看供应商报价情况
 *
 * @param id 询价单ID
 * @param type 0:只是查看 1:截止操作
 * @param outAssistFlag 是否是外协询价 1 是 0 否
 */
function lookQuoteInfo(id, type, outAssistFlag) {
    layui.use('element', function () {
        var element = layui.element;
        $.ajax({
            url: g.ctx + 'pc/inquiry/rest/material/quote/list',
            type: 'GET',
            data: {inquiryId: id},
            success: function (data) {
                var dom = type === 1?'<div style="padding: 0 6px 6px 6px; font-weight: bold;">以下为供应商报价情况，是否继续截止？</div>':'';
                dom += '<table class="table table-responsive table-bordered">';
                if(outAssistFlag){
                    dom += '<thead><tr><th style="width: 25%;">物料组编码</th><th style="width: 60%;">物料组名称</th><th style="width: 15%;">报价情况</th></tr></thead>';
                }else {
                    dom += '<thead><tr><th style="width: 25%;">物料编码</th><th style="width: 60%;">物料名称</th><th style="width: 15%;">报价情况</th></tr></thead>';
                }
                dom += '<tbody>';
                for (var i = 0; i < data.length; i++) {
                    var item = data[i];
                    dom += '<tr>';
                    if(outAssistFlag){
                        dom += '<td>' + item.materialGroup + '</td>';
                        dom += '<td>' + item.materialGroupDesc + '</td>';
                    }else{
                        dom += '<td>' + item.materialCode + '</td>';
                        dom += '<td>' + item.materialName + '</td>';
                    }
                    dom += '<td style="color: #0b69e3;text-align: center;">' + item.quoteInfo +'</td>';
                    dom += '</tr>';
                }
                dom += '</tbody></table>';

                parent.layer.open({
                    title: type === 1?'温馨提示':'报价情况',
                    area: ['550px', '40%'],
                    content: dom,
                    btn: type === 1 ? ['确定', '取消'] : ['关闭'],
                    success: function (layero, index) {
                        setTimeout(function () {
                            element.progress('demo', '50%')
                        }, 1000)
                    },
                    yes: function (index) {
                        parent.layer.close(index);
                        if (type === 1) {
                            var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                            $.ajax({
                                url: g.ctx + 'pc/inquiry/rest/end',
                                method: "post",
                                data: {id: id},
                                success: function () {
                                    $(el.tb).datagrid('reload');
                                    $(el.tb).datagrid('clearSelections');
                                },
                                complete: function(data) {
                                    top.layer.close(loading);
                                },
                                error: function (data) {
                                    parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
                                }
                            });
                        }
                    }
                });
            }
        });
    });
}

/**
 * 查看供应商报价情况
 *
 * @param id 询价单ID
 * @param type 0:只是查看 1:截止操作
 * @param outAssistFlag 是否是外协询价 1 是 0 否
 */
function lookSupplierQuoteInfo(id, type,outAssistFlag) {
    layui.use('element', function () {
        var element = layui.element;
        $.ajax({
            url: g.ctx + 'pc/inquiry/rest/supplierListByInquiryId',
            type: 'GET',
            data: {inquiryId: id},
            success: function (data) {
                var dom = type === 1?'<div style="padding: 0 6px 6px 6px; font-weight: bold;">以下为供应商报价情况，是否继续截止？</div>':'';
                dom += '<table class="table table-responsive table-bordered">';
                dom += '<thead><tr><th style="width: 25%;">供应商编码</th><th style="width: 60%;">供应商名称</th><th style="width: 15%;">报价状态</th></tr></thead>';
                dom += '<tbody>';
                for (var i = 0; i < data.length; i++) {
                    var item = data[i];
                    dom += '<tr>';
                    dom += '<td>' + item.supplierCode + '</td>';
                    dom += '<td>' + item.supplierName + '</td>';
                    if (Number(item.quoteFlag)===0){
                        dom += '<td style="color:grey;text-align: center;">未报价</td>';
                    }else {
                        dom += '<td style="color:green;text-align: center;">已报价</td>';
                    }

                    dom += '</tr>';
                }
                dom += '</tbody></table>';

                parent.layer.open({
                    title: type === 1?'温馨提示':'报价情况',
                    area: ['550px', '40%'],
                    content: dom,
                    btn: type === 1 ? ['确定', '取消'] : ['关闭'],
                    success: function (layero, index) {
                        setTimeout(function () {
                            element.progress('demo', '50%')
                        }, 1000)
                    },
                    yes: function (index) {
                        parent.layer.close(index);
                        if (type === 1) {
                            var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                            $.ajax({
                                url: g.ctx + 'pc/inquiry/rest/end',
                                method: "post",
                                data: {id: id},
                                success: function () {
                                    $(el.tb).datagrid('reload');
                                    $(el.tb).datagrid('clearSelections');
                                },
                                complete: function(data) {
                                    top.layer.close(loading);
                                },
                                error: function (data) {
                                    parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
                                }
                            });
                        }
                    }
                });
            }
        });
    });
}

/**
 * 查看供应商转合同情况
 *
 * @param id 询价单ID
 */
function lookSupplierContractInfo(id) {
    layui.use('element', function () {
        var element = layui.element;
        $.ajax({
            url: g.ctx + 'pc/inquiry/rest/xjlist',
            type: 'POST',
            data: {xjId: id, type: 2},
            success: function (data) {
                var dom = '';
                dom += '<table class="table table-responsive table-bordered">';
                dom += '<thead><tr><th style="width: 15%;">供应商编码</th><th style="width: 50%;">供应商名称</th><th style="width: 10%;">合同类型</th><th style="width: 25%;">转换状态</th></tr></thead>';
                dom += '<tbody>';
                for (var i = 0; i < data.length; i++) {
                    var item = data[i];
                    dom += '<tr>';
                    dom += '<td>' + item.supplierCode + '</td>';
                    dom += '<td>' + item.supplierName + '</td>';
                    dom += '<td>' + item.contractType + '</td>';
                    dom += '<td>'+ CREATE_CONTRACT_COMMON.getContractCode(item) +'</td>';

                    dom += '</tr>';
                }
                dom += '</tbody></table>';

                parent.layer.open({
                    title: '转合同情况',
                    area: ['60%', '70%'],
                    content: dom,
                    btn: ['关闭'],
                    success: function (layero, index) {
                        setTimeout(function () {
                            element.progress('demo', '50%')
                        }, 1000)
                    },
                    yes: function (index) {
                        parent.layer.close(index);
                    }
                });
            }
        });
    });
}