<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="charge.aspx.cs" Inherits="VA.Modules.JDingMember.consume.charge_v1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!--#include virtual="/include/css/edit.aspx"-->
    <link href="/uicontrols/jtongui/themes/default/tabs.css" type="text/css" rel="Stylesheet" />
    <!--#include virtual="/include/js/edit.aspx"-->         
    <script type="text/javascript" src="/uicontrols/jtongui/plugins/jtong.tabs.js"></script>
    <script type="text/javascript">

        function confirm() {

            //调用asp.net验证控件自带的js数据验证脚本对控件进行验证；
            var validationResult = Page_ClientValidate('');
            if (!validationResult) {
                return;
            }

            //var chargeDate = $("#spanChargeDate").html();
            //var operatorName = $("#spanOperatorName").html();
            var totalAmount = $("#txtTotalAmount").val();
            var discountAmount = $("#txtDiscountAmount").val();
            var chargeAmount = $("#txtChargeAmount").val();
            var payTypeName = $("#ddlPayTypes").find("option:selected").text();

            if (parseFloat(discountAmount) < 0) {
                JTongAlert("提示", "优惠金额不能为负数！", "error", function () {
                    $("#txtDiscountAmount").select();
                });
                return;
            }

            //$("#span_Confirm_ChargeDate").html(chargeDate);
            //$("#span_Confirm_OperatorName").html(operatorName);
            $("#span_Confirm_TotalAmount").html(totalAmount);
            $("#span_Confirm_DiscountAmount").html(discountAmount);
            $("#span_Confirm_ChargeAmount").html(chargeAmount);
            $("#span_Confirm_PayTypeName").html(payTypeName);

            $('#winConfirm').css("display", "block");
            $('#winConfirm').window({
                width: 350,
                height: 368,
                left: 180,
                top: 116,
                modal: true,
                maximizable: false,
                minimizable: false,
                collapsible: false,
                title: '确认'
            });
            $("#btnSubmit").focus();
        }

        function cancelSave() {
            $('#winConfirm').window("close");
        }
    
    function save() {

        var hfMemberID = $("#hfMemberID").val();
        var isFreeCustomer = $("#ckbIsFreeCustomer")[0].checked;
        
        if (!isFreeCustomer) {  //如果会员        
            if ($.trim(hfMemberID) == "") {
                JTongAlert('提示', "会员信息不能为空！", 'warning');
                return;
            }
        } else {
            var payTypeCode = $("#ddlPayTypes").val(); 
            if (payTypeCode == "2") {
                JTongAlert('提示', "对于散客，支付方式不能为：会员钱包支付！", 'warning');
                return;
            }
        }

        if (!formEditListTable_checkTableData()) {
            return;
        }

        var requestType = "POST";
        var url = pageName + "?act=add";  //pageName在BasePage中注册到的客户端；
        var dataType = "html";
        var data = $("form").eq(0).serialize();
        var successFN = function (data, textStatus) {
            var bizNo = "";
            if (data.substring(0, 2) == "ok") {
                bizNo = data.split("|")[1];
                showActResult("收银成功！", true, doAfterAdd, bizNo);
            } else if (data.indexOf("01|") != -1) {
                showActResult(data.substring(3), false, doAfterAdd, bizNo);
            }
            else {
                showActResult("收银失败：" + data, false, doAfterAdd, bizNo);
            }
        };
        ajaxRequest(requestType,
            url,
            dataType,
            data,
            successFN,
            errorFN
            );
    }

    function doAfterAdd(actResult, bizNo) {
        if (actResult) {
            if ($("#ckbPrintBill")[0].checked == true) {
                printBill("2", bizNo);
            }

            var isFreeCustomer = $("#ckbIsFreeCustomer")[0].checked;
            if (!isFreeCustomer) { //如果是会员；
                if ($("#ckbNotify")[0].checked == true) {
                    ajaxExecute("get", "../notification/biztransaction_notify.aspx", { "biztype": "consumecharge", "bizno": bizNo });
                }
            }

            resetPage();
            cancelSave();
        }
    }

    //显示操作结果；
    function showActResult(sMsg, actResult, callback, bizNo) {
        var icon = "info";
        if (!actResult) {
            icon = "error";
        }

        JTongAlert('操作结果', sMsg, icon, function () {
            if (callback != null && callback != undefined) {
                callback(actResult, bizNo);
            }
        });
    }

    function resetPage() {

        clearMemberInfo();

        $("#spanSaleStrategyApplyDesc").html("");

        var isFreeCustomer = $("#ckbIsFreeCustomer")[0].checked;
        if (!isFreeCustomer) { //如果是会员；
            $("#ddlPayTypes").attr("disabled", "disabled");
            $("#txtItemName").attr("disabled", "disabled");
            $("#txtWaiter").attr("disabled", "disabled");
            $("#txtRemark").attr("disabled", "disabled");
            $("#btnSubmit").attr("disabled", "disabled");
        }

        $("#txtTotalAmount").val("");
        $("#hfTotalAmount").val("");
        $("#txtDiscountAmount").val("0.00");
        $("#txtChargeAmount").val("");
        $("#hfChargeAmount").val("");
        
        $("#hfStrategyCode").val("");
        $("#hfStrategyName").val("");
        $("#ddlPayTypes")[0].options[0].selected = true;
        $("#txtRemark").val("");
        
        formEditListTable_clearRows();

        clearInputValidatorError();
    }

    //会员信息加载成功时调用的方法；            
    function doWhenMemberInfoLoadSuc(memberInfo) {

        $("#txtItemName").removeAttr("disabled");
        $("#txtWaiter").removeAttr("disabled");
        $("#ddlPayTypes").removeAttr("disabled");
        $("#txtRemark").removeAttr("disabled");
        $("#btnSubmit").removeAttr("disabled");

        //$("#txtItemName").focus();
    }

    //会员信息加载失败时调用的方法；
    function doWhenMemberInfoLoadFail() {

    }    

    function JTongSmartDropDownList_AfterTakeValue(JTongSmartDropDownList_inputObjID, selectedRow) {
        if (selectedRow != null) {

            if (JTongSmartDropDownList_inputObjID == "txtItemName") {
                
                var levelCode = $("#hfLevelCode").val();
                var itemType = selectedRow.cells[0].innerHTML;
                var itemCode = selectedRow.cells[1].innerHTML;
                var itemName = selectedRow.cells[2].innerHTML;
                var unit = selectedRow.cells[3].innerHTML;
                var price = selectedRow.cells[4].innerHTML;
                var quantity = 1.0;

                /*
                var discount = getItemDiscout(itemCode, levelCode);
                var finalPrice = parseFloat(price) * parseFloat(discount);
                */
                var finalPrice = getFinalPrice(itemCode, levelCode, price);

                var amount = parseFloat(price) * quantity; //优惠前金额
                var charges = finalPrice * quantity; //优惠后金额

                if (itemType == "服务") {
                    itemType = "1";
                }
                else if (itemType == "商品") {
                    itemType = "2";
                }
                
                formEditListTable_addRow(itemType,itemCode, itemName, unit, price, finalPrice, quantity);
                $("#txtItemName").val("");
                $("#txtItemName_hiddenValue").val("");
            } else if (JTongSmartDropDownList_inputObjID == "txtWaiter") {

                var code = selectedRow.cells[0].innerHTML;
                var name = selectedRow.cells[1].innerHTML;

                var $srcTable = $("#srcTable");
                $srcTable.find("input.waiterName").each(function () {
                    $(this).val(name);
                });
                $srcTable.find("input.waiterCode").each(function () {
                    $(this).val(code);
                });
            }
        }

        //返回true，继续取值；返回false，取消取值；
        return true;
    }

    function getItemDiscout(itemCode, levelCode) {

        var discount = "1|1"; //参数1:1-代表折扣；2-代表价格； 参数2：代表折扣值或金额；

        $.ajax({
            type: "GET",
            url: "get_chargeitem_discount.aspx",
            dataType: "html",
            async: false, //同步请求；
            data: {
                "itemcode": itemCode,
                "levelcode": levelCode
            },
            success: function (data, textStatus) {
                if (data != "error") {
                    discount = data;
                }
                else {
                    showActResult("计算项目折扣失败 ！", false);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                showActResult("请求失败！textStatus :" + textStatus, false);
            }
        });

        return discount;
    }

    function applySaleStrategy() {

        $("#spanSaleStrategyApplyDesc").html("");

        var customerType = "";
        var consumeAmount = $("#txtTotalAmount").val();
        if ($.trim(consumeAmount) == "") {
            return;
        }
        
        if ($("#ckbIsFreeCustomer")[0].checked == true){
            customerType = "1"; //散客
        }else{
            customerType = "2"; //会员
        }

        $.ajax({
            type: "GET",
            url: "apply_consume_salestategy.aspx",
            dataType: "html",
            async: false,
            data: { "memberID": $("#hfMemberID").val(), "customerType": customerType, "consumeAmount": $("#txtTotalAmount").val() },
            success: function (data, textStatus) {
                if (data != "error") {
                    if (data == "") {
                        //do nothing
                        caculateChargeAmount();
                    } else {
                        var ssResult = JSON.parse(data);
                        var saleStreategyDiscountAmount = parseFloat(ssResult.discountAmount);
                        var oldDiscountAmount = parseFloat($("#txtDiscountAmount").val());
                        var totalDiscountAmount = saleStreategyDiscountAmount + oldDiscountAmount;

                        $("#txtDiscountAmount").val(totalDiscountAmount);
                        $("#hfStrategyCode").val(ssResult.strategyCode);
                        $("#hfStrategyName").val(ssResult.strategyName);

                        caculateChargeAmount();
 
                        $("#spanSaleStrategyApplyDesc").html("提示：系统自动应用了优惠策略：" + ssResult.strategyName);
                    }
                }
                else {
                    showActResult("应用营销策略失败！", false);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                showActResult("请求失败！textStatus :" + textStatus, false);
            }
        });
    }

    function caculateChargeAmount() {
        var sTotalAmount = $.trim($("#txtTotalAmount").val());
        var sDiscountAmount = $.trim($("#txtDiscountAmount").val());
        var chargeAmount = 0.00;
        if (sTotalAmount != "") {

            if (sDiscountAmount == "") {
                sDiscountAmount = "0.00";
            }

            chargeAmount = parseFloat(sTotalAmount) - parseFloat(sDiscountAmount);            
            $("#txtChargeAmount").val(chargeAmount.toFixed(2).toString());
            $("#hfChargeAmount").val(chargeAmount.toFixed(2).toString());
        }
    }

    function loadFavItems() {
        var result = ajaxGetData("charge_getfavitems.aspx", "html", "");
        $("#div_FavItems_DataBody").html(result);
    }

    function manageFavItems() {
        openFrameWindow("常用收费项目管理", 780, 500, "favitem_editlist.aspx", true);
    }

    function refreshFavItems() {
        loadFavItems();
    }

    function sortFavItems() {
        openFrameWindow("常用收费项目排序", 780, 500, "favitem_sort.aspx", true);
    }

    function addRowByFavItem(itemType, itemCode, itemName, unit, price) {

        var levelCode = $("#hfLevelCode").val();
        var quantity = 1.0;
        
        /*
        var discount = getItemDiscout(itemCode, levelCode);
        var finalPrice = parseFloat(price) * parseFloat(discount);
        */
        finalPrice = getFinalPrice(itemCode, levelCode, price);
        
        //if (itemType == "服务") {
        //    itemType = "1";
        //}
        //else if (itemType == "商品") {
        //    itemType = "2";
        //}
        
        formEditListTable_addRow(itemType, itemCode, itemName, unit, price, finalPrice, quantity);
    }

    function loadGroups() {
        var result = ajaxGetData("charge_getgroups.aspx", "html", "");
        $("#div_FavGroups_DataBody").html(result);
    }

    function manageGroups() {
        openFrameWindow("项目组套管理", 780, 500, "charge_group_editlist.aspx", true);
    }

    function refreshGroups() {
        loadGroups();
    }

    function sortGroups() {
        openFrameWindow("项目组套排序", 780, 500, "charge_group_sort.aspx", true);
    }

    function addRowByGroup(groupID) {

        $.get("charge_getgroupitems.aspx", {
            groupid: groupID,
        }, function (data, textStatus) {
            
            var total = data.total;
            var rows = data.rows;

            for (var i = 0; i < rows.length; i++) {
                var itemType = rows[i].itemType;
                var itemCode = rows[i].itemCode;
                var itemName = rows[i].itemName;
                var unit = rows[i].unit;
                var quantity = parseFloat(rows[i].quantity).toString();
                var price = rows[i].price;
                var finalPrice = 0;

                var levelCode = $("#hfLevelCode").val();
                finalPrice = getFinalPrice(itemCode, levelCode, price);

                formEditListTable_addRow(itemType, itemCode, itemName, unit, price, finalPrice, quantity);
            }

        }, "JSON");                    
    }

    function getFinalPrice(itemCode, levelCode, price) {

        var ckbIsFreeCustomer = $("#ckbIsFreeCustomer")[0];
        if (ckbIsFreeCustomer.checked) { //散客；
            return price;
        } else { //会员；

            var finalPrice = 0.0;

            var result = getItemDiscout(itemCode, levelCode);
            var tempArray = result.split("|");
            if (tempArray[0] == "1") { //走折扣
                var discount = parseFloat(tempArray[1]);
                finalPrice = parseFloat(price) * parseFloat(discount);
            } else if (tempArray[0] == "2") { //走价格
                finalPrice = parseFloat(tempArray[1]);
            }

            return finalPrice.toFixed(2).toString();
        }
    }

    $(function () {
        $("#ckbIsFreeCustomer").click(function () {
            var ckbIsFreeCustomer = $("#ckbIsFreeCustomer")[0];
            if (ckbIsFreeCustomer.checked) {

                clearMemberInfo();

                $("#txtKey").attr("disabled", "disabled");
                $("#ddlKeyType").attr("disabled", "disabled");
                $("#btnBrowseMembers").attr("disabled", "disabled");

                $("#txtItemName").removeAttr("disabled");
                $("#ddlPayTypes").removeAttr("disabled");
                $("#txtRemark").removeAttr("disabled");
                $("#btnSubmit").removeAttr("disabled");

                //对于散客，默认选中现金；
                for (var i=0;i<$("#ddlPayTypes")[0].options.length;i++){
                    var optionValue = $("#ddlPayTypes")[0].options[i].value;
                    if (optionValue == "3") { //现金支付；
                        $("#ddlPayTypes")[0].options[i].selected = true;
                        break;
                    }
                }                
            }
            else {
                $("#txtKey").removeAttr("disabled");
                $("#ddlKeyType").removeAttr("disabled");
                $("#btnBrowseMembers").removeAttr("disabled");

                //对于会员，默认选中会员卡账户支付；
                for (var i = 0; i < $("#ddlPayTypes")[0].options.length; i++) {
                    var optionValue = $("#ddlPayTypes")[0].options[i].value;
                    if (optionValue == "2") { //会员卡账户支付；
                        $("#ddlPayTypes")[0].options[i].selected = true;
                        break;
                    }
                }
            }
        });

        $("#txtDiscountAmount").keyup(function (event) {
            var keyCode = event.keyCode;
            caculateChargeAmount();
        });

        $("#ddlPayTypes").attr("disabled", "disabled");
        $("#txtItemName").attr("disabled", "disabled");
        $("#txtWaiter").attr("disabled", "disabled");
        $("#txtDiscountAmount").attr("disabled", "disabled");
        $("#txtRemark").attr("disabled", "disabled");
        $("#btnSubmit").attr("disabled", "disabled");

        $("#spanSaleStrategyApplyDesc").html("");

        JTongTabs_init();

        loadFavItems();
        loadGroups();
    });

    </script>

    <script type="text/javascript">

        var formEditListTable_RowCounter = 0;

        function formEditListTable_addRow(itemType,itemCode, itemName, unit, price, finalPrice, quantity) {
            
            formEditListTable_RowCounter++;

            var $srcTable = $("#srcTable");
            var srcTableID = $srcTable.attr("id");

            //如果找到相同数据行，并进行了数量的合并，则不再添加新的行；
            if (formEditListTable_dataMerge($srcTable, itemCode, quantity)) {
                return;
            }

            var rowHtml = '';
            var $row = null;
            var rowCnt = $srcTable[0].rows.length;
            var rowID = formEditListTable_RowCounter;

            itemName = itemName.replace(/'/g, "‘");
            unit = unit.replace(/'/g, "‘");
                        
            var amount = (price * quantity).toFixed(2).toString(); //优惠前金额
            var charges = (finalPrice * quantity).toFixed(2).toString(); //优惠后金额
            var discount = (parseFloat(amount) - parseFloat(charges)).toFixed(2).toString(); //优惠金额
            
            rowHtml += '<tr id="tr_' + rowID + '">';
            rowHtml += '<td style="text-align:center;" class="tdRowNo"></td>';

            rowHtml += '<td style="text-align:center;">';
            rowHtml += '<span>' + itemCode + '</span>';
            rowHtml += '</td>';

            rowHtml += '<td style="text-align:left;padding-left:5px;">';
            rowHtml += '<span>' + itemName + '</span>';
            rowHtml += '<input type="hidden" name="hfItemType" value="' + itemType + '" />';
            rowHtml += '<input type="hidden" name="hfItemName" value="' + itemName + '" />';
            rowHtml += '<input type="hidden" name="hfItemCode" value="' + itemCode + '" />';
            rowHtml += '</td>';

            rowHtml += '<td style="text-align:center;">';
            rowHtml += '<span>' + unit + '</span>';
            rowHtml += '<input type="hidden" name="hfUnit" value="' + unit + '" />';
            rowHtml += '</td>';

            rowHtml += '<td style="text-align:center;">';
            rowHtml += '<span style="font-weight:bold;">' + price + '</span>';
            rowHtml += '<input type="hidden" name="hfPrice" value="' + price + '" id="hfPrice_' + rowID + '" />';
            rowHtml += '</td>';

            rowHtml += '<td><input type="text" name="txtFinalPrice" value="' + finalPrice + '" id="txtFinalPrice_' + rowID + '" onkeyup="formEditListTable_priceChanged(' + rowID + ')" />';

            rowHtml += '<td><input type="text" name="txtQuantity" value="' + quantity + '" id="txtQuantity_' + rowID + '" onkeyup="formEditListTable_caculateAmount(' + rowID + ')" /></td>';

            rowHtml += '<td style="text-align:right;padding-right:1px;">';
            //rowHtml += '<span style="font-weight:bold;" id="spanAmount_' + rowID + '">' + amount + '</span>';
            rowHtml += '<input type="hidden" name="hfAmount" value="' + amount + '" id="hfAmount_' + rowID + '" />';
            rowHtml += '<span style="font-weight:bold;" id="spanCharges_' + rowID + '">' + charges + '</span>';
            rowHtml += '<input type="hidden" name="hfCharges" value="' + charges + '" id="hfCharges_' + rowID + '" />';
            rowHtml += '</td>';

            rowHtml += '<td style="text-align:right;padding-right:1px;">';
            rowHtml += '<span style="font-weight:bold;" id="spanDiscount_' + rowID + '">' + discount + '</span>';
            rowHtml += '</td>';

            rowHtml += '<td>';
            rowHtml += '<input class="waiterName" type="text" name="txtWaiterName" value="" id="txtWaiterName_' + rowID + '" readonly="true" onclick="takeWaiter(' + rowID + ')" />';
            rowHtml += '<input class="waiterCode" type="hidden" name="hfWaiterCode" value="" id="hfWaiterCode_'+ rowID +'" />';
            rowHtml += '</td>';

            rowHtml += '<td style="text-align:center;"><a href="javascript:formEditListTable_removeRow(' + rowID + ')">删除</a></td>';
            rowHtml += '</tr>';

            $row = $(rowHtml);
            $srcTable.append($row);

            formEditListTable_setRowNo();
            formEditListTable_setTotalAmount();
            formEditListTable_hideTbNoRecord();
        }

        function formEditListTable_setTotalAmount() {
            var $srcTable = $("#srcTable");
            $srcTable.find("#trTotal").remove();

            var totalRowHtml = '';
            var totalAmount = 0.00;
            var totalCharges = 0.00;
            var totalDiscount = 0.00;
            var $hfAmountList = $srcTable.find("input[name=hfAmount]");
            var $hfChargeList = $srcTable.find("input[name=hfCharges]");

            $hfAmountList.each(function () {
                totalAmount += parseFloat($(this).val());
            });

            $hfChargeList.each(function () {
                totalCharges += parseFloat($(this).val());
            });

            totalDiscount = totalAmount - totalCharges;
            
            if ($hfAmountList.length > 0) {  //如果有数据行，则添加合计行
                totalRowHtml += '<tr id="trTotal">';

                totalRowHtml += '<td colspan="7" style="text-align:right;padding-right:5px;font-weight:bold;">合计</td>';

                totalRowHtml += '<td style="text-align:right;padding-right:1px;">';
                totalRowHtml += '<span style="font-weight:bold;" id="spanTotalCharges">' + totalCharges.toFixed(2).toString() + '</span>';
                totalRowHtml += '<input type="hidden" name="hfTotalCharges" value="' + totalCharges.toFixed(2).toString() + '" id="hfTotalCharges" />';
                totalRowHtml += '</td>';

                totalRowHtml += '<td style="text-align:right;padding-right:1px;">';
                totalRowHtml += '<span style="font-weight:bold;" id="spanTotalDiscount">' + totalDiscount.toFixed(2).toString() + '</span>';
                totalRowHtml += '</td>';
                totalRowHtml += '<td></td>';

                totalRowHtml += '</tr>';

                $srcTable.append($(totalRowHtml));

                $("#txtTotalAmount").val(totalAmount.toFixed(2).toString());
                $("#txtChargeAmount").val(totalCharges.toFixed(2).toString());

                var discountAmount = totalAmount - totalCharges;
                console.log("totalAmount:" + totalAmount);
                console.log("totalCharges:" + totalCharges);
                console.log("discountAmount:" + discountAmount);
                $("#txtDiscountAmount").val(discountAmount.toFixed(2).toString());

                $("#hfTotalAmount").val(totalAmount.toFixed(2).toString());
                
                applySaleStrategy();
            } else {
                $("#txtTotalAmount").val("");
                $("#hfTotalAmount").val("");
                $("#txtDiscountAmount").val("0.00");
                $("#txtChargeAmount").val("");
                $("#hfChargeAmount").val("");
            }
        }

        function formEditListTable_priceChanged(rowID) {
            
            var $txtPrice = $("#hfPrice_" + rowID);
            var $txtFinalPrice = $("#txtFinalPrice_" + rowID);

            formEditListTable_caculateAmount(rowID);
        }

        function formEditListTable_caculateAmount(rowID) {
            var $txtQuantity = $("#txtQuantity_" + rowID);
            var $txtPrice = $("#hfPrice_" + rowID);
            var $txtFinalPrice = $("#txtFinalPrice_" + rowID);
            var $spanDiscount = "";
            var sQuantity = $txtQuantity.val();
            var sPrice = $txtPrice.val();
            var sFinalPrice = $txtFinalPrice.val();
            var amount = 0.00; //优惠前
            var charges = 0.00; //优惠后
            var discount = 0.00; //优惠金额

            if (sQuantity == "") {
                sQuantity = "0";
            }
            if (sPrice == "") {
                sPrice = "0";
            }
            if (sFinalPrice == "") {
                sFinalPrice = "0";
            }

            ////清除非数字字符；(会影响光标键输入，故不再使用，更改为判断如果为非数字，直接清空)
            //clearNoNum($txtQuantity[0]);
            //clearNoNum($txtPrice[0]);

            if (isNaN(sQuantity)) {
                alert("数量为无效数字！");
                $txtQuantity.val("");
                $txtQuantity.focus();
                return;
            }
            if (isNaN(sPrice)) {
                alert("单价为无效数字.");
                $txtPrice.val("");
                $txtPrice.focus();
                return;
            }
            if (isNaN(sFinalPrice)) {
                alert("单价为无效数字.");
                $txtPrice.val("");
                $txtPrice.focus();
                return;
            }
            if (parseFloat(sQuantity) > 100000 || parseFloat(sQuantity) <0) {  //限制数量不能超过100000
                alert("数量不能小于0或超过100000.");
                $txtQuantity.val("");
                $txtQuantity.focus();
                return;
            }
            if (parseFloat(sPrice) > 100000 || parseFloat(sPrice) < 0) {  //单价不能超过100000
                alert("单价不能小于0或超过100000.");
                $txtPrice.val("");
                $txtPrice.focus();
                return;
            }

            if ($txtQuantity.hasClass("error")) {
                $txtQuantity.removeClass("error");
            }
            if ($txtPrice.hasClass("error")) {
                $txtPrice.removeClass("error");
            }

            amount = parseFloat(sQuantity) * parseFloat(sPrice);
            charges = parseFloat(sQuantity) * parseFloat(sFinalPrice);
            discount = amount - charges;
            
            $("#hfAmount_" + rowID).val(amount.toFixed(2).toString());
            $("#spanAmount_" + rowID).html(amount.toFixed(2).toString());

            $("#hfCharges_" + rowID).val(charges.toFixed(2).toString());
            $("#spanCharges_" + rowID).html(charges.toFixed(2).toString());

            $("#spanDiscount_" + rowID).html(discount.toFixed(2).toString());

            formEditListTable_setTotalAmount();
        }

        function formEditListTable_checkTableData() {

            var result = true;

            var dataRowCount = 0;
            var $srcTable = $("#srcTable");

            $srcTable.find("input[name=txtQuantity]").each(function () {
                dataRowCount++;
                var sQuantity = $(this).val();
                if ($.trim(sQuantity) == "" || $.trim(sQuantity) == "0") {
                    alert("数量不能为空或0！");
                    $(this).focus();
                    $(this).addClass("error");
                    result = false;
                    return;
                }
            });
            $srcTable.find("input[name=txtFinalPrice]").each(function () {
                var sPrice = $(this).val();
                if ($.trim(sPrice) == "") {
                    alert("单价不能为空！");
                    $(this).focus();
                    $(this).addClass("error");
                    result = false;
                    return;
                }
            });

            if (dataRowCount == 0) {
                alert("消费清单不能为空！");
                result = false;
            }

            return result;
        }        

        function formEditListTable_clearNoNum(obj) {
            obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符  
            obj.value = obj.value.replace(/^\./g, "");  //验证第一个字符是数字而不是. 
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.   
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        }

        //服务员============================================

        var $current_txtWaiterName = null;
        var $current_txtWaiterCode = null;
        function takeWaiter(rowID) {
            var $txtWaiterName = $("#txtWaiterName_" + rowID);
            var $txtWaiterCode = $("#hfWaiterCode_" + rowID);

            $current_txtWaiterName = $txtWaiterName;
            $current_txtWaiterCode = $txtWaiterCode;

            openFrameWindow("员工列表", 730, 419, "../datasrc/get_employee_list.aspx");
        }        
        function takeEmployeeInfo(trObj) {
            closeFrameWindow();

            var employeeCode = $(trObj).find("td.employeeCode").eq(0).html();
            var employeeName = $(trObj).find("td.employeeName").eq(0).html();

            $current_txtWaiterCode.val(employeeCode);
            $current_txtWaiterName.val(employeeName);
        }
        function clearWaiters() {
            var $srcTable = $("#srcTable");
            $srcTable.find("input.waiterName").each(function () {
                $(this).val("");
            });
            $srcTable.find("input.waiterCode").each(function () {
                $(this).val("");
            });
        }
        function clearItems() {
            formEditListTable_clearRows();
        }

    </script>

</head>
<body>
<form id="Form1" method="post" runat="server">

<div id="wrapper" style="height:1%;overflow:hidden;">

<div class="editPageWrapper" style="width:700px;float:left;">

<div class="centerFormTitle">
   <h1>消费收银</h1>
</div>

<table cellspacing="0" cellpadding="3" class="editTable" style="margin-bottom:-1px;">
<tr>
<td style="font-weight:bold;text-align:right;">
    <asp:CheckBox ID="ckbIsFreeCustomer" runat="server"
         Text="散客" />
</td>
</tr>
</table>

<!--#include file="../include/memberinfo.aspx"--> 

<table cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td class="th" style="font-weight:bold;text-align:left;">消费清单</td>
</tr>
</table>
<table cellspacing="0" class="formEditListTable" id="srcTable" style="width:700px;margin-top:-1px;">
<thead>
<tr>
<td style="width:30px;text-align:center;">No.</td>
<td style="width:70px;text-align:center;">项目代码</td>
<td style="width:190px;text-align:center;">项目名称</td>
<td style="width:40px;text-align:center;">单位</td>
<td style="width:50px;text-align:center;">单价</td>    
<td style="width:60px;text-align:center;">折后单价</td>    
<td style="width:40px;text-align:center;">数量</td>
<td style="width:60px;text-align:center;">折后金额</td>
<td style="width:50px;text-align:center;">优惠</td>
<td style="width:50px;text-align:center;">服务员</td>
<td style="text-align:center;">操作</td>
</tr>    
</thead>    

<tbody>
</tbody>
</table>

<table id="tbNoRecord" cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td style="text-align:center;height:70px;">
    暂无数据
</td>
</tr>
</table>

<table id="Table1" cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td style="text-align:right;">
    商品/服务项目：
    <VACTL:TextBox ID="txtItemName" Runat="server"
                EnableViewState="False"
                CssClass="input"
                Width="200px"
                />
    <asp:HiddenField runat="server" id="txtItemName_hiddenValue" />  
    <input type="button" id="btnClearItems" class="simpleBtn" onclick="clearItems()" value="清除项目" />    

    服务员：
    <VACTL:TextBox ID="txtWaiter" Runat="server"
                EnableViewState="False"
                CssClass="input"
                onfocus="JTongSmartDropDownList_OnfocusHandler(this, '../smartdropdownlist_datasrc/get_employees.aspx',true,true,300,180);"
                Width="110px"
                />
    <asp:HiddenField runat="server" id="txtWaiter_hiddenValue" />  
    <input type="button" id="btnClearWaiters" class="simpleBtn" onclick="clearWaiters()" value="清除服务员" />    
</td>
</tr>
</table>

<table cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td class="th">合计金额：</td>
<td>
    <VACTL:TextBox runat="server" ID="txtTotalAmount" 
            CssClass="input" 
            Width="100px"
            CanBeNull="No"
            FieldName="合计金额"
            RequiredFieldType="Money"
            Enabled="false"
            Font-Bold="true"
            />
    <asp:HiddenField runat="server" id="hfTotalAmount" />
    <asp:HiddenField runat="server" id="hfStrategyCode" />
    <asp:HiddenField runat="server" id="hfStrategyName" />
</td>
<td class="th">优惠金额：</td>
<td>
    <VACTL:TextBox runat="server" ID="txtDiscountAmount" 
            CssClass="input" 
            Width="100px"
            CanBeNull="No"
            FieldName="优惠金额"
            RequiredFieldType="Money"
            Text="0.00"
            Enabled="false"
            Font-Bold="true"
            />
</td>
</tr>
<tr>
<td class="th">实收金额：</td>
<td colspan="3">
    <VACTL:TextBox runat="server" ID="txtChargeAmount" 
            CssClass="input" 
            Width="100px"
            CanBeNull="No"
            FieldName="实收金额"
            Enabled="false"
            Font-Bold="true"
            />
    <asp:HiddenField runat="server" id="hfChargeAmount" />
    <span id="spanSaleStrategyApplyDesc" style="color:green;font-weight:bold;">提示：系统自动应用了优惠策略：满100减20</span>
</td>
</tr>
<tr>
<td class="th">支付方式：</td>
<td>
    <asp:DropDownList ID="ddlPayTypes" Runat="server" >
    </asp:DropDownList>
</td>
<td class="th">操 作 员：</td>
    <td>    
	    <%= base.EmployeeName %>
    </td>
</tr>
<tr>
<td class="th">备注：</td>
<td colspan="3">
    <VACTL:TextBox ID="txtRemark" Runat="server"
        EnableViewState="False"
        CssClass="input"
        Width="580px"
        MaxLength="100"
        />        
</td>
</tr>
</table>


<table cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td class="footer">

    <input type="button" id="btnNext" class="btn" style="width:80px" onclick="confirm()" value="收银" />
    <input type="button" id="btnResetPage" class="btn" style="width:80px" onclick="resetPage()" value="重置" />
    <asp:HiddenField ID="hfKey" runat="server" />
    
    <VACTL:Hint ID="Hint1" runat="server" HintImageUrl="/app_themes/default/images/textbox" />
    <VACTL:ValidationSummary ID="ValidationSummary1" runat="server"
            DisplayMode="List"
            EnableClientScript="true" />
    
    <!--注意：这个文件一定要放到页面底部，以便覆盖asp.net验证脚本中的同名函数-->
    <script type="text/javascript" src="/scripts/utils/aspnet_validator_extend.js"></script>
</td>
</tr>
</table>

</div><!--editPageWrapper.END-->

</div><!--"wrapper.END"-->

<!--确认窗口-->    
<div id="winConfirm" style="display:none;">

    <div style="width:300px;margin:auto;">
    
    <br />

    <div class="centerFormTitle">
        <h1>确认收银信息</h1>
    </div>

    <table cellspacing="0" cellpadding="3" class="editTable" style="margin:auto;width:100%;">
    <tr>
    <td class="th">操 作 员：</td>
    <td>    
	    <span id="span_Confirm_OperatorName"><%= base.EmployeeName %></span>
    </td>
    </tr>
    <tr>
    <td class="th">收银日期：</td>
    <td>    
	    <span id="span1"><% = DateTime.Now.ToString("yyyy-MM-dd") %></span>
    </td>
    </tr>
    <tr>
    <td class="th">合计金额：</td>
    <td>    
	    <span id="span_Confirm_TotalAmount" style="font-weight:bold;"></span>
    </td>
    </tr>
    <tr>
    <td class="th">减免金额：</td>
    <td>    
        <span id="span_Confirm_DiscountAmount" style="font-weight:bold;"></span>
    </td>
    </tr>
    <tr>
    <td class="th">实收金额：</td>
    <td>   
        <span id="span_Confirm_ChargeAmount" style="font-weight:bold;"></span> 
    </td>
    </tr>
    <tr>
    <td class="th">支付方式：</td>
    <td>    
        <span id="span_Confirm_PayTypeName" style="font-weight:bold;"></span>
    </td>
    </tr>   
    <tr>
    <td colspan="2" style="text-align:center;">    
        <asp:CheckBox ID="ckbPrintBill" runat="server"
             Text="打票" />         
        <asp:CheckBox ID="ckbNotify" runat="server"
             Text="短信通知" />         
    </td>
    </tr>
    <tr>
    <td colspan="2" class="footer">

        <input type="button" id="btnSubmit" class="btn" style="width:80px" onclick="save()" value="确定" />
        <input type="button" id="btnCancel" class="btn" style="width:80px" onclick="cancelSave()" value="取消" />
    </td>
    </tr>
    </table>
    </div>

</div><!--winConfirm.END-->

<div id="divFavPanel" style="z-index:0;width:250px;height:503px;position:absolute;left:715px;top:40px;padding:0px;">

    <div id="divMemberInfoContaienr">
    <div class="jtongui-tabs" fill="true">
	    <ul class="header" style="border-bottom:solid 0px;">
		    <li class="tabheader-item-selected"><a>常用项目</a></li>        		    
            <li>项目组套</li>			
	    </ul>

	    <div id="div_FavItems" class="tabcontent tabcontent-selected">
	        <table cellspacing="0" class="listTable" style="table-layout:fixed;margin-left:-1px;">
            <thead>
            <tr>
            <td style="width:20px;text-align:center;">No.</td>
            <td style="width:190px;text-align:center;">项目名称</td>    
            <td></td>
            </tr>    
            </thead>    
            </table>
            <div id="div_FavItems_DataBody" style="z-index:-1;height:405px;overflow:auto;overflow-x:hidden;margin-top:-1px;margin-left:0px;border-bottom:solid 1px #B9CAD3;">        
            </div><!--dataBody.END-->

            <div style="height:26px;line-height:26px;margin-top:1px;text-align:right;padding-right:2px;">
                <input type="button" class="simpleBtn" onclick="refreshFavItems()" value="刷新" />
                <input type="button" class="simpleBtn" onclick="manageFavItems()" value="维护常用项目" />
                <input type="button" class="simpleBtn" onclick="sortFavItems()" value="排序" />
            </div>
	    </div><!--div_FavItems.END-->	   
        
        <div id="div_FavGroups" class="tabcontent">
	        
            <table cellspacing="0" class="listTable" style="table-layout:fixed;margin-left:-1px;">
            <thead>
            <tr>
            <td style="width:20px;text-align:center;">No.</td>
            <td style="width:190px;text-align:center;">组套名称</td>    
            <td></td>
            </tr>    
            </thead>    
            </table>
            <div id="div_FavGroups_DataBody" style="z-index:-1;height:405px;overflow:auto;overflow-x:hidden;margin-top:-1px;margin-left:0px;border-bottom:solid 1px #B9CAD3;">        
            </div><!--dataBody.END-->

            <div style="height:26px;line-height:26px;margin-top:1px;text-align:right;padding-right:2px;">
                <input type="button" class="simpleBtn" onclick="refreshGrups()" value="刷新" />
                <input type="button" class="simpleBtn" onclick="manageGroups()" value="维护项目组套" />
                <input type="button" class="simpleBtn" onclick="sortGroups()" value="排序" />
            </div>

	    </div><!--div_FavGroups.END-->	   

    </div>    
    </div><!--divMemberInfoContaienr.END-->   
</div>


<!--每个页面上只能有一个该控件实例-->
<VACTL:SmartDropDownList ID="SmartDropDownList1" runat="server"></VACTL:SmartDropDownList>  


</form>
</body>
</html>

