index.js 23 KB

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