index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. //index.js
  2. //获取应用实例
  3. var http = require("../../utils/http.js");
  4. var util = require('../../utils/util.js');
  5. var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
  6. var qqmapsdk;
  7. const updateManager = wx.getUpdateManager()
  8. import eventBus from '../../utils/eventBus';
  9. Page({
  10. isHand:false,
  11. data: {
  12. active:1,
  13. imgUrl:'https://zswl-shop.oss-cn-chengdu.aliyuncs.com/',
  14. swiperCurrent:0,
  15. swiperList:[],
  16. shopName:'附近暂无可配送门店',
  17. indicatorDots: true,
  18. indicatorColor: '#d1e5fb',
  19. indicatorActiveColor: '#1b7dec',
  20. autoplay: true,
  21. interval: 2000,
  22. duration: 1000,
  23. indexImgs: [],
  24. seq: 0,
  25. news: [],
  26. hotSalesList: [],
  27. sts: 0,
  28. current: 1,
  29. sort: 1,
  30. isAll: false,
  31. snapUpList: [], //秒杀列表
  32. aBulkList: [], //团购列表
  33. pageTopHeight: wx.getWindowInfo().statusBarHeight + 30 + 7,
  34. gapTop: 1,
  35. titleOpacity: 1,
  36. days: 0,
  37. hours: 0,
  38. minutes: 0,
  39. seconds: 0,
  40. hotList: [],
  41. recommendedList: [],
  42. totalNum: 1,
  43. addCarshow: false,
  44. shopDetail: {},
  45. select_address: '',
  46. categoryList: [],
  47. categoryList1: [],
  48. currentIndex: 0,
  49. topCurrentIndex: 0,
  50. currentTop: 0,
  51. shop_id: 0,
  52. get_distance: '',
  53. banner_img: [
  54. {
  55. img:'https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/JrXik2T4vhwp7c25b370159a7498499e7b4b76cfb288.png/1.png',
  56. name:''
  57. },
  58. {
  59. img:'https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/OFG6necEvIOpcd39097fe6f106894503a4d77c14d7b8.png/1.png',
  60. name:''
  61. },
  62. ]
  63. },
  64. onLoad: function () {
  65. // 实例化API核心类
  66. qqmapsdk = new QQMapWX({
  67. key: 'D3MBZ-LQK6U-IONVC-GJDPK-C43GF-UYFOC'
  68. // key: 'UNBBZ-OKDCB-FSTU4-N5EGG-CMJ67-CKB6H'
  69. });
  70. // 绑定页面滚动事件
  71. wx.pageScrollTo({
  72. scrollTop: 0, // 初始滚动位置,可按需调整
  73. duration: 0
  74. });
  75. this.get_setting()
  76. this.setData({
  77. select_address: wx.getStorageSync('ADDRESS')
  78. })
  79. setTimeout(() => {
  80. this.getAllData();
  81. }, 1000)
  82. },
  83. handleTab(e){
  84. this.setData({
  85. active:Number(e.currentTarget.dataset.active),
  86. current:Number(e.currentTarget.dataset.active),
  87. hotSalesList:[],
  88. isHand:true
  89. })
  90. setTimeout(() => {
  91. this.getHotSalesProds()
  92. }, 100);
  93. },
  94. // 顶部轮播滚动
  95. changeIndex(e){
  96. this.setData({
  97. swiperCurrent:e.detail.current
  98. })
  99. },
  100. get_setting: function () {
  101. let that = this
  102. wx.getSetting({
  103. success: (res) => {
  104. let authSetting = res.authSetting
  105. if (authSetting['scope.userLocation'] || authSetting['scope.userFuzzyLocation']) {
  106. that.getCurrentLocation()
  107. } else if (authSetting['scope.userLocation'] || authSetting['scope.userFuzzyLocation'] === false) {
  108. wx.removeStorageSync('ADDRESS')
  109. wx.showModal({
  110. title: '您未开启地理位置授权',
  111. content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
  112. success: (res) => {
  113. if (res.confirm) {
  114. wx.openSetting()
  115. }
  116. }
  117. })
  118. } else {
  119. wx.authorize({
  120. scope: 'scope.userLocation',
  121. scope: 'scope.userFuzzyLocation',
  122. success: () => {
  123. that.getCurrentLocation()
  124. },
  125. fail: () => {
  126. wx.removeStorageSync('ADDRESS')
  127. wx.showModal({
  128. title: '您未开启地理位置授权',
  129. content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
  130. success: (res) => {
  131. if (res.confirm) {
  132. wx.openSetting()
  133. }
  134. }
  135. })
  136. }
  137. })
  138. }
  139. }
  140. })
  141. },
  142. getCurrentLocation() {
  143. let that = this
  144. wx.getFuzzyLocation({
  145. type: 'wgs84',
  146. success: function (res) {
  147. const latitude = res.latitude
  148. const longitude = res.longitude
  149. wx.setStorageSync('LATITUDE', res.latitude)
  150. wx.setStorageSync('LONGITUDE', res.longitude)
  151. // 调用腾讯地图api获取当前位置
  152. qqmapsdk.reverseGeocoder({
  153. location: {
  154. latitude: latitude,
  155. longitude: longitude
  156. },
  157. success: function (res) {
  158. console.log(res.result, '---address_success');
  159. wx.setStorageSync('ADDRESS', res.result.address_component.street)
  160. that.setData({
  161. select_address: wx.getStorageSync('ADDRESS')
  162. })
  163. },
  164. fail: function (res) {
  165. console.log(res, '---address_err');
  166. wx.showToast({
  167. title: res + '地址信息获取失败',
  168. icon: "none"
  169. })
  170. setTimeout(() => {
  171. wx.hideToast();
  172. }, 2000)
  173. },
  174. complete: function (res) {
  175. // console.log(res, '---callback');
  176. }
  177. });
  178. },
  179. fail: function (err) {
  180. wx.removeStorageSync('ADDRESS')
  181. console.log(err);
  182. if (err.errMsg === 'getFuzzyLocation:fail system permission denied') {
  183. wx.showModal({
  184. title: '系统定位未开启',
  185. content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
  186. success: (res) => {}
  187. })
  188. } else if (err.errMsg === 'getFuzzyLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF' ||
  189. err.errMsg === 'getFuzzyLocation:fail system permission denied' ||
  190. err.errMsg === 'getFuzzyLocation:fail:system permission denied' || err.errMsg === 'getFuzzyLocation:fail auth deny') {
  191. wx.showModal({
  192. title: '您未开启地理位置授权',
  193. content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
  194. success: (res) => {
  195. if (res.confirm) {
  196. wx.openSetting()
  197. }
  198. }
  199. })
  200. }
  201. }
  202. })
  203. },
  204. // 页面滚动到指定位置指定元素固定在顶部
  205. onPageScroll: function (e) { //监听页面滚动
  206. if (e.scrollTop < 10) {
  207. this.setData({
  208. titleOpacity: 1
  209. })
  210. }
  211. if (e.scrollTop > 10) {
  212. this.setData({
  213. titleOpacity: 0.8
  214. })
  215. }
  216. if (e.scrollTop > 20) {
  217. this.setData({
  218. titleOpacity: 0.6
  219. })
  220. }
  221. if (e.scrollTop > 30) {
  222. this.setData({
  223. titleOpacity: 0.2
  224. })
  225. }
  226. if (e.scrollTop >= 40) {
  227. this.setData({
  228. titleOpacity: 0
  229. })
  230. }
  231. this.handlePageScroll(e.scrollTop);
  232. this.setData({
  233. scrollTop: e.scrollTop
  234. })
  235. },
  236. handlePageScroll: function (scrollTop) {
  237. const query = wx.createSelectorQuery().in(this);
  238. query.select('#my-element').boundingClientRect();
  239. query.exec((res) => {
  240. if (res && res[0]) {
  241. const elementTop = res[0].top;
  242. const relativeTop = elementTop - scrollTop;
  243. // 也可以将这个距离数据存储到data中,方便在页面中进行展示或其他操作
  244. if (relativeTop < 0.5) {
  245. this.setData({
  246. gapTop: relativeTop
  247. });
  248. } else {
  249. this.setData({
  250. gapTop: 1
  251. });
  252. }
  253. }
  254. });
  255. },
  256. /**
  257. * 广告位
  258. */
  259. getAdv: function () {
  260. var params = {
  261. url: "/advert/search",
  262. method: "GET",
  263. data: {
  264. current: 1,
  265. size:99,
  266. status:1
  267. },
  268. callBack: (res) => {
  269. this.setData({
  270. swiperList: res.records
  271. })
  272. }
  273. };
  274. http.request(params);
  275. },
  276. /**
  277. * 推荐词,type:1关键词,2热门搜索词,3推荐搜索词
  278. */
  279. getRecommended: function () {
  280. var params = {
  281. url: "/keyword/list",
  282. method: "GET",
  283. data: {
  284. type: 2
  285. },
  286. callBack: (res) => {
  287. let reslut = res.filter(item => item.status !== 2) //过滤下线词
  288. let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未生效词
  289. this.setData({
  290. hotList: timeReslut
  291. })
  292. }
  293. };
  294. http.request(params);
  295. },
  296. getRecommendeds: function () {
  297. var params = {
  298. url: "/keyword/list",
  299. method: "GET",
  300. data: {
  301. type: 3
  302. },
  303. callBack: (res) => {
  304. let reslut = res.filter(item => item.status !== 2) //过滤已线下推荐词
  305. let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未到生效时间推荐词
  306. this.setData({
  307. recommendedList: timeReslut
  308. })
  309. }
  310. };
  311. http.request(params);
  312. },
  313. /**
  314. * 推荐词搜索
  315. */
  316. topSwiperChange: function (e) {
  317. this.setData({
  318. topCurrentIndex: e.detail.current // 获取当前滚动到的swiper-item的索引并更新到data中
  319. })
  320. },
  321. topHotSearch: function () {
  322. const topname = this.data.hotList[this.data.topCurrentIndex].name
  323. wx.navigateTo({
  324. // url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
  325. url: `/pages/search-prod-show/search-prod-show?prodName=${topname}&shopId=${this.data.shop_id}`,
  326. })
  327. },
  328. swiperChange: function (e) {
  329. this.setData({
  330. currentIndex: e.detail.current
  331. });
  332. },
  333. inputSearch: function () {
  334. const currentName = this.data.hotList[this.data.currentIndex].name;
  335. wx.navigateTo({
  336. // url: '/pages/search-prod-show/search-prod-show?prodName=' + currentName,
  337. url: `/pages/search-prod-show/search-prod-show?prodName=${currentName}&shopId=${this.data.shop_id}`,
  338. })
  339. },
  340. recommendedSearch: function (e) {
  341. let name = e.currentTarget.dataset.name
  342. wx.navigateTo({
  343. url: `/pages/search-prod-show/search-prod-show?prodName=${name}&shopId=${this.data.shop_id}`,
  344. })
  345. },
  346. /**
  347. * 对象映射,每多一个swiper-item需+10,用以金刚区的分类跳转到指定分类菜单,当菜单类大于三十个时需再次手动添加
  348. * @param {*} e
  349. */
  350. menuSwiper: function (e) {
  351. const topMap = {
  352. 0: 0,
  353. 1: 10,
  354. 2: 20
  355. };
  356. const currentValue = topMap[e.detail.current];
  357. if (currentValue !== undefined) {
  358. this.setData({
  359. currentTop: currentValue
  360. });
  361. }
  362. },
  363. /**
  364. * 当分类大于10时进行切割
  365. */
  366. splitList: function (arr) {
  367. let result = [];
  368. let groupCount = Math.ceil(arr.length / 5);
  369. for (let i = 0; i < groupCount; i++) {
  370. let startIndex = i * 5;
  371. let endIndex = Math.min((i + 1) * 5, arr.length);
  372. result.push(arr.slice(startIndex, endIndex));
  373. }
  374. return result;
  375. },
  376. /**
  377. * 宫格分类
  378. */
  379. getClassInfo: function (shopId) {
  380. let _this = this
  381. //加载分类列表
  382. var params = {
  383. url: "/category/categoryInfo",
  384. method: "GET",
  385. data: {
  386. shopId: shopId,
  387. current:1,
  388. size:99999
  389. },
  390. callBack: function (res) {
  391. let categoryName = ''
  392. res.records.forEach(e => {
  393. categoryName = e.categoryName.split('>')
  394. e.categoryName = categoryName[0]
  395. })
  396. let newRes = _this.splitList(res.records)
  397. let categoryList = newRes.splice(0,2)
  398. if(categoryList.length == 2){
  399. categoryList = categoryList[0].concat(categoryList[1])
  400. }else if(categoryList.length == 1){
  401. categoryList = categoryList[0]
  402. }
  403. _this.setData({
  404. categoryList: categoryList,
  405. categoryList1: newRes,
  406. });
  407. }
  408. };
  409. http.request(params);
  410. },
  411. /**
  412. * 点击宫格
  413. */
  414. selectMenu: function (e) {
  415. console.log(e);
  416. let categoryId = e.currentTarget.dataset.itemid
  417. let index = e.currentTarget.dataset.index + this.data.currentTop
  418. let pic = e.currentTarget.dataset.pic
  419. let categories = e.currentTarget.dataset.categories
  420. // if (categories == null || categories.length < 1) {
  421. // wx.navigateTo({
  422. // url: `/pages/sub-category/sub-category?categoryId=${categoryId}&shopId=${this.data.shop_id}`,
  423. // })
  424. // } else {
  425. // getApp().globalData.categoryId = categoryId
  426. // getApp().globalData.index = index
  427. // getApp().globalData.pic = pic
  428. // wx.switchTab({
  429. // url: '/pages/category/category'
  430. // })
  431. // }
  432. eventBus.emit('categoryId', categoryId);
  433. wx.switchTab({
  434. url: '/pages/category/category'
  435. })
  436. },
  437. // 领红包
  438. toRedPackage: function () {
  439. wx.navigateTo({
  440. url: '/pages/ledRedPackage/ledRedPackage',
  441. })
  442. },
  443. /**
  444. * banner图跳转
  445. * @param {判断条件} e
  446. */
  447. goToLevelPage: function (e) {
  448. let name = e.currentTarget.dataset.name
  449. if (name == 'new') {
  450. wx.navigateTo({
  451. url: '/pages/prod-classify/prod-classify?sts=' + 1
  452. })
  453. } else if (name == 'favorable') {
  454. wx.navigateTo({
  455. url: '/pages/specialDiscount/specialDiscount'
  456. })
  457. } else if (name == 'groupBuy') {
  458. wx.navigateTo({
  459. url: '/pages/aBulkList/aBulkList',
  460. })
  461. } else {
  462. wx.navigateTo({
  463. url: '/pages/snapUpList/snapUpList',
  464. })
  465. }
  466. },
  467. /**
  468. * 跳转到商品详情页
  469. */
  470. toProdPage: function (e) {
  471. var prodid = e.currentTarget.dataset.prodid;
  472. if (prodid) {
  473. wx.navigateTo({
  474. url: '/pages/prod/prod?prodid=' + prodid,
  475. })
  476. }
  477. },
  478. toCouponCenter: function () {
  479. wx.navigateTo({
  480. url: '/pages/couponCenter/couponCenter',
  481. })
  482. },
  483. newToProdPage: function (e) {
  484. let prodId = e.currentTarget.dataset.prod
  485. if (prodId) {
  486. wx.navigateTo({
  487. url: '/pages/prod/prod?prodid=' + prodId,
  488. })
  489. }
  490. },
  491. /**
  492. * 跳转秒杀列表页
  493. */
  494. toSpecialDiscount: function () {
  495. wx.navigateTo({
  496. url: '/pages/specialDiscount/specialDiscount',
  497. })
  498. },
  499. /**
  500. * 跳转到定位页面
  501. */
  502. toLocationPage: function () {
  503. wx.navigateTo({
  504. url: '/pages/locationAdd/locationAdd',
  505. })
  506. },
  507. /**
  508. * 秒杀
  509. */
  510. getSnapUpList: function () {
  511. wx.showLoading()
  512. var params = {
  513. url: "/seckill/pageProd",
  514. method: "GET",
  515. data: {
  516. size: 4,
  517. lat: wx.getStorageSync('LATITUDE'),
  518. lon: wx.getStorageSync('LONGITUDE'),
  519. distance: wx.getStorageSync('DISTANCE') || 0
  520. },
  521. callBack: (res) => {
  522. wx.hideLoading();
  523. let result = res.records.filter(item => util.dateToTimestamp(item.endTime) > new Date().getTime()) //过滤掉秒杀时间已结束的商品
  524. let img = ''
  525. result.map(e => {
  526. img = e.pic.split(',')
  527. e.pic = img[0]
  528. })
  529. this.setData({
  530. snapUpList: result
  531. });
  532. let closestItem = null;
  533. let minTimeDiff = Infinity;
  534. this.data.snapUpList.forEach((e) => {
  535. const endTime = util.dateToTimestamp(e.endTime);
  536. const now = new Date().getTime();
  537. const timeDiff = endTime - now;
  538. // 获取距离时间最近的秒杀时间
  539. if (timeDiff < minTimeDiff && timeDiff > 0) {
  540. minTimeDiff = timeDiff;
  541. closestItem = e;
  542. }
  543. })
  544. if (closestItem) {
  545. const endTime = util.dateToTimestamp(closestItem.endTime);
  546. const interval = setInterval(() => {
  547. const now = new Date().getTime();
  548. const timeDiff = endTime - now;
  549. if (timeDiff <= 0) {
  550. clearInterval(interval);
  551. return;
  552. }
  553. const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
  554. const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  555. const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
  556. const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
  557. this.setData({
  558. days: days,
  559. hours: hours,
  560. minutes: minutes,
  561. seconds: seconds
  562. });
  563. }, 1000);
  564. }
  565. }
  566. };
  567. http.request(params);
  568. },
  569. /**
  570. * 新品推荐
  571. */
  572. getNewList: function () {
  573. // var params = {
  574. // url: "/prod/lastedProdPage",
  575. // method: "GET",
  576. // data: {
  577. // current: 1,
  578. // size: 4,
  579. // lat: wx.getStorageSync('LATITUDE'),
  580. // lon: wx.getStorageSync('LONGITUDE'),
  581. // distance: wx.getStorageSync('DISTANCE') || 0,
  582. // shopId:this.data.shop_id
  583. // },
  584. // callBack: (res) => {
  585. // let img = ''
  586. // res.records.map(e => {
  587. // img = e.pic.split(',')
  588. // e.pic = img[0]
  589. // })
  590. // this.setData({
  591. // newList: res.records,
  592. // })
  593. // }
  594. // };
  595. // http.request(params);
  596. },
  597. /**
  598. * 获取距离最近店铺id
  599. * @param {*} e
  600. */
  601. get_neighborShop: function () {
  602. var params = {
  603. url: "/shop/neighborShop",
  604. method: "GET",
  605. data: {
  606. lat: wx.getStorageSync('LATITUDE'),
  607. lon: wx.getStorageSync('LONGITUDE'),
  608. },
  609. callBack: (res) => {
  610. if(typeof res == 'number'){
  611. this.getaddress_transports(res)
  612. this.setData({
  613. shop_id: res
  614. })
  615. setTimeout(() => {
  616. this.getClassInfo(res);
  617. }, 300)
  618. }else{
  619. this.getaddress_transports(res.shopId)
  620. this.setData({
  621. shop_id: res.shopId,
  622. shopName:res.shopName
  623. })
  624. setTimeout(() => {
  625. this.getClassInfo(res.shopId);
  626. }, 300)
  627. }
  628. }
  629. };
  630. http.request(params);
  631. },
  632. /**
  633. * 获取最大配送范围
  634. */
  635. getaddress_transports: function (shopId) {
  636. let _this = this
  637. var params = {
  638. url: "/p/address/transport2",
  639. method: "GET",
  640. data: {
  641. shopId: shopId,
  642. latitude: wx.getStorageSync('LATITUDE'),
  643. longitude: wx.getStorageSync('LONGITUDE'),
  644. },
  645. callBack: function (res) {
  646. wx.setStorageSync('DISTANCE', res.distance)
  647. _this.setData({
  648. get_distance: res.distance
  649. })
  650. },
  651. errCallBack(res) {
  652. console.log(res);
  653. wx.setStorageSync('DISTANCE', 0)
  654. }
  655. };
  656. http.request(params);
  657. },
  658. onClose: function () {
  659. this.setData({
  660. addCarshow: false
  661. })
  662. },
  663. /**
  664. * 步进器
  665. */
  666. minusButton: function (e) {
  667. let totalNum = this.data.totalNum
  668. if (totalNum > 0) {
  669. this.setData({
  670. totalNum: totalNum - 1
  671. })
  672. }
  673. },
  674. addButton: function (e) {
  675. let totalNum = this.data.totalNum
  676. this.setData({
  677. totalNum: totalNum + 1
  678. })
  679. },
  680. /**
  681. * 跳转秒杀列表页
  682. */
  683. toSnapUpPage: function () {
  684. wx.navigateTo({
  685. url: '/pages/snapUpList/snapUpList',
  686. })
  687. },
  688. toSnapUpListPage: function (e) {
  689. var seckillId = e.currentTarget.dataset.seckillid;
  690. wx.navigateTo({
  691. url: "/pages/snapUpDetail/snapUpDetail?seckillid=" + seckillId,
  692. })
  693. },
  694. /**
  695. * 团购
  696. */
  697. getAbulk: function () {
  698. wx.showLoading()
  699. var param = {
  700. url: "/groupProd/indexList",
  701. method: "GET",
  702. data: {},
  703. callBack: (res) => {
  704. wx.hideLoading();
  705. this.setData({
  706. aBulkList: res
  707. });
  708. }
  709. };
  710. http.request(param);
  711. },
  712. /**
  713. * 跳转团购列表页
  714. */
  715. toAbulkPage: function () {
  716. wx.navigateTo({
  717. url: '/pages/aBulkList/aBulkList',
  718. })
  719. },
  720. toAbulkListPage: function (e) {
  721. var prodId = e.currentTarget.dataset.prodid;
  722. var groupActivityId = e.currentTarget.dataset.groupactivityid;
  723. wx.navigateTo({
  724. url: '/pages/prod/prod?prodid=' + prodId + "&groupActivityId=" + groupActivityId
  725. })
  726. },
  727. // 跳转搜索页
  728. toSearchPage: function () {
  729. wx.navigateTo({
  730. // url: '/pages/search-page/search-page',
  731. url: `/pages/search-page/search-page?shopId=${this.data.shop_id}`,
  732. })
  733. },
  734. //跳转商品活动页面
  735. toClassifyPage: function (e) {
  736. var url = '/pages/prod-classify/prod-classify?sts=' + e.currentTarget.dataset.sts;
  737. var id = e.currentTarget.dataset.id;
  738. var title = e.currentTarget.dataset.title;
  739. if (id) {
  740. url += "&tagid=" + id + "&title=" + title;
  741. }
  742. wx.navigateTo({
  743. url: url
  744. })
  745. },
  746. toSecKillPage: function () {
  747. wx.navigateTo({
  748. url: '/pages/snapUpList/snapUpList',
  749. })
  750. },
  751. //跳转公告列表页面
  752. onNewsPage: function () {
  753. wx.navigateTo({
  754. url: '/pages/recent-news/recent-news',
  755. })
  756. },
  757. onShow: function () {
  758. // this.get_test()
  759. this.setData({
  760. select_address: wx.getStorageSync('ADDRESS')
  761. })
  762. // this.getCurrentLocation()
  763. updateManager.onCheckForUpdate(function (res) {
  764. updateManager.onUpdateReady(function () {
  765. wx.showModal({
  766. title: '更新提示',
  767. content: '新版本已经准备好,是否重启应用?',
  768. success(res) {
  769. if (res.confirm) {
  770. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  771. updateManager.applyUpdate()
  772. }
  773. }
  774. })
  775. })
  776. })
  777. http.getCartCount(); //重新计算购物车总数量
  778. },
  779. /**
  780. * 接口测试用
  781. */
  782. /**
  783. * 选择定位后更新列表
  784. */
  785. go_update() {
  786. this.get_neighborShop()
  787. setTimeout(() => {
  788. this.getNewList();
  789. this.getSnapUpList();
  790. this.getHotSalesProds()
  791. }, 1000)
  792. },
  793. getAllData() {
  794. http.getCartCount(); //重新计算购物车总数量
  795. this.getIndexImgs();
  796. this.get_neighborShop()
  797. // this.getNoticeList();
  798. this.getAbulk();
  799. this.getRecommended()
  800. this.getRecommendeds()
  801. this.getAdv()
  802. setTimeout(() => {
  803. this.getNewList();
  804. this.getSnapUpList();
  805. this.getHotSalesProds();
  806. }, 500)
  807. },
  808. //加载轮播图
  809. getIndexImgs() {
  810. console.log('getIndexImgs');
  811. //加载轮播图
  812. var params = {
  813. url: "/indexImgs/0",
  814. method: "GET",
  815. data: {},
  816. callBack: (res) => {
  817. this.setData({
  818. indexImgs: res,
  819. seq: res
  820. });
  821. wx.hideLoading();
  822. }
  823. };
  824. http.request(params);
  825. },
  826. // getNoticeList() {
  827. // // 加载公告
  828. // var params = {
  829. // url: "/shop/notice/topNoticeList/0",
  830. // method: "GET",
  831. // data: {},
  832. // callBack: (res) => {
  833. // this.setData({
  834. // news: res,
  835. // });
  836. // wx.hideLoading();
  837. // }
  838. // };
  839. // http.request(params);
  840. // },
  841. /**
  842. * 加载热销商品列表
  843. */
  844. getHotSalesProds() {
  845. var param = {
  846. url: "/search/searchProdPage",
  847. method: "GET",
  848. data: {
  849. current: this.data.current,
  850. size: 10,
  851. sort: 3,
  852. orderBy: 1,
  853. lat: wx.getStorageSync('LATITUDE'),
  854. lon: wx.getStorageSync('LONGITUDE'),
  855. distance: wx.getStorageSync('DISTANCE') || 0,
  856. shopId: this.data.shop_id
  857. },
  858. callBack: (res) => {
  859. var hotSalesList = []
  860. let img = ''
  861. res.records.map(e => {
  862. img = e.pic.split(',')
  863. e.pic = img[0]
  864. })
  865. if (this.data.current == 1) {
  866. setTimeout(() => {
  867. this.setData({
  868. hotSalesList: res.records,
  869. pages: res.pages,
  870. current: res.current
  871. });
  872. }, 500)
  873. } else {
  874. hotSalesList = this.data.hotSalesList
  875. hotSalesList.push(...res.records)
  876. this.setData({
  877. hotSalesList
  878. })
  879. if (res.records.length < 1) {
  880. this.setData({
  881. isAll: true
  882. })
  883. }
  884. }
  885. this.setData({
  886. isHand:false
  887. })
  888. }
  889. };
  890. http.request(param);
  891. },
  892. // 触底加载下一页
  893. getNextPage() {
  894. console.log('getNextPage',this.data.current);
  895. if (this.data.pages > this.data.current) {
  896. this.setData({
  897. current: this.data.current + 1
  898. })
  899. !this.data.isHand&&this.getHotSalesProds()
  900. } else {
  901. this.setData({
  902. isAll: true
  903. })
  904. }
  905. },
  906. /**
  907. * 页面上拉触底事件的处理函数
  908. */
  909. onReachBottom: function () {
  910. this.getNextPage()
  911. },
  912. onPullDownRefresh: function () {
  913. // wx.showNavigationBarLoading() //在标题栏中显示加载
  914. //模拟加载
  915. var ths = this;
  916. this.setData({ //下拉刷新
  917. current: 1
  918. })
  919. setTimeout(function () {
  920. ths.getAllData();
  921. // wx.hideNavigationBarLoading() //完成停止加载
  922. wx.stopPullDownRefresh() //停止下拉刷新
  923. }, 100);
  924. },
  925. onShareAppMessage: function (e) {
  926. return {
  927. path: "pages/index/index"
  928. }
  929. }
  930. })