common.js 35 KB

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