/*-------------------------------文档信息-----------------------------------
///功能：税金调整单
///创建人: 翟新乐
///创建时间：2011-07-01
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量
var strTableP040401 = "Tp040401";   //表格ID
var strDialogP040401 = "divP0414"; //窗口ID

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//编辑调整单方法
function showDialog_P040401() {
    try {
        $("#" + strDialogP040401).empty();
        //弹出窗口的创建
        creatDiv_ShowDialog(strDialogP040401, "税金调整", false, false, strTableP040401, "650");

        //创建窗口元素
        creatDialogItem_P040401();

        //设置窗口居中显示
        $("#" + strDialogP040401).dialog("option", "position", "center");
    } catch (e) { }
}

//创建表单元素
function creatDialogItem_P040401() {
    var config = ParseData(window.external.DoOptions(strTableP040401, "GetTableConfig", "{}"));
    if (config == null) {
        window.parent.cihoAlert(msg.other.modelInfoFail);
        return;
    }

    //创建头部
    var i = 0;
    var strForm = "";
    var Item;
    strForm += "<ul>";
    for (i = 0; i < config.pageHeader.length; i++) {
        Item = config.pageHeader[i];
        if (Item.hidden == true) {
            continue;
        }
        if (Item.edittype == "text") {
            if (Item.index == "bz") {
                strForm += "<li>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + "' ";
                strForm += " value=''  ";
                strForm += " id='" + Item.index + "'";
                strForm += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>";
                strForm += "</li>";
            }
            else {
                strForm += "<li>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + "' ";
                strForm += " value=''  ";
                strForm += " id='" + Item.index + "'";
                strForm += " maxlength='50'   onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>";
                strForm += "</li>";
            }
        }
        else {
            strForm += "<li>";
            strForm += Item.xsmc + "：";
            strForm += "<select name='" + Item.index + "' id='" + Item.index + "'";
            strForm += " class='easyui-combobox' >";
            strForm += "</select>";
            strForm += "</li>";
        }
    }
    strForm += "</ul>";
    $("#" + strDialogP040401 + "_divform").append(strForm);
    //添加按钮
    strForm = "<div class=\"clr\"></div>";
    strForm += "<div class=\"box_btn_width\">";
    strForm += "    <div class=\"box_btn\">";
    strForm += "        <div class=\"btn01\"><a onclick=\"saveMyData('" + strDialogP040401 + "', 1, '" + strTableP040401 + "')\">保存退出</a></div>";
    strForm += "    </div>";
    strForm += "</div>";
    $(".pop_box", $("#" + strDialogP040401)).append(strForm);
    //下拉框的值
    var objKp = getComboboxData('Tkpdwxx');
    objKp.push({ "mc": "<font color='red'>添加开票单位</font>", "dm": "-1" });
    //kP
    $("#kpdwdm", $("#" + strDialogP040401 + "_divform")).combobox({
        textField: "mc",
        valueField: "dm",
        onChange: function (newValue, oldValue) {
            dataChangeStateP040401(true);
        },
        afterChange: function (newValue, newText) {
            if (newValue == "-1") {
                ciho.IniData({ id: "divAddType", title: "开票单位", table: "Tflxx" }, { jquery: $("#kpdwdm", "#" + strDialogP040401), model: "Tkpdwxx" });
                ciho.showTypeDialog();
                $("#kpdwdm", "#" + strDialogP040401).combobox("setValue", "");
            }
        }
    });
    if (objKp != "{}") {
        $("#kpdwdm", $("#" + strDialogP040401 + "_divform")).combobox("loadData", objKp);
    }
    //km
    $("#djtypedm", $("#" + strDialogP040401 + "_divform")).combobox({
        textField: "mc",
        valueField: "dm",
        panelHeight: 42,
        editable:false,
        onChange: function (newValue, oldValue) {
            dataChangeStateP040401(true);
        }
    });
    var strTzData = [{ "dm": "805", "mc": "税金增加" }, { "dm": "806", "mc": "税金减少"}];
    $("#djtypedm", $("#" + strDialogP040401 + "_divform")).combobox("loadData", strTzData);
    $(".layoutpanel").css("z-index", "50000009");
    //设置默认值
    $("#djdate", $("#" + strDialogP040401 + "_divform")).val(getNowDate());
    inputAndBindData("djdate", false, "#" + strDialogP040401, dateChange_P040401);
    $("#a1", $("#" + strDialogP040401 + "_divform")).css("ime-mode", "disabled").autoNumeric({ mDec: window.parent.strMoneyPlace, aSep: "" });
    $("#czydm", $("#" + strDialogP040401 + "_divform")).val(window.parent.objLoginInfo.name);
    $("#czydm", $("#" + strDialogP040401 + "_divform")).attr("disabled", true);
    //设定状态
    $(":input", $("#" + strDialogP040401 + "_divform")).change(function () {
        $("#" + strDialogP040401 + "_divform").data("change", true);
    });
    $("#" + strDialogP040401 + "_divform").data("change", false);

    setTimeout('$("#a1", "#" + strDialogP040401).focus()', 100);

    //释放内存
    config = null;
    strForm = null;
    Item = null;
    i = null;
    objKp = {};
    strTzData = {};
}

//日期控件变更，datachange
function dateChange_P040401() {
    dataChangeStateP040401(true);
}

//保存信息
function saveData_P040401() {
    var strKpdm = $("#kpdwdm", $("#" + strDialogP040401 + "_divform")).combobox("getValue");    //开票单位
    if (!strKpdm) {
        window.parent.cihoAlert(msg.sz.kp.SelKpdw, null, function () { $("#kpdwdm", $("#" + strDialogP040401 + "_divform")).combobox('focus'); });
        return;
    }
    var strYwlxdm = $("#djtypedm", $("#" + strDialogP040401 + "_divform")).combobox("getValue");    //调整类型
    if (!strYwlxdm) {
        window.parent.cihoAlert(msg.other.typeErr, null, function () { $("#djtypedm", $("#" + strDialogP040401 + "_divform")).combobox('focus'); });
        return;
    }
    var strDjdate = $("#djdate", $("#" + strDialogP040401 + "_divform")).val();     //日期
    if (strDjdate == "") {    //日期为空
        window.parent.cihoAlert(msg.dt.dtExtentErr, null, function () { $("#djdate", $("#" + strDialogP040401 + "_divform")).focus(); });
        return;
    }
    if ((strDjdate.replace(/-/g, "/")) < (window.parent._startDate.replace(/-/g, "/"))) { //日期超出系统时间范围
        window.parent.cihoAlert(msg.other.djrqExtent, null, function () { $("#djdate").select(); });
        return;
    }
    var strJe = trim($("#a1", $("#" + strDialogP040401 + "_divform")).val());       //金额
    if (strJe == "") {
        window.parent.cihoAlert(msg.other.jenotEmp, null, function () { $("#a1", $("#" + strDialogP040401 + "_divform")).focus(); });
        return;
    }
    var strBz = trim($("#bz", $("#" + strDialogP040401 + "_divform")).val());
    var strDataJson = "{\"djdate\":\"" + strDjdate + "\",\"kpdwdm\":\"" + strKpdm + "\",\"djtypedm\":\"" + strYwlxdm + "\",\"a1\":\"" + strJe + "\",\"czydm\":\"" + window.parent.objLoginInfo.code + "\",\"bz\":\"" + strBz + "\"}";
    var objResult = ParseData(window.external.DoOptions(strTableP040401, "Add", strDataJson));
    if (objResult.ReturnCode == 0) {
        //释放内存
        objResult = null;
        strKpdm = null;
        strYwlxdm = null;
        strDjdate = null;
        strJe = null;
        strBz = null;
        strDataJson = null;
        cihoDlgClose(strDialogP040401);
        searchDataClick_P0414();
        resizeGridScroll(strTableP0414);
    }
    else {
        window.parent.cihoAlert(objResult.MSG);
    }
}

//数据状态
function dataChangeStateP040401(bState) {
    //修改Data change状态
    $("#" + strDialogP040401 + "_divform").data("change", bState);
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**自定义方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/