/**
 * 目录采购-选购商品确认页面JS
 *
 * Created by li.kui on 2021/1/7.
 */
'use strict';
var el = {
    tb: '#tb',
    tableData: [],
    editIndex: undefined,
    receivingUser: '#receivingUser',
    receivingTel: '#receivingTel',
    provinceCityCounty: '#provinceCityCounty',
    provinceName: '#provinceName',
    provinceCode: '#provinceCode',
    cityName: '#cityName',
    cityCode: '#cityCode',
    countyName: '#countyName',
    countyCode: '#countyCode',
    address: '#address',
    invoiceTitle: '#invoiceTitle',
    invoiceType: '#invoiceType',
    invoiceState: '#invoiceState',
    invoiceNo: '#invoiceNo',
    invoiceAddress: '#invoiceAddress',
    invoiceTel: '#invoiceTel',
    openingBank: '#openingBank',
    content: '#content',
    bankAccount: '#bankAccount',
    bankTel: '#bankTel',
    bankAddress: '#bankAddress',
    factoryCode: '#factoryCode',
    purchaseGroup: '#purchaseGroup',
    purchaseOrg: '#purchaseOrg',
    centerCode: '#centerCode',
    companyCode: '#companyCode',
    receivingId: '#receivingId',
    invoiceId: '#invoiceId',
    remark: '#remark',
    mgData: [],
    chosePurchaseApplyDialog: null,
    choseMorePurchaseApplyDialog:null,
    bodyHeight: document.documentElement.clientHeight
};


/**
 * 文档就绪
 */
$(function () {

    $("#fileInput").filebox({
        buttonText: 'Choose', buttonAlign: 'left', onChange: fileUpload
    });

    // 初始化抬头代码选择
    $(el.invoiceTitle).textbox({
        required: true,
        icons: [
            {
                iconCls: 'icon-search',
                handler: function () {
                    choseInvoice();
                }
            }
        ]
    });
    $(el.invoiceTitle).textbox('textbox').css('cursor', 'pointer');
    $(el.invoiceTitle).textbox('textbox').bind('click', function () {
        choseInvoice();
    });

    //初始化收货人选择
    /*$(el.receivingUser).textbox({
        required: true,
        icons: [
            {
                iconCls: 'icon-search',
                handler: function () {
                    choseSupplier();
                }
            }
        ]
    });
    $(el.receivingUser).textbox('textbox').css('cursor', 'pointer');
    $(el.receivingUser).textbox('textbox').bind('click', function () {
        choseSupplier();
    });
*/

    //采购组织
    $(el.purchaseOrg).combobox({
        valueField: 'purchaseOrgCode',
        textField: 'codeWithDesc',
        limitToList: 'true',
        method: 'POST',
        prompt: '--- 请选择 ---',
        url: g.ctx + 'pc/sys/purchaseOrg/rest/listAll',
    });


    //采购组
    $(el.purchaseGroup).combobox({
        valueField: 'purchaseGroupCode',
        textField: 'codeWithDesc',
        limitToList: 'true',
        method: 'POST',
        prompt: '--- 请选择 ---',
        url: g.ctx + 'pc/sys/purchaseGroup/rest/listAll',
    });


    // 初始化工厂下拉框
    $(el.factoryCode).combobox({
        url: g.ctx + 'pc/sys/factory/rest/listAll',
        editable: false,
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
        // onSelect: function (data) {
        //     findCostDataByFactoryCode(data.factoryCode);
        // }
    });

    initDataGird();
});


/**
 * 初始化页面表格
 */
