index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. var supplierHome = new Vue({
  2. el: "#supplierHome",
  3. data: {
  4. requestFlag: true,
  5. userId: 0,
  6. supplierInfo:{},
  7. supplierBanner: [],
  8. mainProducts:[],
  9. params: {
  10. size: 12,
  11. num: 1,
  12. id: 0,
  13. keyword: ''
  14. },
  15. listRecord:0,
  16. productLists:[],
  17. addhtml:'<span class="tag">美博会</span>'
  18. },
  19. computed: {
  20. },
  21. methods: {
  22. getShopInfo: function(){
  23. var _self = this;
  24. $.getJSON(spiServer + "/supplier/home/detail",{supplierId: this.params.id}).done(function (r) {
  25. if (r.code === 0 && r.data) {
  26. _self.supplierInfo = r.data;
  27. }
  28. });
  29. },
  30. getBanners: function(){
  31. var _self = this;
  32. $.getJSON(spiServer + "/supplier/home/images",{supplierId: this.params.id}).done(function (r) {
  33. if (r.code === 0 && r.data) {
  34. _self.supplierBanner = r.data;
  35. _self.supplierBanner = r.data;
  36. setTimeout(function(){
  37. if (isPC) {
  38. $('#supplierBanner').slide({
  39. mainCell:".swiper-wrapper"
  40. ,titCell:".swiper-pagination span"
  41. ,effect: "leftLoop"
  42. ,prevCell:".swiper-button-prev"
  43. ,nextCell:".swiper-button-next"
  44. ,interTime: 2000
  45. ,autoPlay: true
  46. ,autoPage: false
  47. ,trigger: "mouseover"
  48. });
  49. } else {
  50. var swiper = new Swiper('#supplierBanner', {
  51. loop : true,
  52. autoplay: {
  53. delay: 2000,
  54. disableOnInteraction: false
  55. },
  56. navigation: {
  57. nextEl: '.swiper-button-next',
  58. prevEl: '.swiper-button-prev'
  59. },
  60. pagination: {
  61. el: '.swiper-pagination',
  62. clickable :true
  63. }
  64. });
  65. }
  66. },500);
  67. }
  68. });
  69. },
  70. getMainProducts: function(){
  71. var _self = this;
  72. SupplierApi.GetShopProductMain(
  73. {
  74. shopId: _self.params.id,
  75. identity: GLOBAL_USER_IDENTITY
  76. },
  77. function (res) {
  78. if (res.code === 0 && res.data) {
  79. if(_self.userId && _self.userId>0){
  80. var productIdArr = [];
  81. res.data.map(function (item) {
  82. // 0公开价格 1不公开价格 2仅对会员机构公开
  83. if (item.priceFlag !== 1) {
  84. productIdArr.push(item.productId)
  85. }
  86. });
  87. setProductPrice(res.data, productIdArr.join(","), _self.userId, function () {
  88. _self.$forceUpdate();
  89. setTimeout(function(){
  90. // 图片懒加载
  91. $("img[data-original]").lazyload();
  92. },500);
  93. });
  94. }
  95. _self.mainProducts = res.data;
  96. } else {
  97. CAIMEI.Alert(res.msg, '确定');
  98. }
  99. }
  100. );
  101. },
  102. getProductLists: function(){
  103. var _self = this;
  104. SupplierApi.GetSearchQueryProductSupplier(
  105. {
  106. keyword: _self.params.keyword,
  107. pageSize: _self.params.size,
  108. pageNum: _self.params.num,
  109. identity: GLOBAL_USER_IDENTITY,
  110. id:_self.params.id
  111. },
  112. function (res) {
  113. if (res.code === 0 && res.data) {
  114. var result = JSON.parse(res.data);
  115. _self.listRecord = result.total;
  116. var resultData = setSearchProductList(result.items, _self.userId, function () {
  117. _self.$forceUpdate();
  118. setTimeout(function () {
  119. // 图片懒加载
  120. $("img[data-original]").lazyload();
  121. }, 500);
  122. });
  123. _self.productLists = _self.productLists.concat(resultData);
  124. _self.requestFlag = true;
  125. } else {
  126. CAIMEI.Alert(res.msg, '确定');
  127. }
  128. }
  129. );
  130. },
  131. keyupSearch: function(event) {
  132. // 搜索输入框 按回车键搜索
  133. var keyCode = event.keyCode || event.which;
  134. if(keyCode === 13){
  135. this.supplierSearch();
  136. }
  137. },
  138. supplierSearch: function(){
  139. if (this.params.keyword.length < 2) {
  140. $.confirm({
  141. useBootstrap: false,
  142. boxWidth: (isPC?'300px':'70%'),
  143. title:'提示',
  144. content:'请至少输入两个关键字!',
  145. closeIcon: true,
  146. animation: 'opacity',
  147. closeAnimation: 'opacity',
  148. animateFromElement: false,
  149. buttons: {
  150. close: {
  151. text: '确定',
  152. btnClass: 'btn-confirm'
  153. }
  154. }
  155. });
  156. return false;
  157. }
  158. this.productLists = [];
  159. this.getProductLists();
  160. var floorScroll = $('#supProduct').offset().top;
  161. $('html,body').animate({scrollTop: floorScroll},600);
  162. },
  163. upgrade: function () {
  164. location.href='/upgrade.html';
  165. }
  166. },
  167. created: function () {
  168. this.params.id = getUrlParam("id") ? getUrlParam("id") * 1 : 0;
  169. if(this.params.id !== 0) {
  170. this.getShopInfo();
  171. this.getBanners();
  172. }
  173. },
  174. mounted: function () {
  175. if(this.params.id !== 0) {
  176. this.getMainProducts();
  177. this.getProductLists();
  178. }
  179. var userInfo = localStorage.getItem('userInfo');
  180. if(userInfo){
  181. this.userId = JSON.parse(userInfo).userId;
  182. }
  183. var _self = this;
  184. $('.supplierInfo').slide({
  185. mainCell:".tabCon"
  186. ,titCell:".tabTit span"
  187. ,trigger: "click"
  188. });
  189. //上垃加载更多
  190. $(window).on('scroll', function(){
  191. var scrollTop = $(this).scrollTop();
  192. var scrollHeight = $(document).height();
  193. var windowHeight = window.innerHeight + $("footer").height();
  194. if (scrollTop + windowHeight >= scrollHeight) {
  195. //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
  196. var totalPage = Math.ceil(_self.listRecord / _self.params.size)?Math.ceil(_self.listRecord / _self.params.size):1;
  197. var next = _self.params.num+1;
  198. if(next <= totalPage){
  199. if (_self.requestFlag){
  200. _self.params.num = next;
  201. // 获取列表数据
  202. _self.getProductLists();
  203. }
  204. _self.requestFlag = false;
  205. }
  206. }
  207. });
  208. $('body').on("click", '.showSearch', function(){
  209. $('.supplierTit .search').show();
  210. })
  211. }
  212. });