base.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. var coreServer = $("#coreServer").val();
  2. var isPC = ($(window).width()>768);
  3. var globalUserData = '';
  4. var GLOBAL_TOKEN = 'X-Token';
  5. var GLOBAL_USER_ID = 0;
  6. var GLOBAL_USER_IDENTITY = 0;//2-会员机构;3-供应商;4-普通机构
  7. var GLOBAL_SHOP_ID = 0;
  8. var GLOBAL_VIP_FLAG = 0;
  9. if(localStorage.getItem('userInfo')){
  10. globalUserData = JSON.parse(localStorage.getItem('userInfo'));
  11. GLOBAL_TOKEN = globalUserData.token;
  12. GLOBAL_USER_ID = globalUserData.userId*1;
  13. GLOBAL_USER_IDENTITY = globalUserData.userIdentity*1;
  14. GLOBAL_VIP_FLAG = globalUserData.vipFlag;
  15. GLOBAL_SHOP_ID = globalUserData.shopId*1;
  16. if (GLOBAL_USER_ID === 5261 || GLOBAL_USER_ID === 10947 || GLOBAL_USER_ID === 11579) {
  17. GLOBAL_USER_IDENTITY = 1;
  18. }
  19. } else {
  20. var pathname = window.location.pathname;
  21. var weChatLoginFlag = (Number(getBaseCookie("weChatAutoLogin"))===1 || Number(getBaseCookie("weChatAutoLogin"))===2);
  22. if(pathname.indexOf('/product/auth/') === -1 && !weChatLoginFlag ){
  23. var userAgent = navigator.userAgent.toLowerCase();
  24. if (userAgent.match(/MicroMessenger/i)) {
  25. // 微信浏览器自动授权登录
  26. var urlForWeChat = 'https://www.caimei365.com/we_chat/redirect_uri.html';
  27. $.get(coreServer+'/user/login/auth/link?mode=1&redirectUri='+urlForWeChat, function(r){
  28. if(r.code===0 && r.data){
  29. setBaseCookie("weChatAutoLogin", 1);
  30. setBeforeUrl();
  31. window.location.href = r.data;
  32. }
  33. });
  34. }
  35. }
  36. }
  37. // 头部
  38. var globalHead = new Vue({
  39. el: '#globalHead',
  40. data: {
  41. loginStatus: false,
  42. userData: {},
  43. classify: [],
  44. headCart: {
  45. cartList: [],
  46. cartCount: 0,
  47. productCount: 0,
  48. priceTotal: 0
  49. },
  50. shopId:'',
  51. userIdentity:'',
  52. articleType: '',
  53. isFiexd:false,
  54. classifyIndex:1
  55. },
  56. methods: {
  57. changeClassify: function(value){
  58. this.classifyIndex=value;
  59. },
  60. // 初始化分类菜单效果
  61. initClassufyTab: function(){
  62. if(isPC){
  63. setTimeout(function(){
  64. $('#mainClassify').slide({
  65. mainCell:".clsCon",
  66. titCell:".clsTab a",
  67. trigger: "mouseover"
  68. });
  69. $('#mainClassify_1').slide({
  70. mainCell:".tabItem_right",
  71. titCell:".tabItem_lift a",
  72. trigger: "mouseover"
  73. });
  74. $('#mainClassify_2').slide({
  75. mainCell:".tabItem_right",
  76. titCell:".tabItem_lift a",
  77. trigger: "mouseover"
  78. });
  79. $("#mainClassify_2 .tabItem_lift a").eq(0).trigger("mouseover");
  80. $("#mainClassify_1 .tabItem_lift a").eq(0).trigger("mouseover");
  81. },500);
  82. }else{
  83. setTimeout(function(){
  84. $('#mainClassify').slide({
  85. mainCell:".clsCon",
  86. titCell:".clsTab a",
  87. trigger: "click"
  88. });
  89. $('#mainClassify_1').slide({
  90. mainCell:".tabItem_right",
  91. titCell:".tabItem_lift a",
  92. trigger: "click"
  93. });
  94. $('#mainClassify_2').slide({
  95. mainCell:".tabItem_right",
  96. titCell:".tabItem_lift a",
  97. trigger: "click"
  98. });
  99. $("#mainClassify_2 .tabItem_lift a").eq(0).trigger("click");
  100. $("#mainClassify_1 .tabItem_lift a").eq(0).trigger("click");
  101. },500);
  102. }
  103. },
  104. // 头部购物车数据
  105. getHeadCart: function(userId) {
  106. var _self = this;
  107. ShoppingApi.getHeaderCartList({userId: userId},function(response){
  108. if (response.code === 0 && response.data) {
  109. var data = response.data;
  110. _self.headCart.cartList = data.list;
  111. _self.headCart.cartCount = data.list.length;
  112. _self.headCart.productCount = 0;
  113. _self.headCart.priceTotal = 0;
  114. data.list.map(function(item){
  115. _self.headCart.productCount += item.number;
  116. _self.headCart.priceTotal += item.number*item.price;
  117. });
  118. }else if(r.code== -99){
  119. CAIMEI.Storage.clear();
  120. location.href = "/login.html";
  121. }
  122. });
  123. },
  124. goCartsLinkFn:function(){
  125. var _self = this;
  126. if(_self.loginStatus){
  127. window.location.href='/shopping/cart.html';
  128. }else{
  129. window.location.href='/login.html';
  130. }
  131. },
  132. productDetailsFn:function(id){ // 跳转详情
  133. window.location.href='/product-'+id+'.html';
  134. },
  135. DeleteCartProducts:function(id){ // 删除购物车
  136. var _self = this;
  137. ShoppingApi.DeleteCartProducts({userId: this.userData.userId, productIds: id},function(response){
  138. if(response.code === 0){
  139. _self.getHeadCart(_self.userData.userId);
  140. }else{
  141. CAIMEI.Alert(response.msg,'确定',false);
  142. }
  143. });
  144. },
  145. pageLinkSupplier: function(){//预览商品
  146. window.open('/supplier-'+this.shopId+'.html');
  147. },
  148. // 退出登录
  149. userLogOut: function(){
  150. localStorage.removeItem('userInfo');
  151. delBaseCookie("loginBeforePath");
  152. this.loginStatus = false;
  153. window.location.href = "/index.html";
  154. },
  155. showGlobalMenu: function(){
  156. if(!isPC){
  157. $("#mGlobalMenu").show().find(".cShow").slideDown(500);
  158. }
  159. },
  160. hideGlobalMenu: function(){
  161. if(!isPC){
  162. $("#mGlobalMenu").hide().find(".cShow").hide();
  163. }
  164. }
  165. },
  166. created: function () {
  167. // 判断登录状态
  168. if (globalUserData.token) {
  169. this.loginStatus = true;
  170. this.userData = globalUserData;
  171. var userId = this.userData.userId;
  172. if(userId){
  173. var _self = this;
  174. // 获取头部购物车数据
  175. setTimeout(function(){
  176. _self.getHeadCart(userId);
  177. }, 1000);
  178. }
  179. }
  180. // 信息中心
  181. this.articleType = getUrlParam("type");
  182. },
  183. mounted:function(){
  184. var _self = this;
  185. // 初始化分类菜单效果
  186. this.initClassufyTab();
  187. var userData = JSON.parse(window.localStorage.getItem('userInfo'));
  188. if(userData!=null) {
  189. this.userIdentity = userData.userIdentity;
  190. this.shopId = userData.shopId;
  191. }
  192. if($(window).height() > 750){
  193. $(window).on('scroll', function() {
  194. var scrollTop = $(this).scrollTop();
  195. if(scrollTop>200){
  196. _self.isFiexd = true;
  197. }else{
  198. _self.isFiexd = false;
  199. }
  200. })
  201. }
  202. // 判断导航菜单高亮-对比url
  203. setTimeout(function(){
  204. var path = window.location.pathname;
  205. var paramsArr = path.split(".")[0].split("-");
  206. var key = paramsArr[0].split("/")[1];
  207. var pageId = paramsArr.length>=1 ? paramsArr[1] : '';
  208. if(key && key.length>0) {
  209. $('.navBox li').each(function () {
  210. var href = $(this).find('a').attr("href");
  211. if (href.indexOf(path)>=0){
  212. $(this).find('a').addClass('on');
  213. return false;
  214. } else if (key != 'product' && key != 'info' && href.indexOf('/'+key)>=0) {
  215. $(this).find('a').addClass('on');
  216. return false;
  217. }
  218. });
  219. }
  220. },500);
  221. }
  222. });
  223. // 初始化效果
  224. $(function(){
  225. // PC,H5切换时刷新
  226. $(window).resize(function() {
  227. var flag = (isPC && $(window).width()<=768) || (!isPC && $(window).width()>768);
  228. if(flag){
  229. window.location.reload();
  230. }
  231. });
  232. // 导航分类
  233. if(isPC){
  234. jqClickShow(".baseHeadTop .cTab", ".baseHeadTop .cShow");
  235. jqSelect(".jqSelect");
  236. jqHoverShow(".classBtn", "#mainClassify");
  237. }else{
  238. jqMultipleShow("click", ".footLink .list", ".tab", ".con", true);
  239. $('body').on('click', '.baseHeadCenter .mClassBtn',function () {
  240. $('#mainClassify').show();
  241. fixedBody();
  242. }).on('click', '#mainClassify .close,#mainClassify .mClassBtn',function () {
  243. $('#mainClassify').hide();
  244. looseBody();
  245. }).on('click', '#mainClassify',function (e) {
  246. e.stopPropagation();
  247. });
  248. }
  249. // 登录弹窗
  250. function loginAert(content, btnTxt){
  251. $.confirm({
  252. useBootstrap: false,
  253. boxWidth: (isPC?'338px':'74.6vw'),
  254. title: false,
  255. content:'<div class="loginAlert">'+content+'</div>',
  256. closeIcon: true,
  257. animation: 'opacity',
  258. closeAnimation: 'opacity',
  259. animateFromElement: false,
  260. scrollToPreviousElement: false,
  261. buttons: {
  262. login: {
  263. text: btnTxt,
  264. btnClass: 'btn-confirm-login',
  265. action: function(){
  266. setBeforeUrl();
  267. window.location.href = '/login.html';
  268. }
  269. },
  270. close: {
  271. text: '取消',
  272. btnClass: 'btn-cancel-login'
  273. }
  274. }
  275. });
  276. }
  277. // 去登录弹窗
  278. $('body').on("click", '.toLogin',function () {
  279. //loginAert('<span>你还未登录</span><span>请登录后再进行购买</span>', '去登录');
  280. setBeforeUrl();
  281. window.location.href = '/login.html';
  282. });
  283. // 退出登录
  284. $('body').on("click", '.toLogOut',function () {
  285. localStorage.removeItem('userInfo');
  286. delBaseCookie("loginBeforePath");
  287. globalHead.loginStatus = false;
  288. window.location.href = "/index.html";
  289. });
  290. // 置顶
  291. $('#scrollTop').on("click", '.toTop',function () {
  292. $("html,body").animate({scrollTop:0},500);
  293. });
  294. // 热线
  295. if(!isPC){
  296. $('#scrollTop').on("click", '.phone',function () {
  297. $('#scrollTop').find('.phoneHover').show();
  298. fixedBody();
  299. }).on("click", '.phoneHover div',function (e) {
  300. e.stopPropagation();
  301. }).on("click", '.phoneHover,.phoneHover .close',function () {
  302. $('#scrollTop').find('.phoneHover').hide();
  303. looseBody();
  304. });
  305. $('body').on("click", '#centerNav .home',function () {
  306. if($('#centerNav').find('.home').hasClass("on")){
  307. $('#centerNav').find('.home').removeClass("on");
  308. $('#centerNav').find('.centerBox').slideUp();
  309. looseBody();
  310. }else{
  311. $('#centerNav').find('.home').addClass("on");
  312. $('#centerNav').find('.centerBox').slideDown();
  313. fixedBody();
  314. }
  315. }).on("click", '#centerNav .wrap',function (e) {
  316. e.stopPropagation();
  317. }).on("click", '#centerNav .centerBox',function () {
  318. $('#centerNav').find('.home').removeClass("on");
  319. $('#centerNav').find('.centerBox').slideUp();
  320. looseBody();
  321. });
  322. }
  323. // 侧边栏滚动判断
  324. $(window).scroll(function () {
  325. if($('body').attr("style") && $('body').attr("style").indexOf('fixed')>0){
  326. return false;
  327. }
  328. var scoll = Math.max($('html').scrollTop(), $('body').scrollTop());
  329. if(scoll >200){
  330. $('#scrollTop').show();
  331. }else {
  332. $('#scrollTop').hide();
  333. }
  334. });
  335. // 顶部搜索框
  336. $('#topSearch').on("click", '.searchBtn', function(){
  337. var type = isPC ? $('#topSearch').find('[data-select]').attr("data-select")*1 : $('#topSearch').find('select').val()*1;
  338. var keyword = $.trim($('#topSearch').find('.keyword').val());
  339. // 商品,文章
  340. if (keyword.length < 2 && (type === 0 || type > 2)) {
  341. $.confirm({
  342. useBootstrap: false,
  343. boxWidth: (isPC?'300px':'70%'),
  344. title:'提示',
  345. content:'请至少输入两个关键字!',
  346. closeIcon: true,
  347. animation: 'opacity',
  348. closeAnimation: 'opacity',
  349. animateFromElement: false,
  350. buttons: {
  351. close: {
  352. text: '确定',
  353. btnClass: 'btn-confirm'
  354. }
  355. }
  356. });
  357. return false;
  358. }
  359. if (type === 0) {
  360. window.location.href = '/product/list.html?keyword='+encodeURIComponent(keyword);
  361. } else if(type === 1) {
  362. // 供应商
  363. window.location.href = '/supplier/list.html?keyword='+encodeURIComponent(keyword);
  364. } else if (type === 2) {
  365. // 项目仪器
  366. window.location.href = '/equipment/list.html?keyword=' + encodeURIComponent(keyword);
  367. } else{
  368. // 文章
  369. window.location.href = '/info/search-1.html?keyword=' + encodeURIComponent(keyword);
  370. }
  371. }).on('keyup', '.keyword', function(event) {
  372. // 搜索输入框 按回车键搜索
  373. var keyCode = event.keyCode || event.which;
  374. if(keyCode === 13){
  375. $(this).parents('#topSearch').find('.searchBtn').trigger("click");
  376. }
  377. }).on("click", '.hotKey .word', function(){
  378. // 点击热词 触发搜索
  379. $(this).parents('#topSearch').find('.keyword').val($(this).text());
  380. $(this).parents('#topSearch').find('.searchBtn').trigger("click");
  381. });
  382. // 支付弹框复制标识
  383. $('body').on("click", '.payAlert .copy',function () {
  384. var oInput = document.createElement('textarea');
  385. oInput.value = $(this).parents('.payAlert').find('.no').text();
  386. document.body.appendChild(oInput);
  387. oInput.select(); // 选择对象
  388. document.execCommand("Copy"); // 执行浏览器复制命令
  389. document.body.removeChild(oInput);
  390. CAIMEI.dialog('复制成功');
  391. });
  392. });
  393. /*function uuid() {
  394. var s = [];
  395. var hexDigits = "0123456789abcdef";
  396. for (var i = 0; i < 36; i++) {
  397. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  398. }
  399. s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  400. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  401. s[8] = s[13] = s[18] = s[23] = "-";
  402. return s.join("");
  403. }*/
  404. function setBeforeUrl(){
  405. var baseUrl = window.location.href;
  406. var flag = baseUrl.indexOf('/login.html')>0 || baseUrl.indexOf('/register.html')>0 || baseUrl.indexOf('/we_chat/redirect_uri.html')>0;
  407. if(!flag){
  408. setBaseCookie("loginBeforePath", baseUrl);
  409. }
  410. }
  411. // 公共方法
  412. function setBaseCookie(cname,cvalue,exdays){
  413. if (exdays) {
  414. var d = new Date();
  415. d.setTime(d.getTime()+(exdays*24*60*60*1000));
  416. var expires = "expires="+d.toGMTString();
  417. document.cookie = cname+"="+cvalue+"; path=/; "+expires;
  418. } else {
  419. document.cookie = cname+"="+cvalue+"; path=/";
  420. }
  421. }
  422. function getBaseCookie(cname){
  423. if (document.cookie) {
  424. var name = cname + "=";
  425. var ca = document.cookie.split(';');
  426. for(var i=0; i<ca.length; i++) {
  427. var c = ca[i].trim();
  428. if (c && c.indexOf(name)===0) {
  429. return c.substring(name.length,c.length);
  430. }
  431. }
  432. }
  433. return "";
  434. }
  435. function delBaseCookie(cname){
  436. var exp = new Date();
  437. exp.setTime(exp.getTime() - 1);
  438. var cval=getBaseCookie(cname);
  439. if(cval!=null) {
  440. document.cookie= cname + "="+cval+";expires="+exp.toGMTString();
  441. }
  442. }
  443. function getDateStr(dd, addCount) {
  444. dd.setDate(dd.getDate() + addCount);//获取addCount天后的日期
  445. var y = dd.getFullYear();
  446. var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1);//获取当前月份的日期,不足10补0
  447. var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
  448. return y + "/" + m + "/" + d;
  449. }
  450. function jqClickShow(tab, con){
  451. $("body").on("click", tab, function(e){
  452. e.stopPropagation();
  453. if($(tab).hasClass("on")){
  454. $(tab).removeClass("on");
  455. $(con).slideUp("fast");
  456. }else{
  457. $(tab).addClass("on");
  458. $(con).slideDown("fast");
  459. }
  460. }).on("click", function(){
  461. $(tab).removeClass("on");
  462. $(con).slideUp("fast");
  463. });
  464. }
  465. function jqHoverShow(tab, con){
  466. $("body").on("mouseover", tab, function(e){
  467. e.stopPropagation();
  468. if($(tab).hasClass("on")){
  469. $(tab).removeClass("on");
  470. $(con).slideUp("fast");
  471. }else{
  472. $(tab).addClass("on");
  473. $(con).slideDown("fast");
  474. }
  475. }).on("mouseover", con, function(e){
  476. e.stopPropagation();
  477. }).on("mouseover", function(e){
  478. $(tab).removeClass("on");
  479. $(con).slideUp("fast");
  480. });
  481. }
  482. function jqMultipleShow(event, item, tab, con, stop){
  483. $("body").on(event, item+' '+tab, function(e){
  484. e.stopPropagation();
  485. $(this).parents(item).siblings(item).find(con).slideUp("fast");
  486. $(this).parents(item).siblings(item).removeClass("on");
  487. $(this).parents(item).siblings(item).find(tab).removeClass("on");
  488. if($(this).hasClass("on")){
  489. $(this).removeClass("on");
  490. $(this).parents(item).removeClass("on");
  491. $(this).parents(item).find(con).slideUp("fast");
  492. }else{
  493. $(this).addClass("on");
  494. $(this).parents(item).addClass("on");
  495. $(this).parents(item).find(con).slideDown("fast");
  496. }
  497. }).on(event, item+' '+con, function(e){
  498. e.stopPropagation();
  499. }).on(event, function(){
  500. if(stop){
  501. $(item+' '+tab).removeClass("on");
  502. $(item).removeClass("on");
  503. $(item+' '+con).slideUp("fast");
  504. }
  505. });
  506. }
  507. function jqSelect(selectBox){
  508. $("body").on("click", selectBox, function(e){
  509. e.stopPropagation();
  510. var select = $(this).find("select");
  511. var options = select.find("option");
  512. var list = "";
  513. for (var i=0; i<options.length; i++){
  514. list += '<li data-id="'+$(options[i]).val()+'">'+$(options[i]).text()+'</li>';
  515. if($(options[i]).val()===select.val()){
  516. $(this).find("[data-select]").text($(options[i]).text()).attr('data-select',$(options[i]).val());
  517. }
  518. }
  519. $(this).find("ul").html(list);
  520. $(this).find("ul").slideToggle("fast");
  521. }).on("click", selectBox + " li", function(e){
  522. e.stopPropagation();
  523. $(this).parent().prev().attr('data-select',$(this).attr("data-id")).text($(this).text());
  524. $(this).parents("pc").next().val($(this).attr("data-id"));
  525. $(this).parent().slideUp("fast");
  526. }).on("click", function(){
  527. $(selectBox).find("ul").slideUp("fast");
  528. });
  529. }
  530. //解决移动端滚动穿透
  531. function fixedBody(){
  532. var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  533. setTimeout(function(){
  534. document.body.style.cssText += 'position:fixed;top:-'+scrollTop+'px;';
  535. },10);
  536. }
  537. function looseBody() {
  538. var body = document.body;
  539. body.style.position = '';
  540. var top = body.style.top;
  541. document.body.scrollTop = document.documentElement.scrollTop = -parseInt(top);
  542. body.style.top = '';
  543. }
  544. //url参数
  545. function getUrlParam(name) {
  546. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  547. var r = decodeURIComponent(window.location.search).substr(1).match(reg);
  548. if (r != null) {
  549. return (r[2])
  550. }
  551. return null;
  552. }
  553. function updateUrlParam(params) {
  554. var loca = window.location;
  555. var baseUrl = loca.origin + loca.pathname + "?";
  556. var query = loca.search.substr(1).toLowerCase();
  557. var queryArr = query.split("&");
  558. var keys = Object.keys(params);
  559. if (keys.length > 0) {
  560. var obj = {};
  561. for (var i = 0; i < queryArr.length; i++) {
  562. queryArr[i] = queryArr[i].split("=");
  563. obj[queryArr[i][0]] = queryArr[i][1]
  564. }
  565. for (var k = 0; k < keys.length; k++) {
  566. var name = keys[k];
  567. var value = params[name];
  568. obj[name.toLowerCase()] = value;
  569. }
  570. var url = baseUrl + JSON.stringify(obj).replace(/["\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
  571. return url;
  572. }
  573. }
  574. function setSearchProductList(list, userId, callback) {//处理搜索
  575. var productIdArr = [];
  576. var resultData = [];
  577. list.map(function (item) {
  578. resultData.push({
  579. productId: item.productId,
  580. name: item.name,
  581. image: item.image,
  582. unit: item.unit,
  583. brandName: item.brandName,
  584. priceFlag: item.priceFlag,
  585. priceGrade: item.priceGrade,
  586. actStatus: 0,
  587. priceLoaded: false,
  588. beautyActFlag:item.beautyActFlag
  589. });
  590. // 0公开价格 1不公开价格 2仅对会员机构公开
  591. if (item.priceFlag !== 1) {
  592. productIdArr.push(item.productId)
  593. }
  594. });
  595. if (userId && userId > 0) {
  596. setProductPrice(resultData, productIdArr.join(","), userId, callback);
  597. }else {
  598. setProductPrice(resultData, productIdArr.join(","), 0, callback);
  599. }
  600. return resultData;
  601. }
  602. function setProductPrice(productList, productIds, userId, callback){
  603. $.getJSON(coreServer+"/commodity/price/list",{
  604. userId: userId,
  605. productIds: productIds,
  606. source: 1
  607. }).done(function (r) {
  608. if (r.code === 0 && r.data) {
  609. var priceList = r.data;
  610. productList.map(function(product){
  611. priceList.map(function(item){
  612. if(product.productId*1 === item.productId){
  613. product.shopId = item.shopId;
  614. product.userIdentity = item.userIdentity;
  615. product.price = item.price;
  616. product.originalPrice = item.originalPrice;
  617. product.priceLoaded = true;
  618. product.ladderPriceFlag = item.ladderPriceFlag;
  619. product.actStatus =item.actStatus;
  620. product.couponsLogo =item.couponsLogo;
  621. product.promotions =item.promotions;
  622. product.svipPriceTag =item.svipPriceTag;
  623. product.svipPriceType =item.svipPriceType;
  624. product.svipProductFlag =item.svipProductFlag;
  625. }
  626. });
  627. });
  628. }
  629. return callback();
  630. }).fail(function(){
  631. return callback();
  632. })
  633. }
  634. // 登录后返回登录前页面
  635. function toBeforePath(){
  636. var loginBeforePath = getBaseCookie("loginBeforePath");
  637. if (loginBeforePath && loginBeforePath!='undefined' && loginBeforePath.indexOf('.html')>0) {
  638. delBaseCookie("loginBeforePath");
  639. window.location.href = loginBeforePath;
  640. }
  641. window.location.href = '/index.html';
  642. }
  643. function toLogin() {//去登录
  644. setBeforeUrl();
  645. window.location.href = '/login.html';
  646. }
  647. function upgrade () { //升级会员
  648. window.location.href='';
  649. }
  650. function toLogOut() {//登出
  651. localStorage.removeItem('userInfo');
  652. delBaseCookie("loginBeforePath");
  653. this.loginStatus = false;
  654. window.location.href = "/index.html";
  655. }
  656. /**
  657. * 至少保留两位小数
  658. * 10 => "10.00"
  659. * @param {number} num
  660. */
  661. function toFloat(num) {
  662. var temp = String(num).split('.');
  663. if (temp.length === 1 || temp[1].length < 2) {
  664. return Number(num).toFixed(2);
  665. }else{
  666. return Number(num);
  667. }
  668. }
  669. /** 表单输入框校验 */
  670. function verifyHandle(obj){
  671. if ($(obj).is(":hidden")) { return false; }
  672. var v = $.trim($(obj).val()).replace(/\s+/g,"");
  673. var reg = $(obj).attr("rule");
  674. var errorTxt = $(obj).siblings('.errTips').attr("tips");
  675. if ($.trim(v) === '') {
  676. if ($(obj).attr("placeholder") && $(obj).attr("placeholder").indexOf("请输入")>=0) {
  677. errorTxt = $(obj).attr("placeholder").split("请输入")[1]+'不能为空';
  678. } else {
  679. errorTxt = '不能为空';
  680. }
  681. setErrorTxt(obj, errorTxt);
  682. return false;
  683. }else if (typeof reg != "undefined") {
  684. reg = new RegExp(reg);
  685. if (!reg.test(v)) {
  686. setErrorTxt(obj, errorTxt);
  687. return false;
  688. }
  689. }
  690. clearErrorTxt(obj);
  691. }
  692. function setErrorTxt(obj, txt) {
  693. $(obj).parent().addClass("error").find('.checked').removeClass("show");
  694. $(obj).siblings('.errTips').text(txt).addClass("show");
  695. }
  696. function clearErrorTxt(obj) {
  697. $(obj).siblings('.errTips').removeClass("show");
  698. $(obj).parent().removeClass("error").find('.checked').addClass("show");
  699. }
  700. // 提交时验证表单
  701. function verifyForm() {
  702. $("[needverify]:visible").each(function (index, ele) {
  703. if (!$(ele).siblings('.checked').hasClass("show")) {
  704. verifyHandle(ele);
  705. }
  706. });
  707. var len = $('.errTips.show:visible').length;
  708. return (len === 0);
  709. }
  710. // 单个验证表单
  711. function verifyCheack(ele) {
  712. if (!$(ele).siblings('.checked').hasClass("show")) {
  713. verifyHandle(ele);
  714. }
  715. var len = $(ele).siblings('.errTips.show:visible').length;
  716. return (len === 0);
  717. }
  718. // 公共信息提示弹框
  719. function alertInfo(txt,callback) {
  720. $.confirm({
  721. useBootstrap: false,
  722. boxWidth: (isPC?'300px':'70%'),
  723. title:'提示',
  724. content: txt,
  725. closeIcon: true,
  726. animation: 'opacity',
  727. closeAnimation: 'opacity',
  728. animateFromElement: false,
  729. buttons: {
  730. close: {
  731. text: '确定',
  732. btnClass: 'btn-confirm',
  733. action: function () {
  734. callback()
  735. }
  736. }
  737. }
  738. });
  739. }
  740. //公共吐司
  741. function dialog(txt,callback) {
  742. $.confirm({
  743. title: false,
  744. content: txt,
  745. boxWidth: (isPC?'300px':'70%'),
  746. autoClose: 'close|2000',
  747. useBootstrap:false,
  748. buttons: {
  749. close:{
  750. isHidden: true,
  751. action: function () {
  752. callback()
  753. }
  754. }
  755. }
  756. });
  757. }