var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    dataState: '#dataState',
    purchaseBillDetailIds: '#purchaseBillDetailIds',
    transferStatus: '#transferStatus',
    purchaseGroupCode: '#purchaseGroupCode',
    purchaseMethod: '#purchaseMethod',
    purchaseApplyTypeCode: '#purchaseApplyTypeCode',
    purchaseOrderNumber: '#purchaseOrderNumber',
    billCode: '#billCode',
    materialName: '#materialName',
    materialSpec: '#materialSpec',
    materialGroupName: '#materialGroupName',
    createName: '#createName',
    factoryCode: '#factoryCode',
    startCreateDate: '#startCreateDate',
    endCreateDate: '#endCreateDate',
    requireName: '#requireName',
    purchaseGroupCode: '#purchaseGroupCode',
    searchFlag: '#searchFlag',
    purchaseMethod: '#purchaseMethod',
    transferStatus: '#transferStatus',
    procureSubclass: '#procureSubclass',
    bodyHeight: document.documentElement.clientHeight
};
$(function () {
    initDict('apply_project_type,procure_sub_class,gx_contract_subject,apply_type,purchase_method,contract_pay_boot_item,apply_type,purchasing_business_type,contract_item_subject,unit,purchase_way');
    initDictName('purchase_method');
    initNecessaryDatas('pc/sys/purchaseGroup/rest/listAll,pc/sys/company/rest/listAll');
    initCombo();
    loadGrid();
});

function initCombo() {
    // $(el.dataState).combobox({
    //     editable: false,
    //     panelHeight: 'auto',
    //     valueField: 'value',
    //     textField: 'label',
    //     data: [
    //         {value: 0, label: '新增'},
    //         {value: 1, label: '编辑'},
    //         {value: 2, label: '删除'}
    //     ],
    //     multiple: true,
    //     onLoadSuccess: function () {
    //         $(el.dataState).combobox('setValues', JSON.parse('[0,1]'));
    //     }
    // });
    $(el.purchaseGroupCode).combobox({
        valueField: 'purchaseGroupCode',
        textField: 'codeWithDesc',
        method: 'POST',
        prompt: '--- 请选择 ---',
        url: g.ctx + 'pc/sys/purchaseGroup/rest/listAll'
    });

        // $(el.purchaseMethod).combobox({
        //     // url: g.ctx + 'pc/sys/dict/getDicByType?type=purchase_method',
        //     // method: 'GET',
        //     valueField: 'code',
        //     textField: 'codeWithDesc',
        //     prompt: '--- 请选择 ---',
        //     editable: false,
        //     data: [
        //         {label: '询价', value: 'Z0011'},
        //         {label: '招标', value: 'Z002'},
        //         {label: '震坤行商城', value: 'Z003'},
        //         {label: '未转', value: 'Z005'}
        //     ],
        // });
    $(el.purchaseMethod).combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=purchase_method',
        method: 'GET',
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        editable: false
    });


    $(el.transferStatus).combobox({
        valueField: 'value',
        textField: 'label',
        data: [
            {label: '未转', value: 1},
            {label: '震坤行订单', value: 2},
            {label: '第三方订单', value: 3},
            {label: '已转合同', value: 4}
        ],
        editable: false,
        prompt: '-- 请选择 --',
        panelHeight: 'auto'
    });

    $(el.procureSubclass).combobox({
        valueField: 'value',
        textField: 'label',
        data: [
            {label: '办公用品', value: 1},
            {label: '资产-IT设备', value: 2},
            {label: '手板', value: 3},
            {label: '资产-非IT设备', value: 4}
        ],
        editable: false,
        prompt: '-- 请选择 --',
        panelHeight: 'auto'
    });
    $(el.purchaseApplyTypeCode).combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=apply_type',
        method: 'GET',
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        editable: false
    });