function initDataGird(tableData) {
    $(el.tb).datagrid({
        title: '选购商品',
        loadMsg: '数据加载中......',
        data: [],
        height: el.bodyHeight - 400,
        singleSelect: true,
        rownumbers: true,
        // 定义从服务器对数据进行排序
        remoteSort: false,
        pagination: false,
        toolbar: [
            {
                text: '导入商品',
                id: 'btn_excel',
                iconCls: 'icon-redo',
                handler: function () {
                    //$("#fileUpload .filebox-label").click();
                    importDicItem();
                }
            },
            {
                text: '采购申请',
                id: 'btn_search',
                iconCls: 'icon-search',
                handler: function () {
                    //$("#fileUpload .filebox-label").click();
                    purchaseSearch();
                }
            }/*,
            {
                text: '导出',
                iconCls: 'icon-print',
                id: 'icon_print',
                handler: function () {
                    exportExcel();
                }
            },*/

        ],
        frozenColumns: [
            [
                {
                    field: 'opt',
                    title: '操作',
                    width: 60,
                    formatter: function (value, row) {
                        return '<a href="javascript:void(0)" onclick="delData(this)"  style="cursor: pointer;">删除</a>';
                    }
                }
            ]
        ],
        columns: [
            [
                {
                    field: 'source',
                    title: '商城编码',
                    width: 100
                },
                {
                    field: 'sourceName',
                    title: '来源',
                    width: 90
                },
                {
                    field: 'productCode',
                    title: '商品编码',
                    width: 90
                },
                {
                    field: 'productName',
                    title: '商品名称',
                    width: 240,
                    formatter: function (value) {
                        if(value==undefined){
                            return '';
                        }
                        return '<span style="display: inline-block;width: 450px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;" title="' + value + '">' + value + '</span>';
                    }
                },
                {
                    field: 'productUnit',
                    title: '单位',
                    width: 70
                },
                {
                    field: 'productPrice',
                    title: '商品价格',
                    width: 100,
                },
                {
                    field: 'qty',
                    title: '数量',
                    width: 70,
                },
                {
                    field: 'prCode',
                    title: '采购申请单号',
                    width: 240,
                    editor: {
                        type: 'textbox',
                        options: {
                            prompt: '请选择采购申请',
                            editable: false,
                            icons: [
                                {
                                    iconCls: 'icon-clear',
                                    handler: function () {
                                        clearPurchaseApply();
                                    }
                                },
                                {
                                    iconCls: 'icon-search',
                                    handler: function () {
                                        chosePurchaseApply();
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    field: 'prItemNo',
                    title: '行号',
                    width: 80,
                    editor: {type: 'textbox', options: {required: false, editable: false}}
                },
                {
                    field: 'requireNum',
                    title: '请购数量',
                    width: 100,
                    editor: {type: 'textbox', options: {required: false, editable: false}}
                },
                {
                    field: 'materialName',
                    title: '物料描述',
                    width: 220,
                    editor: {type: 'textbox', options: {required: true, editable: false}}
                },
                {
                    field: 'materialSpec',
                    title: '规格',
                    width: 120,
                    editor: {type: 'textbox', options: {required: true, editable: false}}
                }
            ]
        ],
        onLoadSuccess: function () {
            $(el.tb).datagrid('clearSelections');
        },
        onClickRow: function (index) {
            if (el.editIndex !== undefined) {
                endEditor();
                $(el.tb).datagrid('beginEdit', index);
                el.editIndex = index;
            } else {
                $(el.tb).datagrid('beginEdit', index);
                el.editIndex = index;
            }
        }
    });
}

/**
 * 清空采购申请
 */
function clearPurchaseApply() {
    var row = {}, rows = $(el.tb).datagrid('getRows');
    for (var n = 0; n < rows.length; n++) {
        var rowIndex = $(el.tb).datagrid('getRowIndex', rows[n]);
        if (rowIndex === el.editIndex) {
            row = rows[n];
            break;
        }
    }

    if (row.prCode) {
        $(el.tb).datagrid('updateRow', {
            index: el.editIndex,
            row: {
                prCode: '',
                prItemNo: '',
                materialName: '',
                requireNum:'',
                materialSpec:''
            }
        });
    }
}

/**
 * 商城订单明细关联采购申请选择弹框
 */
function purchaseSearch() {
    var url = g.ctx + 'pc/mall/shopping/page/selectMore'
    el.choseMorePurchaseApplyDialog = openDialog('choseMorePr', url, {
        title: '采购申请选择',
        width: '80%',
        height: '100%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.choseMorePurchaseApplyDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '确定',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['choseMorePr'].getSelections(function (data) {
                        appendPurchaseRow(data);
                        el.choseMorePurchaseApplyDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.choseMorePurchaseApplyDialog.dialog('close');
                }
            }
        ]
    });
}

/**
 * 商城订单明细关联采购申请选择弹框
 */
function chosePurchaseApply() {
    /*var pgoCode = $(el.purchaseOrg).combobox('getValue'), pgCode = $(el.purchaseGroup).combobox('getValue'),
        factoryCode = $(el.factoryCode).combobox('getValue'), centerCode = $(el.centerCode).textbox('getValue');
    if (!pgoCode) {
        topWin.layer.msg('请先选择采购组织', {icon: 0});
        return false;
    }
    if (!pgCode) {
        topWin.layer.msg('请先选择采购组', {icon: 0});
        return false;
    }
    if (!factoryCode) {
        topWin.layer.msg('请先选择工厂', {icon: 0});
        return false;
    }
    if (!centerCode) {
        topWin.layer.msg('请先选择成本中心', {icon: 0});
        return false;
    }*/

    // 根据采购组织、采购组、工厂、成本中心获取采购申请
    /*  var url = g.ctx + 'catalog/purchase/chose/purchase/apply/dialog?parentFrameName=choseBuyConfirm' +
          '&pgoCode=' + pgoCode + '&pgCode=' + pgCode + '&factoryCode=' + factoryCode + '&costCenterCode=' + centerCode;*/
    var url = g.ctx + 'pc/mall/shopping/page/select'
    el.chosePurchaseApplyDialog = openDialog('chosePr', url, {
        title: '采购申请选择',
        width: '80%',
        height: '100%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.chosePurchaseApplyDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '确定',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['chosePr'].getChecked(function (data) {
                        console.log(data);
                        chosePrUpdateTableData(data);
                        el.chosePurchaseApplyDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.chosePurchaseApplyDialog.dialog('close');
                }
            }
        ]
    });
}

