index.js 25 KB

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