index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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:'',
  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. var shopid = e.currentTarget.dataset.shopid;
  473. if (prodid) {
  474. wx.navigateTo({
  475. url: `/pages/prod/prod?prodid=${prodid}&shopid=${shopid}`,
  476. })
  477. }
  478. },
  479. toCouponCenter: function () {
  480. wx.navigateTo({
  481. url: '/pages/couponCenter/couponCenter',
  482. })
  483. },
  484. newToProdPage: function (e) {
  485. let prodId = e.currentTarget.dataset.prod
  486. if (prodId) {
  487. wx.navigateTo({
  488. url: '/pages/prod/prod?prodid=' + prodId,
  489. })
  490. }
  491. },
  492. /**
  493. * 跳转秒杀列表页
  494. */
  495. toSpecialDiscount: function () {
  496. wx.navigateTo({
  497. url: '/pages/specialDiscount/specialDiscount',
  498. })
  499. },
  500. /**
  501. * 跳转到定位页面
  502. */
  503. toLocationPage: function () {
  504. wx.navigateTo({
  505. url: '/pages/locationAdd/locationAdd',
  506. })
  507. },
  508. /**
  509. * 秒杀
  510. */
  511. getSnapUpList: function () {
  512. wx.showLoading()
  513. var params = {
  514. url: "/seckill/pageProd",
  515. method: "GET",
  516. data: {
  517. size: 4,
  518. lat: wx.getStorageSync('LATITUDE'),
  519. lon: wx.getStorageSync('LONGITUDE'),
  520. distance: wx.getStorageSync('DISTANCE') || 0
  521. },
  522. callBack: (res) => {
  523. wx.hideLoading();
  524. let result = res.records.filter(item => util.dateToTimestamp(item.endTime) > new Date().getTime()) //过滤掉秒杀时间已结束的商品
  525. let img = ''
  526. result.map(e => {
  527. img = e.pic.split(',')
  528. e.pic = img[0]
  529. })
  530. this.setData({
  531. snapUpList: result
  532. });
  533. let closestItem = null;
  534. let minTimeDiff = Infinity;
  535. this.data.snapUpList.forEach((e) => {
  536. const endTime = util.dateToTimestamp(e.endTime);
  537. const now = new Date().getTime();
  538. const timeDiff = endTime - now;
  539. // 获取距离时间最近的秒杀时间
  540. if (timeDiff < minTimeDiff && timeDiff > 0) {
  541. minTimeDiff = timeDiff;
  542. closestItem = e;
  543. }
  544. })
  545. if (closestItem) {
  546. const endTime = util.dateToTimestamp(closestItem.endTime);
  547. const interval = setInterval(() => {
  548. const now = new Date().getTime();
  549. const timeDiff = endTime - now;
  550. if (timeDiff <= 0) {
  551. clearInterval(interval);
  552. return;
  553. }
  554. const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
  555. const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  556. const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
  557. const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
  558. this.setData({
  559. days: days,
  560. hours: hours,
  561. minutes: minutes,
  562. seconds: seconds
  563. });
  564. }, 1000);
  565. }
  566. }
  567. };
  568. http.request(params);
  569. },
  570. /**
  571. * 新品推荐
  572. */
  573. getNewList: function () {
  574. // var params = {
  575. // url: "/prod/lastedProdPage",
  576. // method: "GET",
  577. // data: {
  578. // current: 1,
  579. // size: 4,
  580. // lat: wx.getStorageSync('LATITUDE'),
  581. // lon: wx.getStorageSync('LONGITUDE'),
  582. // distance: wx.getStorageSync('DISTANCE') || 0,
  583. // shopId:this.data.shop_id
  584. // },
  585. // callBack: (res) => {
  586. // let img = ''
  587. // res.records.map(e => {
  588. // img = e.pic.split(',')
  589. // e.pic = img[0]
  590. // })
  591. // this.setData({
  592. // newList: res.records,
  593. // })
  594. // }
  595. // };
  596. // http.request(params);
  597. },
  598. /**
  599. * 获取距离最近店铺id
  600. * @param {*} e
  601. */
  602. get_neighborShop: function () {
  603. var params = {
  604. url: "/shop/neighborShop",
  605. method: "GET",
  606. data: {
  607. lat: wx.getStorageSync('LATITUDE'),
  608. lon: wx.getStorageSync('LONGITUDE'),
  609. platform:1
  610. },
  611. callBack: (res) => {
  612. if(typeof res == 'number'){
  613. this.getaddress_transports(res)
  614. this.setData({
  615. shop_id: res
  616. })
  617. setTimeout(() => {
  618. this.getClassInfo(res);
  619. }, 300)
  620. }else{
  621. this.getaddress_transports(res.shopId)
  622. this.setData({
  623. shop_id: res.shopId,
  624. shopName:res.shopName
  625. })
  626. setTimeout(() => {
  627. this.getClassInfo(res.shopId);
  628. }, 300)
  629. }
  630. }
  631. };
  632. http.request(params);
  633. },
  634. /**
  635. * 获取最大配送范围
  636. */
  637. getaddress_transports: function (shopId) {
  638. let _this = this
  639. var params = {
  640. url: "/p/address/transport2",
  641. method: "GET",
  642. data: {
  643. shopId: shopId,
  644. latitude: wx.getStorageSync('LATITUDE'),
  645. longitude: wx.getStorageSync('LONGITUDE'),
  646. },
  647. callBack: function (res) {
  648. wx.setStorageSync('DISTANCE', res.distance)
  649. _this.setData({
  650. get_distance: res.distance
  651. })
  652. },
  653. errCallBack(res) {
  654. console.log(res);
  655. wx.setStorageSync('DISTANCE', 0)
  656. }
  657. };
  658. http.request(params);
  659. },
  660. onClose: function () {
  661. this.setData({
  662. addCarshow: false
  663. })
  664. },
  665. /**
  666. * 步进器
  667. */
  668. minusButton: function (e) {
  669. let totalNum = this.data.totalNum
  670. if (totalNum > 0) {
  671. this.setData({
  672. totalNum: totalNum - 1
  673. })
  674. }
  675. },
  676. addButton: function (e) {
  677. let totalNum = this.data.totalNum
  678. this.setData({
  679. totalNum: totalNum + 1
  680. })
  681. },
  682. /**
  683. * 跳转秒杀列表页
  684. */
  685. toSnapUpPage: function () {
  686. wx.navigateTo({
  687. url: '/pages/snapUpList/snapUpList',
  688. })
  689. },
  690. toSnapUpListPage: function (e) {
  691. var seckillId = e.currentTarget.dataset.seckillid;
  692. wx.navigateTo({
  693. url: "/pages/snapUpDetail/snapUpDetail?seckillid=" + seckillId,
  694. })
  695. },
  696. /**
  697. * 团购
  698. */
  699. getAbulk: function () {
  700. wx.showLoading()
  701. var param = {
  702. url: "/groupProd/indexList",
  703. method: "GET",
  704. data: {},
  705. callBack: (res) => {
  706. wx.hideLoading();
  707. this.setData({
  708. aBulkList: res
  709. });
  710. }
  711. };
  712. http.request(param);
  713. },
  714. /**
  715. * 跳转团购列表页
  716. */
  717. toAbulkPage: function () {
  718. wx.navigateTo({
  719. url: '/pages/aBulkList/aBulkList',
  720. })
  721. },
  722. toAbulkListPage: function (e) {
  723. var prodId = e.currentTarget.dataset.prodid;
  724. var groupActivityId = e.currentTarget.dataset.groupactivityid;
  725. wx.navigateTo({
  726. url: '/pages/prod/prod?prodid=' + prodId + "&groupActivityId=" + groupActivityId
  727. })
  728. },
  729. // 跳转搜索页
  730. toSearchPage: function () {
  731. wx.navigateTo({
  732. // url: '/pages/search-page/search-page',
  733. url: `/pages/search-page/search-page?shopId=${this.data.shop_id}`,
  734. })
  735. },
  736. //跳转商品活动页面
  737. toClassifyPage: function (e) {
  738. var url = '/pages/prod-classify/prod-classify?sts=' + e.currentTarget.dataset.sts;
  739. var id = e.currentTarget.dataset.id;
  740. var title = e.currentTarget.dataset.title;
  741. if (id) {
  742. url += "&tagid=" + id + "&title=" + title;
  743. }
  744. wx.navigateTo({
  745. url: url
  746. })
  747. },
  748. toSecKillPage: function () {
  749. wx.navigateTo({
  750. url: '/pages/snapUpList/snapUpList',
  751. })
  752. },
  753. //跳转公告列表页面
  754. onNewsPage: function () {
  755. wx.navigateTo({
  756. url: '/pages/recent-news/recent-news',
  757. })
  758. },
  759. onShow: function () {
  760. // this.get_test()
  761. this.setData({
  762. select_address: wx.getStorageSync('ADDRESS')
  763. })
  764. // this.getCurrentLocation()
  765. updateManager.onCheckForUpdate(function (res) {
  766. updateManager.onUpdateReady(function () {
  767. wx.showModal({
  768. title: '更新提示',
  769. content: '新版本已经准备好,是否重启应用?',
  770. success(res) {
  771. if (res.confirm) {
  772. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  773. updateManager.applyUpdate()
  774. }
  775. }
  776. })
  777. })
  778. })
  779. http.getCartCount(); //重新计算购物车总数量
  780. },
  781. /**
  782. * 接口测试用
  783. */
  784. /**
  785. * 选择定位后更新列表
  786. */
  787. go_update() {
  788. this.get_neighborShop()
  789. setTimeout(() => {
  790. this.getNewList();
  791. this.getSnapUpList();
  792. this.getHotSalesProds()
  793. }, 1000)
  794. },
  795. getAllData() {
  796. http.getCartCount(); //重新计算购物车总数量
  797. this.getIndexImgs();
  798. this.get_neighborShop()
  799. // this.getNoticeList();
  800. this.getAbulk();
  801. this.getRecommended()
  802. this.getRecommendeds()
  803. this.getAdv()
  804. setTimeout(() => {
  805. this.getNewList();
  806. this.getSnapUpList();
  807. this.getHotSalesProds();
  808. }, 500)
  809. },
  810. //加载轮播图
  811. getIndexImgs() {
  812. console.log('getIndexImgs');
  813. //加载轮播图
  814. var params = {
  815. url: "/indexImgs/0",
  816. method: "GET",
  817. data: {},
  818. callBack: (res) => {
  819. this.setData({
  820. indexImgs: res,
  821. seq: res
  822. });
  823. wx.hideLoading();
  824. }
  825. };
  826. http.request(params);
  827. },
  828. // getNoticeList() {
  829. // // 加载公告
  830. // var params = {
  831. // url: "/shop/notice/topNoticeList/0",
  832. // method: "GET",
  833. // data: {},
  834. // callBack: (res) => {
  835. // this.setData({
  836. // news: res,
  837. // });
  838. // wx.hideLoading();
  839. // }
  840. // };
  841. // http.request(params);
  842. // },
  843. /**
  844. * 加载热销商品列表
  845. */
  846. getHotSalesProds() {
  847. var param = {
  848. url: "/search/searchProdPage",
  849. method: "GET",
  850. data: {
  851. current: this.data.current,
  852. size: 10,
  853. sort: 3,
  854. orderBy: 1,
  855. lat: wx.getStorageSync('LATITUDE'),
  856. lon: wx.getStorageSync('LONGITUDE'),
  857. distance: wx.getStorageSync('DISTANCE') || 0,
  858. shopId: this.data.shop_id,
  859. platform:1
  860. },
  861. callBack: (res) => {
  862. var hotSalesList = []
  863. let img = ''
  864. res.records.map(e => {
  865. if(e.pic){
  866. img = e.pic.split(',')
  867. e.pic = img[0]
  868. }
  869. })
  870. if (this.data.current == 1) {
  871. setTimeout(() => {
  872. this.setData({
  873. hotSalesList: res.records,
  874. pages: res.pages,
  875. current: res.current
  876. });
  877. }, 500)
  878. } else {
  879. hotSalesList = this.data.hotSalesList
  880. hotSalesList.push(...res.records)
  881. this.setData({
  882. hotSalesList
  883. })
  884. if (res.records.length < 1) {
  885. this.setData({
  886. isAll: true
  887. })
  888. }
  889. }
  890. this.setData({
  891. isHand:false
  892. })
  893. }
  894. };
  895. http.request(param);
  896. },
  897. // 触底加载下一页
  898. getNextPage() {
  899. console.log('getNextPage',this.data.current);
  900. if (this.data.pages > this.data.current) {
  901. this.setData({
  902. current: this.data.current + 1
  903. })
  904. !this.data.isHand&&this.getHotSalesProds()
  905. } else {
  906. this.setData({
  907. isAll: true
  908. })
  909. }
  910. },
  911. /**
  912. * 页面上拉触底事件的处理函数
  913. */
  914. onReachBottom: function () {
  915. this.getNextPage()
  916. },
  917. onPullDownRefresh: function () {
  918. // wx.showNavigationBarLoading() //在标题栏中显示加载
  919. //模拟加载
  920. var ths = this;
  921. this.setData({ //下拉刷新
  922. current: 1
  923. })
  924. setTimeout(function () {
  925. ths.getAllData();
  926. // wx.hideNavigationBarLoading() //完成停止加载
  927. wx.stopPullDownRefresh() //停止下拉刷新
  928. }, 100);
  929. },
  930. onShareAppMessage: function (e) {
  931. return {
  932. path: "pages/index/index"
  933. }
  934. }
  935. })