/*--------------------------文档信息-------------------------------------------
///功能：      点击采购返利管理——返现——弹出返现单
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
var strTableP010202 = "Tp010202";           //定义表格ID和模块的名称
var strDlgIdP010202 = "divP010202";        //定义弹出单据的层的ID
var bSvaeSignP010202 = 1;                       //定义全局标志位1新增2是修改
var objRetRecord = {};                               //修改时保存一下要修改的记录
var objconfig = {};                                     //列配置
var iRowP010202 = 0;                                //当前选中单元格的row索引
var iColP010202 = 0;                                 //当前选中单元格的col索引
var iRowIdP010202 = 0;                            //当前选中单元格的rowid
var objSpxx = {};                                       //保存商品信息

//在jqGrid中自定义下拉框
//创建select表单元素
function my_inputP010202(value, options) {
    return $('<select name="' + options.name + '" id="' + options.id + ' name="' + options.id + '""></select>').addClass("easyui-combobox");
}

//保存选中的值
function my_valueP010202(ele) {
    return ele.combobox('getText');
}

//money 的格式化
function formatMoneyPlace(cellValue) {
    if (!isNaN(parseFloat(cellValue))) {
        return parseFloat(cellValue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}

//给表格中select控件转化成自定义的形式
function userdefined_P010202() {
    //设置属性custom:绑定combobox：关联药品
    $("#" + strTableP010202).setColProp("spmc", { edittype: "custom" });
    $("#" + strTableP010202).setColProp("spmc", { editoptions: { custom_element: my_inputP010202, custom_value: my_valueP010202} });
    //返利项目
    $("#" + strTableP010202).setColProp("flxm", { edittype: "custom" });
    $("#" + strTableP010202).setColProp("flxm", { editoptions: { custom_element: my_inputP010202, custom_value: my_valueP010202} });
    //编辑状态，绑定事件
    $("#" + strTableP010202).setGridParam({ afterEditCell: afterEditCellP010202 });
}

/*-----------------------------------------------------------------------------
//功能：点击添加按钮，弹出对话框
//参数：
//strType:1：添加
//2：修改
//strTableP010202 表名
-----------------------------------------------------------------------------*/
function showDialog_P010202(strType) {
    try {
        objSpxx = getComboboxData('Tspxx');
        //给药品增加一个添加功能
        objSpxx.push({ "mc": "<font color='red'>添加药品</font>", "dm": "-1" });

        //清空弹出窗口内容
        $("#divP010202").empty();

        //添加
        if (strType == "1") {
            //值为1，插入数据；值为2，更新数据
            bSvaeSignP010202 = "1"; //初次保存insert数据
        }
        //修改
        else if (strType == "2") {
            bSvaeSignP010202 = "2";
        }
        //创建弹出窗口dialog
        creatDiv_ShowDlgHaveTbl(strDlgIdP010202, "返现单", false, true, strTableP010202, "600");

        //获得jqGrid的列名和属性
        objconfig = ParseData(window.external.DoOptions(strTableP010202, 'GetTableConfig', '{}'));
        if (!objconfig) {
            //列配置失败提示信息
            window.parent.cihoAlert(msg.cg.LineFail);
            return;
        }

        //添加表单元素到窗口中
        tableFormP010202(strType);

        //创建表格
        createGridP010202(strTableP010202, objconfig.colNames, objconfig.colModel);

        //给表格中select控件转化成自定义的形式
        userdefined_P010202();

        //添加
        if ("1" == strType) {
            var nowData = getNowDate();     //返现日期，默认当前日期
            $("#fxdate", $("#" + strDlgIdP010202 + "_divform")).val(nowData);
            inputAndBindData("fxdate");
            //加载空记录
            $("#" + strTableP010202).addRowData(1, {});
            nowData = null;
        }
        //修改
        else if ("2" == strType) {
            //设定单据的原始值
            setDjValueP010202();
            iRowIdP010202 = $("#" + strTableP010202).jqGrid("getDataIDs")[0];
        }

        //窗口中的元素添加完毕后，给dialog定位
        $("#" + strDlgIdP010202).dialog("option", "position", "center");
        //设定data change 为false
        dataChangeState(false);
        setTimeout(function () { $("#bz", "#" + strDlgIdP010202).focus(); }, 100);
        //释放内存
    } catch (e) { }
}

