123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- $(function(){
- pushHistory();
- window.addEventListener("popstate", function(e) {
- location.href=base+"/mobile/index.jsp";
- }, false);
- });
- function pushHistory() {
- var state = {
- title: "title",
- url: "#"
- };
- if(window.history.length==1){
- window.history.pushState(state, "title", "#");
- }
- }
- var id=mobile.getUrlVars("id");
- var cutId=mobile.getUrlVars("cutId");
- var help=mobile.getUrlVars("help");
- var data;
- var custom;
- var pageNumber = 1;
- var pageSize=10;
- mui.init();
- /**
- *初始化、添加监听
- */
- mui.ready(function(){
- getCustom();
- if (cutId){
- getCutInfo();
- $(".cut-info").removeClass("mui-hidden");
- $("#cut-list-div").removeClass("mui-hidden");
- }else{
- getProductDetail();
- }
- $("#sendCode").html(Math.floor(Math.random()*9000)+1000);
- $(".header").on("tap",".guanzhu",function(e){
- var html=[];
- html.push('<img src="'+imgUrl+custom.wechat_qrcode+'" style="width:100%">');
- mui.alert(html.join(""), '关注“<span class="main-color">'+custom.wechat_name+'</span>”');
- });
- $(".footer").on("tap",function(e){
- var html=[];
- html.push('<img src="'+imgUrl+custom.custom_qrcode+'" style="width:100%">' +
- '<a class="fs16" href="tel:'+custom.custom_mobile+'">电话:'+custom.custom_mobile+'</a>');
- mui.alert(html.join(""), '长按二维码联系客服');
- });
- $(".merchant").on("tap",function(){
- location.href=base+'/mobile/merchantDetail.jsp?id='+data.merchant.id;
- });
- $(".tel").on("tap",function(){
- location.href = 'tel:'+data.merchant.mobile;
- });
- $(".map").on("tap",function(){
- var locations=bd09togcj02(data.merchant.longitude,data.merchant.latitude);
- wx.ready(function(){
- wx.openLocation({
- latitude: locations[1], // 纬度,浮点数,范围为90 ~ -90
- longitude: locations[0], // 经度,浮点数,范围为180 ~ -180。
- name: data.merchant.merchant_name, // 位置名
- address: data.merchant.address, // 地址详情说明
- scale: 25, // 地图缩放级别,整形值,范围从1~28。默认为最大
- infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转
- });
- });
- });
- $(".comment").on("tap",function(){
- location.href = base+'/mobile/merchantComment.jsp?id='+data.merchant.id;
- });
- $("#login").on("tap",'.mui-icon-left-nav',function(){
- $('#login').removeClass('mui-active');
- });
- $("#sendCode").on("tap",function(e){
- $("#sendCode").html(Math.floor(Math.random()*9000)+1000);
- });
- $("#login-btn").on("tap",function(e){
- var mobilePhone = $.trim($('#mobile').val());
- var code = $.trim($('#code').val());
- if(!mobile.checkMobile(mobilePhone)){
- layer.open({content:'请输入正确手机号码',time:3});
- return;
- }
- if(code!=$("#sendCode").html()){
- layer.open({content:'验证码错误',time:3});
- return;
- }
- user.mobile = mobilePhone;
- mobile.ajaxPost(base+'/users/save',user, function(json) {
- layer.open({content: '登录成功', time: 3});
- setTimeout(function() {
- $("#toOrder").html("立即抢购");
- $('#login').removeClass('mui-active');
- }, 1000);
- });
- });
- $(".btns").on("tap",".baoming",function () {
- if(!user.mobile){
- $('#login').addClass('mui-active');
- }else{
- baoming();
- }
- });
- //我的砍价
- $(".btns").on("tap",".my",function () {
- if (!cutId){
- location.href=base+"/mobile/cutProductDetail.jsp?id="+id+"&cutId="+data.cutInfo.id;
- }else{
- location.href=base+"/mobile/cutProductDetail.jsp?id="+id+"&cutId="+data.myCutInfo.id;
- }
- });
- //其他砍价
- $(".btns").on("tap",".qita",function () {
- location.href=base+"/mobile/cutProductList.jsp";
- });
- //帮好友减价
- $(".btns").on("tap",".cut",function () {
- cut();
- });
- //邀请
- $(".btns").on("tap",".yaoqing",function () {
- $("#share").show();
- });
- //购买
- $(".btns").on("tap",".buy",function () {
- saveOrder();
- });
- //分享
- $(".share-bg").on('tap',function(){
- $("#share").hide();
- });
- //分享
- $(".share-img").on('tap',function(){
- $("#share").hide();
- });
- });
- //获取商品信息
- function getCustom(){
- mobile.ajaxPost(base+"/sysCustom/getById",{},function(json){
- custom = json.data;
- });
- }
- //获取商品信息
- function getProductDetail(){
- mobile.ajaxPost(base+"/product/getProduct",{id:id},function(json){
- if(json.success){
- data = json.data;
- if(data.time_status==0){
- var interval= setInterval(function() {
- var leftTime = (new Date(data.end_time.replace(/-/g, "/"))) - (new Date());
- var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数
- var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时
- var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
- var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
- hours = checkTime(hours);
- minutes = checkTime(minutes);
- seconds = checkTime(seconds);
- $(".time").html("减价剩余<span class='time-tip'>"+days+"</span>天<span class='time-tip'>" + hours+"</span>小时" +
- "<span class='time-tip'>" + minutes+"</span>分<span class='time-tip'>"+seconds+"</span>秒");
- }, 1000);
- if (data.cutInfo){
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 my">去我的减价>></div>');
- }else{
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 baoming">我要报名</div>');
- }
- }else if(data.time_status==1){
- $(".time").html("已抢完");
- }else{
- $(".time").html("已结束");
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 qita">活动已结束,查询其他活动>></div>');
- }
-
- share.title=data.product_name;
- share.imgUrl=imgUrl+data.product_main_img;
- var arr = [];
- if(data.product_img_1){
- arr.push(data.product_img_1);
- $(".pic-box img").attr("src",imgUrl+data.product_img_1);
- }
- if(data.product_img_2){
- arr.push(data.product_img_2);
- }
- if(data.product_img_3){
- arr.push(data.product_img_3);
- }
- var unit = mobile.getDictVal("product_unit",data.product_unit);
- $(".productName").html(data.product_name);
- $(".product-price").html('<span class="color1 fs14">底价 </span><span class="fs14">¥ </span><span class="fs24">'+data.product_price+'</span>');
- $(".old_price").html("原价 ¥"+data.product_old_price+"元");
- $(".visit_num").html(data.visit_num+"人查看");
- $(".share_num").html(data.shareNum+"人分享");
- $(".user_num").html(data.userNum+"人参与");
- $(".use_time").html("兑换有效期至:"+data.use_time);
- $(".product_num").html("仅剩"+(data.product_num-data.sale_num)+"/"+data.product_num+unit+"");
- if(data.sale_num!=0){
- $('.sale-num').html('已售'+data.sale_num+'份');
- getOrderUser();
- }else{
- $('.sale-num-div').hide();
- }
- $(".merchant_name").html(data.merchant.merchant_name);
- $(".merchant img").attr("src", imgUrl+data.merchant.merchant_img1);
- $(".address").html(data.merchant.address);
- if(data.merchant.comment_num!=0){
- $(".comment_num").html(data.merchant.comment_num+"人评价")
- }
- if(data.product_detail){
- $("#detail").html(data.product_detail);
- $("img.lazy").lazyload({
- threshold : 50,
- effect: "fadeIn",
- placeholder: base+'/static/mobile/image/500.gif',
- skip_invisible : false
- });
- }else{
- $("#detail").html('<span class="fs14 color2">暂无信息</span>');
- }
- $('.mui-content').removeClass('mui-hidden');
- $('.mui-bar-tab').removeClass('mui-hidden');
- initSlider(arr);
- //获取评价
- getUserMsg();
-
- wx.ready(function(){
- wx.getLocation({
- type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
- success: function (res) {
- $.ajax({
- url:'http://api.map.baidu.com/geoconv/v1/?coords='+res.longitude+','+res.latitude+'&from=1&to=5&ak=3Q4laSROftZI4chFMPVUno90',
- dataType:'jsonp',
- processData: false,
- type:'get',
- success:function(json){
- if (json.status=='0'){
- var latitude=json.result[0].y;
- var longitude=json.result[0].x;
- var map = new BMap.Map("allmap");
- var pointA = new BMap.Point(longitude,latitude);
- var pointB = new BMap.Point(data.merchant.longitude,data.merchant.latitude);
- var distance = parseInt(map.getDistance(pointA,pointB));
- $(".distance").html(getDistance(distance));
- }
- },
- error:function(XMLHttpRequest, textStatus, errorThrown) {
- layer.msg('坐标转换失败');
- }
- });
- }
- });
- });
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }
- //获取商品信息
- function getCutInfo(){
- mobile.ajaxPost(base+"/product/getCutInfo",{cutId:cutId},function(json){
- if(json.success){
- data = json.data;
- if(data.time_status==0){
- var interval= setInterval(function() {
- var leftTime = (new Date(data.end_time.replace(/-/g, "/"))) - (new Date());
- var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数
- var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时
- var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
- var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
- hours = checkTime(hours);
- minutes = checkTime(minutes);
- seconds = checkTime(seconds);
- $(".time").html("减价剩余<span class='time-tip'>"+days+"</span>天<span class='time-tip'>" + hours+"</span>小时" +
- "<span class='time-tip'>" + minutes+"</span>分<span class='time-tip'>"+seconds+"</span>秒");
- }, 1000);
- if(data.myCutInfo&&data.myCutInfo!=null){
- if (data.myCutInfo.id==data.cutInfo.id){
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 cut">自己减价</div>');
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 yaoqing">邀请好友减价</div>');
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 buy">立即购买</div>');
- }else{
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 cut">帮好友减价</div>');
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 my">去我的减价>></div>');
- }
- }else{
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 cut">帮好友减价</div>');
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 baoming">我要报名</div>');
- }
- }else if(data.time_status==1){
- $(".time").html("已抢完");
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 qita">活动已经抢光,查询其他活动>></div>');
- }else{
- $(".time").html("已结束");
- $(".btns").append('<div class="mui-btn mui-btn-primary ml10 qita">活动已结束,查询其他活动>></div>');
- }
- share.title=data.product_name;
- share.imgUrl=imgUrl+data.product_main_img;
- var arr = [];
- if(data.product_img_1){
- arr.push(data.product_img_1);
- $(".pic-box img").attr("src",imgUrl+data.product_img_1);
- }
- if(data.product_img_2){
- arr.push(data.product_img_2);
- }
- if(data.product_img_3){
- arr.push(data.product_img_3);
- }
- var unit = mobile.getDictVal("product_unit",data.product_unit);
- $(".productName").html(data.product_name);
- $(".product-price").html('<span class="color1 fs14">底价 </span><span class="fs14">¥ </span><span class="fs24">'+data.product_price+'</span>');
- $(".cut-price").html(data.cutInfo.product_price+"元");
- $("#userImg").attr("src",data.user.headimgurl);
- $("#userName").html(data.user.nickname);
- $(".old_price").html("原价 ¥"+data.product_old_price+"元");
- $(".visit_num").html(data.visit_num+"人查看");
- $(".share_num").html(data.shareNum+"人分享");
- $(".user_num").html(data.userNum+"人参与");
- $(".use_time").html("兑换有效期至:"+data.use_time);
- $(".product_num").html("仅剩"+(data.product_num-data.sale_num)+"/"+data.product_num+unit+"");
- if(data.sale_num!=0){
- $('.sale-num').html('已售'+data.sale_num+'份');
- getOrderUser();
- }else{
- $('.sale-num-div').hide();
- }
- if (data.cutDetail){
- $(".help-num").html(data.cutDetail.length+"人");
- $(".cut-list").empty();
- if (data.cutDetail.length>0){
- $.each(data.cutDetail,function (id,item) {
- $(".cut-list").append('<img class="comment-avatar mr5" src="'+item.headimgurl+'">');
- })
- }else{
- $(".cut-list").append('暂无');
- }
- }
- $(".merchant_name").html(data.merchant.merchant_name);
- $(".merchant img").attr("src", imgUrl+data.merchant.merchant_img1);
- $(".address").html(data.merchant.address);
- if(data.merchant.comment_num!=0){
- $(".comment_num").html(data.merchant.comment_num+"人评价")
- }
- if(data.product_detail){
- $("#detail").html(data.product_detail);
- $("img.lazy").lazyload({
- threshold : 50,
- effect: "fadeIn",
- placeholder: base+'/static/mobile/image/500.gif',
- skip_invisible : false
- });
- }else{
- $("#detail").html('<span class="fs14 color2">暂无信息</span>');
- }
- $('.mui-content').removeClass('mui-hidden');
- $('.mui-bar-tab').removeClass('mui-hidden');
- initSlider(arr);
- //获取评价
- getUserMsg();
- wx.ready(function(){
- wx.getLocation({
- type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
- success: function (res) {
- $.ajax({
- url:'http://api.map.baidu.com/geoconv/v1/?coords='+res.longitude+','+res.latitude+'&from=1&to=5&ak=3Q4laSROftZI4chFMPVUno90',
- dataType:'jsonp',
- processData: false,
- type:'get',
- success:function(json){
- if (json.status=='0'){
- var latitude=json.result[0].y;
- var longitude=json.result[0].x;
- var map = new BMap.Map("allmap");
- var pointA = new BMap.Point(longitude,latitude);
- var pointB = new BMap.Point(data.merchant.longitude,data.merchant.latitude);
- var distance = parseInt(map.getDistance(pointA,pointB));
- $(".distance").html(getDistance(distance));
- }
- },
- error:function(XMLHttpRequest, textStatus, errorThrown) {
- layer.msg('坐标转换失败');
- }
- });
- }
- });
- });
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }
- function initSlider(arr){
- $("#slider .mui-slider-group").append('<div class="mui-slider-item mui-slider-item-duplicate">'+
- '<a href="javascript:void(0)">'+
- '<img class="slider-lazy" data-original="'+imgUrl+arr[arr.length-1]+'" >'+
- '</a>'+
- '</div>');
- if(arr.length>1){//数量大于1定时滚动
- for(var i=0;i<arr.length;i++){
- $("#slider .mui-slider-group").append('<div class="mui-slider-item">'+
- '<a href="javascript:void(0)">'+
- '<img class="slider-lazy" data-original="'+imgUrl+arr[i]+'" >'+
- '</a>'+
- '</div>');
- if(i==0){
- $("#slider .mui-slider-indicator").append('<div class="mui-indicator mui-active"></div>');
- }else{
- $("#slider .mui-slider-indicator").append('<div class="mui-indicator"></div>');
- }
- }
- }else{//数量等于1
- $("#slider .mui-slider-group").append('<div class="mui-slider-item">'+
- '<a href="javascript:void(0)">'+
- '<img class="slider-lazy" data-original="'+imgUrl+arr[0]+'" >'+
- '</a>'+
- '</div>');
- }
- $("#slider .mui-slider-group").append('<div class="mui-slider-item mui-slider-item-duplicate">'+
- '<a href="javascript:void(0)">'+
- '<img src="'+imgUrl+arr[0]+'" >'+
- '</a>'+
- '</div>');
- if(arr.length>1){
- var slider = mui("#slider");
- slider.slider({
- interval: 3000
- });
- }
- $("img.slider-lazy").lazyload({
- threshold : 200,
- placeholder: base+'/static/mobile/image/500.gif',
- skip_invisible : false
- });
- }
- function getOrderUser() {
- mobile.ajaxPost(base+'/userOrder/getUserMsgList',{
- productId: id,
- pageSize: pageSize,
- pageNumber: 1
- },function(json){
- if(json.list&&json.list.length>0){
- $.each(json.list,function (id,item) {
- if (id<9){
- $(".sale-num-div").append('<img class="comment-avatar mr5" src="'+item.headimgurl+'">');
- }
- });
- }
- });
- }
- //获取评价
- function getUserMsg(){
- $('.userMsg-content').dropload({
- scrollArea : window,
- loadDownFn : function(me){
- mobile.ajaxPost(base+'/userOrder/getUserMsgList',{
- productId: id,
- pageSize: pageSize,
- pageNumber: pageNumber
- },function(json){
- if(json.list&&json.list.length>0){
- if(pageNumber==json.totalPage){
- me.lock();
- me.noData();
- }else{
- pageNumber++;
- }
- var html=[];
- jQuery.each(json.list,function(id,item){
- html.push('<li class="mui-table-view-cell">');
- html.push('<div class="mui-table">');
- html.push('<div class="mui-table-cell mui-col-xs-3 mui-ellipsis">'+getName(item.nickname)+'</div>');
- if (item.order_amt==data.product_price){
- html.push('<div class="mui-table-cell mui-col-xs-6 main-color">减到低价</div>');
- }else{
- html.push('<div class="mui-table-cell mui-col-xs-6 main-color">'+item.order_amt+'元</div>');
- }
- html.push('<div class="mui-table-cell mui-col-xs-3">'+new Date(item.create_time.replace(/-/g, "/")).format("MM-dd hh:mm")+'</div>');
- html.push('</div>');
- html.push('</li>');
- })
- $("#userMsg").append(html.join(""));
- me.resetload();
- }else{
- me.lock();
- me.noData();
- me.resetload();
- }
- },"");
- }
- });
-
- }
- function checkTime(i){ // 将0-9的数字前面加上0,例1变为01
- if(i<10) {
- i = "0" + i;
- }
- return i;
- }
- function getName(name){
- if(name){
- if(name.length==1){
- return "*";
- }else if(name.length==2){
- return name.substring(0,1)+"*";
- }else{
- return name.substring(0,1)+"*"+name.substring(name.length-1);
- }
- }else{
- return "*";
- }
- }
- function baoming() {
- mobile.ajaxPost(base+'/cutInfo/save',{
- productId: id
- },function(json){
- if(json.success){
- layer.open({content:'报名成功',time:3});
- setTimeout(function() {
- location.href=base+"/mobile/cutProductDetail.jsp?id="+id+"&cutId="+json.data.id;
- }, 1000);
- }else{
- layer.open({content:json.msg,time:3});
- }
- });
- }
- function cut() {
- mobile.ajaxPost(base+'/cutDetail/save',{
- cutId: cutId
- },function(json){
- if(json.success){
- mui.alert('减价成功,帮忙减了'+mobile.toDecimal(json.data.cut_price)+'元', '提示信息');
- $(".cut-price").html(mobile.toDecimal(json.data.product_price)+"元");
- if (json.data.cutDetail){
- $(".help-num").html(json.data.cutDetail.length+"人");
- $(".cut-list").empty();
- if (json.data.cutDetail.length>0){
- $.each(json.data.cutDetail,function (id,item) {
- $(".cut-list").append('<img class="comment-avatar mr5" src="'+item.headimgurl+'">');
- })
- }else{
- $(".cut-list").append('暂无');
- }
- }
- }else{
- layer.open({content:json.msg,time:3});
- }
- });
- }
- function saveOrder(){
- mobile.ajaxPost(base+'/userOrder/saveCut',{
- productId: id,
- cutId:cutId,
- company: sessionStorage.getItem("company"),
- shareUser: sessionStorage.getItem("shareUser")
- },function(json){
- if(json.success){
- location.href=base+"/mobile/userOrderDetail.jsp?id="+json.data.id;
- }else{
- layer.open({content:json.msg,time:3});
- }
- });
- }
- function getDistance(distance){
- var i= parseInt(distance);
- if(i<1000){
- return i+"米";
- }else{
- var f = parseFloat(i/1000);
- if (isNaN(f)) {
- return;
- }
- f = Math.round(i/1000 * 10) / 10;
- return f+"公里";
- }
- }
|