index.js 26 KB

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