/************动态创建表单*********/
function tableFormP010202(strType) {
    //获得列配置
    var strPageHeader = objconfig.pageHeader;
    var strpageFooter = objconfig.pageFooter;

    var strForm = "<ul>";
    for (var i = 0; i < strPageHeader.length; i++) {
        if (strPageHeader[i]["name"] == "gysmc"
         || strPageHeader[i]["name"] == "jsrmc"
         || strPageHeader[i]["name"] == "djbh") {  //过滤
            continue;
        }
        if (strPageHeader[i]["edittype"] == "text") {
            strForm += "<li class='inp_70'>"; //calss类型有：inp_70，inp_150, bz
            strForm += strPageHeader[i]["xsmc"] + "：";
            strForm += "<input id='" + strPageHeader[i]["index"] + "' name='" + strPageHeader[i]["name"] + "' type='text'  maxlength='50'";
            strForm += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
            strForm += "</li>";
        }
        else if (strPageHeader[i]["edittype"] == "select") {
            strForm += "<li >";
            strForm += strPageHeader[i]["xsmc"] + "：";
            strForm += "<select id='" + strPageHeader[i]["index"] + "' name='" + strPageHeader[i]["name"] + "'";
            strForm += "class='easyui-combobox'>";
            strForm += "</select>";
            strForm += "</li>";
        }
    }
    strForm += "</ul>";
    $("#divP010202_divform").append(strForm);

    strTable = "<table id='Tp010202'></table>";
    $("#divP010202_divform").append(strTable);

    //页脚
    var strDown = "<ul>";
    for (var i = 0; i < strpageFooter.length; i++) {
        if (strpageFooter[i]["name"] == "zdrmc" || strpageFooter[i]["name"] == "skje") {
            continue;
        }
        if (strpageFooter[i]["edittype"] == "text") {
            if (strpageFooter[i]["index"] == "bz") {
                strDown += "<li class='bz'>";
                strDown += strpageFooter[i]["xsmc"] + "：";
                strDown += "<input id='" + strpageFooter[i]["index"] + "' name='" + strpageFooter[i]["name"] + "' type='text' ";
                strDown += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
                strDown += "</li>";
            }
            else if (strpageFooter[i]["name"] == "czydm") {
                strDown += "<li class='inp_70'>";
                strDown += strpageFooter[i]["xsmc"] + "：";
                strDown += "<input id='" + strpageFooter[i]["index"] + "' name='" + strpageFooter[i]["name"] + "' type='text'  maxlength='50'";
                strDown += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
                strDown += "</li>";
            }
            else {
                strDown += "<li class='inp_150'>";
                strDown += strpageFooter[i]["xsmc"] + "：";
                strDown += "<input id='" + strpageFooter[i]["index"] + "' name='" + strpageFooter[i]["name"] + "' type='text'  maxlength='50'";
                strDown += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
                strDown += "</li>";
            }
        }
        else if (strpageFooter[i]["edittype"] == "select") {
            //付款账户
            strDown += "<li>";
            strDown += strpageFooter[i]["xsmc"] + "：";
            strDown += "<select id='" + strpageFooter[i]["index"] + "' name='" + strpageFooter[i]["name"] + "'";
            strDown += "class='easyui-combobox' editable='true'>";
            strDown += "</select>";
            strDown += "</li>";
        }
    }
    strDown += "</ul>";
    $("#divP010202_divform").append(strDown);

    //给供应商加载数据
    loadSupplier_P010202();

    //给职员加载数据
    loadMember_P010202();

    //给帐户加载数据
    loadZh_P010202();
    $(".layoutpanel").css("z-index", "50000009");

    //收款日期绑定日期控件
    inputAndBindData("skdate");
    //设定制单人
    $("#czydm", $("#" + strDlgIdP010202 + "_divform")).attr("disabled", true);
    $("#czydm", $("#" + strDlgIdP010202 + "_divform")).val(window.parent.objLoginInfo.name);

    //设定状态
    $(":input[name]", $("#" + strDlgIdP010202 + "_divform")).change(function () {
        dataChangeState(true);
    });

    //释放内存
    strPageHeader = null;
    strpageFooter = null;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**加载combobox专区开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//给供应商加载数据
function loadSupplier_P010202() {
    var objGys = getComboboxData('Tgysxx');     //供应商
    objGys.push({ "mc": "<font color='red'>添加供应商</font>", "dm": "-1" });

    $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        editable: true,
        onChange: function (newValue, oldValue) {
            dataChangeState(true);
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {
                ciho.IniData({ id: "divAddType", title: "供应商", table: "Tflxx" }, { jquery: $("#gysdm", $("#" + strDlgIdP010202 + "_divform")), model: "Tgysxx" });
                ciho.showTypeDialog();
            }
        }
    });
    //加载combobox信息
    $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox("loadData", objGys != "{}" ? objGys : []);
    //释放内存
    objGys = null;
}