//采购方式
//     $(el.purchaseMethod).combobox({
//         url: g.ctx + 'pc/sys/dict/getDicByType?type=purchase_method',
//         method: 'GET',
//         valueField: 'code',
//         textField: 'codeWithDesc',
//         prompt: '--- 请选择 ---',
//         editable: false
//     });
}

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/purchase/apply/bill/detail/rest/list',
        singleSelect: false,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        remoteSort: true,
        rownumbers: true,
        queryParams: {
            purchasingBusinessType: purchasingBusinessType
            // dataStates:$(el.dataState).combobox("getValues").join(',')
            // transferStatus:$(el.transferStatus).combobox('getValue')
        },
        columns: getColumns(),
        toolbar: [
            {
                text: '导出',
                iconCls: 'icon-print',
                id: 'btn_excel_export',
                handler: function () {
                    openExportDialog('pc/inquiry/purchase/apply/bill/detail/rest/export','tb',searchParams());
                }
            }, "-",
            {
                text: '转询价单',
                iconCls: 'icon-reload',
                id:'btn_turn_inquiry',
                handler: function () {
                    transferInquiry();
                }
            }, "-",{
                text: '转招标单',
                iconCls: 'icon-reload',
                id:'btn_turn_bidding',
                handler: function () {
                    transferTender();
                }
            }, "-",
            {
                text: '变更采购组',
                iconCls: 'icon-reload',
                id:'btn_purchase_group',
                handler: function () {
                    purchaseGroupSelect();
                }
            },"-",
            {
                text: '添加采购备注',
                iconCls: 'icon-add',
                id:'btn_purchase_remark',
                handler: function () {
                    addPurchaseRemark();
                }
            },"-",
            {
                text: '设置采购方式',
                iconCls: 'icon-edit',
                id:'btn_purchase_method',
                handler: function () {
                    if (purchasingBusinessType === '02') {
                        editPurchaseMethodTow();
                    } else {
                        editPurchaseMethod();
                    }
                }
            },"-",
            {
                text: '设置采购路径',
                iconCls: 'icon-edit',
                id:'btn_purchase_method',
                handler: function () {
                    editPurchaseWayMethodTow();
                }
            },"-",
            // {
            //     text: '导入采购员/采购组',
            //     iconCls: 'icon-download',
            //     id:'btn_download',
            //     handler: function () {
            //         $("#fileUpload .filebox-label").click();
            //     }
            // }
        ],
        onLoadSuccess: function () {
            displayButtonByUserRole("purchaseApplyBillDetail" + purchasingBusinessType);
            $(el.tb).datagrid('clearSelections');
        },
    });
}

/**
 * 转询价单
 */
function transferInquiry() {

    var rows = $(el.tb).datagrid("getSelections");
    if (rows.length === 0) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return
    }
    var purchaseGroupCode = rows[0].purchaseGroupCode;
    var companyCode = rows[0].companyCode;
    var procureSubclass = rows[0].procureSubclass; // 获取采购类别
    for (var i = 1 ; i < rows.length ; i++) {
        if (!rows[i].materialName){
            topWin.layer.msg("选中数据存在物料描述为空的数据，不可转询价",{icon:0});
            return
        }
        if (purchaseGroupCode !== rows[i].purchaseGroupCode) {
            topWin.layer.msg("请选择相同的采购组数据",{icon:0});
            return
        }
        if (companyCode !== rows[i].companyCode){
            topWin.layer.msg("请选择相同的公司",{icon:0});
            return
        }
    }
    var ids = [];
    $.each(rows, function (index, target) {
        ids.push(target.id);
    });
    var url = g.ctx + 'pc/inquiry/purchase/apply/bill/detail/transfer/inquiry?ids=' + ids.join(',')+"&optType="+otpTypeEnum.ADD + "&purchasingBusinessType=" + purchasingBusinessType +  '&procureSubclass=' + encodeURIComponent(procureSubclass || ''); // 重点编码采购类别
    var dialogElement = openDialog("editDialog", url,{
        title: '询价新增',
        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 transferTender() {

    var rows = $(el.tb).datagrid("getSelections");
    if (rows.length === 0) {
        topWin.layer.alert('请选中一条记录', {icon: 0});
        return
    }
    var purchaseGroupCode = rows[0].purchaseGroupCode;
    var companyCode = rows[0].companyCode;
    var tenderFlag = rows[0].tenderFlag;
    if (tenderFlag === 1) {
        topWin.layer.msg("已转招标单不能再次操作",{icon:0});
        return
    }
    for (var i = 1 ; i < rows.length ; i++) {
        if (rows[i].tenderFlag === 1) {
            topWin.layer.msg("已转招标单不能再次操作",{icon:0});
            return
        }
        if (purchaseGroupCode !== rows[i].purchaseGroupCode) {
            topWin.layer.msg("请选择相同的采购组数据",{icon:0});
            return
        }
        if (companyCode !== rows[i].companyCode){
            topWin.layer.msg("请选择相同的公司",{icon:0});
            return
        }
    }
    var ids = [];
    $.each(rows, function (index, target) {
        ids.push(target.id);
    });
    var url = g.ctx + 'pc/inquiry/purchase/apply/bill/detail/transfer/tender?ids=' + ids.join(',')+"&optType="+otpTypeEnum.ADD + "&purchasingBusinessType=" + purchasingBusinessType;
    var dialogElement = openDialog("editDialog", url, {
        title: '招标新增',
        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'].tenderComm.saveOrUpdate(function () {
                    topWin.layer.msg('数据保存成功', {icon: 1});
                    dialogElement.dialog('close');
                    $(el.tb).datagrid('reload');
                });
            }
        }, {
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                dialogElement.dialog('close');
            }
        }]
    });
}