/**
 * 选择完采购申请后更新表格数据
 *
 * @param data 选择的采购申请数据
 */
function chosePrUpdateTableData(data) {
    $(el.tb).datagrid('updateRow', {
        index: el.editIndex,
        row: {
            prCode: data.billCode,
            prItemNo: data.itemCode,
            materialName: data.materialName,
            requireNum:data.requireNum,
            materialSpec:data.materialSpec
        }
    });
}

function appendPurchaseRow(data) {
    var rows = $(el.tb).datagrid("getRows");
    if (rows && rows.length > 0) {
        for (var i = 0; i < data.length; i++) {
            var flag = true;
            for (var j = 0; j < rows.length; j++) {
                if (data[i].billCode == rows[j].prCode && data[i].itemCode == rows[j].prItemNo) {
                    flag = false;
                }
            }
            if (flag) {
                $(el.tb).datagrid('appendRow', {
                    prCode: data[i].billCode,
                    prItemNo: data[i].itemCode,
                    materialName: data[i].materialName,
                    requireNum:data[i].requireNum,
                    materialSpec:data[i].materialSpec
                });
            }
        }
    } else {
        for (var i = 0; i < data.length; i++) {
            $(el.tb).datagrid('appendRow', {
                prCode: data[i].billCode,
                prItemNo: data[i].itemCode,
                materialName: data[i].materialName,
                requireNum:data[i].requireNum,
                materialSpec:data[i].materialSpec
            });
        }
    }

}
/**
 * 导出excel
 */
function exportExcel() {
    endEditor();
    var rows = $(el.tb).datagrid("getRows");
    var queryStr = [];
    for (var i = 0; i < rows.length; i++) {
        var item = {}, row = rows[i];
        item.productCode ="";
        item.productName = "";
        item.productPrice = "";
        item.qty = "";
        item.productUnit = "";
        item.sourceCode = "";
        item.sourceName = "";
        item.prCode = row.prCode;
        item.prItemNo = row.prItemNo;
        item.requireNum = row.requireNum;
        item.materialSpec = row.materialSpec;
        item.materialName = row.materialName;
        queryStr.push(item);
    }
   /* var url = g.ctx + "pc/mall/shopping/rest/export";
    setTimeout(function (){window.open(url);},500);*/
    openExportDialog('pc/mall/shopping/rest/export', "tb", queryStr)
}

/**
 * 删除数据
 *
 * @param ele 当前操作节点
 */
function delData() {
    var rows = $(el.tb).datagrid('getSelected');
    var rowIndex = $(el.tb).datagrid('getRowIndex', rows);
    $(el.tb).datagrid('deleteRow', rowIndex);

}

/**
 * 结束编辑
 */