//给职员加载数据
function loadMember_P010202() {

    var objZy = getComboboxData('TZyxx');      //操作员，职员
    objZy.push({ "mc": "<font color='red'>添加经手人</font>", "dm": "-1" });

    $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        editable: true,
        onChange: function (newValue, oldValue) {
            dataChangeState(true);
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {
                ciho.IniData({ id: "divAddType", title: "经手人", table: "Tflxx" }, { jquery: $("#zydm", $("#" + strDlgIdP010202 + "_divform")), model: "TZyxx" });
                ciho.showTypeDialog();
            }
        }
    });
    $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox("loadData", objZy != "{}" ? objZy : []);
    //释放内存
    objZy = null;
}

//给帐户加载数据
function loadZh_P010202() {
    //收款账户，会计科目
    var objkjkm = getComboboxData('TKjkm');
    objkjkm.push({ "mc": "<font color='red'>添加收款账户</font>", "dm": "-1" });
    $("#zhmc", $("#" + strDlgIdP010202 + "_divform")).combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        panelHeight: getComHeight(objkjkm),
        editable: true,
        onChange: function (newValue, oldValue) {
            dataChangeState(true);
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {
                ciho.IniData({ id: "divAddType", title: "收款账户", table: "Tflxx" }, { jquery: $("#zhmc", $("#" + strDlgIdP010202 + "_divform")), model: "Tkjkm" });
                ciho.showTypeDialog();
            }
            else {
                if (newValue) {
                    //日期不为空，为其赋值skdate
                    if ($("#skdate").val() == "") {
                        $("#skdate").val($("#fxdate", $("#" + strDlgIdP010202 + "_divform")).val());
                    }
                }
            }
        }
    });
    //load数据
    $("#zhmc").combobox("loadData", objkjkm != "{}" ? objkjkm : []);

    //释放内存
    objkjkm = null;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**加载combobox专区结束**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

/******修改时，设定单据的原值的方法******/
function setDjValueP010202() {
    try {
        var strDjbh = $("#" + strTableP0102).getCell(intSelRowIDP0102, "djbh");

        //选中行ID；
        objRetRecord = ParseData(window.external.DoOptions(strTableP010202, 'GetList', "{'djbh':'" + strDjbh + "'}"));
        if (!objRetRecord) {
            //"DB操作失败！"
            window.parent.cihoAlert(msg.other.dbOprateErr);
            return;
        }
        else {
            if (objRetRecord.Records == "{}") {
                //数据为空
                window.parent.cihoAlert(msg.other.dataEmp);
                return;
            }
            else {
                //加载数据
                objRetRecord.Records[0]["glsl"] = objRetRecord.Records[0]["flxm"];
                $("#" + strTableP010202).setColProp("fxje", { formatter: formatMoneyPlace });
                //填充表格
                loadTreeData(strTableP010202, objRetRecord.Records);
            }
        }

        //填充数据到窗口各元素
        //加载返现单编号
        $("#idMust", $("#" + strDlgIdP010202)).append("NO:" + objRetRecord.Records[0].djbh);
        //返现日期
        $("#fxdate", $("#" + strDlgIdP010202 + "_divform")).val(objRetRecord.fxdate);
        //返现日期不可编辑
        $("#fxdate", $("#" + strDlgIdP010202 + "_divform")).attr("disabled", true);

        $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox('setValue', objRetRecord.Records[0]["gysdm"]);
        $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox('setText', objRetRecord.Records[0]["gysmc"]);

        $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox('setValue', objRetRecord.Records[0]["zydm"]);
        $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox('setText', objRetRecord.Records[0]["jsrmc"]);
        
        $("#zhmc", $("#" + strDlgIdP010202 + "_divform")).combobox('setValue', objRetRecord.Records[0]["kmdm"]);
        $("#zhmc", $("#" + strDlgIdP010202 + "_divform")).combobox('setText', objRetRecord.Records[0]["zhmc"]);
        
        $("#skdate", $("#" + strDlgIdP010202 + "_divform")).val(objRetRecord.skdate);
        $("#czydm", $("#" + strDlgIdP010202 + "_divform")).val(objRetRecord.Records[0]["zdrmc"]);
        $("#bz", $("#" + strDlgIdP010202 + "_divform")).val(escape(objRetRecord.bz));
        //释放内存
        strDjbh = null;
    } catch (e) { }
}

