merchantView.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var id=mobile.getUrlVars("id");
  2. var data;
  3. var custom;
  4. /**
  5. *初始化、添加监听
  6. */
  7. $(document).ready(function(){
  8. //document.onkeydown=jumpPage;
  9. document.onkeydown = function(event) {
  10. var evt = event ? event : (window.event ? window.event : null);
  11. return jumpPage(Event.mapping(evt));
  12. };
  13. document.onirkeypress = function(event) {
  14. var evt = event ? event : (window.event ? window.event : null);
  15. return jumpPage(Event.mapping(evt));
  16. };
  17. document.onsystemevent = function(event) {
  18. var evt = event ? event : (window.event ? window.event : null);
  19. return jumpPage(Event.mapping(evt));
  20. };
  21. getProductDetail();
  22. });
  23. //获取商品信息
  24. function getProductDetail(){
  25. mobile.ajaxPost(base+"/merchant/getById",{id:id},function(json){
  26. data = json.data;
  27. $(".merchant-name").html(data.merchant_name);
  28. $(".merchant-address").html(data.address);
  29. $(".time").html(data.start_hour+" - "+data.end_hour);
  30. $(".mobile").html(data.mobile);
  31. $(".cost").html(data.cost+"元");
  32. $(".visit-num").html(data.visit_num+"人关注");
  33. if(data.merchant_detail){
  34. $(".merchant-detail").append(data.merchant_detail);
  35. }
  36. $(".merchant-detail").append("<div class='footer'></div>");
  37. var qrtext = "http://www.3water.cn/buying/mobile/merchantDetail.jsp?company=1&id="+id ;
  38. $("#qrcode img").attr("src",base+"/common/qrcode?width=360&height=360&content="+escape(qrtext));
  39. });
  40. }
  41. //获取评价
  42. function getComment(){
  43. mobile.ajaxPost(base+"/userOrderComment/getList",{productId:id},function(json){
  44. if(json.success){
  45. if(json.data&&json.data.length>0){
  46. var html=[];
  47. $.each(json.data,function(id,item){
  48. if(!item.nickname){
  49. item.nickname="匿名用户";
  50. }
  51. if(!item.headimgurl){
  52. item.headimgurl=base+"static/mobile/image/avatar.png";
  53. }
  54. html.push('<li class="mui-table-view-cell mui-media">');
  55. html.push('<div class="mui-media-body">');
  56. html.push('<img class="comment-avatar mr5" src="'+item.headimgurl+'">');
  57. html.push('<div class="mui-inline lh24 mr5">'+item.nickname+'</div>');
  58. html.push('<div class="icons mui-inline lh24">');
  59. for(var i=0;i<parseInt(item.comment_rank);i++){
  60. html.push('<i class="mui-icon mui-icon-star-filled"></i>');
  61. }
  62. for(var i=0;i<5-parseInt(item.comment_rank);i++){
  63. html.push('<i class="mui-icon mui-icon-star"></i>');
  64. }
  65. html.push('</div>');
  66. html.push('<p class="color1 mb5">'+item.comment_content+'</p>');
  67. html.push('<p class="fs12">'+item.create_time+'</p>');
  68. html.push('</div>');
  69. html.push('</li>');
  70. });
  71. $("#item3 ul").html(html.join(""));
  72. }else{
  73. $("#item3").html('<div class="fs14 color2 pd15 bgcolor1">暂无评价</div>');
  74. }
  75. }else{
  76. layer.open({content: json.msg,time: 3});
  77. }
  78. },"");
  79. }
  80. function checkTime(i){ // 将0-9的数字前面加上0,例1变为01
  81. if(i<10) {
  82. i = "0" + i;
  83. }
  84. return i;
  85. }
  86. function jumpPage(event) {
  87. if (event.code==37 || event.code=="KEY_LEFT")//左
  88. fun_left();
  89. if (event.code==38 || event.code=="KEY_UP")//上
  90. fun_up();
  91. if (event.code==39 || event.code=="KEY_RIGHT" )//右
  92. fun_right();
  93. if (event.code==40 || event.code=="KEY_DOWN" )//下
  94. fun_down();
  95. if (event.code==13 || event.code=="KEY_SELECT")//enter
  96. fun_enter();
  97. if (event.code==640 || event.code=="KEY_BACK")//enter
  98. fun_back();
  99. }
  100. var h=360;
  101. function fun_left(){
  102. }
  103. function fun_right(){
  104. }
  105. function fun_up(){
  106. var p = h/($(".footer").position().top+720)*640;
  107. if($(".merchant-detail").position().top+h>0){
  108. $(".merchant-detail").css("top",'0px');
  109. $(".page-btn").css("top","0px");
  110. }else{
  111. $(".merchant-detail").css("top",$(".merchant-detail").position().top+h+'px');
  112. $(".page-btn").css("top",$(".page-btn").position().top-p+"px");
  113. }
  114. }
  115. function fun_down(){
  116. var p = h/($(".footer").position().top+720)*640;
  117. if(-($(".merchant-detail").position().top-h)+720>$(".footer").position().top){
  118. $(".merchant-detail").css("top",-$(".footer").position().top+720+"px");
  119. $(".page-btn").css("top","640px");
  120. }else{
  121. $(".merchant-detail").css("top",$(".merchant-detail").position().top-h+"px");
  122. $(".page-btn").css("top",$(".page-btn").position().top+p+"px");
  123. }
  124. }
  125. function fun_enter(){
  126. if($("#code").is(":hidden")&&$(".mui-btn").hasClass("active")){
  127. $("#main").hide();
  128. $("#code").show();
  129. }
  130. }
  131. function fun_back(){
  132. if($("#code").is(":hidden")){
  133. history.back();
  134. }else{
  135. $("#code").hide();
  136. $("#main").show();
  137. return true;
  138. }
  139. }