function endEditor() {
    $(el.tb).datagrid('endEdit', el.editIndex);
    el.editIndex = undefined;
}


/**
 * 数据保存
 *
 * @callback 回调函数
 */
function dataSave(callback) {
    endEditor();
    var rows = $(el.tb).datagrid('getRows');
    if (rows.length === 0) {
        topWin.layer.msg('当前选购商品为空不允许提交, 请检查', {icon: 0});
        return false;
    }

    /*var receivingItem = {};
    receivingItem.receivingUser = $(el.receivingUser).val();
    receivingItem.receivingTel = $(el.receivingTel).val();
    receivingItem.provinceName = $(el.provinceName).val();
    receivingItem.provinceCode = $(el.provinceCode).val();
    receivingItem.cityName = $(el.cityName).val();
    receivingItem.cityCode = $(el.cityCode).val();
    receivingItem.countyName = $(el.countyName).val();
    receivingItem.countyCode = $(el.countyCode).val();
    receivingItem.address = $(el.address).val();
    receivingItem.id = $(el.receivingId).val();*/

    /*    if (receivingItem.receivingUser === '') {
            topWin.layer.msg('收货人不能为空', {icon: 0});
            return false;
        }
        if (receivingItem.receivingTel === '') {
            topWin.layer.msg('收货电话不能为空', {icon: 0});
            return false;
        }
        if (receivingItem.provinceCode === '') {
            topWin.layer.msg('省份不能为空', {icon: 0});
            return false;
        }
        if (receivingItem.address === '') {
            topWin.layer.msg('详细地址不能为空', {icon: 0});
            return false;
        }*/

    var dateItem = {};
    dateItem.factoryCode = $(el.factoryCode).combobox('getValue');
    dateItem.factoryName = $(el.factoryCode).combobox('getText');
    //dateItem.centerCode = $(el.centerCode).textbox('getValue');
    dateItem.purchaseGroup = $(el.purchaseGroup).combobox('getValue');
    dateItem.purchaseOrg = $(el.purchaseOrg).combobox('getValue');
    dateItem.remark = $(el.remark).textbox('getValue');
    if (dateItem.purchaseOrg === '') {
        topWin.layer.msg('采购组织不能为空', {icon: 0});
        return false;
    }
    if (dateItem.purchaseGroup === '') {
        topWin.layer.msg('采购组不能为空', {icon: 0});
        return false;
    }
    if (dateItem.factoryCode === '') {
        topWin.layer.msg('工厂不能为空', {icon: 0});
        return false;
    }
    /*if (dateItem.centerCode === '') {
        topWin.layer.msg('成本中心不能为空', {icon: 0});
        return false;
    }*/

    var invoiceItem = {};
    invoiceItem.invoiceState = $(el.invoiceState).val();
    invoiceItem.invoiceType = $(el.invoiceType).val();
    invoiceItem.invoiceTitle = $(el.invoiceTitle).val();
    invoiceItem.invoiceNo = $(el.invoiceNo).val();
    invoiceItem.invoiceAddress = $(el.invoiceAddress).val();
    invoiceItem.invoiceTel = $(el.invoiceTel).val();
    invoiceItem.content = $(el.content).val();
    invoiceItem.openingBank = $(el.openingBank).val();
    invoiceItem.bankAccount = $(el.bankAccount).val();
    invoiceItem.bankTel = $(el.bankTel).val();
    invoiceItem.bankAddress = $(el.bankAddress).val();
    invoiceItem.id = $(el.invoiceId).val();

    if (Number(invoiceItem.invoiceState) === 1) {
        if (invoiceItem.invoiceNo === '') {
            topWin.layer.msg('纳税人识别号不能为空', {icon: 0});
            return false;
        }

        if (Number(invoiceItem.invoiceType) === 2) {
            if (invoiceItem.invoiceTitle === '') {
                topWin.layer.msg('发票抬头不能为空', {icon: 0});
                return false;
            }
            if (invoiceItem.invoiceAddress === '') {
                topWin.layer.msg('注册地址不能为空', {icon: 0});
                return false;
            }
            if (invoiceItem.receivingTel === '') {
                topWin.layer.msg('注册电话不能为空', {icon: 0});
                return false;
            }
            if (invoiceItem.openingBank === '') {
                topWin.layer.msg('开户银行不能为空', {icon: 0});
                return false;
            }
            if (invoiceItem.bankAccount === '') {
                topWin.layer.msg('开户银行不能为空', {icon: 0});
                return false;
            }
            if (invoiceItem.address === '') {
                topWin.layer.msg('开户银行不能为空', {icon: 0});
                return false;
            }
        }
    }

    if (!invoiceItem.content) {
        topWin.layer.msg('发票内容不能为空', {icon: 0});
        return false;
    }

    var params = [];
    for (var i = 0; i < rows.length; i++) {
        var item = {}, row = rows[i];
        if (!row.productCode) {
            topWin.layer.msg('选购商品中存在商品编码为空的记录, 请检查', {icon: 0});
            return false;
        }
        if (!row.productPrice) {
            topWin.layer.msg('选购商品中存在商品价格为空的记录, 请检查', {icon: 0});
            return false;
        }
        if (!row.qty) {
            topWin.layer.msg('选购商品中存在数量为空的记录, 请检查', {icon: 0});
            return false;
        }
        if (!row.prCode) {
            topWin.layer.msg('选购商品中存在采购申请单号为空的记录, 请检查', {icon: 0});
            return false;
        }
        item.productCode = row.productCode;
        item.productName = row.productName;
        item.productPrice = row.productPrice;
        item.qty = row.qty;
        item.productUnit = row.productUnit;
        item.sourceCode = row.source;
        item.sourceName = row.sourceName;
        item.mgCode = row.mgCode;
        item.mgName = row.mgName;
        item.prCode = row.prCode;
        item.prItemNo = row.prItemNo;
        item.requireNum = row.requireNum;
        item.materialSpec = row.materialSpec;
        params.push(item);
    }

    topWin.layer.confirm('您确定要提交当前列表数据吗?', {icon: 3}, function (index) {
        topWin.layer.close(index);

        var loading = topWin.layer.msg('数据提交中, 请耐心等待......', {icon: 16, time: 0, shade: 0.1});
        $.ajax({
            type: 'POST',
            url: '/pc/mall/shopping/rest/push/mall/excel/cart',
            data: {
                params: JSON.stringify(params),
                //receivingItem: JSON.stringify(receivingItem),
                invoiceItem: JSON.stringify(invoiceItem),
                dateItem: JSON.stringify(dateItem)
            },
            success: function (data) {
                if (Number(data.code) === 0) {
                    topWin.layer.close(loading);
                    //topWin.layer.msg(data.errorMsg, {icon: 1});
                    callback();
                } else {
                    topWin.layer.close(loading);
                    //parent.layer.alert(data.errorMsg, {icon: 2});
                    callback();
                }
            },
            error: function (data) {
                topWin.layer.close(loading);
                topWin.layer.alert(data.responseJSON, {icon: 2});
            }
        });
    });
}