/*----------------------------------------------------
功能：创建一个jqGrid表格
******strTableID：表格的ID
******objColNames：表格的列名
******objColModel：表格的列配
-----------------------------------------------------*/
function createGridP010202(strTableID, objColNames, objColModel) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: [],
        rownumbers: true,
        rowNum: 9999,
        sortname: "id",
        autowidth: true,
        cellEdit: true,
        cellsubmit: "clientArray",
        gridview: true
    });
    //增加表头‘序号’列
    $("#" + strTableID).setLabel("rn", "序号");
    //给表格设定一个高度
    $("#" + strTableID).setGridHeight(47);
    //调整表格列宽度
    resizeGridScroll(strTableID);
}

//编辑状态，设置单元格属性
function afterEditCellP010202(rowId, cellname, value, iRow, iCol) {
    iRowIdP010202 = rowId;
    iRowP010202 = iRow;
    iColP010202 = iCol;
    var item = $("#" + rowId + " :input[name='" + cellname + "']", this);
    switch (cellname) {
        case "spmc":
            item.combobox({
                width: _iWidth150,
                listWidth: _iWidth150,
                valueField: "dm",
                textField: "mc",
                editable: true
            });
            //加载数据
            item.combobox("loadData", objSpxx == "{}" ? [] : objSpxx);

            //给选中的combobox设定获得焦点。
            item.combobox('focus');

            //设定选中值
            item.combobox("setValue", $(this).getCell(rowId, "spdm"));
            if (item.combobox("getText") == $(this).getCell(rowId, "spdm")) {
                item.combobox('setText', value);
            }
            //关联药品
            item.combobox({
                onChange: function (newValue, oldValue) {
                    if (newValue != undefined) {
                        $("#" + strTableP010202).setCell(rowId, "spdm", newValue);
                    }
                    else {
                        $("#" + strTableP010202).setCell(rowId, "spdm", "&nbsp;");
                    }
                    //修改Data change状态
                    dataChangeState(true);
                },
                afterChange: function (newValue, newText) {
                    if (newValue == "-1") {
                        ciho.IniData({ id: "divAddType", title: "药品", table: "Tflxx" }, { jquery: $(this), model: "Tspxx" });
                        ciho.showTypeDialog();
                    }
                }
            });
            break;

        case "flxm":
            //返利项目
            item.combobox({
                width: _iWidth150,
                listWidth: _iWidth150,
                valueField: "dm",
                textField: "mc",
                panelHeight: 42,
                editable: false,
                onChange: function (newValue, oldValue) {
                    //修改Data change状态
                    dataChangeState(true);
                },
                onSelect: function (Record) {
                    if (Record.dm != null && Record.dm != undefined) {

                        //glsl:该列隐藏，没有使用，此处用来保存combobox返利项目的key值。
                        $("#" + strTableP010202).setCell(rowId, "glsl", Record.dm);
                    }
                    else {

                        //返利项目为空或者不存在！
                        window.parent.cihoAlert(msg.cg.backObj);
                        $("#" + strTableP010202).setCell(rowId, "glsl", "");
                    }
                }
            });

            //加载数据
            var arrFlxm = [{ "dm": "任务达成", "mc": "任务达成" }, { "dm": "业务支持", "mc": "业务支持"}];
            item.combobox("loadData", arrFlxm);

            //给选中的combobox设定获得焦点。
            item.combobox('focus');

            //设定选中值
            item.combobox("setValue", $(this).getCell(rowId, "glsl"));

            break;
        case "fxje":
            item.change(function () { dataChangeState(true) }); //返现金额
            item.autoNumeric({ mDec: window.parent.strMoneyPlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled");
            break;
    }
    $(".layoutpanel").css("z-index", "50000009");
    item = null;
    arrFlxm = null;
}

/******返现单保存的方法***********/
function saveDataP010202(strType) {
    try {
        //关闭提示信息窗口
        if (strType == 0 && $("#" + strDlgIdP010202 + "_divform").data("change") == true) {
            $("#divMessage").dialog("close");
        }
        //数据有效性验证,组织要保存的数据
        var strRecord = checkDataValidateP010202();
        if (!strRecord) {
            return;
        }
        //添加
        if (bSvaeSignP010202 == "1") {
            var objRet = ParseData(window.external.DoOptions(strTableP010202, 'Add', strRecord));
        }
        else { //修改
            var objRet = ParseData(window.external.DoOptions(strTableP010202, 'Edit', strRecord));
        }
        if (!objRet) {
            //DB操作失败!
            window.parent.cihoAlert(msg.other.dbOprateErr);
            return;
        }

        //操作成功
        if ("0" == objRet.ReturnCode) {

            //重新加载管理画面数据
            loadGridDataP0102();
            $("#idMust", $("#" + strDlgIdP010202)).empty();
            //保存新增
            if (strType == "2") {
                //保存标志为设置为添加
                bSvaeSignP010202 = "1";

                //清空当前窗口数据
                $(":input[name]", $("#" + strDlgIdP010202 + "_divform")).val("");
                //清除单据编号
                $("#" + strDlgIdP010202 + "_pop_box_top").empty();

                $("#fxdate", $("#" + strDlgIdP010202 + "_divform")).val(getNowDate()); //返现日期
                $("#fxdate", $("#" + strDlgIdP010202 + "_divform")).attr("disabled", false);

                $("#czydm", $("#" + strDlgIdP010202 + "_divform")).val(window.parent.objLoginInfo.name); //制单人
                //清空combobox
                $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox("setValue", "");
                $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox("setValue", "");
                $("#zhmc").combobox("setValue", "");


                //清空表格中的元素
                $("#" + strTableP010202).jqGrid("clearGridData");
                //加载空记录
                $("#" + strTableP010202).addRowData(1, {});
                $("#bz", "#" + strDlgIdP010202).focus();
                //表单元素置为未修改
                dataChangeState(false);
            }
            //保存退出/关闭
            else {
                //关闭当前窗口
                cihoDlgClose(strDlgIdP010202);
            }
        }
        //操作失败，弹出提示消息
        else {
            window.parent.cihoAlert(msg.set.save.saveFail);
        }
        //内存释放区域
        strRecord = null;
        objRet = null;
    } catch (e) { }
}

/********返现单保存前验证的方法********/
function checkDataValidateP010202() {
    //取消表格中的数据的编辑状态，保存数据
    $("#" + strTableP010202).saveCell(iRowP010202, iColP010202);

    //组织要保存的数据
    var arrList = "";

    var strFxdate = trim($("#fxdate", $("#" + strDlgIdP010202 + "_divform")).val());
    if (!strFxdate) {
        //返现日期不能为空！
        window.parent.cihoAlert(msg.cg.backData, null, function () { $("#fxdate", $("#" + strDlgIdP010202 + "_divform")).focus(); });
        return;
    }
    if ((strFxdate.replace(/-/g, "/")) < (window.parent._startDate.replace(/-/g, "/"))) {
        window.parent.cihoAlert(msg.other.fxrqExtent, null, function () { $("#fxdate").select(); });
        return;
    }
    arrList += "\"fxdate\":\"" + strFxdate + "\",";

    var strGysdm = $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox('getValue');
    if (!strGysdm) {
        //修改时，验证数据是否是停用的数据
        if (bSvaeSignP010202 == "2" && $("#gysdm", $("#" + strDlgIdP010202 + "_divform")).combobox('getText') == objRetRecord.Records[0]["gysmc"]) {
            strGysdm = objRetRecord.Records[0]["gysdm"];
        }
        else {
            //供应商不存在或者为空！
            window.parent.cihoAlert(msg.sz.gys.empOrNotExit, null, function () {
                $("#gysdm", "#" + strDlgIdP010202).combobox('focus');
            });
            return;
        }
    }
    arrList += "\"gysdm\":\"" + strGysdm + "\",";

    //经手人
    var strJsr = $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox('getValue');
    if (!strJsr) {
        //修改时，验证数据是否是停用的数据
        if (bSvaeSignP010202 == "2" && $("#zydm", $("#" + strDlgIdP010202 + "_divform")).combobox('getText') == objRetRecord.Records[0]["jsrmc"]) {
            strJsr = objRetRecord.Records[0]["zydm"];
        }
        else {
            //经手人为空或者不存在
            window.parent.cihoAlert(msg.sz.jsr.empOrNotExit, null, function () {
                $("#zydm", "#" + strDlgIdP010202).combobox('focus');
            });
            return;
        }
    }
    arrList += "\"zydm\":\"" + strJsr + "\",";
    //收款账户不为空，收款金额，收款日期都不能为空。
    var strZhmc = $("#zhmc", $("#" + strDlgIdP010202 + "_divform")).combobox('getValue');
    //如果账户代码为空，判断是否因停用而取不到
    if (!strZhmc) {
        if (bSvaeSignP010202 == "2" && trim($("#zhmc").combobox('getText')) == objRetRecord.Records[0]["zhmc"]) {
            strZhmc = objRetRecord.Records[0]["kmdm"];
        }
        else {
            //收款账户为空或者不存在
            window.parent.cihoAlert(msg.cg.collectionPerson, null, function () {
                $("#zhmc", "#" + strDlgIdP010202).combobox('focus');
            });
            return;
        }
    }
    arrList += "\"kmdm\":\"" + strZhmc + "\",";
    var strSkrq = trim($("#skdate", $("#" + strDlgIdP010202 + "_divform")).val());
    if (!strSkrq) {
        //收款日期为空或者不存在
        window.parent.cihoAlert(msg.cg.collentionData, null, function () { $("#skdate").focus(); });
        return;
    }
    if ((strSkrq.replace(/-/g, "/")) < (window.parent._startDate.replace(/-/g, "/"))) {
        window.parent.cihoAlert(msg.other.skriExtent, null, function () { $("#skdate").select(); });
        return;
    }
    arrList += "\"skdate\":\"" + strSkrq + "\",";
    if (bSvaeSignP010202 == "1") {
        //制单人
        arrList += "\"czydm\":\"" + window.parent.objLoginInfo.code + "\",";
    }
    else {
        //制单人
        arrList += "\"czydm\":\"" + objRetRecord.Records[0]["czydm"] + "\",";
    }
    //备注
    arrList += "\"bz\":\"" + trim($("#bz", $("#" + strDlgIdP010202 + "_divform")).val()) + "\",";

    //获得表格的数据
    var strFxje = $("#" + strTableP010202).jqGrid("getCell", iRowIdP010202, "fxje");
    if (!strFxje || strFxje == "0.00" || strFxje == "0") {
        //返现金额不能为空
        window.parent.cihoAlert(msg.cg.backMoney);
        return;
    }
    arrList += "\"skje\":\"" + strFxje + "\"";
    //glsl保存了项目支持的key值
    var strFlxm = $("#" + strTableP010202).jqGrid("getCell", iRowIdP010202, "glsl");
    if (!strFlxm) {
        //返利项目为空或者不存在！
        window.parent.cihoAlert(msg.cg.backObj);
        return;
    }
    var strSpdm = $("#" + strTableP010202).jqGrid("getCell", iRowIdP010202, "spdm");
    var strSpmc = $("#" + strTableP010202).jqGrid("getCell", iRowIdP010202, "spmc")
    if (!strSpdm || strSpmc == "") {
        //关联药品为空或者不存在！
        window.parent.cihoAlert(msg.cg.relevanceSp);
        return;
    }

    var strRecord = "{\"Records\":";
    strRecord += "[{";
    if (bSvaeSignP010202 == "2") {
        strRecord += "\"mxguid\":\"";
        strRecord += objRetRecord.Records[0]["mxguid"] + "\",";
        strRecord += "\"djbh\":\"";
        strRecord += objRetRecord.Records[0]["djbh"] + "\",";
    }
    strRecord += "\"fxje\":\"" + strFxje + "\"";
    strRecord += ",\"a7\":\"" + strFlxm + "\"";
    strRecord += ",\"spdm\":\"" + strSpdm + "\"";
    strRecord += "}],";
    strRecord += arrList;
    strRecord += "}";
    return strRecord;
    //释放内存
    arrList = null;
    strFxdate = null;
    strGysdm = null;
    strJsr = null;
    strZhmc = null;
    strSkrq = null;
    strRecord = null;
    strFxje = null;
}

/*****状态监听的方法*************/
function dataChangeState(bState) {
    //修改Data change状态
    $("#" + strDlgIdP010202 + "_divform").data("change", bState);
}