index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. var supplierHome = new Vue({
  2. el: "#supplierHome",
  3. mixins: [cmSysVitaMixins],
  4. data: {
  5. requestFlag: true,
  6. userId: 0,
  7. supplierInfo: {},
  8. supplierBanner: [],
  9. shopCategory: [],
  10. mainProducts: [],
  11. choiceIndex: '',
  12. handleTabIndex: 1,
  13. params: {
  14. size: 12,
  15. num: 1,
  16. id: 0,
  17. keyword: ''
  18. },
  19. listRecord: 0,
  20. productLists: [],
  21. categoryProducts: [],// 类别商品列表
  22. isShopAll: true,
  23. addhtml: '<span class="tag">美博会</span>'
  24. },
  25. computed: {
  26. floorData: function () {
  27. return [
  28. {
  29. type: 1,
  30. title: '主推商品',
  31. productList: this.mainProducts,
  32. showEmpty: false
  33. },
  34. {
  35. type: 2,
  36. title: '全部商品',
  37. productList: this.productLists,
  38. showEmpty: true
  39. }
  40. ]
  41. }
  42. },
  43. filters: {
  44. NumFormat: function (value) {
  45. return Number(value).toFixed(2);
  46. }
  47. },
  48. methods: {
  49. handleTabClick(type) {
  50. this.handleTabIndex = type
  51. },
  52. // 是否显示vip标签价格
  53. showVipPriceTag(pros) {
  54. //非会员
  55. // if(!GLOBAL_VIP_FLAG === 1) return false;
  56. // 商品所有机构可见
  57. if (pros.priceFlag === 0) return true;
  58. // 商品价格仅资质机构可见
  59. if (pros.priceFlag === 2 && GLOBAL_USER_IDENTITY === 2) return true;
  60. // 商品价格仅医美机构可见
  61. if (pros.priceFlag === 3 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE === 1) return true;
  62. // 其它
  63. return false;
  64. },
  65. getShopInfo() {
  66. const _self = this;
  67. SupplierApi.getShopHomeData({shopId: this.params.id }, function (res) {
  68. if (res.code === 0) {
  69. const data = res.data
  70. _self.supplierInfo = data
  71. _self.supplierBanner = data.shopHomeImages // 供应商轮播
  72. _self.shopCategory = data.shopCategory// 供应商类别
  73. _self.getMainProducts()
  74. _self.getProductLists()
  75. setTimeout(function () {
  76. if (isPC) {
  77. $('#supplierBanner').slide({
  78. mainCell: ".swiper-wrapper"
  79. , titCell: ".swiper-pagination span"
  80. , effect: "leftLoop"
  81. , prevCell: ".swiper-button-prev"
  82. , nextCell: ".swiper-button-next"
  83. , interTime: 2000
  84. , autoPlay: true
  85. , autoPage: false
  86. , trigger: "mouseover"
  87. });
  88. } else {
  89. const swiper = new Swiper('#supplierBanner', {
  90. loop: true,
  91. autoplay: {
  92. delay: 2000,
  93. disableOnInteraction: false
  94. },
  95. navigation: {
  96. nextEl: '.swiper-button-next',
  97. prevEl: '.swiper-button-prev'
  98. },
  99. pagination: {
  100. el: '.swiper-pagination',
  101. clickable: true
  102. }
  103. })
  104. }
  105. }, 500);
  106. }
  107. });
  108. },
  109. // 点击全部
  110. handleChangeAll() {
  111. this.choiceIndex = ''
  112. this.isShopAll = true
  113. this.getMainProducts()
  114. this.getProductLists(false)
  115. },
  116. handleCategory(category, index) {
  117. this.isShopAll = false
  118. this.choiceIndex = index
  119. this.getCategoryProducts({shopId: this.handleShopId, categoryId: category.id})
  120. },
  121. // 获取类别商品列表
  122. getCategoryProducts(params) {
  123. const _self = this;
  124. SupplierApi.getCategoryProducts(params, function (res) {
  125. if (res.code === 0) {
  126. if (_self.userId && _self.userId > 0) {
  127. const productIdArr = [];
  128. res.data.map((item) => {
  129. // 0公开价格 1不公开价格 2仅对会员机构公开
  130. if (item.priceFlag !== 1) {
  131. productIdArr.push(item.productId)
  132. }
  133. });
  134. setProductPrice(res.data, productIdArr.join(","), _self.userId, function () {
  135. _self.$forceUpdate();
  136. });
  137. }
  138. _self.categoryProducts = res.data
  139. setTimeout(function () {
  140. // 图片懒加载
  141. $("img[data-original]").lazyload();
  142. }, 500);
  143. }
  144. });
  145. },
  146. getMainProducts() {
  147. const _self = this;
  148. SupplierApi.GetShopProductMain({ shopId: _self.params.id,identity: IDENTITY },function (res) {
  149. if (res.code === 0 && res.data) {
  150. if (_self.userId && _self.userId > 0) {
  151. const productIdArr = [];
  152. res.data.map(function (item) {
  153. // 0公开价格 1不公开价格 2仅对会员机构公开
  154. if (item.priceFlag !== 1) {
  155. productIdArr.push(item.productId)
  156. }
  157. });
  158. setProductPrice(res.data, productIdArr.join(","), _self.userId, function () {
  159. _self.$forceUpdate();
  160. });
  161. }
  162. _self.mainProducts = res.data;
  163. setTimeout(function () {
  164. // 图片懒加载
  165. $("img[data-original]").lazyload();
  166. }, 500);
  167. }
  168. }
  169. );
  170. },
  171. getProductLists(flag) {
  172. const _self = this;
  173. SupplierApi.GetSearchQueryProductSupplier(
  174. {
  175. keyword: _self.params.keyword,
  176. pageSize: _self.params.size,
  177. pageNum: _self.params.num,
  178. identity: IDENTITY,
  179. id: _self.params.id
  180. },
  181. function (res) {
  182. if (res.code === 0 && res.data) {
  183. const result = JSON.parse(res.data);
  184. _self.listRecord = result.total;
  185. const resultData = setSearchProductList(result.items, _self.userId, function () {
  186. _self.$forceUpdate();
  187. setTimeout(function () {
  188. // 图片懒加载
  189. $("img[data-original]").lazyload();
  190. }, 500);
  191. });
  192. if (flag) {
  193. _self.productLists = _self.productLists.concat(resultData);
  194. } else {
  195. _self.productLists = []
  196. _self.productLists = resultData
  197. }
  198. console.log('productLists', _self.productLists)
  199. _self.requestFlag = true;
  200. }
  201. }
  202. );
  203. },
  204. PromotionsFormat(promo) {//促销活动类型数据处理
  205. if (promo != null) {
  206. if (promo.type === 1 && promo.mode === 1) {
  207. return true
  208. } else {
  209. return false
  210. }
  211. }
  212. return false
  213. },
  214. keyupSearch(event) {
  215. // 搜索输入框 按回车键搜索
  216. var keyCode = event.keyCode || event.which;
  217. if (keyCode === 13) {
  218. this.supplierSearch();
  219. }
  220. },
  221. supplierSearch() {
  222. if (this.params.keyword.length < 2) {
  223. $.confirm({
  224. useBootstrap: false,
  225. boxWidth: (isPC ? '300px' : '70%'),
  226. title: '提示',
  227. content: '请至少输入两个关键字!',
  228. closeIcon: true,
  229. animation: 'opacity',
  230. closeAnimation: 'opacity',
  231. animateFromElement: false,
  232. buttons: {
  233. close: {
  234. text: '确定',
  235. btnClass: 'btn-confirm'
  236. }
  237. }
  238. });
  239. return false;
  240. }
  241. this.choiceIndex = ''
  242. this.isShopAll = true
  243. this.productLists = [];
  244. this.getProductLists(false);
  245. var floorScroll = $('#supProduct').offset().top;
  246. $('html,body').animate({scrollTop: floorScroll}, 600);
  247. },
  248. upgrade: function () {
  249. location.href = '/upgrade.html';
  250. }
  251. },
  252. created() {
  253. const paramsArr = window.location.pathname.split(".")[0].split("-");
  254. this.params.id = this.cmSysParams.shopId = this.handleShopId = paramsArr.length >= 1 ? paramsArr[1] * 1 : 0;
  255. this.cmSysParams.pageType = 14;
  256. this.cmSysParams.pageLabel = `供应商主页`;//设置统计数据标签
  257. if (globalUserData) {
  258. this.userId = globalUserData.userId;
  259. }
  260. if (this.params.id !== 0) {
  261. this.getShopInfo();
  262. }
  263. },
  264. mounted: function () {
  265. //上垃加载更多
  266. const _self = this;
  267. $(window).on('scroll', function () {
  268. const scrollTop = $(this).scrollTop();
  269. const scrollHeight = $(document).height();
  270. const windowHeight = window.innerHeight + $("footer").height();
  271. if (scrollTop + windowHeight >= scrollHeight) {
  272. //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
  273. const totalPage = Math.ceil(_self.listRecord / _self.params.size) ? Math.ceil(_self.listRecord / _self.params.size) : 1;
  274. const next = _self.params.num + 1;
  275. if (next <= totalPage) {
  276. if (_self.requestFlag) {
  277. _self.params.num = next;
  278. // 获取列表数据
  279. _self.getProductLists(true);
  280. }
  281. _self.requestFlag = false;
  282. }
  283. }
  284. });
  285. $('body').on("click", '.showSearch', function () {
  286. $('.supplierTit .search').show();
  287. })
  288. }
  289. });