function purchaseGroupSelect(){
    var rows = $(el.tb).datagrid('getSelections');
    if (rows.length < 1) {
        layer.msg('请至少选中一个数据进行操作', {icon: 0});
        return false;
    }
    var ids = [];
    for(var i = 0; i < rows.length; i++){
        ids.push(rows[i].id);
    }
    var selectPurchaseGroupElement = openDialog("selectPurchaseGroupDialog", g.ctx + 'pc/sys/purchaseGroup/dialog', {
        title: '选择采购组',
        width: '60%',
        height: '75%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            selectPurchaseGroupElement.dialog('destroy');
        },
        buttons: [{
            text: '确定',
            iconCls: 'icon-save',
            handler: function () {
                topWin.frames['selectPurchaseGroupDialog'].chooseRow(function (data) {
                    let ps = $(el.tb).datagrid('getRows');
                    parent.layer.confirm('是否确认操作？', function (index) {
                        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
                        $.ajax({
                            url: g.ctx + 'pc/inquiry/purchase/apply/bill/detail/rest/updatePurchaseGroupCode',
                            method: "post",
                            data: {
                                ids: JSON.stringify(ids),
                                purchaseGroupCode:data.purchaseGroupCode
                            },
                            success: function () {
                                parent.layer.close(index);
                                selectPurchaseGroupElement.dialog('close');
                                topWin.layer.msg('数据保存成功', {icon: 1});
                                $(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: '温馨提示'});
                            }
                        });
                    });
                });
            }
        }, {
            text: '关闭',
            iconCls: 'icon-cancel',
            handler: function () {
                selectPurchaseGroupElement.dialog('close');
            }
        }]
    });
}

/**
 * 添加采购备注
 */
function addPurchaseRemark() {
    let rows = $(el.tb).datagrid('getSelections');
    if(rows.length !== 1){
        layer.msg("请选择一条数据");
        return;
    }
    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/purchase/apply/bill/detail/rest/updateDetailRemark',
            method: "post",
            data:{detailRemark:text,id:rows[0].id},
            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: '温馨提示'});
            }
        });
    });
}
/**
 * 添加采购备注
 */
function editPurchaseMethod() {
    let rows = $(el.tb).datagrid('getSelections');
    if(rows.length !== 1){
        layer.msg("请选择一条数据");
        return;
    }
    var id= '';
    var cbox = $('#tb').datagrid('getSelected');
    if (cbox === null || cbox === undefined) {
        layer.msg("请选中一条记录");
        return;
    }
    id = cbox.id;
    var purchaseMethodDialog = openDialog('purchaseMethodDialog', g.ctx + 'pc/inquiry/purchase/apply/bill/detail/purchaseMethodEdit?id=' + id , {
        title: '编辑',
        width: '400px',
        height: '60%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            purchaseMethodDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.save,
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['purchaseMethodDialog'].savePurchaseMethod(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        purchaseMethodDialog.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: itablei8n.close,
                iconCls: 'icon-cancel',
                handler: function () {
                    purchaseMethodDialog.dialog('close');
                }
            }
        ]
    });
}

