﻿///<reference path="/Scripts/jquery-1.5.1.min.js" />
///<reference path="/Scripts/Utility.js"/>
///<reference path="/Scripts/artDialog/jquery.artDialog.js" />

(function (win, undefined) {
    var HuaPuCls = function () { };
    win.HuaPu = new HuaPuCls();
    //用户操作类
    var UserCls = function () {
        //默认图片
        this.DefaultLogo = function (o) { $(o).attr('src', '/Content/images/nobody.gif'); };
        //用户登录
        this.Login = function () {
            var _t = $('#Login_Tel').val(), _p = $('#Login_Pass').val(); if (_t == '' || _p == '') { Utility.Dialog.Open('帐号、密码不能为空！', '提示', 'warning', 2, true); }
            Utility.Dialog.Open('正在登录中，请稍候~~~', '提醒', 'face-smile', null, true, true);
            $.post("/Ajax/UserLogin", { Tel: _t, Pass: _p }, function (Msg) {
                var Jo = Utility.JSON.StringToJson(Msg);
                if (Jo.State) {
                    if (Jo.AlertMsg == '') { Utility.Dialog.Open('登录成功，跳转中~', '', 'succeed', 4, true); top.location.reload(); }
                    else { Utility.Dialog.Open('<div style="width:280px">登录成功，您以下资料尚未完善：<br/>' + Jo.AlertMsg + '</div>', '登录成功', null, null, true, true, [{ name: '现在完善', focus: true, callback: function () { top.location.href = '/User'; return false; } }, { name: '稍候完善', callback: function () { top.location.reload(); } }]) }
                } else { Utility.Dialog.Open(Jo.Msg, '登录失败', 'error', 2, true); }
            });
        };
        this.LoginWin = function () {
            Utility.Dialog.Open('<div><form method="post" action="">手机号码：<input type="text" name="" id="Login_Tel" /><br />登录密码：<input type="password" id="Login_Pass" /></form></div>',
        '用户登录', null, null, true, true, [{ name: '登录', focus: true, callback: function () { HuaPu.User.Login(); return false; } }, { name: '注册', callback: function () { HuaPu.User.Reg(); return false; } }]
        );
        };
        //用户注册提交
        var RegSubmit = function () {
            if ($('#FormReg input[name="Tel"]').val() == '') { Utility.Dialog.Open('请输入用于登录的手机号！', null, 'warning', 1, true); $('#FormReg input[name="Tel"]').focus(); return false; }
            if ($('#FormReg input[name="Pass"]').val() == '') { Utility.Dialog.Open('请输入用于登录的密码！', null, 'warning', 1, true); $('#FormReg input[name="Pass"]').focus(); return false; }
            if ($('#FormReg input[name="Pass2"]').val() == '') { Utility.Dialog.Open('请重复输入登录密码！', null, 'warning', 1, true); $('#FormReg input[name="Pass2"]').focus(); return false; }
            if ($('#FormReg input[name="Pass"]').val() != $('#FormReg input[name="Pass2"]').val()) { Utility.Dialog.Open('两次输入的密码不匹配！', null, 'warning', 1, true); $('#FormReg input[name="Pass2"]').focus(); return false; }
            if ($('#FormReg input[name="XingMing"]').val() == '') { Utility.Dialog.Open('请输入您的姓名！', null, 'warning', 1, true); $('#FormReg input[name="XingMing"]').focus(); return false; }
            Utility.Dialog.Open('正在提交资料，请稍候~~~', '提醒', 'face-smile', null, true, true);
            $('#FormReg').ajaxSubmit(function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { alert('注册成功，请进一步完善资料！'); top.location.href = '/User'; } else { Utility.Dialog.Open(Jo.Msg, null, 'error'); } });
            return false;
        };
        //用户注册
        this.Reg = function () {
            $.dialog({ id: 'Reg', title: '免费注册', content: document.getElementById('RegTableDiv'), fixed: true, lock: true, button: [{ name: '注册', focus: true, callback: RegSubmit }, { name: '我有帐号', callback: function () { HuaPu.User.LoginWin(); return false; } }] });
            Utility.ProvinceCity.getProvinceOption();
        };
        //商家用户注册
        var RegShopLayer = function () {
            if ($('body').data('RegShopLayer') == '' || $('body').data('RegShopLayer') == undefined) {
                $('body').data('RegShopLayer', $('#RegTableShowDiv').html()); $('#RegTableShowDiv').remove()
            } return $('body').data('RegShopLayer');
        }
        var RegShopSubmit = function () {
            if ($('#FormShopReg input[name="DianMing"]').val() == '') { Utility.Dialog.Open('请输入您的昵称！', null, 'warning', 1, true); $('#FormShopReg input[name="DianMing"]').focus(); return false; }
            if ($('#FormShopReg input[name="Tel"]').val() == '') { Utility.Dialog.Open('请输入用于登录的手机号！', null, 'warning', 1, true); $('#FormShopReg input[name="Tel"]').focus(); return false; }
            if ($('#FormShopReg input[name="XingMing"]').val() == '') { Utility.Dialog.Open('请输入您的姓名！', null, 'warning', 1, true); $('#FormShopReg input[name="XingMing"]').focus(); return false; }
            if ($('#FormShopReg input[name="Pass"]').val() == '') { Utility.Dialog.Open('请输入用于登录的密码！', null, 'warning', 1, true); $('#FormShopReg input[name="Pass"]').focus(); return false; }
            if ($('#FormShopReg input[name="Pass2"]').val() == '') { Utility.Dialog.Open('请重复输入登录密码！', null, 'warning', 1, true); $('#FormShopReg input[name="Pass2"]').focus(); return false; }
            if ($('#FormShopReg input[name="Pass"]').val() != $('#FormShopReg input[name="Pass2"]').val()) { Utility.Dialog.Open('两次输入的密码不匹配！', null, 'warning', 1, true); $('#FormShopReg input[name="Pass2"]').focus(); return false; }
            Utility.Dialog.Open('正在提交资料，请稍候~~~', '提醒', 'face-smile', null, true, true);
            $('#FormShopReg').ajaxSubmit(function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { alert('注册成功，请完善店铺资料并上传花卉信息！'); top.location.href = '/User'; } else { Utility.Dialog.Open(Jo.Msg, null, 'error'); } });
            return false;
        };
        this.RegShop = function () {
            $.dialog({ id: 'RegShop', title: '免费开店', content: RegShopLayer(), fixed: true, lock: true, button: [{ name: '注册', focus: true, callback: RegShopSubmit }, { name: '我有帐号', callback: function () { HuaPu.User.LoginWin(); return false; } }] });
            Utility.ProvinceCity.getProvinceOption(null,null, '_Shop');
        };
        //保存公告
        this.SaveGongGao = function () {
            var Gg = $('#UserGongGao').val();
            if (Gg == '') { Utility.Dialog.Open('请输入新的公告内容！', null, 'error', 1, true, true); return; }
            $.post("/Ajax/SaveGongGao", { GongGao: Gg }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { $('#UsergongGaoShow').html(Gg); $('#UserGongGao').val(''); } else { Utility.Dialog.Open(Jo.Msg, '', 'error', 1, true); } });
        };
        //设置域名
        this.SetDoMain = function () {
            var dm = $('#DoMain').val(); if (dm == '') { Utility.Dialog.Open('请输入要使用的域名！', '', 'warning', 1, true); return; }
            $.post('/Ajax/SetDoMain', { DoMain: dm }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); Utility.Dialog.Open(Jo.Msg, '', 'warning', 1, true); });
        };
        //设置顶级域名
        this.SetDoMainDing = function () {
            var dm = $('#DoMainDing').val(); if (dm == '') { Utility.Dialog.Open('请输入要使用的域名！', '', 'warning', 1, true); return; }
            $.post('/Ajax/SetDoMainDing', { DoMain: dm }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); Utility.Dialog.Open(Jo.Msg, '', 'warning', 1, true); });
        };
        //花铺分类操作
        var SubjectId = 0;
        var SubjectEditLayer = function () {
            var o = $('body').data('AddSubjectDiv');
            if (o == null || o == undefined || o == '') { o = $('#AddSubject').html(); $('body').data('AddSubjectDiv', o); $('#AddSubject').remove(); }
            return o;
        };
        var SubjetAddSubmit = function () {
            var o, n; o = $('#S_Order').val(); n = $('#S_Name').val(); if (n == '') { alert('分类名称不能为空！'); return false; }
            $.post('/Ajax/SubjectAdd', { N: n, O: o, Id: SubjectId }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); alert(Jo.Msg); top.location.reload(); });
            return false;
        };
        this.SubjectAdd = function () { SubjectId = 0; Utility.Dialog.Open(SubjectEditLayer(), '添加分类', null, null, true, true, [{ name: '添加', focus: true, callback: SubjetAddSubmit }, { name: '取消'}]); };
        this.SubjectEdit = function (_id) {
            Utility.Dialog.Open(SubjectEditLayer(), '编辑分类', null, null, true, true, [{ name: '更新', focus: true, callback: SubjetAddSubmit }, { name: '取消'}]);
            $('#S_Order').val($('#Sub_Order_' + _id).html()); $('#S_Name').val($('#Sub_Name_' + _id).html()); SubjectId = _id;
        };
        this.SubjectDel = function (_id) { $.post('/Ajax/SubjectDel', { id: _id }, function (Msg) { alert(Msg); top.location.reload(); }); }
        //友情链接操作
        var LinkId = 0;
        var LinkEditLayer = function () { var o = $('body').data('AddLinkDiv'); if (o == null || o == undefined || o == '') { o = $('#AddLink').html(); $('body').data('AddLinkDiv', o); $('#AddLink').remove(); } return o; };
        var LinkAddSubmit = function () {
            var u, n; n = $('#Link_Name').val(); u = $('#Link_Url').val(); if (n == '') { alert('链接名称不能为空！'); return false; } if (u == '') { alert('链接URL名称不能为空！'); return false; }
            $.post('/Ajax/LinkAdd', { N: n, U: u, Id: LinkId }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); alert(Jo.Msg); top.location.reload(); });
            return false;
        };
        this.LinkAdd = function () { LinkId = 0; Utility.Dialog.Open(LinkEditLayer(), '添加友情链接', null, null, true, true, [{ name: '添加', focus: true, callback: LinkAddSubmit }, { name: '取消'}]); };
        this.LinkEdit = function (_id) {
            Utility.Dialog.Open(LinkEditLayer(), '编辑链接', null, null, true, true, [{ name: '更新', focus: true, callback: LinkAddSubmit }, { name: '取消'}]);
            $('#Link_Name').val($('#Link_N_' + _id).html()); $('#Link_Url').val($('#Link_U_' + _id).html()); LinkId = _id;
        };
        this.LinkDel = function (_id) { $.post('/Ajax/LinkDel', { Id: _id }, function (Msg) { alert(Msg); top.location.reload(); }) };
        //密码操作
        this.PassChange = function () {
            var Po, Pn, Pc;
            Po = $('#Pass_Old').val(); Pn = $('#Pass_New').val(); Pc = $('#Pass_Confirm').val();
            if (Po == '') { Utility.Dialog.Open('请输入原始密码！', '', 'error', 1, true); return; }
            if (Pn == '') { Utility.Dialog.Open('请输入新密码！', '', 'error', 1, true); return; }
            if (Pn.length < 7) { Utility.Dialog.Open('新密码不能小于7位字符！', '', 'error', 1, true); return; }
            if (Pc == '') { Utility.Dialog.Open('请输入确认密码！', '', 'error', 1, true); return; }
            if (Pc != Pn) { Utility.Dialog.Open('确认密码与新密码不匹配！', '', 'error', 1, true); return; }
            $.post('/Ajax/PassChange', { Po: Po, Pn: Pn, Pc: Pc }, function (Msg) { alert(Msg); top.location.reload(); });
        };
        //密码找回
        this.PassFind = function () {
            var _c = '<div style="width:360px;"><label>请输入您的昵称和手机号，我们将把新的临时密码以短信发送到您的手机，请使用临时密码登陆并及时修改密码</label><br/><form method="post" action="/Ajax/PassFind" id="PassFindForm">昵称：<input name="Xm" type="text"/><br/>手机：<input name="Tel" type="text"/></form><span class="red">如果您已忘记昵称或手机号，请联系管理员协助修改密码！</span></div>';
            Utility.Dialog.Open(_c, '找回密码', null, null, true, true, [{ name: '发送', focus: true, callback: function () {
                $('#PassFindForm').ajaxSubmit({ success: function (msg) { if (msg == '') { alert('我们已将新密码以短信发送到您的手机，请查收！'); Utility.Dialog.Close(); } else { alert(msg); } } });
                return false;
            }
            }, { name: '取消'}]);
        };
        //回复留言
        this.LiuYanHuiFu = function (_id) {
            Utility.Dialog.Open('<form method="post" action="/Ajax/LiuYanHuiFu/' + _id + '" id="LiuYanHuiFuForm"><textarea name="Hf" style="width:300px; height:60px;"></textarea></form>', '留言回复', null, null,
            true, true, [{ name: '回复', focus: true, callback: function () {
                $('#LiuYanHuiFuForm').ajaxSubmit({ success: function () { top.location.reload(); } });
                return false;
            }
            }, { name: '取消'}]);
        };
        //上传花卉
        this.FlowerUpWinShow = function () { window.open("/User/FlowerUp", '花卉上传', "height=500,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no"); };
        this.FlowerDel = function (_id) { if (confirm('确定要删除该花卉吗？（不可恢复）')) { $.post('/Ajax/FlowerDel', { Id: _id }, function (Msg) { alert(Msg); top.location.reload(); }); } };
        var FlowerId = 0;
        this.FlowerEdit = function (_id) {
            try {
                $('#FlowerEditForm_' + _id).ajaxSubmit({ success: function () {
                    $('#SucceedTip_' + _id).html('保存成功~'); setTimeout(function () { $('#SucceedTip_' + _id).html(''); }, 2000);
                },
                    fail: function () { $('#SucceedTip_' + _id).html('参数错误~'); setTimeout(function () { $('#SucceedTip_' + _id).html(''); }, 2000); }
                });
            } catch (e) { $('#SucceedTip_' + _id).html('参数错误~'); setTimeout(function () { $('#SucceedTip_' + _id).html(''); }, 2000); }
        };
        var FlowerEditByOneHtml = null;
        this.FlowerEditByOne = function (id, _n, _p, _c, _num) {
            if (FlowerEditByOneHtml == null) { FlowerEditByOneHtml = $('#FlowerEditDiv').html(); $('#FlowerEditDiv').remove(); }
            Utility.Dialog.Open(FlowerEditByOneHtml, '花卉编辑', null, null, true, true, [{ name: '保存', focus: true, callback: function () {
                try {
                    $('#FlowerEditByOneForm').ajaxSubmit({ success: function (msg) { alert(msg); if (msg == '花卉信息更新成功！') { top.location.reload(); } } });
                } catch (e) { alert('保存失败！'); }
                return false;
            }
            }, { name: '取消'}]);
            $('#FlowerEditByOneForm input[name="Fid"]').val(id);
            $('#FlowerEditByOneForm input[name="Name"]').val(_n);
            $('#FlowerEditByOneForm input[name="Price"]').val(_p);
            $('#FlowerEditByOneForm input[name="ChiCun"]').val(_c);
            $('#FlowerEditByOneForm input[name="Num"]').val(_num);
        };
        //花卉分类页面批量编辑提交
        this.FlowerEditBySubjectPageSubmit = function (Fid) {
            var _p = $('#FlowerList_' + Fid);
            var _f = _p.find('form');
            _f.ajaxSubmit({ success: function (msg) {
                if (msg == '花卉信息更新成功！') {
                    _p.find('.f_n a').html(_f.find('input[name="Name"]').val());
                    _p.find('.f_p').html('价格：' + _f.find('input[name="Price"]').val());
                    _p.find('.f_c').html('尺寸：' + _f.find('input[name="ChiCun"]').val());
                    $('#FlowerList_' + Fid + ' .F_I_S').show(); $('#FlowerList_' + Fid + ' .FlowerEditByListForm').hide();
                } else { Utility.Dialog.Open(msg, '错误', 'error', 2, true, true); }
            }
            });
        };
        //花卉分类页面批量编辑取消
        this.FlowerEditBySubjectPageCancel = function (Fid) { $('#FlowerList_' + Fid + ' .F_I_S').show(); $('#FlowerList_' + Fid + ' .FlowerEditByListForm').hide(); };
        //花卉分类页面批量转换分类
        this.FlowerChangeSubject = function () {
            var fids = ''; $.each($('input[name="ChangeSubjectCheckbox"]:checked'), function (i, v) { fids += ',' + $(v).val(); });
            if (fids == '') { Utility.Dialog.Open('<div class="ChangeSubjectNoSelect"><span>您未选择任何花卉，请在要转移的花卉中点击右图所示红框区域的图标来选择花卉！</span><img src="/Content/IconPic/NoSelect.png" /><div class="clear"></div></div>', '提示', null, null, true, true, [{ name: '我知道了', focus: true}]); return; }
            Utility.Dialog.Open('<div style="width:200px;">转移至：<select id="SubjectChangeToId">' + $('#FlowerChangeSubjectSelectOption').html() + '</select></div>', '转换分类', null, null, true, true, [{ name: '开始转移', focus: true, callback: function () {
                $.post('/Ajax/SubjectChange', { FidStr: fids, SubjectId: $('#SubjectChangeToId').val() }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { top.location.reload(); } else { alert(Jo.Msg); } });
            }
            }, { name: '取消'}]);
        };
        //花卉分类页面批量删除
        this.FlowerBatchDelete = function () {
            var fids = ''; $.each($('input[name="ChangeSubjectCheckbox"]:checked'), function (i, v) { fids += ',' + $(v).val(); });
            if (fids == '') { Utility.Dialog.Open('<div class="ChangeSubjectNoSelect"><span>您未选择任何花卉，请在要删除的花卉中点击右图所示红框区域的图标来选择花卉！</span><img src="/Content/IconPic/NoSelect.png" /><div class="clear"></div></div>', '提示', null, null, true, true, [{ name: '我知道了', focus: true}]); return; }
            $.post('/Ajax/FlowerBatchDelete', { FidStr: fids }, function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { top.location.reload(); } else { alert(Jo.Msg); } });
        };
        //上传Logo
        this.UpLogo = function () {
            try {
                Utility.Dialog.Open('<form id="UpLogoForm" method="post" action="/Ajax/UserLogoSave"><input type="file" name="logofile" /></form>', '上传Logo', null, null, true, true, [{ name: '上传', callback: function () {
                    $('#UpLogoForm').ajaxSubmit({ error: function () { top.location.reload(); }, success: function (Msg, status) { var jo = Utility.JSON.StringToJson(Msg); if (jo.State) { top.location.reload(); } else { alert(jo.Msg); } } });
                    return false;
                }
                }, { name: '取消'}]);
            } catch (e) { top.location.reload(); }
        };
        var LayerADData, LayerAD = function () { if (LayerADData == null) { LayerADData = $('#DivTuiGuangRequest').html(); $('#DivTuiGuangRequest').remove(); } return LayerADData; };
        this.ADRequest = function () {
            Utility.Dialog.Open(LayerAD(), '申请推广', null, null, true, true, [{ name: '提交申请', focus: true, callback: function () {
                $('#TuiGuangRequestAddForm').ajaxSubmit({ success: function (msg) {
                    var Jo = Utility.JSON.StringToJson(msg);
                    if (Jo.State) { Utility.Dialog.Open('<span class="red">推广申请已经提交，您可以选择一下方式付款：<br/></span>方式一：支付宝在线支付（立即生效）<br/>方式二：线下支付（管理员审核生效）', '推广申请', null, null, true, true, [{ name: '支付宝付款', focus: true, callback: function () { top.location.href = '/Pay/AlipayPay?OrderKey=TuiGuang'; return false; } }]); } else { alert(Jo.Msg); top.location.href = '/Pay/AlipayPay?OrderKey=TuiGuang'; }
                }, error: function () { alert('参数错误！'); }
                });
                return false;
            }
            }, { name: '取消'}]);
        };
        //团购信息操作
        var TuanCls = function () {
            var TuanAddRequestLayer = function () { var o = $('body').data('TuanAddRequest'); if (o == null || o == undefined || o == '') { o = $('#TuanAddRequestDiv').html(); $('body').data('TuanAddRequest', o); $('#TuanAddRequestDiv').remove(); } return o; };
            this.AddRequestShow = function (_id) {
                Utility.Dialog.Open(TuanAddRequestLayer(), '提交团购信息', null, null, true, true, [{ name: '提交团购申请', focus: true, callback: AddSubmit }, { name: '取消'}]);
                var Edit = $('.TuanInfo').xheditor({ tools: 'Pastetext,|,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Align,Outdent,Indent,Link,Unlink,Img,Emot,Source,Fullscreen,Face', upImgUrl: "/Scripts/XhEditor/upload.aspx", upImgExt: "jpg,jpeg,gif,png", upBtnText: "上传图片" });
                $('#TName').val('团购：' + $('#Flower_name_' + _id).val()); $('#TMPrice').val($('#Flower_price_' + _id).val()); Edit.setSource($('#Flower_pic_' + _id).html()); $('#TuanFid').val(_id);
                $('#TBTime').DatePicker({
                    format: 'Y-m-d', date: '', starts: 1, position: 'right',
                    onChange: function (formated, dates) { if (formated != 'NaN-NaN-NaN') { $('#TBTime').val(formated); $('#TBTime').DatePickerHide(); } }
                });
                $('#TETime').DatePicker({
                    format: 'Y-m-d', date: '', starts: 1, position: 'right',
                    onChange: function (formated, dates) { if (formated != 'NaN-NaN-NaN') { $('#TETime').val(formated); $('#TETime').DatePickerHide(); } }
                });
            };
            this.AddRequest = function (_id) {
                Utility.Dialog.Open('<div style="width:360px; line-height:23px;color:red">商家发起团，所有产品只能网站交易，当团购结束以后花铺网会统一把款打到商家帐户，然后扣除手续费1.5%，没有任何交易，不扣任何费用,结款时间，团购结束后，必须用户确认收到货后，花铺网客户才能把款打到商家的帐户里。</div>',
                '团购协议', null, null, true, true, [{ name: '我同意', focus: true, callback: function () { HuaPu.User.Tuan.AddRequestShow(_id); return false; } }]);
            };
            this.Del = function (_id) { if (confirm('确定要取消该次团购吗？')) { $.post('/Ajax/TuanDel', { Tid: _id }, function (Msg) { alert(Msg); top.location.reload(); }); } };
            var AddSubmit = function () { $('#TuanAddForm').ajaxSubmit({ success: function (Msg) { alert(Msg); if (Msg == '团购申请已经提交，请等待管理员审核！') { Utility.Dialog.Close(); } } }); return false; }
        };
        this.Tuan = new TuanCls();
        //订单管理
        var OrderCls = function () {
            this.SaveForTuan = function () {
                $('#OrderSaveForTuanForm').ajaxSubmit({ success: function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { alert('团购订单提交成功！'); top.location.href = '/Pay/AlipayPay?OrderKey=' + Jo.OrderSn; } else { alert(Jo.Msg); } } });
            };
            //保存购物车订单
            this.SaveForBuyCar = function () {
                $('#BuyCarSaveForm').ajaxSubmit({ success: function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { alert('购物车保存成功订单提交成功！'); top.location.href = '/Pay/AlipayPay?OrderKey=' + Jo.OrderSn; } else { alert(Jo.Msg); } } });
            };
            //填写发货信息
            this.SavePostInfoWin = function (_orderSn) {
                $('#OrderPostForm').parent().parent().remove();

                var Wl = '<option value="圆通快递">圆通快递</option>';
                Wl += '<option value="申通快递">申通快递</option>';
                Wl += '<option value="EMS">EMS</option>'; Wl += '<option value="邮政">邮政</option>';
                Wl += '<option value="韵达快递">韵达快递</option>';
                Wl += '<option value="天天快递">天天快递</option>';
                Wl += '<option value="顺丰快递">顺丰快递</option>';
                Wl += '<option value="中通快递">中通快递</option>';
                Wl += '<option value="汇通快递">汇通快递</option>';
                Wl += '<option value="宅急送">宅急送</option>';
                Wl += '<option value="鑫飞鸿速递">鑫飞鸿速递</option>';
                Wl += '<option value="德邦物流">德邦物流</option>';
                Wl += '<option value="优速快递">优速快递</option>';
                Wl += '<option value="港中能达运">港中能达运</option>';
                Wl += '<option value="全峰快递">全峰快递</option>';
                Wl += '<option value="信丰物流">信丰物流</option>';
                Wl += '<option value="其他">其他</option>';
                $('#Order_Tr_' + _orderSn).after('<tr><td colspan="7" style="height:40px;" align="right"><form id="OrderPostForm" action="/Ajax/OrderPostSave?OrderSn=' + _orderSn + '" method="post">订单编号：' + _orderSn + ' 物流公司：<select name="PostModel">' + Wl + '</select> 物流单号：<input name="PostKey" id="PostKey" type="text" /> <button onclick="return HuaPu.User.Order.SavePostInfo();">确认发货</button></form></td></tr>');
            };
            this.SavePostInfo = function () {
                if ($('#PostKey').val() == '') { alert('请输入支付单号！'); return false; }
                $('#OrderPostForm').ajaxSubmit({ success: function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { top.location.reload(); } else { alert(Jo.Msg); } } }); return false;
            };
            //保存付款信息
            this.SavePayInfoWin = function (_orderSn) {
                $('#OrderPayForm').parent().parent().remove();
                $('#Order_Tr_' + _orderSn).after('<tr><td colspan="7" style="height:40px;" align="right"><form id="OrderPayForm" action="/Ajax/OrderPaySave?OrderSn=' + _orderSn + '" method="post">订单编号：' + _orderSn + ' 付款方式：<select name="PayModel"><option value="Alipay">支付宝</option><option value="Palpay">财付通</option><option value="WebBank">网银</option><option value="99Bill">快钱</option></select> 付款单号：<input name="PayKey" id="PayKey" type="text" /> <button onclick="return HuaPu.User.Order.SavePayInfo();">确认付款</button></form></td></tr>');
            };
            //提交付款信息
            this.SavePayInfo = function () {
                if ($('#PayKey').val() == '') { alert('请输入支付单号！'); return false; }
                $('#OrderPayForm').ajaxSubmit({ success: function (Msg) { var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { top.location.reload(); } else { alert(Jo.Msg); } } }); return false;
            };
            //确认收货
            this.Reach = function (_orderSn) {
                if (confirm('请拿到货物后确认收货，否则将钱财两空！\r\n是否确认收货？')) {
                    $.post('/Ajax/OrderReach', { OrderSn: _orderSn }, function (Msg) {
                        var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { top.location.href = '/User/OrderBuy?t=Finish'; } else { alert(Jo.Msg); }
                    });
                }
            };
            //取消订单
            this.Delete = function (_orderSn) {
                if (confirm('确定要取消该订单吗？（不可恢复）')) {
                    $.post('/Ajax/OrderDelete', { OrderSn: _orderSn }, function (Msg) {
                        var Jo = Utility.JSON.StringToJson(Msg); if (Jo.State) { top.location.reload(); } else { alert(Jo.Msg); }
                    });
                }
            };
        };
        this.Order = new OrderCls();
        //地址簿管理
        var AddressCls = function () {
            var getWin = function () { var o = $('body').data('AddAddressDiv'); if (o == null || o == undefined || o == '') { o = $('.AddAddress').html(); $('body').data('AddAddressDiv', o); $('.AddAddress').remove(); } return o; };
            var Save = function () {
                if ($('#XingMing').val() == '') { alert('请输入收货姓名！'); return false; }
                if ($('#Tel').val() == '') { alert('请输入联系电话！'); return false; }
                if ($('#Address').val() == '') { alert('请输入收货地址！'); return false; }
                $('#AddAddressForm').ajaxSubmit({ success: function (Msg) { top.location.reload(); } });
                return false;
            };
            this.Add = function () { Utility.Dialog.Open(getWin(), '添加地址', null, null, true, true, [{ name: '添加', focus: true, callback: Save }, { name: '取消'}]); };
            this.Edit = function (id) {
                Utility.Dialog.Open(getWin(), '编辑地址', null, null, true, true, [{ name: '保存更新', focus: true, callback: Save }, { name: '取消'}]);
                $('#AddAddressForm input[name=XingMing]').val($.trim($('tr.Address_' + id + ' td:eq(0)').html()));
                $('#AddAddressForm input[name=Id]').val(id);
                $('#AddAddressForm input[name=Tel]').val($.trim($('tr.Address_' + id + ' td:eq(1)').html()));
                $('#AddAddressForm input[name=PostNumber]').val($.trim($('tr.Address_' + id + ' td:eq(2)').html()));
                $('#AddAddressForm input[name=Address]').val($.trim($('tr.Address_' + id + ' td:eq(3)').html()));
            };
            this.Del = function (id) { $.post('/Ajax/AddressDel', { Id: id }, function () { $('.Address_' + id).remove(); }) };
        };
        this.Address = new AddressCls();
        //购物车操作类
        var BuyCarCls = function () {
            this.getCount = function () { $.get('/Ajax/BuyCarGetCount', function (Msg) { if (Msg > 0) { $('#BuyCarNum').html('(' + Msg + ')'); } }); }
            this.addToBuyCarSubmit = function (_f, _n) {
                $.post('/Ajax/BuyCarAdd', { FlowerId: _f, BuyNum: _n }, function (Msg) {
                    var Jo = Utility.JSON.StringToJson(Msg);
                    if (Jo.State) { if (confirm('成功添加到购物车，去结算购物车？')) { top.location.href = '/Shop/BuyCar'; } } else { alert(Msg); }
                });
            }
            this.addToBuyCar = function (_fid, _num, _selleruid) {
                if (_num == null || _num == undefined || _num < 1) { alert('请输入购买数量！'); return; }
                $.post('/Ajax/BuyCarCheckSellerUser', { SellerUid: _selleruid }, function (Msg) {
                    if (!eval(Msg)) {
                        if (confirm('购物车中存在其他商家的商品，继续添加将清空购物车中原有商品，是否继续？')) { $.get('/Ajax/BuyCarClear', function () { HuaPu.User.BuyCar.addToBuyCarSubmit(_fid, _num); }); }
                        else { top.location.href = '/Shop/BuyCar'; }
                    }
                    else { HuaPu.User.BuyCar.addToBuyCarSubmit(_fid, _num); }
                });
            };
            //在单个花卉页面点击购买按钮。该操作添加成功后直接跳转至购物车订单确认提交页面
            this.BuyOneFlower = function (_fid, _num) {
                if (_num == null || _num == undefined || _num < 1) { alert('请输入购买数量！'); return; }
                $.get('/Ajax/BuyCarClear', function () {
                    $.post('/Ajax/BuyCarAdd', { FlowerId: _fid, BuyNum: _num }, function (Msg) {
                        var Jo = Utility.JSON.StringToJson(Msg);
                        if (Jo.State) { top.location.href = '/Shop/BuyCarShow'; } else { alert(Msg); }
                    });
                });
            };
        };
        this.BuyCar = new BuyCarCls();
        //花卉实体类
        var FlowerCls = function () {
            var Page = 1;
            var getSameSubjectFlowerLoad = function (Fid) {
                $.get("/Ajax/getSameSubjectFlowerNext", { Fid: Fid, Page: Page }, function (Msg) {
                    var Jo = Utility.JSON.StringToJson(Msg);
                    HuaPu.User.Flower.setPage(Jo.Page);

                    var str = "";
                    $.each(Jo.Data, function (i, v) { str += '<div class="cp_tupic"><a href="/Flower/' + v.Fid + '.html"><img src="' + v.Pic + '" width="100" height="80" /></a></div>' });
                    $('#SameListTd').html(str);
                });
            };
            this.setPage = function (p) { Page = p; };
            this.getSameSubjectFlowerNext = function (Fid) { Page += 1; getSameSubjectFlowerLoad(Fid); };
            this.getSameSubjectFlowerPrev = function (Fid) { Page -= 1; getSameSubjectFlowerLoad(Fid); };
            this.EditLayer = function (id, _n, _p, _c, _num) {
            }
        };
        this.Flower = new FlowerCls();
    };
    HuaPuCls.prototype.User = new UserCls();
    //顶部搜索
    HuaPuCls.prototype.Search = function () {
        var t = $('#SearchType').val(); if (t == '') { alert('请选择搜索内容类型！'); return; } var v = $('#SearchKey').val(); if (v == '') { alert('请输入搜索关键词！'); return; }
        top.location.href = '/' + t + '?key=' + v;
    };
})(window, undefined);
///页面加载完成自动执行函数
$(function () {    
    HuaPu.User.BuyCar.getCount();   //加载购物车中商品数量
});


