index.js 24 KB

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