function editPurchaseMethodTow() {
    let rows = $(el.tb).datagrid('getSelections');
    if(rows.length !== 1){
        layer.msg("请选择一条数据");
        return;
    }
    var id= '';
    var cbox = $('#tb').datagrid('getSelected');
    if (cbox === null || cbox === undefined) {
        layer.msg("请选中一条记录");
        return;
    }
    id = cbox.id;
    var purchaseMethodDialogTow = openDialog('purchaseMethodDialogTow', g.ctx + 'pc/inquiry/purchase/apply/bill/detail/purchaseMethodEditTow?id=' + id , {
        title: '编辑',
        width: '400px',
        height: '50%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            purchaseMethodDialogTow.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.save,
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['purchaseMethodDialogTow'].savePurchaseMethod(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        purchaseMethodDialogTow.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: itablei8n.close,
                iconCls: 'icon-cancel',
                handler: function () {
                    purchaseMethodDialogTow.dialog('close');
                }
            }
        ]
    });
}

function editPurchaseWayMethodTow() {
    var rows = $(el.tb).datagrid('getSelections');
    if (rows.length < 1) {
        layer.msg('请至少选中一个数据进行操作', {icon: 0});
        return false;
    }
    var ids = [];
    for(var i = 0; i < rows.length; i++){
        ids.push(rows[i].id);
    }
    var purchaseWayMethodDialogTow = openDialog('purchaseWayMethodDialogTow', g.ctx + 'pc/inquiry/purchase/apply/bill/detail/purchaseWayMethodEditTow?ids=' + ids.join(','),{
        title: '编辑',
        width: '400px',
        height: '50%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            purchaseWayMethodDialogTow.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.save,
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['purchaseWayMethodDialogTow'].savePurchaseWayMethod(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        purchaseWayMethodDialogTow.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: itablei8n.close,
                iconCls: 'icon-cancel',
                handler: function () {
                    purchaseWayMethodDialogTow.dialog('close');
                }
            }
        ]
    });
}

function searchInfo1() {
    var queryParams = {};
    queryParams.purchasingBusinessType = purchasingBusinessType;
    queryParams.purchaseMethod = $.trim($(el.purchaseMethod).val());
    queryParams.purchaseOrderNumber = $.trim($(el.purchaseOrderNumber).val());
    queryParams.billCode = $.trim($(el.billCode).val());
    queryParams.materialName = $.trim($(el.materialName).val());
    queryParams.materialSpec = $.trim($(el.materialSpec).val());
    queryParams.materialGroupName = $.trim($(el.materialGroupName).val());
    queryParams.transferStatus = $.trim($(el.transferStatus).val());
    queryParams.createName = $.trim($(el.createName).val());
    queryParams.factoryCode = $.trim($(el.factoryCode).val());
    queryParams.startCreateDate = $.trim($(el.startCreateDate).val());
    queryParams.endCreateDate = $.trim($(el.endCreateDate).val());
    queryParams.requireName = $.trim($(el.requireName).val());
    queryParams.searchFlag = $.trim($(el.searchFlag).val());
    queryParams.purchaseGroupCode = $.trim($(el.purchaseGroupCode).val());

    $(el.tb).datagrid('options').queryParams = queryParams;
    $(el.tb).datagrid('load');
    // searchInfo()
}
/**
 * 数据查询重置
 */
function searchReset() {
    $(el.purchaseMethod).combobox('setValue',null);
    $(el.purchaseOrderNumber).val('');
    $(el.billCode).val('');
    $(el.materialName).val('');
    $(el.materialSpec).val('');
    $(el.materialGroupName).val('');
    $(el.createName).val('');
    $(el.factoryCode).val('');
    $(el.searchFlag).val(1);
    $(el.startCreateDate).datebox('setValue','');
    $(el.endCreateDate).datebox('setValue','');
    $(el.requireName).val('');
    $(el.purchaseGroupCode).combobox('setValue','');
    $(el.transferStatus).combobox('setValue','');
    $(el.procureSubclass).combobox('setValue','');
    setTimeout(function f() {
        searchInfo1();
    }, 500);

}

