index.js 25 KB

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