/**
 * 选择收货地址
 */

/*function choseSupplier() {
    var receivingUser = $(el.receivingUser).textbox('getValue');
    var url = '/pc/mall/address/page/chose/address/dialog?supCodes=' + receivingUser + '&singleSelect=1&parentFrameName=addOrEditPaa';
    el.choseSupplierDialog = openDialog('choseSupplier', url, {
        title: '收货地址选择',
        width: '850px',
        height: '560px',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.choseSupplierDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '确定',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['choseSupplier'].confirmChose(function (data) {
                        $(el.receivingId).val(data[0].id);
                        $(el.receivingUser).textbox('setValue', data[0].receivingUser);
                        $(el.receivingTel).textbox('setValue', data[0].receivingTel);
                        $(el.address).textbox('setValue', data[0].address);
                        $(el.provinceCityCounty).textbox('setValue', data[0].provinceName + '/' + data[0].cityName + '/' + data[0].countyName);
                        $(el.provinceName).val(data[0].provinceName);
                        $(el.provinceCode).val(data[0].provinceCode);
                        $(el.cityName).val(data[0].cityName);
                        $(el.cityCode).val(data[0].cityCode);
                        $(el.countyName).val(data[0].countyName);
                        $(el.countyCode).val(data[0].countyCode);

                        el.choseSupplierDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.choseSupplierDialog.dialog('close');
                }
            }
        ]
    });
}*/


/**
 * 选择发票信息
 */
