/*-------------------------------文档信息-----------------------------------
///功能：应收往来对账
///创建人: 翟新乐
///创建时间：------------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP021503 = "Tp021503";   //表格ID
var objSelRowP021503 = {};          //选择行的数据
var intSelRowIDP021503 = 0;         //选择行的ID
var strPageP021503 = "divPageP021503";
var objPageParamP021503 = { sortfield: "", orderby: "", where: "", flag: 0 };  //分页控件使用

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    //$("#" + strDialog).dialog("close");
    cihoDlgClose(strDialog);
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//页面加载方法
function pageLoad_P021503() {
    //选择日期范围
    dateExtent_P021503();
    //加载客户信息
    loadCustomerData_P021503();
    //药品下拉框信息的加载
    loadDrugData_P021503();
    //销售员信息
    loadZyData_P021503();
    var objConfig = ParseData(window.external.DoOptions(strTableP021503, "GetTableConfig", "{}"));
    //添加列格式化方法
    for (var i = 0; i < objConfig.colModel.length; i++) {
        if (objConfig.colModel[i].name == "xsje" || objConfig.colModel[i].name == "thje" || objConfig.colModel[i].name == "hkyh"
            || objConfig.colModel[i].name == "hkje" || objConfig.colModel[i].name == "yszj"
            || objConfig.colModel[i].name == "ysjs") {
            objConfig.colModel[i].formatter = formatterP021503Money;
        }
        if (objConfig.colModel[i].name == "ysye") {
            objConfig.colModel[i].formatter = formatterYsyeMoney;
        }
        if (objConfig.colModel[i].name == "xh") {
            objConfig.colModel[i].hidden = true;
        }
    }
    //创建表格
    createGrid(strTableP021503, objConfig.colNames, objConfig.colModel, [], null, null, true);
    //表格事件的添加
    addGridEvent_P021503();
    resizeGrid(strTableP021503, true, true);
    //创建分页
    createPage(strPageP021503, strTableP021503);
    //加载表格数据(触发查询按钮的点击事件)
    searchDataClick_P021503();
    //resizeGrid(strTableP021503);
    objConfig = {};
}

//查询按钮的方法
function searchDataClick_P021503() {
    try {
        objPageParamP021503.sortfield = ""; //排序字段
        objPageParamP021503.orderby = "";     //排序顺序
        objPageParamP021503.flag = 1;             //表示点击查询按钮
        loadGridDataP021503();                     //加载数据
        objPageParamP021503.flag = 0;              //使用完后，设置为零
        //resizeGrid(strTableP021503);
    } catch (e) { }
}

//加载数据
function loadGridDataP021503() {
    var objResult = [];
    objPageParamP021503.where = getSelJson_P021503();
    objResult = loadGridData_Page(objPageParamP021503);
    //后台返回的合计
    if (objResult) {
        if (objResult.Records.length > 0) {
            $("#" + strTableP021503).footerData("set", { rn: "合计",
                xsje: objResult.xshj.toFixed(window.parent.strMoneyPlace),
                thje: objResult.thhj.toFixed(window.parent.strMoneyPlace),
                hkyh: objResult.yhhj.toFixed(window.parent.strMoneyPlace),
                hkje: objResult.hkhj.toFixed(window.parent.strMoneyPlace),
                yszj: objResult.zjhj.toFixed(window.parent.strMoneyPlace),
                ysjs: objResult.jshj.toFixed(window.parent.strMoneyPlace)
            }, false);
        } else {
            $("#" + strTableP021503).footerData("set", { rn: "合计", xsje: "&nbsp;", thje: "&nbsp;", hkyh: "&nbsp;", hkje: "&nbsp;", yszj: "&nbsp;", ysjs: "&nbsp;" }, false);
        }
    }
    objResult = {};
    intSelRowIDP021503 = "";
    objSelRowP021503 = {};
}

//取得查询条件
function getSelJson_P021503() {
    //combobox的key不存在，赋值空
    if (!$("#cmbCustomerP021503").combobox("getValue")) {
        $("#cmbCustomerP021503").combobox("setValue", "");
    }
    if (!$("#cmbDrugP021503").combobox("getValue")) {
        $("#cmbDrugP021503").combobox("setValue", "");
    }
    if (!$("#cmbZyP021503").combobox("getValue")) {
        $("#cmbZyP021503").combobox("setValue", "");
    }
    //查询条件的取得
    var strWhereJson = "";
    strWhereJson = "\"sdate\":\"" + $("#dateStartTimeP021503").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP021503").val() + "\",";
    strWhereJson += "\"khdm\":\"" + $("#cmbCustomerP021503").combobox("getValue") + "\",";
    strWhereJson += "\"spdm\":\"" + $("#cmbDrugP021503").combobox("getValue") + "\",";
    strWhereJson += "\"zydm\":\"" + $("#cmbZyP021503").combobox("getValue") + "\"";
    return strWhereJson;
}

//查看单据按钮的方法
function viewReceipt_P021503() {
    try {
        if (intSelRowIDP021503 > 0) {
            if (objSelRowP021503.ywlx == "销售") {
                //销售单据
                showDialogP021103_xsd("divP021503", objSelRowP021503.djbh);
            }
            else if (objSelRowP021503.ywlx == "销售退货") {
                //销售退货单据
                showDialogP021103_thd("divP021503", objSelRowP021503.djbh);
            }
            else if (objSelRowP021503.ywlx == "收款") {
                //收款单据
                showDialogP021303_skd("divP021503", objSelRowP021503.djbh);
            }
            else if (objSelRowP021503.ywlx == "应收增加" || objSelRowP021503.ywlx == "应收减少") {
                //应收调整单据
                showDialogP021503_ysd("divP021503", objSelRowP021503.djbh);
            }
        }
        else {
            window.parent.cihoAlert(msg.other.selDataRow);
        }
    } catch (e) { }
}

//返回按钮的方法
function pageBack_P021503() {
    //改变标签的Name
    $(window.parent.document).find("#span_215").text("应收查询");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-215").css("display", ""); //显示统计页面
    $(window.parent.document).find("#idIframe-21503").css("display", "none"); //隐藏明细页面
    $(window.parent.document).find("#idIframe-21503").attr("src", "");
}

//日期范围修改方法
function dateTimeChange_P021503() {
    if ($("#cmbDateExtentP021503").combobox("getText") != "自定义") {
        $("#cmbDateExtentP021503").combobox("setValue", "");
        $("#cmbDateExtentP021503").combobox("setText", "自定义");
    }
}

/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**事件方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//选择日期范围
function dateExtent_P021503() {
    $("#cmbDateExtentP021503").combobox({
        valueField: "dm",
        textField: "mc",
        editable: false,
        panelHeight: 82,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP021503", "dateEndTimeP021503");
        },
        enterDown: function () {
            dateExtentCalculation($(this).combobox("getValue"), "dateStartTimeP021503", "dateEndTimeP021503");
            //searchDataClick_P021503();
        }
    });
    //加载数据
    $("#cmbDateExtentP021503").combobox("loadData", [{ dm: "本月", mc: "本月", selected: true },
        { dm: "上一月", mc: "上一月" },
        { dm: "过去三个月", mc: "过去三个月" },
        { dm: "本年", mc: "本年"}]);

    $("#cmbDateExtentP021503").combobox("setValue", $(window.parent.document).find("#idIframe-21503").attr("dname"));
    $("#cmbDateExtentP021503").combobox("setText", $(window.parent.document).find("#idIframe-21503").attr("dname"));
    $("#dateStartTimeP021503").val( $(window.parent.document).find("#idIframe-21503").attr("sdate"));
    $("#dateEndTimeP021503").val($(window.parent.document).find("#idIframe-21503").attr("edate"));
}

//客户下拉框信息的加载
function loadCustomerData_P021503() {
    $("#cmbCustomerP021503").combobox({
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbCustomerP021503").combobox("getText") == "") {
                $("#cmbCustomerP021503").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbCustomerP021503").combobox("getText") == "全部客户") {
                $("#cmbCustomerP021503").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P021503();
        },
        afterChange: function (newValue, newText) {
            $(this).combobox("setText", newText.replace(/&nbsp;/g, ""));
        }
    });

    //客户信息的取得
    var objProvider = getComboboxData('Tkhxx2');
    if (objProvider == "{}") {
        objProvider = [];
    }
    //加载数据
    objProvider.unshift({ "dm": "", "mc": "全部客户" });
    $("#cmbCustomerP021503").combobox("loadData", objProvider);
    //设定默认值
    $("#cmbCustomerP021503").combobox("setValue", $(window.parent.document).find("#idIframe-21503").attr("khdm"));
    $("#cmbCustomerP021503").combobox("setText", $(window.parent.document).find("#idIframe-21503").attr("khmc").replace(/&nbsp;/g, ""));
    objProvider = {};
}

//药品下拉框信息的加载
function loadDrugData_P021503() {
    $("#cmbDrugP021503").combobox({
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbDrugP021503").combobox("getText") == "") {
                $("#cmbDrugP021503").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbDrugP021503").combobox("getText") == "全部药品") {
                $("#cmbDrugP021503").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P021503();
        }
    });

    //药品信息的取得
    var objDrug = getComboboxData('Tspxx2');
    if (objDrug == "{}") {
        objDrug = [];
    }
    //加载数据
    objDrug.unshift({ "dm": "", "mc": "全部药品" });
    $("#cmbDrugP021503").combobox("loadData", objDrug);
    //设定默认值
    $("#cmbDrugP021503").combobox("setValue", $(window.parent.document).find("#idIframe-21503").attr("spdm"));
    objDrug = {};
}

//加载销售员
function loadZyData_P021503() {
    $("#cmbZyP021503").combobox({
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbZyP021503").combobox("getText") == "") {
                $("#cmbZyP021503").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbZyP021503").combobox("getText") == "全部销售员") {
                $("#cmbZyP021503").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P021503();
        }
    });

    //药品信息的取得
    var objZyxx = getComboboxData('TZyxx2');
    if (objZyxx == "{}") {
        objZyxx = [];
    }
    //加载数据
    objZyxx.unshift({ "dm": "", "mc": "全部销售员", "selected": true });
    objZyxx.push({ "dm": "-1", "mc": "其他销售员" });
    $("#cmbZyP021503").combobox("loadData", objZyxx);
    //设定默认值
    $("#cmbZyP021503").combobox("setValue", $(window.parent.document).find("#idIframe-21503").attr("zydm"));
    objZyxx = {};
}

//表格事件的添加
function addGridEvent_P021503() {
    $("#" + strTableP021503).setGridParam({
        //当前选择行数据取得
        onSelectRow: function (rowId) {
            intSelRowIDP021503 = rowId;
            objSelRowP021503 = $(this).getRowData(rowId);
        },
        ondblClickRow: function (rowId) {   //双击事件
            viewReceipt_P021503();
        }
    });
}

//dj,je格式化money
function formatterP021503Money(cellvalue, options, rowObject) {
    if (!isNaN(parseFloat(cellvalue))&&(parseFloat(cellvalue)) != "0") {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}

//格式化余额
function formatterYsyeMoney(cellvalue,options,rowObject) {
    if(!isNaN(parseFloat(cellvalue))) {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**自定义方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/