var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    purchaseGroupCode: '#purchaseGroupCode',
    status: '#status',
    inquiryType: '#inquiryType',
    purchaseType: '#purchaseType',
    genPriceInfo: '#genPriceInfo',
    stateTurned: '#stateTurned',
    btn_look: '#btn_look',
    btn_bargain: '#btn_bargain',
    btn_big_bargain: '#btn_big_bargain',
    btn_price_confirm: '#btn_price_confirm',
    btn_charge_confirm: '#btn_charge_confirm',
    btn_ding_close: '#btn_ding_close',
    btn_contract: '#btn_contract',
    btn_batch_contract: '#btn_batch_contract',
    cost_tender_contract: '#cost_tender_contract',
    fixPriceDialogElement: undefined,
    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.status).combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        data: [
            {value: '', label: '全部'},
            {value: 3, 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: 15, 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',
    });
    //转合同情况
    $(el.stateTurned).combobox({
        valueField: 'code',
        textField: 'name',
        limitToList: 'true',
        data: [
            {'name': '未转', 'code': '3'},
            {'name': '部分转', 'code': '2'},
            {'name': '全部转', 'code': '1'}
        ],
        editable: false,
        prompt: '--- 请选择 ---',
        multiple:true,
        panelHeight: 'auto',
    });
    //价格信息
    $(el.genPriceInfo).combobox({
        valueField: 'code',
        textField: 'name',
        limitToList: 'true',
        data: [
            {'name': '未生成', 'code': '0'},
            {'name': '已生成', 'code': '1'},
            {'name': '无需生成', 'code': '2'}
        ],
        editable: false,
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
    });
}
function loadGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight, 37, 40);
    var statusLists = "";
   if(typeof types === 'undefined'){
       statusLists = "3,5,6,7,8,9,10,11,15";
   }else{
       statusLists =  types;
   }
    $(el.tb).datagrid({
        height: el.bodyHeight - searchHeight,
        url: g.ctx + 'pc/inquiry/rest/list?statusLists=' + statusLists,
        singleSelect: true,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        rownumbers: true,
        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>';
                            case 15:
                                return '<span style="color:green;">完成</span>';
                            default:
                                return '';
                        }
                    }
                },
                {
                    field: 'inquiryCode',
                    title: '询价单编号',
                    width: 140,
                    formatter: function (value) {
                        return '<u style="color: blue;">' + value + '</u>'
                    }
                },
                {
                    field: 'oaWorkId',
                    title: 'OA流程号',
                    width: 200,
                    sortable: true,
                    formatter: function (value, row) {
                        return oaTrack(value, OaProcessType.INQUIRY_PRICE)
                    }
                },
            ]
        ],
        columns: [
            [
                {
                    field: 'inquiryTitle',
                    title: '询价主题',
                    width: 150

                },
                {
                    field: 'genPriceInfo',
                    title: '价格信息',
                    width: 80,
                    formatter: function (value, row) {
                        if (value&&Number(value)===0){
                            return '<span style="color:red;">未生成</span>'
                        }else if (value&&Number(value)===1){
                            return '<span style="color:green;">已生成</span>'
                        }else if (value&&Number(value)===2){
                            return '<span style="color:blue;">无需生成</span>'
                        }else {
                            return '<span style="color:red;">未生成</span>'
                        }
                    }
                },
                // {
                //     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: 'inquiryType',
                //     title: '询价类别',
                //     width: 100,
                //     formatter: function (value) {
                //         return getDicName('inquiry_type',value)
                //     }
                // },
                {
                    field: 'bargainNum',
                    title: '议价中数量',
                    width: 100,
                    align: 'center',
                    formatter: function (value, row) {
                        if (row.status===5){
                            return '<a style="color: green">0</a>'
                        }else {
                            if (Number(value) === 0) {
                                return '<a style="color: green">' + value + '</a>'

                            } else {
                                return '<a style="color: red">' + value + '</a>'
                            }
                        }
                    }
                },
                {
                    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: 'createUserName',
                    title: '创建人',
                    width: 90
                },
                {
                    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
                }
            ]
        ],
        toolbar: [
            {
                text: '查看',
                iconCls: 'icon-find',
                id: 'btn_look',
                handler: function () {
                    fixPrice(0);
                }
            }, "-",
            {
                text: '定价/议价',
                iconCls: 'icon-anchor',
                id: 'btn_bargain',
                handler: function () {
                    fixPrice(1);
                }
            }, "-",
            {
                text: '大数据定价/议价',
                iconCls: 'icon-anchor',
                id: 'btn_big_bargain',
                handler: function () {
                    fixPrice(2);
                }
            }, "-",
            {
                text: '主管审批',
                iconCls: 'icon-confirm',
                id: 'btn_charge_confirm',
                handler: function () {
                    fixPrice(5);
                }
            }, "-",
            {
                text: '总监审批',
                iconCls: 'icon-confirm',
                id: 'btn_price_confirm',
                handler: function () {
                    fixPrice(4);
                }
            }, "-",
            {
                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_batch_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 && row.status !== 15) {
                        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-cancel',
                id: 'btn_ding_close',
                handler: function () {

                    var row = $(el.tb).datagrid('getSelected');
                    if (!row) {
                        topWin.layer.alert('请选中一条记录', {icon: 0});
                        return false;
                    }
                    topWin.layer.confirm('是否确认关闭该条记录定/议价？',{icon: 3}, function (iid) {
                        $.ajax({
                            url: g.ctx + 'pc/inquiry/rest/close',
                            method: "post",
                            data: {id: row.id},
                            success: function () {
                                topWin.layer.msg('操作成功', {icon: 1});
                                $(el.tb).datagrid('reload');
                                $(el.tb).datagrid('clearSelections');
                                topWin.layer.close(iid);
                            },
                            complete: function(data) {
                                topWin.layer.close(iid);
                            },
                            error: function (data) {
                                topWin.layer.alert(data.responseJSON.message, {icon: 2});
                                topWin.layer.close(iid);
                                // parent.layer.alert(JSON.parse(data.responseText).message,{icon: 2, shadeClose: true, title: '温馨提示'});
                            }
                        })
                    })


                }
            },
        ],
        onLoadSuccess: function () {
            displayButtonByUserRole("inquiry.fix.index");
            $(el.tb).datagrid('clearSelections');
        },
        onDblClickRow: function () {
            look();
        },
        onCheck: function (rowIndex) {
            var rows = $(el.tb).datagrid('getRows');
            var status = rows[rowIndex].status;
            var genPriceInfo = rows[rowIndex].genPriceInfo;
            //1-新增；2-发布；3-截止；4-取消；5-定价完成; 15 不定价关闭动作执行的修改 完成状态
            switch (Number(status)) {
                case 3:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('enable');
                    $(el.btn_big_bargain).linkbutton('enable');
                    $(el.btn_price_confirm).linkbutton('disable');
                    $(el.btn_charge_confirm).linkbutton('disable');
                    $(el.btn_ding_close).linkbutton('enable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 5:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('enable');
                    $(el.btn_charge_confirm).linkbutton('disable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('enable');
                    $(el.btn_batch_contract).linkbutton('enable');
                    $(el.cost_tender_contract).linkbutton('enable');
                    break;
                case 6:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('disable');
                    $(el.btn_charge_confirm).linkbutton('disable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 7:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('enable');
                    $(el.btn_big_bargain).linkbutton('enable');
                    $(el.btn_price_confirm).linkbutton('enable');
                    $(el.btn_charge_confirm).linkbutton('enable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 8:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('disable');
                    $(el.btn_charge_confirm).linkbutton('disable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 9:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('disable');
                    $(el.btn_charge_confirm).linkbutton('enable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 10:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('disable');
                    $(el.btn_charge_confirm).linkbutton('enable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 11:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('enable');
                    $(el.btn_charge_confirm).linkbutton('disable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                case 15:
                    $(el.btn_look).linkbutton('enable');
                    $(el.btn_bargain).linkbutton('disable');
                    $(el.btn_big_bargain).linkbutton('disable');
                    $(el.btn_price_confirm).linkbutton('disable');
                    $(el.btn_charge_confirm).linkbutton('disable');
                    $(el.btn_ding_close).linkbutton('disable');
                    $(el.btn_contract).linkbutton('disable');
                    $(el.btn_batch_contract).linkbutton('disable');
                    $(el.cost_tender_contract).linkbutton('disable');
                    break;
                default:
                    break;
            }
            if (genPriceInfo===1){
                $(el.btn_price_confirm).linkbutton('disable');
            }
        }
    });
}

/**
 * 定价
 * @param optType 操作类型；0-查看；1-定价；2-大数据定价；3-商务定价；4-价格确认；5-主管确认
 * @returns {boolean}
 */
function fixPrice(optType){
    var row = $(el.tb).datagrid('getSelected'), userId = $(el.userId).val();
    if (!row) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return false;
    }
    var id = row.id;
    var buttons = [{
        text: '定价',
        iconCls: 'icon-ok',
        handler: function () {
            setOperationLog("比价定价","定价按钮");
            topWin.frames['fixPriceDialog'].fixPrice(function () {
                topWin.layer.msg('定价成功', {icon: 1});
                el.fixPriceDialogElement.dialog('close');
                $(el.tb).datagrid('reload');
            },1);
        }
    },{
        text: '暂存',
        iconCls: 'icon-save',
        handler: function () {
            setOperationLog("比价定价","暂存按钮");
            topWin.frames['fixPriceDialog'].fixPrice(function () {
                topWin.layer.msg('数据保存成功', {icon: 1});
                el.fixPriceDialogElement.dialog('close');
                $(el.tb).datagrid('reload');
            },0);
        }
    }, {
        text: '关闭',
        iconCls: 'icon-cancel',
        handler: function () {
            el.fixPriceDialogElement.dialog('close');
        }
    }];
    if (optType===0){
        buttons = [{
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                el.fixPriceDialogElement.dialog('close');
            }
        }];
    }
    if (optType===4){
        buttons = [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                setOperationLog("比价定价","确认按钮");
                topWin.frames['fixPriceDialog'].fixConfirm(function () {
                    topWin.layer.msg('确认成功', {icon: 1});
                    el.fixPriceDialogElement.dialog('close');
                    $(el.tb).datagrid('reload');
                },1);
            }
        },{
            text: '驳回',
            iconCls: 'icon-clear',
            handler: function () {
                setOperationLog("比价定价","驳回按钮");
                topWin.frames['fixPriceDialog'].fixConfirm(function () {
                    topWin.layer.msg('驳回成功', {icon: 1});
                    el.fixPriceDialogElement.dialog('close');
                    $(el.tb).datagrid('reload');
                },2);
            }
        },{
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                el.fixPriceDialogElement.dialog('close');
            }
        }];
    }

    if (optType===5){
        buttons = [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                setOperationLog("比价定价","确认按钮");
                topWin.frames['fixPriceDialog'].chargeConfirm(function () {
                    topWin.layer.msg('确认成功', {icon: 1});
                    el.fixPriceDialogElement.dialog('close');
                    $(el.tb).datagrid('reload');
                },1);
            }
        },{
            text: '驳回',
            iconCls: 'icon-clear',
            handler: function () {
                setOperationLog("比价定价","驳回按钮");
                topWin.frames['fixPriceDialog'].chargeConfirm(function () {
                    topWin.layer.msg('驳回成功', {icon: 1});
                    el.fixPriceDialogElement.dialog('close');
                    $(el.tb).datagrid('reload');
                },2);
            }
        },{
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                el.fixPriceDialogElement.dialog('close');
            }
        }];
    }
     el.fixPriceDialogElement = openDialog("fixPriceDialog", g.ctx + "pc/inquiry/fix/fixPrice?id="+id+"&optType="+optType, {
        title: (optType === 0 ? "查看" :optType===1?"定价/议价":optType===2?"大数据定价/议价":optType===3?"商务定价":optType===4?"总监审批":"主管审批"),
        width: '100%',
        height: '100%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            el.fixPriceDialogElement.dialog('destroy');
        },
        buttons: buttons
    });

}

function closeFixPriceDialog() {
    el.fixPriceDialogElement.dialog('close');
    $(el.tb).datagrid('reload');
}

/**
 * 查看供应商报价情况
 *
 * @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);
                    }
                });
            }
        });
    });
}