function choseInvoice() {
    /* var centerCode = $(el.centerCode).textbox('getValue');
     if (!centerCode) {
         topWin.layer.msg('请先选择成本中心', {icon: 0});
         return false;
     }*/
    var companyCode = $(el.companyCode).val();
    var url = '/pc/mall/invoice/page/chose/invoice/dialog?companyCode=' + companyCode + '&singleSelect=1';
    el.choseInvoiceDialog = openDialog('choseInvoice', url, {
        title: '发票信息',
        width: '850px',
        height: '560px',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            el.choseInvoiceDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '确定',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['choseInvoice'].confirmChose(function (data) {
                        $(el.invoiceTitle).textbox('setValue', data[0].invoiceTitle);
                        $(el.invoiceNo).textbox('setValue', data[0].invoiceNo);
                        $(el.invoiceAddress).textbox('setValue', data[0].invoiceAddress);
                        $(el.invoiceTel).textbox('setValue', data[0].invoiceTel);
                        $(el.openingBank).textbox('setValue', data[0].openingBank);
                        $(el.bankAccount).textbox('setValue', data[0].bankAccount);
                        $(el.bankTel).textbox('setValue', data[0].bankTel);
                        $(el.bankAddress).textbox('setValue', data[0].bankAddress);
                        $(el.invoiceId).val(data[0].id);
                        el.choseInvoiceDialog.dialog('close');
                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    el.choseInvoiceDialog.dialog('close');
                }
            }
        ]
    });
}


/*function fileUpload() {
    let addFiles = [];
    let files = $("#fileInput").filebox('files'), formData = new FormData()
    for (let r = 0; r < files.length; r++) {
        addFiles.push(files[r]);
    }
    for (let n = 0; n < addFiles.length; n++) {
        formData.append('files', addFiles[n]);
    }
    if (addFiles.length > 0) {
        $.ajax({
            url: '/pc/mall/cart/rest/form/excelShopCart', type: 'POST', data: formData, processData: false,// ⑧告诉jQuery不要去处理发送的数据
            contentType: false,
            success: function (res) {
                $(el.tb).datagrid('loadData',res);
                topWin.layer.msg('上传成功', {icon: 1});
                //$(el.tb).datagrid('reload');
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
        $("#fileInput").filebox('clear')
    }

}*/

/**
 * 开票方式和发票类型 修改后重置发票信息
 */
function typeChange() {
    $(el.invoiceTitle).textbox('setValue', '');
    $(el.invoiceNo).textbox('setValue', '');
    $(el.invoiceAddress).textbox('setValue', '');
    $(el.invoiceTel).textbox('setValue', '');
    $(el.content).textbox('setValue', '');
    $(el.openingBank).textbox('setValue', '');
    $(el.bankAccount).textbox('setValue', '');
    $(el.bankTel).textbox('setValue', '');
    $(el.bankAddress).textbox('setValue', '');
}

/**
 * 导入
 */
function importDicItem() {
    endEditor();
    var rows = $(el.tb).datagrid("getRows");
    var queryStr = [];
    for (var i = 0; i < rows.length; i++) {
        var item = {}, row = rows[i];
        item.productCode ="";
        item.productName = "";
        item.productPrice = "";
        item.qty = "";
        item.productUnit = "";
        item.sourceCode = "";
        item.sourceName = "";
        item.prCode = row.prCode;
        item.prItemNo = row.prItemNo;
        item.requireNum = row.requireNum;
        item.materialSpec = row.materialSpec;
        item.materialName = row.materialName;
        queryStr.push(item);
    }
    var a = openQueryImportExcelDialog('pc/mall/shopping/rest/export',queryStr,'queryStr',function(file){

        // var a = openImportExcelDialog("static/excel/buy_confirm_list.xlsx", '选购商品导入', function (file) {
        let formData = new FormData();
        formData.append("files", file);
        $.ajax({
            url: '/pc/mall/cart/rest/form/excelShopCart', type: 'POST', data: formData, processData: false,// ⑧告诉jQuery不要去处理发送的数据
            contentType: false,
            success: function (res) {
                topWin.layer.msg('上传成功', {icon: 1});
                a.dialog('close');
                $(el.tb).datagrid('loadData', res);
                //$(el.tb).datagrid('reload');
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
        $("#fileInput").filebox('clear');
    });
}