/// /// /// (function () { ec.user = { api: new ec.api("user"), setMenu: function (i) { $(".sidenav dd").eq(i).addClass("bg5 fb3").find("a").addClass("ch1"); $(".sitemap span").html($(".sidenav a").eq(i).html()); }, favorite: function (id, el) { var isFav = $(el).find(".ico").hasClass("ico-star-gray-hover"); var url = "favorite/"; url += (isFav ? "delete" : "insert"); this.api.post(url + "/" + id, null, function (r) { ec.notify(isFav ? L.G("取消收藏成功") : L.G("收藏成功")); $(el).find(".ico").toggleClass("ico-star-gray-hover"); $(el).find("label").html(isFav ? L.G("加入收藏") : L.G("取消收藏")); }); }, baseInfo: { init: function (data) { ke.ui.render(); ke.bindObject(data); Country.bindStore(new ke.table().load(ec.utilities.getCountry(), true)); Country.change(function () { var country = Country.get(); Province.bindStore(new ke.table().load(ec.utilities.getProvince(country), true)); Province.setTriggerChange(""); City.setTriggerChange(""); }); Province.change(function () { var country = Country.get(); var province = Province.get(); City.bindStore(new ke.table().load(ec.utilities.getCity(country, province), true)); }); Country.setTriggerChange(data.Country); Province.setTriggerChange(data.Province); City.setTriggerChange(data.City); }, save: function () { var info = ke.createObject(); self.api.post("info/update", info, function (r) { window.location.href = L.route + "/user/success?type=info"; }); } }, password: { init: function () { ke.ui.render(); Pwd.change(function () { self.password.format(); }); }, seePassword: function (el, box) { var btn = el.find(".ico"); var see = btn.hasClass("ico-eye-close"); btn.toggleClass("ico-eye-close", !see); box.find("input").attr('type', !see ? "password" : "text"); }, format: function () { if (Pwd.get()) { new ec.api("account").post("validate/password?password=" + Pwd.get(), function (r) { if (r) ec.utilities.showError1($("#Pwd"), r); }); }; }, validate: function () { var msg = ""; var items = ke.ui.findControls("#register", "input"); items.forEach(function (d) { if (!d.validate()) msg = d.skin.title.replace("*", "") + L.G(" 不可为空"); }); if (CheckPwd.get() != Pwd.get()) msg = L.G("两次输入的密码不一致,请重新输入"); return msg; }, save: function () { var msg = this.validate(); var callback = function () { new ec.api("account").post("user/forgetpwd?oldPwd=" + OldPwd.get() + "&pwd=" + Pwd.get(), function (r) { if (!r) window.location.href = L.route + "/user/success?type=password"; }); }; if (msg) ec.notify(msg, "question", 3000); else callback(); }, }, email: { init: function () { ke.ui.render(); this.account = $("#account"); this.verify = $("#verify"); }, getCode: function () { ec.api.errorEnd = function () { ec.utilities.validateLoading(false); } var msg = "" if (!Email.get()) { msg = L.G("请输入邮箱"); ec.utilities.showError1($("#Email"), msg); }; if (!msg) { ec.utilities.validateLoading(true); new ec.api("account").post("getValidateCode/bindEmail?email=" + Email.get(), function (r) { if (r == true) ec.utilities.validateMsgBtn(60); else ec.notify(r, "question", 3000); }); }; }, save: function () { ec.api.errorEnd = null; var msg = ""; if (!Email.get()) { msg = L.G("请输入邮箱"); ec.utilities.showError1($("#Email"), msg); } else if (!ValidateCode.get()) { msg = L.G("请输入验证码"); ec.utilities.showError1($("#ValidateCode"), msg); } if (!msg) { new ec.api("account").post("bindEmail?email=" + Email.get() + "&code=" + ValidateCode.get(), function (r) { if (r) { window.location.href = L.route + "/user/success?type=email"; } }); } } } } ec.address = { init: function (data, userData) { ke.ui.render(); Country.bindStore(new ke.table().load(ec.utilities.getCountry(), true)); Country.change(function () { var country = Country.get(); Province.bindStore(new ke.table().load(ec.utilities.getProvince(country), true)); Province.setTriggerChange(""); Province.find(".box").removeClass("illegal"); }); Province.change(function () { var country = Country.get(); var province = Province.get(); City.bindStore(new ke.table().load(ec.utilities.getCity(country, province), true)); City.setTriggerChange(""); City.find(".box").removeClass("illegal"); }); Country.setTriggerChange(L.isEn ? "China" : "中国"); if (userData.UserId != 0) ec.address.setCountry(userData.Country, userData.Province, userData.City); if (data.RID != 0) { ke.bindObject(data); ec.address.setCountry(data.Country, data.Province, data.City); }; }, setCountry: function (country, province, city) { if (country) Country.setTriggerChange(country); if (province) Province.setTriggerChange(province); if (city) City.setTriggerChange(city); }, validate: function () { var msg = ""; var items = ke.ui.findControls("#inputContent", "input"); items.forEach(function (d) { if (!d.validate()) { msg = d.skin.title.replace("*", "") + L.G("不可为空"); } }); return msg; }, submit: function () { var info = ke.createObject(); var msg = this.validate(info); if (!msg && info.RID != 0) this.update(info); else if (!msg) this.insert(info); else window.top.ec.notify(msg, "question"); }, insert: function (info) { self.api.post("address/insert", info, function (r) { window.parent.ec.notify(L.G("添加成功")); window.parent[ke.parm("callback")](r); ec.hideWindow(); }); }, update: function (info) { self.api.post("address/update", info, function (r) { window.parent.ec.notify(L.G("修改成功")); window.parent[ke.parm("callback")](r); ec.hideWindow(); }); }, del: function (id) { self.api.post("address/delete?id=" + id, null, function (r) { ec.notify(L.G("删除成功")); var index = ec.receiver.data.get({ RID: id }, true); ec.receiver.data.splice(index, 1) ec.receiver.render(); }); }, setDefault: function (id, callback) { self.api.post("address/setDefault?id=" + id, null, function (r) { ec.notify(L.G("设置默认地址成功")); callback(); }); } } ec.receiver = { data: {}, init: function (data) { this.data = data; this.render(); }, add: function () { window.addressCallback = function (d) { ec.receiver.data = d; ec.receiver.render(); }; ec.open.address("Shipping", L.G("新增收货地址"), "addressCallback", 650, 620); }, alter: function (id) { window.addressCallback = function (d) { ec.receiver.data = d; ec.receiver.render(d); }; ec.open.address("Shipping", L.G("修改收货地址"), "addressCallback", 650, 620, id) }, remove: function (id) { var callback = function () { ec.address.del(id); }; ec.confirm("" + L.G("确定要删除吗?"), L.G("删除选中的收货地址"), callback); }, setDefault: function (id) { var callback = function () { ec.receiver.data.forEach(function (d) { d.IsDefault = (d.RID == id); }); ec.receiver.render() }; ec.address.setDefault(id, callback); }, render: function () { var hasData = ec.receiver.data.length > 0; htm = window.top.ke.template.get("rec_address_html").render({ arr: ec.receiver.data }); $("#rec_address").html(htm); $("#rec_address_notfind").toggle(!hasData); } } ec.invAddress = { data: {}, init: function (data) { this.data = data; this.render(); }, add: function () { window.addressCallback = function (d) { ec.invAddress.data = d; ec.invAddress.render(); }; ec.open.address("Invoice", L.G("新增收票地址"), "addressCallback", 650, 632); }, alter: function (id) { window.addressCallback = function (d) { ec.invAddress.data = d[0]; ec.invAddress.render(); }; ec.open.address("Invoice", L.G("编辑收票地址"), "addressCallback", 650, 632, id); }, remove: function (id) { var callback = function () { self.api.post("address/delete?id=" + id, null, function (r) { ec.notify(L.G("删除成功")); var index = ec.invAddress.data.get({ RID: id }, true); ec.invAddress.data.splice(index, 1) ec.invAddress.render(); }); }; ec.confirm("" + L.G("确定要删除吗?"), L.G("删除选中的收票地址"), callback); }, setDefault: function (id) { var callback = function () { ec.invAddress.data.forEach(function (d) { d.IsDefault = (d.RID == id); }); ec.invAddress.render() }; ec.address.setDefault(id, callback); }, render: function () { var hasData = ec.invAddress.data.length > 0; htm = window.top.ke.template.get("inv_address_html").render({ arr: ec.invAddress.data }); $("#inv_address").html(htm); $("#inv_address_notfind").toggle(!hasData); } } ec.invoice = { data: {}, type:1, init: function (data) { this.data = data; this.render(); }, add: function () { window.invoiceCallback = function (d) { ec.invoice.data = d; ec.invoice.render(); }; ec.open.invoice(L.G("新增发票信息"), "invoiceCallback"); }, alter: function (id) { window.invoiceCallback = function (d) { ec.invoice.data = d; ec.invoice.render(); }; ec.open.invoice(L.G("编辑发票信息"), "invoiceCallback", id); }, remove: function (id) { var callback = function () { self.api.post("invoice/delete?id=" + id, null, function (r) { ec.notify(L.G("删除成功")); var index = ec.invoice.data.get({ RID: id }, true); ec.invoice.data.splice(index, 1) ec.invoice.render(); }); }; ec.confirm("" + L.G("确定要删除吗?"), L.G("删除选中的发票信息"), callback); }, setDefault: function (id) { var callback = function () { ec.invoice.data.forEach(function (d) { d.IsDefault = (d.RID == id); }); ec.invoice.render() }; self.api.post("invoice/setDefault?id=" + id, null, function (r) { ec.notify(L.G("设置默认发票成功")); callback(); }); }, render: function () { var hasData = ec.invoice.data.length > 0; htm = window.top.ke.template.get("inv_info_html").render({ arr: ec.invoice.data }); $("#inv_info").html(htm); $("#inv_info_notfind").toggle(!hasData); }, changeDisplayMode: function (type) { this.type = type; $(".invoice-spec").toggle(type != 1); ec.changeWindowH(type != 1 ? "580" : "416"); }, validate: function () { var msg = ""; var item; if (this.type == 1) items = ke.ui.findControls("input_part", "input"); else items = ke.ui.findControls("input_all", "input"); items.forEach(function (d) { if (!d.validate() && msg == "") { msg = d.skin.title.replace("*", "") + L.G("不可为空"); } }); return msg; }, save: function () { var callback = function () { self.api.post("invoice/update", info, function (r) { window.parent.ec.notify(info.RID != 0 ? L.G("修改成功") : L.G("添加成功")); window.parent[ke.parm("callback")](r); ec.hideWindow(); }); }; var info = ke.createObject(); info.InvTypeName = InvType.getText(); info.RID = RID.get(); var msg = this.validate(); if (msg) window.top.ec.notify(msg, "question", 3000); else callback(); } } var self = ec.user; })();