/*-------------------------------文档信息-----------------------------------
///功能：采购返货单
///创建人: 翟新乐
///创建时间：------------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
var strTableP010201 = "Tp010201";       //全局变量，表格ID
var strDlgIdP010201 = "divP010201";     //全局变量,弹出层ID
var objCk = [];               //存放仓库信息
var bSaveSignP010201 = "1";    //标志位：1为插入，2为更新
var objRetRecord_P010201 = [];        //修改时保存要修改的记录
var iRowP010201 = 1;    //当前选中单元格的row索引
var iColP010201 = 1;    //当前选中单元格的col索引
var strBjData = "";           //check修改单据后的字段数据字符串
var strBlData = [];     //存放要check的字段

//格式数量的方法
function formatCountPlace_P010201(cellValue) {
    if (!isNaN(parseFloat(cellValue))) {
        return parseFloat(cellValue).toFixed(window.parent.strCountPlace);
    }
    else {
        return "&nbsp;";
    }
}

//格式价格的方法
function formatPricePlace_P010201(cellValue) {
    if (!isNaN(parseFloat(cellValue))) {
        return parseFloat(cellValue).toFixed(window.parent.strPricePlace);
    }
    else {
        return "&nbsp;";
    }
}

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

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

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

//释放内存
function freeMemory_P010201() {
    var objCk = [];
    var bSaveSignP010201 = "1";
    var objRetRecord_P010201 = [];
    var iRowP010201 = 1;
    var iColP010201 = 1;
    var strBjData = "";
    var strBlData = [];
}
//添加表单元素的方法
function tableForm_P010201(strType) {
    //获得jqGrid的列名和属性
    var objConfig_P010201 = ParseData(window.external.DoOptions(strTableP010201, 'GetTableConfig', '{}'));
    if (!objConfig_P010201) {
        window.parent.cihoAlert(msg.other.modelInfoFail);
        return;
    }
    //创建表单顶部风格
    var strTop = "";
    //创建表单第二个风格
    var strForm = "";
    //创建表单第三个风格
    var strTable = "";

    //创建表单底部风格
    var strDown = "";
    if (strType == "2") {   //修改单据时，显示djbh
        $("#idMust", $("#" + strDlgIdP010201)).append("NO:" + objSelRowP0102.djbh);
    }
    var strName = objConfig_P010201.colNames;
    var strModel = objConfig_P010201.colModel;
    var strPageHeader = objConfig_P010201.pageHeader;   //头部字段
    var strpageFooter = objConfig_P010201.pageFooter;   //页尾字段
    strForm = "<ul>";
    for (var i = 0; i < strPageHeader.length; i++) {
        if (strPageHeader[i]["name"] == "gysmc" || strPageHeader[i]["name"] == "jsrmc" || strPageHeader[i]["name"] == "ckmc") {
            continue;
        }
        else {
            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 name='" + strPageHeader[i]["name"] + "' id='" + strPageHeader[i]["name"] + "'";
                strForm += " class='easyui-combobox'>";
                strForm += "</select>";
                strForm += "</li>";
            }
        }
    }
    strForm += "</ul>";

    $("#" + strDlgIdP010201 + "_divform").append(strForm);
    //加入表格
    strTable = "<table id='Tp010201'></table>";
    $("#" + strDlgIdP010201 + "_divform").append(strTable);

    strDown = "<ul>";
    strDown += "<li class='unline'>";
    strDown += "<input type='checkbox'  value=''  name='fy'";
    strDown += " id='fy'";
    strDown += "/>";
    strDown += "<label for='fy'>";      //开票费用控制账户，付款金额，日期的编辑性
    strDown += "开票费用";
    strDown += "</label>";
    strDown += "</li>";

    for (var i = 0; i < strpageFooter.length; i++) {
        if (strpageFooter[i]["name"] == "zhmc" || strpageFooter[i]["name"] == "zdrmc") {
            continue;
        }
        else {
            if (strpageFooter[i]["edittype"] == "text") {
                if (strpageFooter[i]["name"] == "fkje" || strpageFooter[i]["name"] == "fkdate") { //付款金额，付款日期
                    strDown += "<li class='inp_100'>";
                    strDown += strpageFooter[i]["xsmc"] + "：";
                    strDown += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                    strDown += " id='" + strpageFooter[i]["name"] + "' maxlength='50' "; //限制输入长度
                    strDown += " maxlength='50'   onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>";
                    strDown += "</li>";
                }
                else if (strpageFooter[i]["name"] == "czydm") {     //制单人
                    strDown += "<li class='inp_150'>";
                    strDown += strpageFooter[i]["xsmc"] + "：";
                    strDown += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                    strDown += " id='" + strpageFooter[i]["name"] + "' "; //限制输入长度
                    strDown += " maxlength='50'   onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>";
                    strDown += "</li>";
                }
                else {
                    strDown += "<li class='bz'>";
                    strDown += strpageFooter[i]["xsmc"] + "：";
                    strDown += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "'";
                    strDown += " id='" + strpageFooter[i]["name"] + "' ";
                    strDown += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>";
                    strDown += "</li>";

                }
            }
            else if (strpageFooter[i]["edittype"] == "select") {
                strDown += "<li>";
                strDown += strpageFooter[i]["xsmc"] + "：";
                strDown += "<select name='" + strpageFooter[i]["name"] + "' id='" + strpageFooter[i]["name"] + "' disabled";
                strDown += " class='easyui-combobox'>";
                strDown += "</select>";
                strDown += "</li>";
            }
        }
    }
    strDown += "</ul>";

    $("#" + strDlgIdP010201 + "_divform").append(strDown);
    //loadData，加载combobox数据
    loadGysData_P010201();  //加载供应商信息
    loadZyData_P010201();   //加载经手人信息
    loadCkData_P010201(strType);    //加载仓库信息
    loadKmData_P010201();   //加载账户信息
    $(".layoutpanel").css("z-index", "50000009");

    //创建jqGrid
    createGrid_P010201(strTableP010201, objConfig_P010201.colNames, objConfig_P010201.colModel, []);
    //$("#gbox_" + strTableP010201).css("height", "53");
    $("#" + strTableP010201).setGridHeight(47);
    //$("#" + strTableP010201).setGridWidth(880);
    resizeGridScroll(strTableP010201);
    $("#" + strTableP010201).setColProp("ypmc", { edittype: "custom" });
    $("#" + strTableP010201).setColProp("ypmc", { editoptions: { custom_element: my_input_P010201, custom_value: my_value_P010201} });
    //是否带票
    $("#" + strTableP010201).setColProp("a3", { edittype: "custom" });
    $("#" + strTableP010201).setColProp("a3", { editoptions: { custom_element: my_input_P010201, custom_value: my_value_P010201} });
    //返利项目
    $("#" + strTableP010201).setColProp("a7", { edittype: "custom" });
    $("#" + strTableP010201).setColProp("a7", { editoptions: { custom_element: my_input_P010201, custom_value: my_value_P010201} });
    //开票单位
    $("#" + strTableP010201).setColProp("kpdwmc", { edittype: "custom" });
    $("#" + strTableP010201).setColProp("kpdwmc", { editoptions: { custom_element: my_input_P010201, custom_value: my_value_P010201} });

    //给开票费用绑定控制事件
    $("#fy").click(function () {
        if ($("#fy").is(":checked")) {      //选中 可编辑
            $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox('enable');
            $("#fkje").attr("disabled", false);
            $("#fkdate").attr("disabled", false);
        }
        else {      //No checked 清空数据，不可编辑
            $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox('disable');
            $("#fkje").attr("disabled", true);
            $("#fkdate").attr("disabled", true);
            $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", "");
            $("#fkje").val("");
            $("#fkdate").val("");
        }
    });
    inputAndBindData("fhdate", false, "#" + strDlgIdP010201, dateChange_P010201);     //绑定日期控件
    inputAndBindData("fkdate", false, "#" + strDlgIdP010201, dateChange_P010201);
    //给付款金额设置格式化
    $("#fkje", $("#" + strDlgIdP010201 + "_divform")).css("ime-mode", "disabled").autoNumeric({ mDec: window.parent.strMoneyPlace, aSep: "" });
    //给制单人赋值
    $("#czydm", $("#" + strDlgIdP010201 + "_divform")).val(window.parent.objLoginInfo.name);
    $("#czydm", $("#" + strDlgIdP010201 + "_divform")).attr("disabled", true);
    setTimeout(function () { $("#bz", $("#" + strDlgIdP010201 + "_divform")).focus(); }, 100);
    //绑定设定状态事件
    $(":input[name]", $("#" + strDlgIdP010201 + "_divform")).change(function () {
        dataChangeStateP010201(true);
    });
    //释放内存
    strTop = null;
    strForm = null;
    strDown = null;
    strTable = null;
    objConfig_P010201 = null;
    strName = null;
    strModel = null;
    strpageFooter = null;
    strPageHeader = null;
}

//日期控件变更时datachange
function dateChange_P010201() {
    dataChangeStateP010201(true);
}

//加载供应商combobox的方法
function loadGysData_P010201() {
    var objGys = getComboboxData('Tgysxx');         //供应商信息
    objGys.push({ "mc": "<font color='red'>添加供应商</font>", "dm": "-1" });
    $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        editable: true,
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {     //添加供应商
                ciho.IniData({ id: "divAddType", title: "供应商", table: "Tflxx" },
                { jquery: $("#gysdm", "#" + strDlgIdP010201), model: "Tgysxx" });
                ciho.showTypeDialog();
                $("#gysdm", "#" + strDlgIdP010201).combobox("setValue", "");
            }
        },
        onChange: function (newValue, oldValue) {
            dataChangeStateP010201(true);
        }
    });
    $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox("loadData", objGys != "{}" ? objGys : []);
    objGys = {};
}

//加载职员combobox的方法
function loadZyData_P010201() {
    var objZy = getComboboxData('TZyxx');           //职员信息
    objZy.push({ "mc": "<font color='red'>添加经手人</font>", "dm": "-1" });
    $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        editable: true,
        onChange: function (newValue, oldValue) {
            dataChangeStateP010201(true);
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {     //添加经手人
                ciho.IniData({ id: "divAddType", title: "经手人", table: "Tflxx" },
                 { jquery: $("#zydm", "#" + strDlgIdP010201), model: "TZyxx" });
                ciho.showTypeDialog();
                $("#zydm", "#" + strDlgIdP010201).combobox("setValue", "");
            }
        }
    });
    $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox("loadData", objZy != "{}" ? objZy : []);
    objZy = {};
}

//加载仓库combobox的方法
function loadCkData_P010201(strType) {
    objCk = getComboboxData('TCkxx');           //仓库信息
    objCk.push({ "mc": "<font color='red'>添加仓库</font>", "dm": "-1" });
    $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        editable: true,
        onChange: function (newValue, oldValue) {
            dataChangeStateP010201(true);
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {         //添加仓库
                ciho.IniData({ id: "divAddType", title: "仓库", table: "Tflxx" },
                { jquery: $("#ckdm", "#" + strDlgIdP010201), model: "TCkxx" });
                ciho.showTypeDialog();
                $("#ckdm", "#" + strDlgIdP010201).combobox("setValue", "");
            }
        }
    });
    $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox("loadData", objCk != "{}" ? objCk : []);
    //如果ck。length==2，把第一个仓库赋给ckdm
    if (strType == "1") {
        if (objCk.length == 2) {
            $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", objCk[0].dm);
        }
    }
}

//加载付款账户combobox的方法
function loadKmData_P010201() {
    var objKm = getComboboxData('TKjkm');           //账户信息
    objKm.push({ "mc": "<font color='red'>添加付款账户</font>", "dm": "-1" });
    $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        editable: true,
        panelHeight: getComHeight(objKm),
        onChange: function (newValue, oldValue) {
            dataChangeStateP010201(true);
            if (newValue) {
                $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox('enable');
            }
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {         //添加付款账户
                ciho.IniData({ id: "divAddType", title: "付款账户", table: "Tflxx" },
                { jquery: $("#kmdm", "#" + strDlgIdP010201), model: "Tkjkm" });
                ciho.showTypeDialog();
                $("#kmdm", "#" + strDlgIdP010201).combobox("setValue", "");
            }
            else {
                if (newValue) {
                    if ($("#fkdate").val() == "") {     //代入付款日期
                        $("#fkdate").val($("#fhdate").val());
                    }
                }
            }
        }
    });
    $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox("loadData", objKm != "{}" ? objKm : []);
    objKm = {};
}

//创建jqGrid的方法
function createGrid_P010201(strTableID, objColNames, objColModel, objJsonData) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: objJsonData,
        rownumbers: true,
        rowNum: 1,
        sortname: "id",
        cellEdit: true,
        cellsubmit: "clientArray",
        autowidth: true,
        //        height: "100%",
        afterEditCell: function (rowId, cellname, value, iRow, iCol) {
            iRowP010201 = iRow;
            iColP010201 = iCol;
            var grid = $("#" + strTableP010201);
            var item = $("#" + rowId + " :input:[name='" + cellname + "']", this);
            var objRecord;
            //开票单位信息
            var objKpdwxx = getComboboxData('Tkpdwxx');
            objKpdwxx.push({ "mc": "<font color='red'>添加收票单位</font>", "dm": "-1" });
            switch (cellname) {
                case "ypmc":                //药品单元格
                    item.combobox({
                        valueField: "dm",
                        textField: "mc",
                        width: _iWidth80,
                        listWidth: _iWidth80,
                        editable: true
                    });

                    //设定选中值
                    var objYpList = getComboboxData("Tspxx");
                    objYpList.push({ "mc": "<font color='red'>添加药品</font>", "dm": "-1" });
                    item.combobox("loadData", objYpList);
                    item.combobox("setValue", $(this).getCell(rowId, "spdm"));
                    if (item.combobox("getText") == $(this).getCell(rowId, "spdm")) {
                        item.combobox('setText', value);
                    }
                    item.combobox('focus');
                    item.combobox({
                        onChange: function (newValue, oldValue) {
                            if (!newValue) {
                                $("#" + strTableP010201).setCell(rowId, "spdm", "&nbsp;");
                            }
                            else {
                                $("#" + strTableP010201).setCell(rowId, "spdm", newValue);
                                $("#" + strTableP010201).setCell(rowId, "a3", "否");             //供应商和药品追踪的开票单位，药品单价，开票单价
                                $("#" + strTableP010201).setColProp("a4", { editable: false });
                                $("#" + strTableP010201).setColProp("a5", { editable: false });
                                $("#" + strTableP010201).setColProp("kpdwmc", { editable: false });
                                grid.setCell(rowId, "kpdwmc", null);
                                grid.setCell(rowId, "a8", null);
                                grid.setCell(rowId, "a4", null);
                                grid.setCell(rowId, "a5", null);
                                grid.setCell(rowId, "kpje", null);
                                grid.setCell(rowId, "kpdwdm", null);
                                if ($("#gysdm").combobox("getValue")) {  //后台取得追踪数据
                                    grid.setCell(rowId, "a2", null);
                                    objRecord = ParseData(window.external.DoOptions(strTableP010201, "DoOthers", "{gysdm:'" + $("#gysdm").combobox("getValue") + "',spdm:'" + newValue + "'}"));
                                    if (objRecord.ReturnCode == 0 && objRecord.Records.length == "1") {
                                        var strDj0102 = parseFloat(objRecord.Records[0].a1).toFixed(window.parent.strPricePlace);
                                        grid.setCell(rowId, "a2", strDj0102);
                                    }
                                }
                                //计算返货金额
                                var fhsl = grid.getCell(rowId, "a1");
                                var fhdj = grid.getCell(rowId, "a2");
                                grid.setCell(rowId, "fhje", (fhsl * fhdj).toFixed(window.parent.strMoneyPlace));
                            }
                            dataChangeStateP010201(true);
                        },
                        afterChange: function (newValue, newText) {
                            if (newValue == "-1") {     //添加药品
                                ciho.IniData({ id: "divAddType", title: "药品", table: "Tflxx" }, { model: "Tspxx", jquery: $(this) });
                                ciho.showTypeDialog();
                                $(this).combobox("setValue", "");
                            }
                        }
                    });
                    break;
                case "a3":
                    item.combobox({                                                           //是否带票下拉框
                        valueField: "s",
                        textField: "f",
                        width: _iWidth80,
                        listWidth: _iWidth80,
                        editable: false,
                        panelHeight: 42,
                        onSelect: function (option) {
                            if (option.s == "是") {  //选择是，开票单价，数量，单位可编辑，并且代入追踪或相应的值
                                //debugger
                                var intKpdj = 0;
                                var strKpdw = "";
                                $("#" + strTableP010201).setColProp("a4", { editable: true });
                                $("#" + strTableP010201).setColProp("a5", { editable: true });
                                $("#" + strTableP010201).setColProp("kpdwmc", { editable: true });
                                if ($("#gysdm").combobox("getValue") && $("#" + strTableP010201).getCell(rowId, "spdm")) {
                                    var objRecordData = ParseData(window.external.DoOptions(strTableP010201, "DoOthers", "{gysdm:'" + $("#gysdm").combobox("getValue") + "',spdm:'" + $("#" + strTableP010201).getCell(rowId, "spdm") + "'}"));
                                    if (objRecordData.ReturnCode == 0 && objRecordData.Records.length == "1") {
                                        intKpdj = parseFloat(objRecordData.Records[0].a2).toFixed(window.parent.strPricePlace);
                                        strKpdw = objRecordData.Records[0].kpdwdm;
                                    }
                                }
                                if (intKpdj != undefined && !isNaN(intKpdj) && intKpdj != 0) {
                                    var fhNum = grid.getCell(rowId, "a1");
                                    grid.setCell(rowId, "a4", fhNum);
                                    grid.setCell(rowId, "a5", intKpdj);
                                    grid.setCell(rowId, "kpje", parseFloat(fhNum * intKpdj).toFixed(window.parent.strMoneyPlace));
                                    for (var intI = 0; intI < objKpdwxx.length; intI++) {
                                        if (strKpdw == objKpdwxx[intI].dm) {
                                            grid.setCell(rowId, "kpdwmc", objKpdwxx[intI].mc);
                                            grid.setCell(rowId, "kpdwdm", strKpdw);
                                            var strdksl = objKpdwxx[intI].dksl;     //选择开票单位，代入相应的抵扣税率
                                            grid.setCell(rowId, "a8", parseFloat(strdksl));
                                        }
                                    }
                                }
                                else {
                                    var fhNum = grid.getCell(rowId, "a1");
                                    var fhPrice = grid.getCell(rowId, "a2");
                                    var fhje = grid.getCell(rowId, "fhje");
                                    grid.setCell(rowId, "a4", fhNum);
                                    grid.setCell(rowId, "a5", fhPrice);
                                    grid.setCell(rowId, "kpje", fhje);
                                }
                            }
                            else if (option.s == "否") {         //选择否，不可编辑，清空数据
                                $("#" + strTableP010201).setColProp("a4", { editable: false });
                                $("#" + strTableP010201).setColProp("a5", { editable: false });
                                $("#" + strTableP010201).setColProp("kpdwmc", { editable: false });
                                grid.setCell(rowId, "kpdwmc", null);
                                grid.setCell(rowId, "a8", null);
                                grid.setCell(rowId, "a4", null);
                                grid.setCell(rowId, "a5", null);
                                grid.setCell(rowId, "kpje", null);
                                grid.setCell(rowId, "kpdwdm", null);
                            }
                            $("#" + strTableP010201).saveCell(iRow, iCol);
                        }
                    });
                    var sfdpData = [{ "s": "是", "f": "是" }, { "s": "否", "f": "否"}];
                    item.combobox("loadData", sfdpData);
                    item.combobox('focus');
                    item.combobox("setValue", value);
                    break;
                case "kpdwmc":
                    item.combobox({             //开票单位
                        valueField: "dm",
                        textField: "mc",
                        width: _iWidth80,
                        listWidth: _iWidth80,
                        editable: true
                    });
                    item.combobox("loadData", objKpdwxx == "{}" ? [] : objKpdwxx);
                    item.combobox('focus');
                    //设定选中值
                    item.combobox("setValue", $(this).getCell(rowId, "kpdwdm"));
                    if (item.combobox("getText") == $(this).getCell(rowId, "kpdwdm")) {
                        item.combobox('setText', value);
                    }
                    item.combobox({
                        onChange: function (newValue, oldValue) {
                            if (!newValue) {
                                $("#" + strTableP010201).setCell(rowId, "kpdwdm", "&nbsp;");
                            }
                            else {
                                $("#" + strTableP010201).setCell(rowId, "kpdwdm", newValue);
                                var objKpData = getComboboxData('Tkpdwxx');
                                for (var intJ = 0; intJ < objKpData.length; intJ++) {
                                    if (newValue == objKpData[intJ].dm) {
                                        var strAkpsl = objKpData[intJ].dksl;    //代入抵扣税率
                                        grid.setCell(rowId, "a8", parseFloat(strAkpsl));
                                    }
                                }
                            }
                            dataChangeStateP010201(true);
                        },
                        afterChange: function (newValue, newText) {
                            if (newValue == "-1") {         //添加开票单位
                                ciho.IniData({ id: "divAddType", title: "收票单位", table: "Tflxx" }, { model: "Tkpdwxx", jquery: $(this) });
                                ciho.showTypeDialog();
                                $(this).combobox("setValue", "");
                            }
                        }
                    });
                    break;
                case "a7":
                    item.combobox({                                                           //返利项目下拉框
                        valueField: "dm",
                        textField: "mc",
                        width: _iWidth80,
                        listWidth: _iWidth80,
                        editable: false,
                        panelHeight: 42,
                        onChange: function (newValue, oldValue) {
                            dataChangeStateP010201(true);
                        },
                        onSelect: function (Record) {
                            if (Record.dm != null && Record.dm != undefined) {
                                $("#" + strTableP010201).setCell(rowId, "a6", Record.dm);
                            }
                            else {
                                $("#" + strTableP010201).setCell(rowId, "a6", "");
                            }
                        }
                    });
                    var flxmData = [{ "dm": "任务达成", "mc": "任务达成" }, { "dm": "业务支持", "mc": "业务支持"}];
                    item.combobox("loadData", flxmData);
                    item.combobox('focus');
                    item.combobox("setValue", $(this).getCell(rowId, "a6"));
                    item.combobox("setText", value);

                    break;
                case "a1":              //单元格数据长度
                    item.val(value);
                    item.change(function () { dataChangeStateP010201(true) });
                    item.autoNumeric({ mDec: window.parent.strCountPlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled").attr("maxlength", "7");
                    break;
                case "a2":
                    item.val(value);
                    item.change(function () { dataChangeStateP010201(true) });
                    item.autoNumeric({ mDec: window.parent.strPricePlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled").attr("maxlength", "7");
                    break;
                case "a4":
                    item.val(value);
                    item.change(function () { dataChangeStateP010201(true) });
                    item.autoNumeric({ mDec: window.parent.strCountPlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled").attr("maxlength", "7");
                    break;
                case "a5":
                    item.val(value);
                    item.change(function () { dataChangeStateP010201(true) });
                    item.autoNumeric({ mDec: window.parent.strPricePlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled").attr("maxlength", "7");
                    break;
                case "fhje":
                    item.val(value);
                    item.change(function () { dataChangeStateP010201(true) });
                    item.autoNumeric({ mDec: window.parent.strMoneyPlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled");
                    break;
                case "kpje":
                    item.val(value);
                    item.change(function () { dataChangeStateP010201(true) });
                    item.autoNumeric({ mDec: window.parent.strMoneyPlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled");
                    break;
            }
            $(".layoutpanel").css("z-index", "50000009");
        },
        afterSaveCell: function (rowId, cellname, value) {   //计算返货金额和开票金额
            switch (cellname) {
                case "a1":
                case "a2":
                    var fhNum = $(this).getCell(rowId, "a1");      //返货数量
                    var fhPrice = $(this).getCell(rowId, "a2");  //返货单
                    $("#" + strTableID).setCell(rowId, "fhje", (fhNum * fhPrice).toFixed(window.parent.strMoneyPlace));
                    break;
                case "a4":
                case "a5":
                    var kpNum = $(this).getCell(rowId, "a4");      //返货数量
                    var kpPrice = $(this).getCell(rowId, "a5");   //返货单价
                    if (kpNum && kpPrice) {
                        $("#" + strTableID).setCell(rowId, "kpje", (kpNum * kpPrice).toFixed(window.parent.strMoneyPlace));
                    }
                    break;
            }
        }
    });
    //设置开票单价，数量，开票单位为不可编辑
    $("#" + strTableP010201).setColProp("a4", { editable: false });
    $("#" + strTableP010201).setColProp("a5", { editable: false });
    $("#" + strTableP010201).setColProp("kpdwmc", { editable: false });
    //增加表头‘序号’列
    //$("table.ui-jqgrid-htable th:first", $("#gbox_" + strTableID)).text("序号");
    $("#" + strTableP010201).setLabel("rn", "序号");
    //$("#" + strTableID).setGridHeight("100%");
}

//打开窗口的方法
function showDialogP0102_FH(strType) {
    try {
        $(".operate").remove();
        //清空弹出窗口内容
        $("#" + strDlgIdP010201).empty();

        //创建窗口
        creatDiv_ShowDlgHaveTbl(strDlgIdP010201, "采购返货单", false, true, strTableP010201, "900");

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

        if (strType == "1") {
            //值为1，插入数据；值为2，更新数据
            bSaveSignP010201 = "1";
            $("#" + strTableP010201).addRowData(1, {});
            //单据日期为当前日期
            var nowData = getNowDate();
            $("#fhdate").val(nowData);
        }
        else if (strType == "2") {
            bSaveSignP010201 = "2";
            //修改 取得数据
            loadGridData_P010201();
        }
        //$('#' + strDlgIdP010201 + "_content").css("margin-top", "15px");
        //设定data change 为false
        dataChangeStateP010201(false);
    } catch (e) {
        proceError(strTableP010201, "");
    }
}

//修改时，加载数据的方法
function loadGridData_P010201() {
    objRetRecord_P010201 = ParseData(window.external.DoOptions(strTableP010201, 'GetList', '{"djbh":"' + objSelRowP0102.djbh + '"}'));

    var myList = objRetRecord_P010201.Records;

    objRetRecord_P010201.Records[0]["a6"] = objRetRecord_P010201.Records[0]["a7"];         //存放返利项目的dm
    if (myList[0].a3 == "True") {       //是否带票为是,可编辑
        myList[0].a3 = "是";
        $("#" + strTableP010201).setColProp("a4", { editable: true });
        $("#" + strTableP010201).setColProp("a5", { editable: true });
        $("#" + strTableP010201).setColProp("kpdwmc", { editable: true });
    }
    else {
        myList[0].a3 = "否";         //为否，不可编辑
        $("#" + strTableP010201).setColProp("a4", { editable: false });
        $("#" + strTableP010201).setColProp("a5", { editable: false });
        $("#" + strTableP010201).setColProp("kpdwmc", { editable: false });
    }
    //格式单元格
    $("#" + strTableP010201).setColProp("a1", { formatter: formatCountPlace_P010201 });
    $("#" + strTableP010201).setColProp("a2", { formatter: formatPricePlace_P010201 });
    $("#" + strTableP010201).setColProp("a4", { formatter: formatCountPlace_P010201 });
    $("#" + strTableP010201).setColProp("a5", { formatter: formatPricePlace_P010201 });
    $("#" + strTableP010201).setColProp("fhje", { formatter: formatMoneyPlace_P010201 });
    $("#" + strTableP010201).setColProp("kpje", { formatter: formatMoneyPlace_P010201 });

    loadTreeData(strTableP010201, myList);  //加载数据
    //给返货日期绑定值
    $("#fhdate", $("#" + strDlgIdP010201 + "_divform")).attr("disabled", true);
    $("#fhdate").val(objRetRecord_P010201.fhdate);
    //供应商
    $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", myList[0].gysdm);
    $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setText", myList[0].gysmc);
    //经手人
    $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", myList[0].zydm);
    $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox("setText", myList[0].jsrmc);
    //付款账户
    $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", myList[0].kmdm);
    $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setText", myList[0].zhmc);
    //仓库
    $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", myList[0].ckdm);
    $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setText", myList[0].ckmc);
    if ($("#kmdm").combobox('getText') != "" || objRetRecord_P010201.fkje != "") {  //账户不为空时，可编辑
        $("#fy").attr("checked", true);
        $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox("enable");
        $("#fkje").attr("disabled", false);
        $("#fkdate").attr("disabled", false);
    }
    //给付款金额绑定值
    if (!isNaN(parseFloat(objRetRecord_P010201.fkje))) {
        $("#fkje", $("#" + strDlgIdP010201 + "_divform")).val(parseFloat(objRetRecord_P010201.fkje).toFixed(window.parent.strMoneyPlace));
    }
    //给付款日期赋值
    $("#fkdate", $("#" + strDlgIdP010201 + "_divform")).val(objRetRecord_P010201.fkdate);
    //制单人
    $("#czydm", $("#" + strDlgIdP010201 + "_divform")).val(objRetRecord_P010201.Records[0]["zdrmc"]);
    //给备注赋值
    $("#bz", $("#" + strDlgIdP010201 + "_divform")).val(escape(myList[0].bz));

    //查看是否有修改
    strBlData.push("spdm");
    strBlData.push("a1");
    strBlData.push("a2");
    strBjData = getCompareData(strTableP010201, strBlData);     //返回要检查的字段数据字符串
    myList = null;
}

//检查关联数量
function saveMyData_P010201(strType) {
    $("#" + strTableP010201).saveCell(iRowP010201, iColP010201);
    var objTable = $("#" + strTableP010201);
    var arrIDs = objTable.jqGrid("getDataIDs")[0];
    var strGlsl = parseFloat(objTable.jqGrid("getCell", arrIDs, "glsl"));
    if (strGlsl != 0 && !isNaN(strGlsl)) {          //关联了药品数量，修改时数量与关联的数量不一致
        if (parseFloat(objTable.jqGrid("getCell", arrIDs, "a1")) != strGlsl) {
            window.parent.cihoAlert(msg.other.plGl, msgBox.dlgBtn.OK, function (result) {
                if (result == msgBox.dlgRst.Ok) {
                    objTable = null;
                    saveStartData_P010201(strType);
                }
            });
            return;
        }
    }
    objTable = null;
    saveStartData_P010201(strType);
}

//保存方法,strType:0:关闭； 1：保存退出  2：保存新增
function saveStartData_P010201(strType) {
    //传递的数据字符串
    var strRecord = checkDataValidateP010201();
    if (strRecord == "" || strRecord == null) {
        return;
    }
    if (bSaveSignP010201 == "1") {        //新增
        var objRet = ParseData(window.external.DoOptions(strTableP010201, 'Add', strRecord));
    }
    else {      //修改
        var objRet = ParseData(window.external.DoOptions(strTableP010201, 'Edit', strRecord));
    }
    if (!objRet) {
        window.parent.cihoAlert(msg.other.dbOprateErr);
        return;
    }
    if ("0" == objRet.ReturnCode) {
        if (bSaveSignP010201 == "2") {      //check修改前和修改后的数据
            var strNewData = getCompareData(strTableP010201, strBlData);
            if (strBjData != strNewData) {      //有修改 传递数据给后台
                window.external.DoOptions(strTableP010201, 'DoOthers', "{'flag':true,'djdate':'" + objRetRecord_P010201.fhdate + "'}");
            }
            strNewData = null;
        }

        $("#idMust", $("#" + strDlgIdP010201)).empty();
        loadGridDataP0102();    //管理画面查询出新增或修改的数据
        //resizeGrid(strTableP0102);
        //释放内存
        strRecord = null;
        objRet = null;
        if (strType == "2") {
            bSaveSignP010201 = "1";
            $(":input[name]", $("#" + strDlgIdP010201 + "_divform")).val("");
            //清除单据编号
            $("#" + strDlgIdP010201 + "_pop_box_top").empty();
            //时间日期控件
            $("#fhdate", $("#" + strDlgIdP010201 + "_divform")).val(getNowDate());
            $("#fhdate", $("#" + strDlgIdP010201 + "_divform")).attr("disabled", false);
            $("#czydm", $("#" + strDlgIdP010201 + "_divform")).val(window.parent.objLoginInfo.name);
            //清空combobox
            $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", "");
            $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", "");
            if (objCk.length == 2) {            //仓库中数据只有2个，设置第一个为默认
                $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", objCk[0].dm);
            }
            else {
                $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", "");
            }

            $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox("setValue", "");
            //把fhje置清空
            $("#" + strTableP010201).clearGridData();
            $("#" + strTableP010201).addRowData(1, {});
            $("#fy").attr("checked", false);
            $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox('disable');
            $("#fkje", $("#" + strDlgIdP010201 + "_divform")).attr("disabled", true);
            $("#fkdate", $("#" + strDlgIdP010201 + "_divform")).attr("disabled", true);
            dataChangeStateP010201(false);
            $("#bz", "#" + strDlgIdP010201).focus();
        }
        //关闭/保存退出
        else{
            cihoDlgClose(strDlgIdP010201);
        }
        freeMemory_P010201();
    }
    else {
        window.parent.cihoAlert(objRet.MSG);
        return false;
    }
}

//验证数据并组成字符串的方法
function checkDataValidateP010201() {
    $("#" + strTableP010201).saveCell(iRowP010201, iColP010201);
    var arrList = "";
    var strFhdate = trim($("#fhdate", $("#" + strDlgIdP010201 + "_divform")).val());    //返货日期
    if (strFhdate == "" || strFhdate == null) {
        window.parent.cihoAlert(msg.dt.inputFhDt, null, function () { $("#fhdate").focus(); });
        return;
    }
    if ((strFhdate.replace(/-/g, "/")) < (window.parent._startDate)) {
        window.parent.cihoAlert(msg.other.fhrqExtent, null, function () { $("#fhdate").select(); });
        return;
    }
    arrList += "\"fhdate\":\"" + strFhdate + "\",";
    var strGysdm = $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox('getValue');      //供应商
    if (!strGysdm) {
        if (bSaveSignP010201 == "2" && $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox('getText') == objRetRecord_P010201.Records[0]["gysmc"]) {
            strGysdm = objRetRecord_P010201.Records[0]["gysdm"];
        }
        else {
            window.parent.cihoAlert(msg.sz.gys.empOrNotExit, null, function () { $("#gysdm", $("#" + strDlgIdP010201 + "_divform")).combobox('focus'); });
            return;
        }
    }
    arrList += "\"gysdm\":\"" + strGysdm + "\",";
    var strJsr = $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox('getValue');     //经手人
    if (!strJsr) {
        if (bSaveSignP010201 == "2" && $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox('getText') == objRetRecord_P010201.Records[0]["jsrmc"]) {
            strJsr = objRetRecord_P010201.Records[0]["zydm"];
        }
        else {
            window.parent.cihoAlert(msg.sz.jsr.empOrNotExit, null, function () { $("#zydm", $("#" + strDlgIdP010201 + "_divform")).combobox('focus'); });
            return;
        }
    }
    arrList += "\"zydm\":\"" + strJsr + "\",";
    var strCk = $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox('getValue');      //仓库
    if (!strCk) {
        if (bSaveSignP010201 == "2" && $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox('getText') == objRetRecord_P010201.Records[0]["ckmc"]) {
            strCk = objRetRecord_P010201.Records[0]["ckdm"];
        }
        else {
            window.parent.cihoAlert(msg.sz.ck.empOrNotExit, null, function () { $("#ckdm", $("#" + strDlgIdP010201 + "_divform")).combobox('focus'); });
            return;
        }
    }
    arrList += "\"ckdm\":\"" + strCk + "\",";
    if ($("#fy").attr("checked")) {//收款账户不为空，收款金额，收款日期都不能为空。
        var strZhmc = $("#kmdm", $("#" + strDlgIdP010201 + "_divform")).combobox('getValue');
        //如果账户代码为空，判断是否因停用而取不到
        if (!strZhmc) {
            if (bSaveSignP010201 == "2" && trim($("#kmdm").combobox('getText')) == objRetRecord_P010201.Records[0]["zhmc"]) {
                strZhmc = objRetRecord_P010201.Records[0]["kmdm"];
            }
        }
        var strFkje = trim($("#fkje", $("#" + strDlgIdP010201 + "_divform")).val());
        var strFkdate = trim($("#fkdate", $("#" + strDlgIdP010201 + "_divform")).val());
        //三项全为空
        if (!strZhmc && !strFkje && !strFkdate) {
            arrList += "\"kmdm\":\"\",";
            arrList += "\"fkje\":\"\",";
            arrList += "\"fkdate\":\"\",";
        }
        else {
            if (!strZhmc) {
                window.parent.cihoAlert(msg.other.inputFkzh, null, function () { $("#kmdm",$("#"+strDlgIdP010201+"_divform")).combobox('focus'); });
                return;
            }
            if (!strFkje) {
                window.parent.cihoAlert(msg.other.inputFkje, null, function () { $("#fkje").focus(); });
                return;
            }
            if (!strFkdate) {
                window.parent.cihoAlert(msg.dt.inputFkDt, null, function () { $("#fkdate").focus(); });
                return;
            }
            if ((strFkdate.replace(/-/g, "/")) < (window.parent._startDate.replace(/-/g, "/"))) {
                window.parent.cihoAlert(msg.other.fkrqExtent, null, function () { $("#fkdate").select(); });
                return;
            }
            arrList += "\"kmdm\":\"" + strZhmc + "\",";
            arrList += "\"fkje\":\"" + strFkje + "\",";
            arrList += "\"fkdate\":\"" + strFkdate + "\",";
        }
    }
    if (bSaveSignP010201 == "1") {   //新增时，制单人的dm取自登陆用户的dm
        arrList += "\"czydm\":\"" + window.parent.objLoginInfo.code + "\",";
    }
    else {    //修改时，制单人的dm取自返回的数据
        arrList += "\"czydm\":\"" + objRetRecord_P010201.Records[0]["czydm"] + "\",";
    }
    //备注
    arrList += "\"bz\":\"" + trim($("#bz", $("#" + strDlgIdP010201 + "_divform")).val()) + "\"";
    //获得表格的数据
    var strSelRowIdP010201 = $("#" + strTableP010201).jqGrid("getDataIDs")[0];
    var strSpdm = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "spdm");    //药品代码
    if (!strSpdm) {
        window.parent.cihoAlert(msg.sz.yp.empOrNotExit);
        return;
    }
    var strFhsl = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a1");   //数量
    if (!strFhsl) {
        window.parent.cihoAlert(msg.other.inputFhsl, null, function () { $("#a1").select(); });
        return;
    }
    else {
        if (parseFloat(strFhsl) <= 0) {
            window.parent.cihoAlert(msg.cg.fhslNotZero);
            return;
        }
    }
    var strFhdj = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a2");     //单价
    if (!strFhdj) {
        window.parent.cihoAlert(msg.other.inputFhdj);
        return;
    }
    else {
        if (parseFloat(strFhdj) <= 0) {
            window.parent.cihoAlert(msg.cg.fhdjNOtZero);
            return;
        }
    }
    var strFhje = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "fhje");   //返货金额
    if (strFhje > window.parent._MaxPerBill) {      //返货金额大于1亿
        window.parent.cihoAlert(msg.other.fhjeExtent);
        return;
    }
    else {
        if (!strFhje) {
            window.parent.cihoAlert(msg.other.intputFhje);
            return;
        }
    }
    var strKpdwdm = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "kpdwdm");   //开票单位
    //开票单位的抵扣税率
    var strDkslP010201 = parseFloat($("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a8"));
    //开票数量，单价，金额
    var strKpsl = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a4");
    var strKpdj = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a5");
    var strKpje = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "kpje");
    if (bSaveSignP010201 == "1") {    //返利项目
        var strFlxm = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a6");
        if (!strFlxm) {
            window.parent.cihoAlert(msg.other.flxmEmpOrNotExit);
            return;
        }
    }
    else {
        var strFlxm = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a7");
        if (!strFlxm) {
            window.parent.cihoAlert(msg.other.flxmEmpOrNotExit);
            return;
        }
    }
    var strDp = $("#" + strTableP010201).jqGrid("getCell", strSelRowIdP010201, "a3");
    if (strDp == "否") {   //如果不带票，清空相应数据
        strDp = "False";
        strKpdwdm = "";
        strDkslP010201 = "";
        strKpsl = "";
        strKpdj = "";
        strKpje = "";
    }
    else {
        strDp = "True";
        if (!strKpdwdm) {
            window.parent.cihoAlert(msg.sz.kp.nameEmp);
            return;
        }
        if (!strDkslP010201) {
            window.parent.cihoAlert(msg.sz.kp.DkKpNoEmpty);
            return;
        }
        if (!strKpsl) {
            window.parent.cihoAlert(msg.other.inputKpsl);
            return;
        }
        if (!strKpdj) {
            window.parent.cihoAlert(msg.other.inputKpdj);
            return;
        }
        if (!strKpje) {
            window.parent.cihoAlert(msg.other.intputKpje);
            return;
        }
        else {
            if (strKpje <= 0) {
                window.parent.cihoAlert(msg.other.kpjeIsnotZero);
                return;
            }
        }
    }
    var strRecord = "{\"Records\":";
    strRecord += "[{";
    if (bSaveSignP010201 == "2") {
        strRecord += "\"mxguid\":\"";
        strRecord += objRetRecord_P010201.Records[0]["mxguid"] + "\",";
        strRecord += "\"djbh\":\"";
        strRecord += objSelRowP0102.djbh + "\",";
    }
    strRecord += "\"spdm\":\"" + strSpdm + "\"";
    strRecord += ",\"a1\":\"" + strFhsl + "\"";
    strRecord += ",\"a2\":\"" + strFhdj + "\"";
    strRecord += ",\"fhje\":\"" + strFhje + "\"";
    strRecord += ",\"kpdwdm\":\"" + strKpdwdm + "\"";
    strRecord += ",\"a8\":\"" + strDkslP010201 + "\"";
    strRecord += ",\"a4\":\"" + strKpsl + "\"";
    strRecord += ",\"a5\":\"" + strKpdj + "\"";
    strRecord += ",\"kpje\":\"" + strKpje + "\"";
    strRecord += ",\"a7\":\"" + strFlxm + "\"";
    strRecord += ",\"a3\":\"" + strDp + "\"";
    strRecord += "}],";
    strRecord += arrList;
    strRecord += "}";
    //释放内存
    arrList = null;
    strFhdate = null;
    strCk = null;
    strDkslP010201 = null;
    strFhdj = null;
    strFhje = null;
    strFhsl = null;
    strFkdate = null;
    strFkje = null;
    strFlxm = null;
    strSpdm = null;
    strKpdwdm = null;
    strKpdj = null;
    strKpsl = null;
    strKpje = null;
    strDp = null;
    strGysdm = null;
    strJsr = null;
    strZhmc = null;
    return strRecord;
}

//数据是否改变的状态的方法
function dataChangeStateP010201(bState) {
    //修改Data change状态
    $("#" + strDlgIdP010201 + "_divform").data("change", bState);
}