common.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. $(function() {
  2. var controller = $('#search ul.tab').attr('dstype');
  3. if (controller == "Storelist") {
  4. $('#search ul.tab li span').eq(0).html('店铺');
  5. $('#search ul.tab li span').eq(1).html('商品');
  6. $('#search-form').attr("action", HOMESITEURL + "/Storelist/index.html");
  7. } else {
  8. $('#search ul.tab li span').eq(0).html('商品');
  9. $('#search ul.tab li span').eq(1).html('店铺');
  10. $('#search-form').attr("action", HOMESITEURL + "/Search/index.html");
  11. }
  12. $('#search').hover(function() {
  13. $('#search ul.tab li').eq(1).show();
  14. $('#search ul.tab li i').addClass('over').removeClass('arrow');
  15. }, function() {
  16. $('#search ul.tab li').eq(1).hide();
  17. $('#search ul.tab li i').addClass('arrow').removeClass('over');
  18. });
  19. $('#search ul.tab li').eq(1).click(function() {
  20. $(this).hide();
  21. if ($(this).find('span').html() == '店铺') {
  22. $('#keyword').attr("placeholder", "请输入您要搜索的店铺关键字");
  23. $('#search ul.tab li span').eq(0).html('店铺');
  24. $('#search ul.tab li span').eq(1).html('商品');
  25. $('#search-form').attr("action", HOMESITEURL+"/Storelist/index.html");
  26. } else {
  27. $('#keyword').attr('placeholder', '请输入您要搜索的商品关键字');
  28. $('#search ul.tab li span').eq(0).html('商品');
  29. $('#search ul.tab li span').eq(1).html('店铺');
  30. $('#search-form').attr("action", HOMESITEURL+"/Search/index.html");
  31. }
  32. $("#keyword").focus();
  33. });
  34. });
  35. /**
  36. *
  37. * @param {type} formid form表单ID
  38. * @param {type} type 返回类型 reload 刷新当前界面 default 保持默认状态不做刷新
  39. * @param {type} url 跳转的连接地址
  40. * @param {type} time 跳转的时间
  41. * @returns {undefined}
  42. */
  43. function ds_ajaxpost(formid,type,url,waittime){
  44. if (typeof(waittime) == "undefined"){
  45. waittime = 1000;
  46. }
  47. var _form = $("#"+formid);
  48. $.ajax({
  49. type: "POST",
  50. url: _form.attr('action'),
  51. data: _form.serialize(),
  52. dataType:"json",
  53. success: function (res) {
  54. layer.msg(res.message, {time: waittime}, function () {
  55. if (res.code == 10000) {
  56. if (typeof (type) == 'undefined' && type == null && type == '') {
  57. location.reload();
  58. } else if(type=='url') {
  59. location.href = url;
  60. } else if(type=='default') {
  61. //不做操作只显示
  62. }else{
  63. location.reload();
  64. }
  65. }
  66. });
  67. }
  68. });
  69. }
  70. /**
  71. *
  72. * @param {type} url URL链接地址
  73. * @param {type} type 返回类型 reload remove(移除指定行) default默认不做任何操作
  74. * @param {type} param 参数
  75. * @returns {undefined}
  76. */
  77. function ds_ajaxget(url,type,param)
  78. {
  79. $.ajax({
  80. url: url,
  81. type: "get",
  82. dataType: "json",
  83. success: function (data) {
  84. layer.msg(data.message, {time: 1000}, function () {
  85. if (data.code == 10000) {
  86. if (typeof (type) == "undefined" || type == null || type == '' || type=='reload') {
  87. location.reload();
  88. } else if (type == "remove") {
  89. $("#ds_row_" + param).remove();
  90. }else {
  91. //不做操作
  92. }
  93. }
  94. });
  95. }
  96. });
  97. }
  98. /**
  99. *
  100. * @param {type} url URL链接地址
  101. * @param {type} msg 显示提示内容
  102. * @param {type} type 返回类型 reload remove(移除指定行) default默认不做任何操作
  103. * @param {type} param 参数
  104. * @returns {undefined}
  105. */
  106. function ds_ajaxget_confirm(url,msg,type,param) {
  107. if (typeof (msg) != 'undefined' && msg != null && msg != '') {
  108. layer.confirm(msg, {
  109. btn: ['确定', '取消'],
  110. title: false,
  111. }, function () {
  112. ds_ajaxget(url,type,param);
  113. });
  114. }else{
  115. ds_ajaxget(url,type,param);
  116. }
  117. }
  118. /**
  119. *
  120. * @param {type} msg 显示提示
  121. * @param {type} url 跳转URL
  122. * @returns {undefined}
  123. */
  124. function ds_get_confirm(msg, url){
  125. if(msg != ''){
  126. layer.confirm(msg, {
  127. btn: ['确定', '取消'],
  128. title: false,
  129. }, function () {
  130. window.location = url;
  131. });
  132. }else{
  133. window.location = url;
  134. }
  135. }
  136. function go(url){
  137. window.location = url;
  138. }
  139. /* 格式化金额 */
  140. function price_format(price){
  141. if(typeof(PRICE_FORMAT) == 'undefined'){
  142. PRICE_FORMAT = '¥%s';
  143. }
  144. price = number_format(price, 2);
  145. return price;
  146. }
  147. function number_format(num, ext){
  148. if(ext < 0){
  149. return num;
  150. }
  151. num = Number(num);
  152. if(isNaN(num)){
  153. num = 0;
  154. }
  155. var _str = num.toString();
  156. var _arr = _str.split('.');
  157. var _int = _arr[0];
  158. var _flt = _arr[1];
  159. if(_str.indexOf('.') == -1){
  160. /* 找不到小数点,则添加 */
  161. if(ext == 0){
  162. return _str;
  163. }
  164. var _tmp = '';
  165. for(var i = 0; i < ext; i++){
  166. _tmp += '0';
  167. }
  168. _str = _str + '.' + _tmp;
  169. }else{
  170. if(_flt.length == ext){
  171. return _str;
  172. }
  173. /* 找得到小数点,则截取 */
  174. if(_flt.length > ext){
  175. _str = _str.substr(0, _str.length - (_flt.length - ext));
  176. if(ext == 0){
  177. _str = _int;
  178. }
  179. }else{
  180. for(var i = 0; i < ext - _flt.length; i++){
  181. _str += '0';
  182. }
  183. }
  184. }
  185. return _str;
  186. }
  187. /* 火狐下取本地全路径 */
  188. function getFullPath(obj)
  189. {
  190. if(obj)
  191. {
  192. //ie
  193. if (window.navigator.userAgent.indexOf("MSIE")>=1)
  194. {
  195. obj.select();
  196. if(window.navigator.userAgent.indexOf("MSIE") == 25){
  197. obj.blur();
  198. }
  199. return document.selection.createRange().text;
  200. }
  201. //firefox
  202. else if(window.navigator.userAgent.indexOf("Firefox")>=1)
  203. {
  204. if(obj.files)
  205. {
  206. //return obj.files.item(0).getAsDataURL();
  207. return window.URL.createObjectURL(obj.files.item(0));
  208. }
  209. return obj.value;
  210. }
  211. return obj.value;
  212. }
  213. }
  214. /* 转化JS跳转中的 & */
  215. function transform_char(str)
  216. {
  217. if(str.indexOf('&'))
  218. {
  219. str = str.replace(/&/g, "%26");
  220. }
  221. return str;
  222. }
  223. //图片垂直水平缩放裁切显示
  224. (function($){
  225. $.fn.VMiddleImg = function(options) {
  226. var defaults={
  227. "width":null,
  228. "height":null
  229. };
  230. var opts = $.extend({},defaults,options);
  231. return $(this).each(function() {
  232. var $this = $(this);
  233. var objHeight = $this.height(); //图片高度
  234. var objWidth = $this.width(); //图片宽度
  235. var parentHeight = opts.height||$this.parent().height(); //图片父容器高度
  236. var parentWidth = opts.width||$this.parent().width(); //图片父容器宽度
  237. var ratio = objHeight / objWidth;
  238. if (objHeight > parentHeight && objWidth > parentWidth) {
  239. if (objHeight > objWidth) { //赋值宽高
  240. $this.width(parentWidth);
  241. $this.height(parentWidth * ratio);
  242. } else {
  243. $this.height(parentHeight);
  244. $this.width(parentHeight / ratio);
  245. }
  246. objHeight = $this.height(); //重新获取宽高
  247. objWidth = $this.width();
  248. if (objHeight > objWidth) {
  249. $this.css("top", (parentHeight - objHeight) / 2);
  250. //定义top属性
  251. } else {
  252. //定义left属性
  253. $this.css("left", (parentWidth - objWidth) / 2);
  254. }
  255. }
  256. else {
  257. if (objWidth > parentWidth) {
  258. $this.css("left", (parentWidth - objWidth) / 2);
  259. }
  260. $this.css("top", (parentHeight - objHeight) / 2);
  261. }
  262. });
  263. };
  264. })(jQuery);
  265. function ResizeImage(ImgD,FitWidth,FitHeight){
  266. var image=new Image();
  267. image.src=ImgD.src;
  268. if(image.width>0 && image.height>0)
  269. {
  270. if(image.width/image.height>= FitWidth/FitHeight)
  271. {
  272. if(image.width>FitWidth)
  273. {
  274. ImgD.width=FitWidth;
  275. ImgD.height=(image.height*FitWidth)/image.width;
  276. }
  277. else
  278. {
  279. ImgD.width=image.width;
  280. ImgD.height=image.height;
  281. }
  282. }
  283. else
  284. {
  285. if(image.height>FitHeight)
  286. {
  287. ImgD.height=FitHeight;
  288. ImgD.width=(image.width*FitHeight)/image.height;
  289. }
  290. else
  291. {
  292. ImgD.width=image.width;
  293. ImgD.height=image.height;
  294. }
  295. }
  296. }
  297. }
  298. function trim(str) {
  299. return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
  300. }
  301. //弹出框登录
  302. function login_dialog(){
  303. CUR_DIALOG = ajax_form('login','登录',HOMESITEURL+'/Login/login.html?inajax=1',360,1);
  304. }
  305. /* 显示Ajax表单 */
  306. function ajax_form(id, title, url, width, model)
  307. {
  308. if (!width) width = 480;
  309. if (!model) model = 1;
  310. var d = DialogManager.create(id);
  311. d.setTitle(title);
  312. d.setContents('ajax', url);
  313. d.setWidth(width);
  314. d.show('center',model);
  315. return d;
  316. }
  317. //显示一个内容为自定义HTML内容的消息
  318. function html_form(id, title, _html, width, model) {
  319. if (!width) width = 480;
  320. if (!model) model = 0;
  321. var d = DialogManager.create(id);
  322. d.setTitle(title);
  323. d.setContents(_html);
  324. d.setWidth(width);
  325. d.show('center',model);
  326. return d;
  327. }
  328. //收藏店铺js
  329. function collect_store(fav_id, jstype, jsobj) {
  330. $.get(HOMESITEURL+'/Index/login', function(result) {
  331. if (result == '0') {
  332. login_dialog();
  333. } else {
  334. var url = HOMESITEURL+'/Memberfavorites/favoritesstore';
  335. $.getJSON(url, {'fid': fav_id}, function(data) {
  336. if (data.done) {
  337. layer.msg(data.msg);
  338. if (jstype == 'count') {
  339. $('[dstype="' + jsobj + '"]').each(function() {
  340. $(this).html(parseInt($(this).text()) + 1);
  341. });
  342. }
  343. if (jstype == 'succ') {
  344. $('[dstype="' + jsobj + '"]').each(function() {
  345. $(this).html("收藏成功");
  346. });
  347. }
  348. if (jstype == 'store') {
  349. $('[ds_store="' + fav_id + '"]').each(function() {
  350. $(this).before('<span class="goods-favorite" title="该店铺已收藏"><i class="have">&nbsp;</i></span>');
  351. $(this).remove();
  352. });
  353. }
  354. }
  355. else
  356. {
  357. layer.msg(data.msg);
  358. }
  359. });
  360. }
  361. });
  362. }
  363. //收藏商品js
  364. function collect_goods(fav_id, jstype, jsobj) {
  365. $.get(HOMESITEURL+'/Index/login.html', function(result) {
  366. if (result == '0') {
  367. login_dialog();
  368. } else {
  369. var url = HOMESITEURL+'/Memberfavorites/favoritesgoods';
  370. $.getJSON(url, {'fid': fav_id}, function(data) {
  371. if (data.done)
  372. {
  373. layer.msg(data.msg);
  374. if (jstype == 'count') {
  375. $('[dstype="' + jsobj + '"]').each(function() {
  376. $(this).html(parseInt($(this).text()) + 1);
  377. });
  378. }
  379. if (jstype == 'succ') {
  380. $('[dstype="' + jsobj + '"]').each(function() {
  381. $(this).html("收藏成功");
  382. });
  383. }
  384. }
  385. else
  386. {
  387. layer.msg(data.msg);
  388. }
  389. });
  390. }
  391. });
  392. }
  393. //加载购物车信息
  394. function load_cart_information() {
  395. $.getJSON(HOMESITEURL + '/Cart/ajax_load', function(result) {
  396. var obj = $('.header .user_menu .my-cart');
  397. var mini =$('#rtoolbar_cartlist');
  398. if (result) {
  399. var html = '';
  400. if (result.cart_goods_num > 0) {
  401. for (var i in result['list']) {
  402. var goods = result['list'][i];
  403. html += '<dl id="cart_item_' + goods['cart_id'] + '"><dt class="goods-name"><a href="' + goods['goods_url'] + '">' + goods['goods_name'] + '</a></dt>';
  404. html += '<dd class="goods-thumb"><a href="' + goods['goods_url'] + '" title="' + goods['goods_name'] + '"><img src="' + goods['goods_image'] + '"></a></dd>';
  405. html += '<dd class="goods-sales"></dd>';
  406. html += '<dd class="goods-price"><em>&yen;' + goods['goods_price'] + '×' + goods['goods_num'] + '</dd>';
  407. html += '<dd class="handle"><a href="javascript:void(0);" onClick="drop_topcart_item(' + goods['cart_id'] + ',' + goods['goods_id'] + ');">删除</a></dd>';
  408. html += "</dl>";
  409. }
  410. obj.find('.incart-goods').html(html);
  411. obj.find('.incart-goods-box').perfectScrollbar('destroy');
  412. obj.find('.incart-goods-box').perfectScrollbar({suppressScrollX: true});
  413. html = "共<i>" + result.cart_goods_num + "</i>种商品&nbsp;&nbsp;总计金额:<em>&yen;" + result.cart_all_price + "</em>";
  414. obj.find('.total-price').html(html);
  415. mini.find('.total-price').html('<p>共<em class="goods-price" style="margin-left: 5px">' + result.cart_goods_num + '</em>种商品</p><p>共计:<em class="goods-price">&yen;' + result.cart_all_price + '</em></p>');
  416. if (obj.find('.addcart-goods-num').size() == 0) {
  417. obj.append('<div class="addcart-goods-num">0</div>');
  418. }
  419. obj.find('.addcart-goods-num').html(result.cart_goods_num);
  420. $('#rtoobar_cart_count').html(result.cart_goods_num).show();
  421. } else {
  422. html = "<div class='no-order'><span>您的购物车中暂无商品,赶快选择心爱的商品吧!</span></div>";
  423. obj.find('.incart-goods').html(html);
  424. mini.find('.total-price').html(html);
  425. obj.find('.total-price').html('');
  426. if (obj.find('.addcart-goods-num').size() == 0) {
  427. obj.append('<div class="addcart-goods-num">0</div>');
  428. }
  429. obj.find('.addcart-goods-num').html(result.cart_goods_num);
  430. $('#rtoobar_cart_count').html('').hide();
  431. }
  432. }
  433. });
  434. }
  435. //头部删除购物车信息,登录前使用goods_id,登录后使用cart_id
  436. function drop_topcart_item(cart_id, goods_id) {
  437. $.getJSON(HOMESITEURL + '/Cart/del',{'cart_id': cart_id, 'goods_id': goods_id}, function(result) {
  438. if (result.state == 'true') {
  439. $("[ds_type='cart_item_"+cart_id+"']").remove();
  440. load_cart_information();
  441. } else {
  442. alert(result.msg);
  443. }
  444. });
  445. }
  446. //加载最近浏览的商品
  447. function load_history_information(){
  448. $.getJSON(HOMESITEURL+'/Index/viewed_info.html', function(result){
  449. var obj = $('.header .user_menu .my-mall');
  450. if(result['m_id'] >0){
  451. if (typeof result['consult'] !== 'undefined') obj.find('#member_consult').html(result['consult']);
  452. if (typeof result['consult'] !== 'undefined') obj.find('#member_voucher').html(result['voucher']);
  453. }
  454. var goods_id = 0;
  455. var text_append = '';
  456. var n = 0;
  457. if (typeof result['viewed_goods'] !== 'undefined') {
  458. for (goods_id in result['viewed_goods']) {
  459. var goods = result['viewed_goods'][goods_id];
  460. text_append += '<li class="goods-thumb"><a href="'+goods['url']+'" title="'+goods['goods_name']+
  461. '" target="_blank"><img src="'+goods['goods_image']+'" alt="'+goods['goods_name']+'"></a>';
  462. text_append += '</li>';
  463. n++;
  464. if (n > 4) break;
  465. }
  466. }
  467. if (text_append == '') text_append = '<li class="no-goods">暂无商品</li>';;
  468. obj.find('.browse-history ul').html(text_append);
  469. });
  470. }
  471. /*
  472. * 弹出窗口
  473. */
  474. (function($) {
  475. $.fn.ds_show_dialog = function(options) {
  476. var that = $(this);
  477. var settings = $.extend({}, {width: 480, title: '', close_callback: function() {}}, options);
  478. var init_dialog = function(title) {
  479. var _div = that;
  480. that.addClass("dialog_wrapper");
  481. that.wrapInner(function(){
  482. return '<div class="dialog_content">';
  483. });
  484. that.wrapInner(function(){
  485. return '<div class="dialog_body" style="position: relative;">';
  486. });
  487. that.find('.dialog_body').prepend('<h3 class="dialog_head" style="cursor: move;"><span class="dialog_title"><span class="dialog_title_icon">'+settings.title+'</span></span><span class="dialog_close_button">X</span></h3>');
  488. that.append('<div style="clear:both;"></div>');
  489. $(".dialog_close_button").click(function(){
  490. settings.close_callback();
  491. _div.hide();
  492. });
  493. that.draggable({handle: ".dialog_head"});
  494. };
  495. if(!$(this).hasClass("dialog_wrapper")) {
  496. init_dialog(settings.title);
  497. }
  498. settings.left = $(window).scrollLeft() + ($(window).width() - settings.width) / 2;
  499. settings.top = ($(window).height() - $(this).height()) / 2;
  500. $(this).attr("style","display:none; z-index: 1100; position: fixed; width: "+settings.width+"px; left: "+settings.left+"px; top: "+settings.top+"px;");
  501. $(this).show();
  502. };
  503. })(jQuery);
  504. /**
  505. * Membership card
  506. *
  507. *
  508. * Example:
  509. *
  510. * HTML part
  511. * <a href="javascript" dstype="mcard" data-param="{'id':5}"></a>
  512. *
  513. * JAVASCRIPT part
  514. * <script type="text/javascript" src="<?php echo HOME_SITE_ROOT;?>/js/qtip/jquery.qtip.min.js"></script>
  515. * <link href="<?php echo HOME_SITE_ROOT;?>/js/qtip/jquery.qtip.min.css" rel="stylesheet" type="text/css">
  516. * $('a[dstype="mcard"]').membershipCard();
  517. */
  518. (function($){
  519. $.fn.membershipCard = function(options){
  520. var defaults = {
  521. type:''
  522. };
  523. options = $.extend(defaults,options);
  524. return this.each(function(){
  525. var $this = $(this);
  526. var data_str = $(this).attr('data-param');eval('data_str = '+data_str);
  527. var _uri = HOMESITEURL+'/Membercard/index.html?callback=?&uid='+data_str.id+'&from='+options.type;
  528. $this.qtip({
  529. content: {
  530. text: 'Loading...',
  531. ajax: {
  532. url: _uri,
  533. type: 'GET',
  534. dataType: 'jsonp',
  535. success: function(data) {
  536. if(data){
  537. var _dl = $('<dl></dl>');
  538. // sex
  539. $('<dt class="member-id"></dt>').append('<i class="sex'+data.sex+'"></i>')
  540. .append('<a href="javascript:void(0)" target="_blank">'+data.name+'</a>'+(data.nickname != ''?'('+data.nickname+')':''))
  541. .appendTo(_dl);
  542. // avatar
  543. $('<dd class="avatar"><a href="javascript:void(0)" target="_blank"><img src="'+data.avatar+'" /></a><dd>')
  544. .appendTo(_dl);
  545. // info
  546. var _info = '';
  547. if(typeof connect !== 'undefined' && connect === 1 && data.follow != 2){
  548. var class_html = 'chat_offline';
  549. var text_html = '离线';
  550. if (typeof user_list[data.id] !== 'undefined' && user_list[data.id]['online'] > 0 ) {
  551. class_html = 'chat_online';
  552. text_html = '在线';
  553. }
  554. _info += '<a class="chat '+class_html+'" title="点击这里给我发消息" href="JavaScript:chat('+data.id+');">'+text_html+'</a>';
  555. }
  556. if(data.qq != ''){
  557. _info += '<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin='+data.qq+'&site=qq&menu=yes" title="QQ: '+data.qq+'"><img border="0" src="http://wpa.qq.com/pa?p=2:'+data.qq+':52" style=" vertical-align: middle;"/></a>';
  558. }
  559. if(data.ww != ''){
  560. _info += '<a target="_blank" href="http://amos.im.alisoft.com/msg.aw?v=2&amp;uid='+data.ww+'&site=cntaobao&s=1" ><img border="0" src="http://amos.im.alisoft.com/online.aw?v=2&uid='+data.ww+'&site=cntaobao&s=2" alt="点击这里给我发消息" style=" vertical-align: middle;"/></a>';
  561. }
  562. if(_info == ''){
  563. _info = '--';
  564. }
  565. var _ul = $('<ul></ul>').append('<li>城市:'+((data.areainfo != null)?data.areainfo:'--')+'</li>')
  566. .append('<li>生日:'+((data.birthday != null)?data.birthday:'--')+'</li>')
  567. .append('<li>联系:'+_info+'</li>').appendTo('<dd class="info"></dd>').parent().appendTo(_dl);
  568. // ajax info
  569. if(data.url != ''){
  570. $.getJSON(data.url+'/Membercard/mcard_info.html?uid='+data.id, function(d){
  571. if(d){
  572. eval('var msg = '+options.type+'_function(d);');
  573. msg.appendTo(_dl);
  574. }
  575. });
  576. data.url = '';
  577. }
  578. // bottom
  579. var _bottom;
  580. if(data.follow != 2){
  581. _bottom = $('<div class="bottom"></div>');
  582. var _a;
  583. if(data.follow == 1){
  584. $('<div class="follow-handle" dstype="follow-handle'+data.id+'" data-param="{\'mid\':'+data.id+'}"></div>')
  585. .append('<a href="javascript:void(0);" >已关注</a>')
  586. .append('<a href="javascript:void(0);" dstype="nofollow">取消关注</a>').find('a[dstype="nofollow"]').click(function(){
  587. onfollow($(this));
  588. }).end().appendTo(_bottom);
  589. }else{
  590. $('<div class="follow-handle" dstype="follow-handle'+data.id+'" data-param="{\'mid\':'+data.id+'}"></div>')
  591. .append('<a href="javascript:void(0);" dstype="follow">加关注</a>').find('a[dstype="follow"]').click(function(){
  592. follow($(this));
  593. }).end().appendTo(_bottom);
  594. }
  595. $('<div class="send-msg"> <a href="'+HOMESITEURL+'/Membermessage/sendmsg.html?member_id='+data.id+'" target="_blank"><i></i>站内信</a> </div>').appendTo(_bottom);
  596. }
  597. var _content = $('<div class="member-card"></div>').append(_dl).append(_bottom);
  598. this.set('content.text', ' ');this.set('content.text', _content);
  599. }
  600. }
  601. }
  602. },
  603. position: {
  604. viewport: $(window)
  605. },
  606. hide: {
  607. fixed: true,
  608. delay: 300
  609. },
  610. style: 'qtip-wiki'
  611. });
  612. });
  613. function follow(o){
  614. var data_str = o.parent().attr('data-param');
  615. eval( "data_str = "+data_str);
  616. $.getJSON(HOMESITEURL+'/Membersnsfriend/addfollow.html?callback=?&mid='+data_str.mid, function(data){
  617. if(data.code==10000){
  618. $('[dstype="follow-handle'+data_str.mid+'"]').html('<a href="javascript:void(0);" >已关注</a> <a href="javascript:void(0);" dstype="nofollow">取消关注</a>').find('a[dstype="nofollow"]').click(function(){
  619. onfollow($(this));
  620. });
  621. }
  622. });
  623. }
  624. function onfollow(o){
  625. var data_str = o.parent().attr('data-param');
  626. eval( "data_str = "+data_str);
  627. $.getJSON(HOMESITEURL+'/Membersnsfriend/delfollow.html?callback=?&mid='+data_str.mid, function(data){
  628. if(data.code==10000){
  629. $('[dstype="follow-handle'+data_str.mid+'"]').html('<a href="javascript:void(0);" dstype="follow">加关注</a>').find('a[dstype="follow"]').click(function(){
  630. follow($(this));
  631. });
  632. }
  633. });
  634. }
  635. function shop_function(d){
  636. return $('<dd class="ajax-info">买家信用:'+((d.member_credit == 0)?'暂无信用':d.member_credit)+'</dd>');
  637. }
  638. };
  639. })(jQuery);
  640. (function($) {
  641. $.fn.ds_region = function(options) {
  642. var $region = $(this);
  643. var settings = $.extend({}, {
  644. area_id: 0,
  645. region_span_class: "_region_value",
  646. src: "cache",
  647. show_deep: 0,
  648. btn_style_html: "",
  649. tip_type: ""
  650. }, options);
  651. settings.islast = false;
  652. settings.selected_deep = 0;
  653. settings.last_text = "";
  654. this.each(function() {
  655. var $inputArea = $(this);
  656. if ($inputArea.val() === "") {
  657. initArea($inputArea)
  658. } else {
  659. var $region_span = $('<span id="_area_span" class="' + settings.region_span_class + '">' + $inputArea.val() + "</span>");
  660. var $region_btn = $('<input type="button" class="input-btn" ' + settings.btn_style_html + ' value="编辑" />');
  661. $inputArea.after($region_span);
  662. $region_span.after($region_btn);
  663. $region_btn.on("click", function() {
  664. $region_span.remove();
  665. $region_btn.remove();
  666. initArea($inputArea)
  667. });
  668. settings.islast = true
  669. }
  670. this.settings = settings;
  671. if ($inputArea.val() && /^\d+$/.test($inputArea.val())) {
  672. $.getJSON(HOMESITEURL + "/Index/json_area_show?area_id=" + $inputArea.val() + "&callback=?", function(data) {
  673. $("#_area_span").html(data.text == null ? "无" : data.text)
  674. })
  675. }
  676. });
  677. function initArea($inputArea) {
  678. settings.$area = $("<select></select>");
  679. $inputArea.before(settings.$area);
  680. loadAreaArray(function() {
  681. loadArea(settings.$area, settings.area_id)
  682. })
  683. }
  684. function loadArea($area, area_id) {
  685. if ($area && ds_a[area_id].length > 0) {
  686. var areas = [];
  687. areas = ds_a[area_id];
  688. if (settings.tip_type && settings.last_text != "") {
  689. $area.append("<option value=''>" + settings.last_text + "(*)</option>")
  690. } else {
  691. $area.append("<option value=''>-请选择-</option>")
  692. }
  693. for (i = 0; i < areas.length; i++) {
  694. $area.append("<option value='" + areas[i][0] + "'>" + areas[i][1] + "</option>")
  695. }
  696. settings.islast = false
  697. }
  698. $area.on("change", function() {
  699. var region_value = "",
  700. area_ids = [],
  701. selected_deep = 1;
  702. $(this).nextAll("select").remove();
  703. $region.parent().find("select").each(function() {
  704. if ($(this).find("option:selected").val() != "") {
  705. region_value += $(this).find("option:selected").text() + " ";
  706. area_ids.push($(this).find("option:selected").val())
  707. }
  708. });
  709. settings.selected_deep = area_ids.length;
  710. settings.area_ids = area_ids.join(" ");
  711. $region.val(region_value);
  712. settings.area_id_1 = area_ids[0] ? area_ids[0] : "";
  713. settings.area_id_2 = area_ids[1] ? area_ids[1] : "";
  714. settings.area_id_3 = area_ids[2] ? area_ids[2] : "";
  715. settings.area_id_4 = area_ids[3] ? area_ids[3] : "";
  716. settings.last_text = $region.prevAll("select").find("option:selected").last().text();
  717. var area_id = settings.area_id = $(this).val();
  718. if ($('#_area_1').length > 0) $("#_area_1").val(settings.area_id_1);
  719. if ($('#_area_2').length > 0) $("#_area_2").val(settings.area_id_2);
  720. if ($('#_area_3').length > 0) $("#_area_3").val(settings.area_id_3);
  721. if ($('#_area_4').length > 0) $("#_area_4").val(settings.area_id_4);
  722. if ($('#_area').length > 0) $("#_area").val(settings.area_id);
  723. if ($('#_areas').length > 0) $("#_areas").val(settings.area_ids);
  724. if (settings.show_deep > 0 && $region.prevAll("select").size() == settings.show_deep) {
  725. settings.islast = true;
  726. if (typeof settings.last_click == 'function') {
  727. settings.last_click(area_id);
  728. }
  729. return
  730. }
  731. if (area_id > 0) {
  732. if (ds_a[area_id] && ds_a[area_id].length > 0) {
  733. var $newArea = $("<select></select>");
  734. $(this).after($newArea);
  735. loadArea($newArea, area_id);
  736. settings.islast = false
  737. } else {
  738. settings.islast = true;
  739. if (typeof settings.last_click == 'function') {
  740. settings.last_click(area_id);
  741. }
  742. }
  743. } else {
  744. settings.islast = false
  745. }
  746. if ($('#islast').length > 0) $("#islast").val("");
  747. })
  748. }
  749. function loadAreaArray(callback) {
  750. if (typeof ds_a === "undefined") {
  751. $.getJSON(HOMESITEURL + "/Index/json_area.html?src=" + settings.src + "&callback=?", function(data) {
  752. ds_a = data;
  753. callback()
  754. })
  755. } else {
  756. callback()
  757. }
  758. }
  759. if (typeof jQuery.validator != 'undefined') {
  760. jQuery.validator.addMethod("checklast", function(value, element) {
  761. return $(element).fetch('islast');
  762. }, "请将地区选择完整");
  763. }
  764. };
  765. $.fn.fetch = function(k) {
  766. var p;
  767. this.each(function() {
  768. if (this.settings) {
  769. p = eval("this.settings." + k);
  770. return false
  771. }
  772. });
  773. return p
  774. }
  775. })(jQuery);
  776. /* 加入购物车 */
  777. function addcart(goods_id, quantity, callbackfunc,dir) {
  778. var url = HOMESITEURL + '/Cart/add.html';
  779. quantity = parseInt(quantity);
  780. $.getJSON(url, {'goods_id': goods_id, 'quantity': quantity}, function(data) {
  781. if (data != null) {
  782. if (data.state) {
  783. if (callbackfunc) {
  784. eval(callbackfunc + "(data)");
  785. }
  786. // 头部加载购物车信息
  787. load_cart_information();
  788. $("#rtoolbar_cartlist").load(HOMESITEURL + '/Cart/ajax_load?type=html');
  789. if(dir) {
  790. layer.msg('添加购物车成功');
  791. }
  792. } else {
  793. layer.msg(data.msg);
  794. }
  795. }
  796. });
  797. }
  798. function setCookie(name, value, days) {
  799. var exp = new Date();
  800. exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
  801. var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  802. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  803. }
  804. function getCookie(name) {
  805. var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  806. if (arr != null) {
  807. return unescape(arr[2]);
  808. return null;
  809. }
  810. }
  811. function delCookie(name) {
  812. var exp = new Date();
  813. exp.setTime(exp.getTime() - 1);
  814. var cval = getCookie(name);
  815. if (cval != null) {
  816. document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  817. }
  818. }
  819. (function($) {
  820. $.fn.F_slider = function(options){
  821. var defaults = {
  822. page : 1,
  823. len : 0, // 滚动篇幅
  824. axis : 'y' // y为上下滚动,x为左右滚动
  825. }
  826. var options = $.extend(defaults,options);
  827. return this.each(function(){
  828. var $this = $(this);
  829. var len = options.len;
  830. var page = options.page;
  831. if(options.axis == 'y'){
  832. var Val = $(this).find('.F-center').height();
  833. var Param = 'top';
  834. }else if(options.axis == 'x'){
  835. var Val = $(this).find('.F-center').parent().width();
  836. var Param = 'left';
  837. }
  838. $this.find('.F-prev').click(function(){
  839. if( page == 1){
  840. eval("$this.find('.F-center').animate({"+Param+":'-=' + Val*(len-1)},'slow');");
  841. page=len;
  842. }else{
  843. eval("$this.find('.F-center').animate({"+Param+":'+=' + Val},'slow');");
  844. page--;
  845. }
  846. });
  847. $this.find('.F-next').click(function(){
  848. if(page == len){
  849. eval("$this.find('.F-center').animate({"+Param+":0},'slow');");
  850. page=1;
  851. }else{
  852. eval("$this.find('.F-center').animate({"+Param+":'-=' + Val},'show');");
  853. page++;
  854. }
  855. });
  856. });
  857. }
  858. })(jQuery);