index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  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: "/keyword/list",
  292. method: "GET",
  293. data: {
  294. type: 2
  295. },
  296. callBack: (res) => {
  297. let reslut = res.filter(item => item.status !== 2) //过滤下线词
  298. let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未生效词
  299. this.setData({
  300. hotList: timeReslut
  301. })
  302. }
  303. };
  304. http.request(params);
  305. },
  306. getRecommendeds: function () {
  307. var params = {
  308. url: "/keyword/list",
  309. method: "GET",
  310. data: {
  311. type: 3
  312. },
  313. callBack: (res) => {
  314. let reslut = res.filter(item => item.status !== 2) //过滤已线下推荐词
  315. let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未到生效时间推荐词
  316. this.setData({
  317. recommendedList: timeReslut
  318. })
  319. }
  320. };
  321. http.request(params);
  322. },
  323. /**
  324. * 推荐词搜索
  325. */
  326. topSwiperChange: function (e) {
  327. this.setData({
  328. topCurrentIndex: e.detail.current // 获取当前滚动到的swiper-item的索引并更新到data中
  329. })
  330. },
  331. topHotSearch: function () {
  332. const topname = this.data.hotList[this.data.topCurrentIndex].name
  333. wx.navigateTo({
  334. // url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
  335. url: `/pages/search-prod-show/search-prod-show?prodName=${topname}&shopId=${this.data.shop_id}`,
  336. })
  337. },
  338. swiperChange: function (e) {
  339. this.setData({
  340. currentIndex: e.detail.current
  341. });
  342. },
  343. inputSearch: function () {
  344. const currentName = this.data.hotList[this.data.currentIndex].name;
  345. wx.navigateTo({
  346. // url: '/pages/search-prod-show/search-prod-show?prodName=' + currentName,
  347. url: `/pages/search-prod-show/search-prod-show?prodName=${currentName}&shopId=${this.data.shop_id}`,
  348. })
  349. },
  350. recommendedSearch: function (e) {
  351. let name = e.currentTarget.dataset.name
  352. wx.navigateTo({
  353. url: `/pages/search-prod-show/search-prod-show?prodName=${name}&shopId=${this.data.shop_id}`,
  354. })
  355. },
  356. /**
  357. * 对象映射,每多一个swiper-item需+10,用以金刚区的分类跳转到指定分类菜单,当菜单类大于三十个时需再次手动添加
  358. * @param {*} e
  359. */
  360. menuSwiper: function (e) {
  361. const topMap = {
  362. 0: 0,
  363. 1: 10,
  364. 2: 20
  365. };
  366. const currentValue = topMap[e.detail.current];
  367. if (currentValue !== undefined) {
  368. this.setData({
  369. currentTop: currentValue
  370. });
  371. }
  372. },
  373. /**
  374. * 当分类大于10时进行切割
  375. */
  376. splitList: function (arr) {
  377. let result = [];
  378. let groupCount = Math.ceil(arr.length / 5);
  379. for (let i = 0; i < groupCount; i++) {
  380. let startIndex = i * 5;
  381. let endIndex = Math.min((i + 1) * 5, arr.length);
  382. result.push(arr.slice(startIndex, endIndex));
  383. }
  384. return result;
  385. },
  386. /**
  387. * 宫格分类
  388. */
  389. getClassInfo: function (shopId) {
  390. let _this = this
  391. //加载分类列表
  392. var params = {
  393. url: "/category/categoryInfo",
  394. method: "GET",
  395. data: {
  396. shopId: shopId,
  397. current:1,
  398. size:99999
  399. },
  400. callBack: function (res) {
  401. console.log(res);
  402. let categoryName = ''
  403. res.records.forEach(e => {
  404. categoryName = e.categoryName.split('>')
  405. e.categoryName = categoryName[0]
  406. })
  407. let newRes = _this.splitList(res.records)
  408. let categoryList = newRes.splice(0,2)
  409. if(categoryList.length == 2){
  410. categoryList = categoryList[0].concat(categoryList[1])
  411. }else if(categoryList.length == 1){
  412. categoryList = categoryList[0]
  413. }
  414. newRes = newRes.flat(Infinity)
  415. _this.setData({
  416. categoryList: categoryList,
  417. categoryList1: newRes,
  418. });
  419. }
  420. };
  421. http.request(params);
  422. },
  423. /**
  424. * 点击宫格
  425. */
  426. selectMenu: function (e) {
  427. console.log(e);
  428. let categoryId = e.currentTarget.dataset.itemid
  429. let index = e.currentTarget.dataset.index + this.data.currentTop
  430. let pic = e.currentTarget.dataset.pic
  431. let categories = e.currentTarget.dataset.categories
  432. // if (categories == null || categories.length < 1) {
  433. // wx.navigateTo({
  434. // url: `/pages/sub-category/sub-category?categoryId=${categoryId}&shopId=${this.data.shop_id}`,
  435. // })
  436. // } else {
  437. // getApp().globalData.categoryId = categoryId
  438. // getApp().globalData.index = index
  439. // getApp().globalData.pic = pic
  440. // wx.navigateTo({
  441. // url: '/pages/category/category'
  442. // })
  443. // }
  444. // eventBus.emit('categoryId', categoryId);
  445. wx.setStorageSync('categoryId', categoryId)
  446. wx.navigateTo({
  447. url: '/pages/category1/category'
  448. })
  449. // wx.switchTab({
  450. // url: '/pages/category/category'
  451. // })
  452. },
  453. // 领红包
  454. toRedPackage: function () {
  455. wx.navigateTo({
  456. url: '/pages/ledRedPackage/ledRedPackage',
  457. })
  458. },
  459. /**
  460. * banner图跳转
  461. * @param {判断条件} e
  462. */
  463. goToLevelPage: function (e) {
  464. let name = e.currentTarget.dataset.name
  465. if (name == 'new') {
  466. wx.navigateTo({
  467. url: '/pages/prod-classify/prod-classify?sts=' + 1
  468. })
  469. } else if (name == 'favorable') {
  470. wx.navigateTo({
  471. url: '/pages/specialDiscount/specialDiscount'
  472. })
  473. } else if (name == 'groupBuy') {
  474. wx.navigateTo({
  475. url: '/pages/aBulkList/aBulkList',
  476. })
  477. } else {
  478. wx.navigateTo({
  479. url: '/pages/snapUpList/snapUpList',
  480. })
  481. }
  482. },
  483. /**
  484. * 跳转到商品详情页
  485. */
  486. toProdPage: function (e) {
  487. var prodid = e.currentTarget.dataset.prodid;
  488. var shopid = e.currentTarget.dataset.shopid;
  489. if (prodid) {
  490. wx.navigateTo({
  491. url: `/pages/prod/prod?prodid=${prodid}&shopid=${shopid}`,
  492. })
  493. }
  494. },
  495. toCouponCenter: function () {
  496. wx.navigateTo({
  497. url: '/pages/couponCenter/couponCenter',
  498. })
  499. },
  500. newToProdPage: function (e) {
  501. let prodId = e.currentTarget.dataset.prod
  502. if (prodId) {
  503. wx.navigateTo({
  504. url: '/pages/prod/prod?prodid=' + prodId,
  505. })
  506. }
  507. },
  508. /**
  509. * 跳转秒杀列表页
  510. */
  511. toSpecialDiscount: function () {
  512. wx.navigateTo({
  513. url: '/pages/specialDiscount/specialDiscount',
  514. })
  515. },
  516. /**
  517. * 跳转到定位页面
  518. */
  519. toLocationPage: function () {
  520. wx.navigateTo({
  521. url: '/pages/locationAdd/locationAdd',
  522. })
  523. },
  524. /**
  525. * 秒杀
  526. */
  527. getSnapUpList: function () {
  528. wx.showLoading()
  529. var params = {
  530. url: "/seckill/pageProd",
  531. method: "GET",
  532. data: {
  533. size: 4,
  534. lat: wx.getStorageSync('LATITUDE'),
  535. lon: wx.getStorageSync('LONGITUDE'),
  536. distance: wx.getStorageSync('DISTANCE') || 0
  537. },
  538. callBack: (res) => {
  539. wx.hideLoading();
  540. let result = res.records.filter(item => util.dateToTimestamp(item.endTime) > new Date().getTime()) //过滤掉秒杀时间已结束的商品
  541. let img = ''
  542. result.map(e => {
  543. img = e.pic.split(',')
  544. e.pic = img[0]
  545. })
  546. this.setData({
  547. snapUpList: result
  548. });
  549. let closestItem = null;
  550. let minTimeDiff = Infinity;
  551. this.data.snapUpList.forEach((e) => {
  552. const endTime = util.dateToTimestamp(e.endTime);
  553. const now = new Date().getTime();
  554. const timeDiff = endTime - now;
  555. // 获取距离时间最近的秒杀时间
  556. if (timeDiff < minTimeDiff && timeDiff > 0) {
  557. minTimeDiff = timeDiff;
  558. closestItem = e;
  559. }
  560. })
  561. if (closestItem) {
  562. const endTime = util.dateToTimestamp(closestItem.endTime);
  563. const interval = setInterval(() => {
  564. const now = new Date().getTime();
  565. const timeDiff = endTime - now;
  566. if (timeDiff <= 0) {
  567. clearInterval(interval);
  568. return;
  569. }
  570. const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
  571. const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  572. const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
  573. const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
  574. this.setData({
  575. days: days,
  576. hours: hours,
  577. minutes: minutes,
  578. seconds: seconds
  579. });
  580. }, 1000);
  581. }
  582. }
  583. };
  584. http.request(params);
  585. },
  586. /**
  587. * 新品推荐
  588. */
  589. getNewList: function () {
  590. // var params = {
  591. // url: "/prod/lastedProdPage",
  592. // method: "GET",
  593. // data: {
  594. // current: 1,
  595. // size: 4,
  596. // lat: wx.getStorageSync('LATITUDE'),
  597. // lon: wx.getStorageSync('LONGITUDE'),
  598. // distance: wx.getStorageSync('DISTANCE') || 0,
  599. // shopId:this.data.shop_id
  600. // },
  601. // callBack: (res) => {
  602. // let img = ''
  603. // res.records.map(e => {
  604. // img = e.pic.split(',')
  605. // e.pic = img[0]
  606. // })
  607. // this.setData({
  608. // newList: res.records,
  609. // })
  610. // }
  611. // };
  612. // http.request(params);
  613. },
  614. /**
  615. * 获取距离最近店铺id
  616. * @param {*} e
  617. */
  618. get_neighborShop: function () {
  619. var params = {
  620. url: "/shop/neighborShop",
  621. method: "GET",
  622. data: {
  623. lat: wx.getStorageSync('LATITUDE'),
  624. lon: wx.getStorageSync('LONGITUDE'),
  625. platform:1
  626. },
  627. callBack: (res) => {
  628. if(typeof res == 'number'){
  629. this.getaddress_transports(res)
  630. this.setData({
  631. shop_id: res
  632. })
  633. setTimeout(() => {
  634. this.getClassInfo(res);
  635. }, 300)
  636. }else{
  637. this.getaddress_transports(res.shopId)
  638. this.setData({
  639. shop_id: res.shopId,
  640. shopName:res.shopName
  641. })
  642. setTimeout(() => {
  643. this.getClassInfo(res.shopId);
  644. }, 300)
  645. }
  646. }
  647. };
  648. http.request(params);
  649. },
  650. /**
  651. * 获取最大配送范围
  652. */
  653. getaddress_transports: function (shopId) {
  654. let _this = this
  655. var params = {
  656. url: "/p/address/transport2",
  657. method: "GET",
  658. data: {
  659. shopId: shopId,
  660. latitude: wx.getStorageSync('LATITUDE'),
  661. longitude: wx.getStorageSync('LONGITUDE'),
  662. },
  663. callBack: function (res) {
  664. wx.setStorageSync('DISTANCE', res.distance)
  665. _this.setData({
  666. get_distance: res.distance
  667. })
  668. },
  669. errCallBack(res) {
  670. console.log(res);
  671. wx.setStorageSync('DISTANCE', 0)
  672. }
  673. };
  674. http.request(params);
  675. },
  676. onClose: function () {
  677. this.setData({
  678. addCarshow: false
  679. })
  680. },
  681. /**
  682. * 步进器
  683. */
  684. minusButton: function (e) {
  685. let totalNum = this.data.totalNum
  686. if (totalNum > 0) {
  687. this.setData({
  688. totalNum: totalNum - 1
  689. })
  690. }
  691. },
  692. addButton: function (e) {
  693. let totalNum = this.data.totalNum
  694. this.setData({
  695. totalNum: totalNum + 1
  696. })
  697. },
  698. /**
  699. * 跳转秒杀列表页
  700. */
  701. toSnapUpPage: function () {
  702. wx.navigateTo({
  703. url: '/pages/snapUpList/snapUpList',
  704. })
  705. },
  706. toSnapUpListPage: function (e) {
  707. var seckillId = e.currentTarget.dataset.seckillid;
  708. wx.navigateTo({
  709. url: "/pages/snapUpDetail/snapUpDetail?seckillid=" + seckillId,
  710. })
  711. },
  712. /**
  713. * 团购
  714. */
  715. getAbulk: function () {
  716. wx.showLoading()
  717. var param = {
  718. url: "/groupProd/indexList",
  719. method: "GET",
  720. data: {},
  721. callBack: (res) => {
  722. wx.hideLoading();
  723. this.setData({
  724. aBulkList: res
  725. });
  726. }
  727. };
  728. http.request(param);
  729. },
  730. /**
  731. * 跳转团购列表页
  732. */
  733. toAbulkPage: function () {
  734. wx.navigateTo({
  735. url: '/pages/aBulkList/aBulkList',
  736. })
  737. },
  738. toAbulkListPage: function (e) {
  739. var prodId = e.currentTarget.dataset.prodid;
  740. var groupActivityId = e.currentTarget.dataset.groupactivityid;
  741. wx.navigateTo({
  742. url: '/pages/prod/prod?prodid=' + prodId + "&groupActivityId=" + groupActivityId
  743. })
  744. },
  745. // 跳转搜索页
  746. toSearchPage: function () {
  747. wx.navigateTo({
  748. // url: '/pages/search-page/search-page',
  749. url: `/pages/search-page/search-page?shopId=${this.data.shop_id}`,
  750. })
  751. },
  752. //跳转商品活动页面
  753. toClassifyPage: function (e) {
  754. var url = '/pages/prod-classify/prod-classify?sts=' + e.currentTarget.dataset.sts;
  755. var id = e.currentTarget.dataset.id;
  756. var title = e.currentTarget.dataset.title;
  757. if (id) {
  758. url += "&tagid=" + id + "&title=" + title;
  759. }
  760. wx.navigateTo({
  761. url: url
  762. })
  763. },
  764. toSecKillPage: function () {
  765. wx.navigateTo({
  766. url: '/pages/snapUpList/snapUpList',
  767. })
  768. },
  769. //跳转公告列表页面
  770. onNewsPage: function () {
  771. wx.navigateTo({
  772. url: '/pages/recent-news/recent-news',
  773. })
  774. },
  775. onShow: function () {
  776. // this.get_test()
  777. this.setData({
  778. select_address: wx.getStorageSync('ADDRESS')
  779. })
  780. // this.getCurrentLocation()
  781. updateManager.onCheckForUpdate(function (res) {
  782. updateManager.onUpdateReady(function () {
  783. wx.showModal({
  784. title: '更新提示',
  785. content: '新版本已经准备好,是否重启应用?',
  786. success(res) {
  787. if (res.confirm) {
  788. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  789. updateManager.applyUpdate()
  790. }
  791. }
  792. })
  793. })
  794. })
  795. http.getCartCount(); //重新计算购物车总数量
  796. },
  797. /**
  798. * 接口测试用
  799. */
  800. /**
  801. * 选择定位后更新列表
  802. */
  803. go_update() {
  804. this.get_neighborShop()
  805. setTimeout(() => {
  806. this.getNewList();
  807. this.getSnapUpList();
  808. this.getHotSalesProds()
  809. }, 1000)
  810. },
  811. getAllData() {
  812. http.getCartCount(); //重新计算购物车总数量
  813. this.getIndexImgs();
  814. this.get_neighborShop()
  815. // this.getNoticeList();
  816. this.getAbulk();
  817. this.getRecommended()
  818. this.getRecommendeds()
  819. this.getAdv()
  820. setTimeout(() => {
  821. this.getNewList();
  822. this.getSnapUpList();
  823. this.getHotSalesProds();
  824. }, 500)
  825. },
  826. //加载轮播图
  827. getIndexImgs() {
  828. console.log('getIndexImgs');
  829. //加载轮播图
  830. var params = {
  831. url: "/indexImgs/0",
  832. method: "GET",
  833. data: {},
  834. callBack: (res) => {
  835. this.setData({
  836. indexImgs: res,
  837. seq: res
  838. });
  839. wx.hideLoading();
  840. }
  841. };
  842. http.request(params);
  843. },
  844. // getNoticeList() {
  845. // // 加载公告
  846. // var params = {
  847. // url: "/shop/notice/topNoticeList/0",
  848. // method: "GET",
  849. // data: {},
  850. // callBack: (res) => {
  851. // this.setData({
  852. // news: res,
  853. // });
  854. // wx.hideLoading();
  855. // }
  856. // };
  857. // http.request(params);
  858. // },
  859. /**
  860. * 加载热销商品列表
  861. */
  862. getHotSalesProds() {
  863. if(!this.data.shop_id||this.data.shop_id == 0){
  864. return
  865. }
  866. var param = {
  867. url: "/search/searchProdPage",
  868. method: "GET",
  869. data: {
  870. current: this.data.current,
  871. size: 10,
  872. sort: 3,
  873. orderBy: 1,
  874. lat: wx.getStorageSync('LATITUDE'),
  875. lon: wx.getStorageSync('LONGITUDE'),
  876. distance: wx.getStorageSync('DISTANCE') || 0,
  877. shopId: this.data.shop_id,
  878. platform:1
  879. },
  880. callBack: (res) => {
  881. var hotSalesList = []
  882. let img = ''
  883. res.records.map(e => {
  884. if(e.pic){
  885. img = e.pic.split(',')
  886. e.pic = img[0]
  887. }
  888. })
  889. if (this.data.current == 1) {
  890. setTimeout(() => {
  891. this.setData({
  892. hotSalesList: res.records,
  893. pages: res.pages,
  894. current: res.current
  895. });
  896. }, 500)
  897. } else {
  898. hotSalesList = this.data.hotSalesList
  899. hotSalesList.push(...res.records)
  900. this.setData({
  901. hotSalesList
  902. })
  903. if (res.records.length < 1) {
  904. this.setData({
  905. isAll: true
  906. })
  907. }
  908. }
  909. this.setData({
  910. isHand:false
  911. })
  912. }
  913. };
  914. http.request(param);
  915. },
  916. // 触底加载下一页
  917. getNextPage() {
  918. console.log('getNextPage',this.data.current);
  919. if (this.data.pages > this.data.current) {
  920. this.setData({
  921. current: this.data.current + 1
  922. })
  923. !this.data.isHand&&this.getHotSalesProds()
  924. } else {
  925. this.setData({
  926. isAll: true
  927. })
  928. }
  929. },
  930. /**
  931. * 页面上拉触底事件的处理函数
  932. */
  933. onReachBottom: function () {
  934. this.getNextPage()
  935. },
  936. onPullDownRefresh: function () {
  937. // wx.showNavigationBarLoading() //在标题栏中显示加载
  938. //模拟加载
  939. var ths = this;
  940. this.setData({ //下拉刷新
  941. current: 1
  942. })
  943. setTimeout(function () {
  944. ths.getAllData();
  945. // wx.hideNavigationBarLoading() //完成停止加载
  946. wx.stopPullDownRefresh() //停止下拉刷新
  947. }, 100);
  948. },
  949. onShareAppMessage: function (e) {
  950. return {
  951. path: "pages/index/index"
  952. }
  953. }
  954. })