index.js 23 KB

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