index.js 22 KB

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