/**
 * 获取表格列信息
 */
function getColumns() {
    let columns;
    if (purchasingBusinessType === "01") {
        // 费用类
        columns = [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'purchasingBusinessType',
                    title: '业务类型',
                    width: 120,

                    exportEnum:getDictList('purchasing_business_type'),
                    formatter: function (value) {
                        return getDicName('purchasing_business_type',value);
                    }
                },
                {
                    field: 'billCode',
                    title: '资产申请单号',
                    width: 140,
                    sortable: true
                },
                {
                    field: 'itemCode',
                    title: '行项目',
                    align : 'center',
                    width: 50
                },
                {
                    field: 'companyCode',
                    title: '公司',
                    width: 300,
                    sortable: true,
                    exportEnum:getNecessaryDataList('pc/sys/company/rest/listAll'),
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/company/rest/listAll',value);
                    }
                },
                {
                    field: 'applyUserName',
                    title: '申请人姓名',
                    width: 80,
                    sortable: true
                },
                {
                    field: 'applyDeptName',
                    title: '申请部门',
                    align : 'left',
                    width: 210,
                    sortable: true
                },
                {
                    field: 'applyTime',
                    title: '申请时间',
                    width: 80,
                    sortable: true,
                    exportDateFormatter:'dateTime',
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return moment(value).format('YYYY-MM-DD');
                    }
                },
                {
                    field: 'purchaseGroupCode',
                    title: '采购组',
                    width: 80,
                    sortable: true,
                    exportEnum:getNecessaryDataList('pc/sys/purchaseGroup/rest/listAll'),
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/purchaseGroup/rest/listAll',value);
                    }
                },
                { field: 'transferStatus', title: '数据状态', width: 80,
                    exportEnum:[
                        {code:1,codeWithDesc:'未转'},
                        {code:4,codeWithDesc:'已转合同'}
                    ],
                    formatter: function (value) {
                        switch (value) {
                            case 1:
                                return '<span>未转</span>';
                            case 4:
                                return '<span>已转合同</span>';
                            default:
                                return '';
                        }
                    }
                },
                { field: 'contractNo', title: '合同编号', width: 150 },
                {
                    field: 'mainUses',
                    title: '主要用途',
                    width: 250
                },
                {
                    field: 'expenseTypeLongName',
                    title: '报销类别-长名称',
                    width: 150,
                    sortable: true
                },
                {
                    field: 'materialSpec',
                    title: '详细规格参数',
                    width: 150
                },
                {
                    field: 'costUndertakeDeptCode',
                    title: '费用承担部门编码',
                    width: 120,
                    sortable: true
                },
                {
                    field: 'costUndertakeDeptName',
                    title: '费用承担部门名称',
                    width: 200
                },
                {
                    field: 'costCenterCode',
                    title: '成本中心编码',
                    width: 120,
                    sortable: true
                },
                {
                    field: 'costCenterName',
                    title: '成本中心名称',
                    width: 200
                },
                {
                    field: 'price',
                    title: '申请金额（含税）',
                    width: 120,
                    align: 'right',
                    formatter: function (value) {
                        return formatNumber(value, 2, 1);
                    }
                },
                {
                    field: 'currency',
                    title: '币种',
                    width: 50,
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'materialName',
                    title: '物品名称',
                    width: 150
                },
                {
                    field: 'factoryCode',
                    title: '工厂',
                    width: 80,
                    sortable: true
                },
                {
                    field: 'approvalNumber',
                    title: '数量',
                    width: 50,
                    align: 'right',
                    sortable: true
                },
                {
                    field: 'unitCodeBase',
                    title: '单位',
                    width: 120,
                    sortable: true,
                    formatter: function (value, row) {
                        return getDicName('unit',value);
                    }
                }
            ]
        ];
    } else if (purchasingBusinessType === "02") {
        // 资产类
        columns = [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'purchasingBusinessType',
                    title: '业务类型',
                    width: 100,
                    sortable: true,
                    exportEnum:getDictList('purchasing_business_type'),
                    formatter: function (value) {
                        var vv =  getDicName('purchasing_business_type',value);
                        if (vv === undefined || vv === "") {
                            return "（02）资产类"
                        } else {
                            return vv;
                        }
                    }
                },
                {
                    field: 'billCode',
                    title: '资产申请单号',
                    sortable: true,
                    width: 150
                },
                {
                    field: 'itemCode',
                    title: '行项目',
                    align : 'center',
                    sortable: true,
                    width: 50
                },
                {
                    field: 'procureSubclass',
                    title: '采购类别',
                    sortable: true,
                    width: 100,
                    formatter: function (value) {
                        var vv =  getDicName('procure_sub_class',value);
                        if (vv === undefined || vv === "") {
                            return value
                        } else {
                            return vv;
                        }
                        //
                        //
                        // if (value === "01") {
                        //     return "（01）办公用品";
                        // } else if (value === "02") {
                        //     return "（02）资产";
                        // } else {
                        //     return "低耗类资产";
                        // }
                    }
                },
                {
                    field: 'companyCode',
                    title: '公司编码',
                    sortable: true,
                    width: 250,
                    exportEnum:getNecessaryDataList('pc/sys/company/rest/listAll'),
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/company/rest/listAll',value);
                    }
                },
                {
                    field: 'supplierCode',
                    title: '供应商代码',
                    sortable: true,
                    width: 100,
                    hidden: true
                },
                {
                    field: 'supplierName',
                    title: '模具供应商名称',
                    sortable: true,
                    width: 220
                },
                {
                    field: 'materialName',
                    title: '物品名称/开模件名称',
                    sortable: true,
                    width: 180
                },
                {
                    field: 'modelType',
                    title: '模具类型',
                    sortable: true,
                    width: 100,
                    formatter: function (value) {
                        if (value === "01") {
                            return "（01）冲压";
                        } else if (value === "02") {
                            return "（02）压铸";
                        } else if (value === "03") {
                            return "（03）注塑";
                        } else if (value === "04") {
                            return "（04）组件模具";
                        } else if (value === "05") {
                            return "（05）型材模具";
                        } else if (value === "06") {
                            return "（06）硅胶模具";
                        } else if (value === "07") {
                            return "（07）刀模";
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'modelNumber',
                    title: '模具编号',
                    sortable: true,
                    width: 100
                },
                {
                    field: 'materialSpec',
                    title: '详细规格参数',
                    sortable: true,
                    width: 100
                },
                {
                    field: 'brand',
                    title: '品牌',
                    sortable: true,
                    width: 120
                },
                {
                    field: 'currency',
                    title: '币种',
                    sortable: true,
                    width: 80
                },
                {
                    field: 'approvalNumber',
                    title: '数量',
                    sortable: true,
                    width: 60
                },
                {
                    field: 'unitCodeBase',
                    title: '单位',
                    sortable: true,
                    width: 60
                },
                {
                    field: 'price',
                    title: '预估单价',
                    sortable: true,
                    width: 60
                },
                {
                    field: 'totalAmount',
                    title: '申请金额',
                    sortable: true,
                    width: 80
                },
                {
                    field: 'applyUserName',
                    title: '申请人姓名',
                    sortable: true,
                    width: 80
                },
                {
                    field: 'applyDeptName',
                    title: '申请部门',
                    sortable: true,
                    align : 'left',
                    width: 120
                },
                {
                    field: 'applyTime',
                    title: '申请时间',
                    sortable: true,
                    width: 80,
                    exportDateFormatter:'dateTime',
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return moment(value).format('YYYY-MM-DD');
                    }
                },
                {
                    field: 'userName',
                    title: '使用人姓名',
                    width: 80
                },
                {
                    field: 'useDeptName',
                    title: '使用部门-名称',
                    align : 'left',
                    width: 120
                },
                {
                    field: 'costCenterName',
                    title: '成本中心',
                    align : 'left',
                    width: 120
                },


                {
                    field: 'purchaseGroupCode',
                    title: '采购组',
                    sortable: true,
                    width: 80,
                    exportEnum:getNecessaryDataList('pc/sys/purchaseGroup/rest/listAll'),
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/purchaseGroup/rest/listAll',value);
                    }
                },

                {
                    field: 'purchaseWay',
                    title: '采购路径',
                    sortable: true,
                    width: 130,
                    exportEnum:getDictList('purchase_way'),
                    formatter: function (value) {
                        return getDicName('purchase_way',value);
                    }
                },
                {
                    field: 'purchaseMethod',
                    title: '采购方式',
                    sortable: true,
                    width: 80,
                    exportEnum:getDictList('purchase_method'),
                    formatter: function (value) {
                        return getDicName('purchase_method',value);
                    }
                },
                { field: 'transferStatus', title: '数据状态', width: 80,
                    exportEnum:[
                        {code:1,codeWithDesc:'未转'},
                        {code:4,codeWithDesc:'已转合同'}
                    ],
                    formatter: function (value) {
                        switch (value) {
                            case 1:
                                return '<span>未转</span>';
                            case 4:
                                return '<span>已转合同</span>';
                            default:
                                return '';
                        }
                    }
                },
                { field: 'contractNo', title: '合同编号', width: 150 },
                {
                    field: 'applyProjectType',
                    title: '申请样品制作项目类型',
                    sortable: true,
                    width: 130,
                    formatter: function (value) {
                        var vv =  getDicName('apply_project_type',value);
                        if (vv === undefined || vv === "") {
                            return value
                        } else {
                            return vv;
                        }
                        // if (value === "01") {
                        //     return "金属件";
                        // } else if (value === "02") {
                        //     return "散热片";
                        // } else if (value === "03") {
                        //     return "塑胶件";
                        // } else if (value === "04") {
                        //     return "其他";
                        // } else {
                        //     return "";
                        // }
                    }
                },
                {
                    field: 'modelApply',
                    title: '模具申请',
                    sortable: true,
                    width: 150,
                    formatter: function (value) {
                        if (value === "01") {
                            return "手板";
                        } else if (value === "02") {
                            return "开模";
                        } else if (value === "03") {
                            return "修模";
                        }
                    }
                },

                {
                    field: 'detailRemark',
                    title: '备注',
                    width: 80
                },
                {
                    field: 'subjectTypeCode',
                    title: '采购细类',
                    width: 80,
                    exportEnum:getDictList('gx_contract_subject'),
                    formatter: function (value) {
                        return getDicName('gx_contract_subject',value);
                    }
                },
                {
                    field: 'projectNo',
                    title: '项目编码',
                    sortable: true,
                    width: 80
                },
                {
                    field: 'projectName',
                    title: '项目名称',
                    sortable: true,
                    width: 120
                },
                {
                    field: 'customerCode',
                    title: '服务客户编码',
                    sortable: true,
                    width: 80
                },
                {
                    field: 'customerName',
                    title: '服务客户名称',
                    sortable: true,
                    width: 150
                },
                {
                    field: 'applyBillType',
                    title: '资产申请单据类型',
                    // sortable: true,
                    width: 120
                },
                {
                    field: 'createUserCode',
                    title: '申请人工号',
                    // sortable: true,
                    width: 80
                }
                ,
                {
                    field: 'mainUses',
                    title: '主要用途',
                    // sortable: true,
                    width: 150
                },
                {
                    field: 'stockCode',
                    title: '存放地点',
                    hidden: true,
                    width: 150
                },
                {
                    field: 'stockName',
                    title: '存放地点',
                    // sortable: true,
                    width: 150
                },
                {
                    field: 'projectProcess',
                    title: '项目所处阶段',
                    // sortable: true,
                    width: 100
                },
                {
                    field: 'costCenterCode',
                    title: '成本中心',
                    // sortable: true,
                    width: 100
                },
                {
                    field: 'expiredServiceYear',
                    title: '预计使用年限',
                    // sortable: true,
                    width: 100
                }
                ,
                {
                    field: 'userCode',
                    title: '使用人员',
                    // sortable: true,
                    width: 100
                },
                {
                    field: 'useDeptCode',
                    title: '使用部门',
                    // sortable: true,
                    width: 100
                }
            ]
        ];
    } else {
        // 其他类
        columns = [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                { field: 'billCode', title: '资产申请单号', align : 'left', width: 220},
                { field: 'itemCode', title: '行项目', align : 'left', width: 50},
                { field: 'purchaseApplyTypeCode', title: '采购类别', width: 110,
                    exportEnum:getDictList('apply_type'),
                    formatter: function (value) {
                        return getDicName('apply_type',value);
                    }
                },
                { field: 'purchaseOrderNumber', title: '采购单号', align : 'left', width: 120},
                { field: 'requireName', title: '申请人', width: 60 },
                { field: 'purchaseMethod', title: '采购方式', width: 80,
                    exportEnum:getDictList('purchase_method'),
                    formatter: function (value) {
                        return getDicName('purchase_method',value);
                    }
                },
                { field: 'transferStatus', title: '数据状态', width: 80,
                    exportEnum:[
                        {code:1,codeWithDesc:'未转'},
                        {code:2,codeWithDesc:'震坤行订单'},
                        {code:3,codeWithDesc:'第三方订单'},
                        {code:4,codeWithDesc:'已转合同'}
                    ],
                    formatter: function (value) {
                        switch (value) {
                            case 1:
                                return '<span>未转</span>';
                            case 2:
                                return '<span>震坤行订单</span>';
                            case 3:
                                return '<span>第三方订单</span>';
                            case 4:
                                return '<span>已转合同</span>';
                            default:
                                return '';
                        }
                    }
                },
                { field: 'materialGroupName', title: '物料组名称', width: 100 },
                { field: 'materialName', title: '物品名称', width: 240},
                { field: 'materialSpec', title: '详细规格参数', width: 100 },
                { field: 'unitCode', title: '采购单位', width: 80},
                { field: 'requireNum', title: '需求数量', width: 120},
                { field: 'price', title: '预估单价', width: 140},
                { field: 'totalAmount', title: '预估总金额', align : 'left', width: 80},
                { field: 'realityTotalAmount', title: '实际采购金额', align : 'left', width: 100},
                { field: 'contractNo', title: '合同号', align : 'left', width: 250},
                { field: 'increasePrice', title: '降价率', align : 'left', width: 80},
                { field: 'purchaseGroupCode', title: '采购组', width: 120,
                    exportEnum:getNecessaryDataList('pc/sys/purchaseGroup/rest/listAll'),
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/purchaseGroup/rest/listAll',value);
                    }
                },
                { field: 'costCenterName', title: '成本中心名称', width: 240},
                { field: 'factor', title: '驱动因素', width: 240,
                    formatter: function (value) {
                        return getDicName('contract_pay_boot_item',value);
                    }
                },
                { field: 'applyTime', title: '申请日期', width: 140,
                    exportDateFormatter:'dateTime',
                    formatter: function (value) {
                        if (!value) {
                            return '';
                        }
                        return moment(value).format('YYYY-MM-DD');
                    }
                },
                { field: 'urgency', title: '紧急程度', width: 100 },
                { field: 'detailRemark', title: '行备注', width: 240,        formatter: function(value, row, index) {
                        return '<a href="#" style="color: black" title="' + value + '" class="note">' + value + '</a>';
                    }},
                { field: 'customerName', title: '服务客户名称', width: 240},
                { field: 'companyCode', title: '公司', width: 180,
                    exportEnum:getNecessaryDataList('pc/sys/company/rest/listAll'),
                    formatter: function (value) {
                        return getNecessaryDataName('pc/sys/company/rest/listAll',value);
                    }
                },
                { field: 'factoryCode', title: '工厂', width: 120},
                { field: 'teamName', title: '申请人部门', align : 'left', width: 80},
                { field: 'tenderCode', title: '招标单号', width: 100 },
                { field: 'enquiryCode', title: '询价单号', width: 150 },
            ]
        ];
    }
    return columns;
}