index.js 25 KB

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