/*--------------------------文档信息-------------------------------------------
///功能：      销售回款明细
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP021303 = "Tp021303";               //表格ID
var strPageP021303 = "divPageP021303";    //分页层的ID
var objSelRowP021303 = {};                          //选择行的数据
var intSelRowIDP021303 = 0;                        //选择行的ID
var objPageParamP021303 = { sortfield: "djdate", orderby: "asc", where: "", flag: 1 };     //分页控件使用

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    cihoDlgClose(strDialog);                 //关闭弹出层
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//页面加载方法
function pageLoad_P021303() {
    try {
        //选择日期范围
        dateExtent_P021303();
        //加载客户商信息
        loadProviderData_P021303();
        //药品下拉框信息的加载
        loadDrugData_P021303();
        //销售人员下拉框信息的加载
        loadXsryData_P021303();
        //获得表格的列属性
        objConfig = ParseData(window.external.DoOptions(strTableP021303, "GetTableConfig", "{}"));
        //格式化表中的数据
        setData_P021303(objConfig.colModel);
        //创建表格
        createGrid(strTableP021303, objConfig.colNames, objConfig.colModel, [], null, null, true, null);
        //添加事件
        addGridEvent_P021303();
        //调整表格的大小
        resizeGrid(strTableP021303, true, true);
        //创建分页
        createPage(strPageP021303, strTableP021303);
        //加载表格数据(触发查询按钮的点击事件)
        searchDataClick_P021303();
    } catch (e) { }
}

//查询按钮的事件
function searchDataClick_P021303() {
    try {
        var objResult = {};     //定义变量用于接收从后台获得的数据集
        if (!$("#cmbProviderP021303").combobox("getValue")) {            //"当前选择的客户不存在时,赋值为【全部客户】"
            $("#cmbProviderP021303").combobox("setValue", "");
        }
        if (!$("#cmbDrugP021303").combobox("getValue")) {           //"当前选择的药品不存在时,赋值为【全部药品】"
            $("#cmbDrugP021303").combobox("setValue", "");
        }
        if (!$("#cmbXsyP021303").combobox("getValue")) {           //"当前选择的销售员不存在时,赋值为【全部销售员】"
            $("#cmbXsyP021303").combobox("setValue", "");
        }

        //查询条件的取得
        objPageParamP021303.where = mySearchWhereJson();
        objPageParamP021303.sortfield = "djdate";
        objPageParamP021303.orderby = "asc";
        objPageParamP021303.flag = 1;
        objResult = loadGridData_Page(objPageParamP021303);
        var intIDLength = $("#" + strTableP021303).getDataIDs();
        if (intIDLength.length > 0) {
            $("#" + strTableP021303).footerData("set", { rn: "合计",
                a2: parseFloat(objResult.yhje).toFixed(window.parent.strMoneyPlace),
                a3: parseFloat(objResult.ssje).toFixed(window.parent.strMoneyPlace)
            }, false);
        }
        else {
            $("#" + strTableP021303).footerData("set", { rn: "合计",
                a2: "&nbsp;",
                a3: "&nbsp;"
            }, false);
        }
    } catch (e) { }
}

//查看单据按钮的事件
function viewReceipt_P021303() {
    if (intSelRowIDP021303 > 0) {
        if (objSelRowP021303.djbh.substr(0, 2) == "SK") {
            //收款单据
            showDialogP021303_skd("divP021303_skd", objSelRowP021303.djbh);
        }
    }
    else {
        //"请选择数据！"
        window.parent.cihoAlert(msg.other.selDataRow);
    }
}

//返回按钮的事件
function pageBack_P021303() {
    //改变标签的Name
    $(window.parent.document).find("#span_213").text("销售回款统计");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-213").css("display", ""); //显示统计页面
    $(window.parent.document).find("#idIframe-21303").css("display", "none"); //隐藏明细页面
    $(window.parent.document).find("#idIframe-21303").attr("src", "");
}

//日期范围修改事件
function dateTimeChange_P021303() {
    if ($("#cmbDateExtentP021303").combobox("getText") != "自定义") {
        $("#cmbDateExtentP021303").combobox("setValue", "");
        $("#cmbDateExtentP021303").combobox("setText", "自定义");
    }
}

//表格中的事件
function addGridEvent_P021303() {
    $("#" + strTableP021303).setGridParam({
        onSelectRow: function (rowid) {
            intSelRowIDP021303 = rowid;
            objSelRowP021303 = $(this).getRowData(rowid);
        },
        ondblClickRow: function () {
            viewReceipt_P021303();
        },
        onSortCol: function (index, colindex, sortorder) {
            objPageParamP021303.sortfield = index;
            objPageParamP021303.orderby = sortorder;
            objPageParamP021303.flag = "";
            loadGridData_Page(objPageParamP021303);
            return "stop";
        }
    });
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**事件方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//格式化数据
function setData_P021303(objP021303) {
    for (var i = 0; i < objP021303.length; i++) {
        if (objP021303[i].name == "a2" || objP021303[i].name == "a3") {
            objP021303[i].formatter = formatterP0213Money;
        }
    }
}

//选择日期范围
function dateExtent_P021303() {
    dateExtentCalculation("本月", "dateStartTimeP021303", "dateEndTimeP021303");
    $("#cmbDateExtentP021303").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        panelHeight: 102,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP021303", "dateEndTimeP021303");
        },
        enterDown: function () {
            dateExtentCalculation($("#cmbDateExtentP021303").combobox("getValue"), "dateStartTimeP021303", "dateEndTimeP021303");
        }
    });
    //加载数据
    $("#cmbDateExtentP021303").combobox("loadData",
    [{ dm: "本月", mc: "本月", selected: true },
    { dm: "上一月", mc: "上一月" },
    { dm: "本周", mc: "本周" },
    { dm: "过去三个月", mc: "过去三个月" },
    { dm: "本年", mc: "本年"}]);
    var strDateItem = $(window.parent.document).find("#idIframe-21303").attr("dname");
    //设置默认日期为本月
    if (strDateItem != "") {
        $("#cmbDateExtentP021303").combobox("setValue", strDateItem);
        dateExtentCalculation(strDateItem, "dateStartTimeP021303", "dateEndTimeP021303");
    }
    else {
        var strStartTime = $(window.parent.document).find("#idIframe-21303").attr("sdate");
        var strEndTime = $(window.parent.document).find("#idIframe-21303").attr("edate");
        $("#cmbDateExtentP021303").combobox("setText", "自定义");
        $("#dateStartTimeP021303").val(strStartTime);
        $("#dateEndTimeP021303").val(strEndTime);
    }
    //释放内存
    strDateItem = null;
    strStartTime = null;
    strEndTime = null;
}

//客户下拉框信息的加载
function loadProviderData_P021303() {
    //添加变更事件
    $("#cmbProviderP021303").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbProviderP021303").combobox("getText") == "") {
                $("#cmbProviderP021303").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbProviderP021303").combobox("getText") == "全部客户") {
                $("#cmbProviderP021303").combobox("setText", "");
            }
        },
        afterChange: function (newValue, newText) {
            $(this).combobox("setText", newText.replace(/&nbsp;/g, ""));
        }
    });

    //客户信息的取得
    var objProvider = getComboboxData("Tkhxx2");
    //取得一下统计页面中设定的khdm
    var strProviderID = $(window.parent.document).find("#idIframe-21303").attr("khdm");
    //取得一下统计页面中设定的khmc
    var strProviderText = $(window.parent.document).find("#idIframe-21303").attr("khmc");
    if (objProvider == "{}") {
        objProvider = [];
    }
    //加载数据
    objProvider.unshift({ "dm": "", "mc": "全部客户", "selected": true });
    $("#cmbProviderP021303").combobox("loadData", objProvider);
    //设定默认值
    $("#cmbProviderP021303").combobox("setValue", strProviderID);
    $("#cmbProviderP021303").combobox("setText", strProviderText);
    //释放内存
    objProvider = null;
    strProviderID = null;
}

//药品下拉框信息的加载
function loadDrugData_P021303() {
    //添加变更事件
    $("#cmbDrugP021303").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbDrugP021303").combobox("getText") == "") {
                $("#cmbDrugP021303").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbDrugP021303").combobox("getText") == "全部药品") {
                $("#cmbDrugP021303").combobox("setText", "");
            }
        }
    });
    //药品信息的取得
    var objDrug = getComboboxData("Tspxx2");
    var strDrugID = $(window.parent.document).find("#idIframe-21303").attr("spdm");
    var strDrugText = $(window.parent.document).find("#idIframe-21303").attr("spmc");
    if (objDrug == "{}") {
        objDrug = [];
    }
    //加载数据
    objDrug.unshift({ "dm": "", "mc": "全部药品", "selected": true });
    $("#cmbDrugP021303").combobox("loadData", objDrug);
    //设定默认值
    $("#cmbDrugP021303").combobox("setValue", strDrugID);
    $("#cmbDrugP021303").combobox("setText", strDrugText);
    //释放内存
    objDrug = null;
    strDrugID = null;
}

// 销售人员下拉框信息的加载
function loadXsryData_P021303() {
    //添加变更事件
    $("#cmbXsyP021303").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbXsyP021303").combobox("getText") == "") {
                $("#cmbXsyP021303").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbXsyP021303").combobox("getText") == "全部销售员") {
                $("#cmbXsyP021303").combobox("setText", "");
            }
        },
        enterDown: function () {

        }
    });

    //药品信息的取得
    var objXsy = getComboboxData("TZyxx2");
    objXsy.push({ "dm": "-1", "mc": "其他销售员" });
    var strXsyID = $(window.parent.document).find("#idIframe-21303").attr("xsydm");
    var strXsyText = $(window.parent.document).find("#idIframe-21303").attr("xsymc");
    if (objXsy == "{}") {
        objXsy = [];
    }
    //加载数据
    objXsy.unshift({ "dm": "", "mc": "全部销售员", "selected": true });
    $("#cmbXsyP021303").combobox("loadData", objXsy);
    //设定默认值
    $("#cmbXsyP021303").combobox("setValue", strXsyID);
    $("#cmbXsyP021303").combobox("setText", strXsyText);
    //释放内存
    objXsy = null;
    strXsyID = null;
}

//money格式化
function formatterP0213Money(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = 0;
    }
    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
}

//当基本资料数据有修改时 刷新相关的combobox
function refreshMyCombobox() {
    var strModels = $("#idRefreshCombobox").val();
    var data = getComboboxData(strModels + "2");

    if (strModels == "Tspxx") {
        data.unshift({ dm: "", mc: "全部药品", "selected": true });
        reLoadCombobox("cmbDrugP021303", data);
    }
    if (strModels == "TZyxx") {
        data.unshift({ dm: "", mc: "全部销售员", "selected": true });
        data.push({ dm: "-1", mc: "其他销售员" });
        reLoadCombobox("cmbXsyP021303", data);
    }
    if (strModels == "Tkhxx") {
        data.unshift({ dm: "", mc: "全部客户", "selected": true });
        reLoadCombobox("cmbProviderP021303", data);
    }
}

//查询条件的取得
function mySearchWhereJson() {
    var strWhereJson = "";
    //查询条件的取得
    strWhereJson += "{\"sdate\":\"" + $("#dateStartTimeP021303").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP021303").val() + "\",";
    strWhereJson += "\"khdm\":\"" + $("#cmbProviderP021303").combobox("getValue") + "\",";
    strWhereJson += "\"spdm\":\"" + $("#cmbDrugP021303").combobox("getValue") + "\",";
    strWhereJson += "\"zydm\":\"" + $("#cmbXsyP021303").combobox("getValue") + "\"}";
    return strWhereJson.replace(/[{}]/g, "");
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 结束**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/


