index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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. showPopup:false,
  12. imageUrl:'',
  13. isHand:false,
  14. shopList:[],
  15. showShopList:false,
  16. isScroll:false,
  17. active:1,
  18. imgUrl:'',
  19. swiperCurrent:0,
  20. swiperList:[],
  21. shopName:'附近暂无可配送门店',
  22. indicatorDots: true,
  23. indicatorColor: '#d1e5fb',
  24. indicatorActiveColor: '#1b7dec',
  25. autoplay: true,
  26. interval: 2000,
  27. duration: 1000,
  28. indexImgs: [],
  29. seq: 0,
  30. news: [],
  31. hotSalesList: [],
  32. sts: 0,
  33. current: 1,
  34. sort: 1,
  35. isAll: false,
  36. snapUpList: [], //秒杀列表
  37. aBulkList: [], //团购列表
  38. pageTopHeight: wx.getWindowInfo().statusBarHeight + 30 + 7,
  39. gapTop: 1,
  40. titleOpacity: 1,
  41. days: 0,
  42. hours: 0,
  43. minutes: 0,
  44. seconds: 0,
  45. hotList: [],
  46. recommendedList: [],
  47. totalNum: 1,
  48. shopDetail: {},
  49. select_address: '',
  50. categoryList: [],
  51. categoryList1: [],
  52. currentIndex: 0,
  53. topCurrentIndex: 0,
  54. currentTop: 0,
  55. shop_id: 0,
  56. get_distance: '',
  57. banner_img: [
  58. {
  59. img:'https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/JrXik2T4vhwp7c25b370159a7498499e7b4b76cfb288.png/1.png',
  60. name:''
  61. },
  62. {
  63. img:'https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/OFG6necEvIOpcd39097fe6f106894503a4d77c14d7b8.png/1.png',
  64. name:''
  65. },
  66. ]
  67. },
  68. onLoad: function () {
  69. console.log('load');
  70. // 实例化API核心类
  71. qqmapsdk = new QQMapWX({
  72. key: 'D3MBZ-LQK6U-IONVC-GJDPK-C43GF-UYFOC'
  73. // key: 'UNBBZ-OKDCB-FSTU4-N5EGG-CMJ67-CKB6H'
  74. });
  75. // 绑定页面滚动事件
  76. wx.pageScrollTo({
  77. scrollTop: 0, // 初始滚动位置,可按需调整
  78. duration: 0
  79. });
  80. this.get_setting()
  81. this.setData({
  82. select_address: wx.getStorageSync('ADDRESS')
  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. getDialog: function () {
  280. var params = {
  281. url: "/popup/config",
  282. method: "GET",
  283. data: {
  284. },
  285. callBack: (res) => {
  286. this.setData({
  287. showPopup:res.showPopup,
  288. imageUrl:res.imageUrl
  289. })
  290. }
  291. };
  292. http.request(params);
  293. },
  294. onClickHide:function(){
  295. this.setData({showPopup:false})
  296. },
  297. /**
  298. * 广告位
  299. */
  300. getAdv: function () {
  301. var params = {
  302. url: "/advert/search",
  303. method: "GET",
  304. data: {
  305. current: 1,
  306. size:99,
  307. status:1
  308. },
  309. callBack: (res) => {
  310. this.setData({
  311. swiperList: res.records
  312. })
  313. }
  314. };
  315. http.request(params);
  316. },
  317. /**
  318. * 推荐词,type:1关键词,2热门搜索词,3推荐搜索词
  319. */
  320. getRecommended: function () {
  321. var params = {
  322. url: "/searchTerm/hotSearchWord",
  323. method: "GET",
  324. data: {
  325. current:1,
  326. size:9999
  327. },
  328. callBack: (res) => {
  329. let reslut = res.records.filter(item => item.status !== 2) //过滤下线词
  330. let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未生效词
  331. this.setData({
  332. hotList: timeReslut
  333. })
  334. console.log(2222,this.data.hotList);
  335. }
  336. };
  337. http.request(params);
  338. },
  339. getRecommendeds: function () {
  340. var params = {
  341. url: "/searchTerm/recommendSearchWord",
  342. method: "GET",
  343. data: {
  344. current:1,
  345. size:9999
  346. },
  347. callBack: (res) => {
  348. let reslut = res.records.filter(item => item.status !== 2) //过滤已线下推荐词
  349. let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未到生效时间推荐词
  350. this.setData({
  351. recommendedList: timeReslut
  352. })
  353. }
  354. };
  355. http.request(params);
  356. },
  357. /**
  358. * 推荐词搜索
  359. */
  360. topSwiperChange: function (e) {
  361. this.setData({
  362. topCurrentIndex: e.detail.current // 获取当前滚动到的swiper-item的索引并更新到data中
  363. })
  364. },
  365. topHotSearch: function () {
  366. const topname = this.data.hotList[this.data.topCurrentIndex].name
  367. wx.navigateTo({
  368. // url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
  369. url: `/pages/search-prod-show/search-prod-show?prodName=${topname}&shopId=${this.data.shop_id}`,
  370. })
  371. },
  372. swiperChange: function (e) {
  373. this.setData({
  374. currentIndex: e.detail.current
  375. });
  376. },
  377. inputSearch: function () {
  378. const currentName = this.data.hotList[this.data.currentIndex].name;
  379. wx.navigateTo({
  380. // url: '/pages/search-prod-show/search-prod-show?prodName=' + currentName,
  381. url: `/pages/search-prod-show/search-prod-show?prodName=${currentName}&shopId=${this.data.shop_id}`,
  382. })
  383. },
  384. recommendedSearch: function (e) {
  385. let name = e.currentTarget.dataset.name
  386. wx.navigateTo({
  387. url: `/pages/search-prod-show/search-prod-show?prodName=${name}&shopId=${this.data.shop_id}`,
  388. })
  389. },
  390. /**
  391. * 对象映射,每多一个swiper-item需+10,用以金刚区的分类跳转到指定分类菜单,当菜单类大于三十个时需再次手动添加
  392. * @param {*} e
  393. */
  394. menuSwiper: function (e) {
  395. const topMap = {
  396. 0: 0,
  397. 1: 10,
  398. 2: 20
  399. };
  400. const currentValue = topMap[e.detail.current];
  401. if (currentValue !== undefined) {
  402. this.setData({
  403. currentTop: currentValue
  404. });
  405. }
  406. },
  407. /**
  408. * 当分类大于10时进行切割
  409. */
  410. splitList: function (arr) {
  411. let result = [];
  412. let groupCount = Math.ceil(arr.length / 5);
  413. for (let i = 0; i < groupCount; i++) {
  414. let startIndex = i * 5;
  415. let endIndex = Math.min((i + 1) * 5, arr.length);
  416. result.push(arr.slice(startIndex, endIndex));
  417. }
  418. return result;
  419. },
  420. /**
  421. * 获取用户信息
  422. */
  423. getUserInfo: function() {
  424. return new Promise((resolve,reject)=>{
  425. var that = this;
  426. var param = {
  427. url: '/p/user/userInfo',
  428. method: 'GET',
  429. data: {},
  430. callBack: (res) => {
  431. res.channelId&&wx.setStorageSync('channelId',res.channelId)
  432. resolve()
  433. }
  434. }
  435. http.request(param)
  436. })
  437. },
  438. /**
  439. * 宫格分类
  440. */
  441. getClassInfo: function (shopId) {
  442. let _this = this
  443. //加载分类列表
  444. var params = {
  445. url: "/category/listCategoryForUser",
  446. method: "GET",
  447. data: {
  448. shopId: wx.getStorageSync('shopInfo').shopId,
  449. channelId:wx.getStorageSync('channelId')||3
  450. },
  451. callBack: function (res) {
  452. console.log(res);
  453. let categoryName = ''
  454. res.forEach(e => {
  455. categoryName = e.categoryName.split('>')
  456. e.categoryName = categoryName[0]
  457. })
  458. let newRes = _this.splitList(res)
  459. let categoryList = newRes.splice(0,2)
  460. if(categoryList.length == 2){
  461. categoryList = categoryList[0].concat(categoryList[1])
  462. }else if(categoryList.length == 1){
  463. categoryList = categoryList[0]
  464. }
  465. newRes = newRes.flat(Infinity)
  466. _this.setData({
  467. categoryList: categoryList,
  468. categoryList1: newRes,
  469. });
  470. }
  471. };
  472. http.request(params);
  473. },
  474. /**
  475. * 点击宫格
  476. */
  477. selectMenu: function (e) {
  478. console.log(e);
  479. let categoryId = e.currentTarget.dataset.itemid
  480. let hassecond = e.currentTarget.dataset.hassecond
  481. let index = e.currentTarget.dataset.index + this.data.currentTop
  482. let pic = e.currentTarget.dataset.pic
  483. let categories = e.currentTarget.dataset.categories
  484. wx.setStorageSync('categoryId', categoryId)
  485. wx.navigateTo({
  486. url: '/pages/category1/category'
  487. })
  488. // wx.switchTab({
  489. // url: '/pages/category/category'
  490. // })
  491. },
  492. // 领红包
  493. toRedPackage: function () {
  494. wx.navigateTo({
  495. url: '/pages/ledRedPackage/ledRedPackage',
  496. })
  497. },
  498. /**
  499. * banner图跳转
  500. * @param {判断条件} e
  501. */
  502. goToLevelPage: function (e) {
  503. let name = e.currentTarget.dataset.name
  504. if (name == 'new') {
  505. wx.navigateTo({
  506. url: '/pages/prod-classify/prod-classify?sts=' + 1
  507. })
  508. } else if (name == 'favorable') {
  509. wx.navigateTo({
  510. url: '/pages/specialDiscount/specialDiscount'
  511. })
  512. } else if (name == 'groupBuy') {
  513. wx.navigateTo({
  514. url: '/pages/aBulkList/aBulkList',
  515. })
  516. } else {
  517. wx.navigateTo({
  518. url: '/pages/snapUpList/snapUpList',
  519. })
  520. }
  521. },
  522. /**
  523. * 跳转到商品详情页
  524. */
  525. toProdPage: function (e) {
  526. var prodid = e.currentTarget.dataset.prodid;
  527. var shopid = e.currentTarget.dataset.shopid;
  528. if (prodid) {
  529. wx.navigateTo({
  530. url: `/pages/prod/prod?prodid=${prodid}&shopid=${this.data.shop_id}`,
  531. })
  532. }
  533. },
  534. toCouponCenter: function () {
  535. wx.navigateTo({
  536. url: '/pages/couponCenter/couponCenter',
  537. })
  538. },
  539. newToProdPage: function (e) {
  540. let prodId = e.currentTarget.dataset.prod
  541. if (prodId) {
  542. wx.navigateTo({
  543. url: '/pages/prod/prod?prodid=' + prodId,
  544. })
  545. }
  546. },
  547. /**
  548. * 跳转秒杀列表页
  549. */
  550. toSpecialDiscount: function () {
  551. wx.navigateTo({
  552. url: '/pages/specialDiscount/specialDiscount',
  553. })
  554. },
  555. /**
  556. * 跳转到定位页面
  557. */
  558. toLocationPage: function () {
  559. wx.navigateTo({
  560. url: '/pages/locationAdd/locationAdd',
  561. })
  562. },
  563. /**
  564. * 获取距离最近店铺id
  565. * @param {*} e
  566. */
  567. get_neighborShop: function () {
  568. return new Promise((resolve,reject)=>{
  569. var params = {
  570. // url: "/shop/neighborShop",
  571. url: "/shop/addrShop",
  572. method: "GET",
  573. data: {
  574. lat: wx.getStorageSync('LATITUDE'),
  575. lon: wx.getStorageSync('LONGITUDE'),
  576. channelId:wx.getStorageSync('channelId')||3
  577. },
  578. callBack: (res) => {
  579. this.setData({
  580. shopList:res
  581. })
  582. if(res.every(i=>!i.hasProduct)){
  583. return this.setData({
  584. showShopList:true
  585. })
  586. }
  587. for (let i = 0; i < res.length; i++) {
  588. const item = res[i];
  589. if(item.hasProduct){
  590. console.log('==========================');
  591. wx.setStorageSync('shopInfo', item)
  592. // this.getaddress_transports(item.shopId)
  593. this.setData({
  594. shop_id: item.shopId,
  595. shopName:item.shopName
  596. })
  597. this.getClassInfo(item.shopId);
  598. resolve()
  599. break; // 直接终止整个循环(输出1,2)
  600. }
  601. }
  602. }
  603. };
  604. http.request(params);
  605. })
  606. },
  607. /**
  608. * 获取最大配送范围
  609. */
  610. getaddress_transports: function (shopId) {
  611. let _this = this
  612. var params = {
  613. url: "/p/address/transport2",
  614. method: "GET",
  615. data: {
  616. shopId: shopId,
  617. latitude: wx.getStorageSync('LATITUDE'),
  618. longitude: wx.getStorageSync('LONGITUDE'),
  619. },
  620. callBack: function (res) {
  621. wx.setStorageSync('DISTANCE', res.distance)
  622. _this.setData({
  623. get_distance: res.distance
  624. })
  625. },
  626. errCallBack(res) {
  627. console.log(res);
  628. wx.setStorageSync('DISTANCE', 0)
  629. }
  630. };
  631. http.request(params);
  632. },
  633. onClose: function () {
  634. this.setData({
  635. showShopList: false
  636. })
  637. },
  638. /**
  639. * 步进器
  640. */
  641. minusButton: function (e) {
  642. let totalNum = this.data.totalNum
  643. if (totalNum > 0) {
  644. this.setData({
  645. totalNum: totalNum - 1
  646. })
  647. }
  648. },
  649. addButton: function (e) {
  650. let totalNum = this.data.totalNum
  651. this.setData({
  652. totalNum: totalNum + 1
  653. })
  654. },
  655. /**
  656. * 跳转秒杀列表页
  657. */
  658. toSnapUpPage: function () {
  659. wx.navigateTo({
  660. url: '/pages/snapUpList/snapUpList',
  661. })
  662. },
  663. toSnapUpListPage: function (e) {
  664. var seckillId = e.currentTarget.dataset.seckillid;
  665. wx.navigateTo({
  666. url: "/pages/snapUpDetail/snapUpDetail?seckillid=" + seckillId,
  667. })
  668. },
  669. /**
  670. * 团购
  671. */
  672. getAbulk: function () {
  673. wx.showLoading()
  674. var param = {
  675. url: "/groupProd/indexList",
  676. method: "GET",
  677. data: {},
  678. callBack: (res) => {
  679. wx.hideLoading();
  680. this.setData({
  681. aBulkList: res
  682. });
  683. }
  684. };
  685. http.request(param);
  686. },
  687. /**
  688. * 跳转团购列表页
  689. */
  690. toAbulkPage: function () {
  691. wx.navigateTo({
  692. url: '/pages/aBulkList/aBulkList',
  693. })
  694. },
  695. toAbulkListPage: function (e) {
  696. var prodId = e.currentTarget.dataset.prodid;
  697. var groupActivityId = e.currentTarget.dataset.groupactivityid;
  698. wx.navigateTo({
  699. url: '/pages/prod/prod?prodid=' + prodId + "&groupActivityId=" + groupActivityId
  700. })
  701. },
  702. // 跳转搜索页
  703. toSearchPage: function () {
  704. wx.navigateTo({
  705. // url: '/pages/search-page/search-page',
  706. url: `/pages/search-page/search-page?shopId=${this.data.shop_id}`,
  707. })
  708. },
  709. //跳转商品活动页面
  710. toClassifyPage: function (e) {
  711. var url = '/pages/prod-classify/prod-classify?sts=' + e.currentTarget.dataset.sts;
  712. var id = e.currentTarget.dataset.id;
  713. var title = e.currentTarget.dataset.title;
  714. if (id) {
  715. url += "&tagid=" + id + "&title=" + title;
  716. }
  717. wx.navigateTo({
  718. url: url
  719. })
  720. },
  721. toSecKillPage: function () {
  722. wx.navigateTo({
  723. url: '/pages/snapUpList/snapUpList',
  724. })
  725. },
  726. //跳转公告列表页面
  727. onNewsPage: function () {
  728. wx.navigateTo({
  729. url: '/pages/recent-news/recent-news',
  730. })
  731. },
  732. onShow: function () {
  733. this.getDialog()
  734. // this.get_test()
  735. this.setData({
  736. select_address: wx.getStorageSync('ADDRESS')
  737. })
  738. // this.getCurrentLocation()
  739. updateManager.onCheckForUpdate(function (res) {
  740. updateManager.onUpdateReady(function () {
  741. wx.showModal({
  742. title: '更新提示',
  743. content: '新版本已经准备好,是否重启应用?',
  744. success(res) {
  745. if (res.confirm) {
  746. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  747. updateManager.applyUpdate()
  748. }
  749. }
  750. })
  751. })
  752. })
  753. http.getCartCount(); //重新计算购物车总数量
  754. },
  755. /**
  756. * 接口测试用
  757. */
  758. /**
  759. * 选择定位后更新列表
  760. */
  761. go_update() {
  762. this.setData({
  763. current:1,
  764. })
  765. this.get_neighborShop().then(res=>{
  766. this.getHotSalesProds()
  767. })
  768. },
  769. getAllData(type) {
  770. console.log('=========type',type);
  771. this.setData({
  772. current:1,
  773. shop_id: wx.getStorageSync("shopInfo").shopId,
  774. shopName:wx.getStorageSync("shopInfo").shopName
  775. })
  776. http.getCartCount(); //重新计算购物车总数量
  777. this.getIndexImgs();
  778. // this.getClassInfo(this.data.shopId);
  779. // this.getNoticeList();
  780. this.getAbulk();
  781. this.getRecommended()
  782. this.getRecommendeds()
  783. this.getAdv()
  784. if(type == 'refresh'){//切换店铺
  785. this.getHotSalesProds()
  786. }else{
  787. this.get_neighborShop().then(res=>{
  788. this.getHotSalesProds()
  789. })
  790. }
  791. },
  792. //加载轮播图
  793. getIndexImgs() {
  794. console.log('getIndexImgs');
  795. //加载轮播图
  796. var params = {
  797. url: "/indexImgs/0",
  798. method: "GET",
  799. data: {},
  800. callBack: (res) => {
  801. this.setData({
  802. indexImgs: res,
  803. seq: res
  804. });
  805. wx.hideLoading();
  806. }
  807. };
  808. http.request(params);
  809. },
  810. // getNoticeList() {
  811. // // 加载公告
  812. // var params = {
  813. // url: "/shop/notice/topNoticeList/0",
  814. // method: "GET",
  815. // data: {},
  816. // callBack: (res) => {
  817. // this.setData({
  818. // news: res,
  819. // });
  820. // wx.hideLoading();
  821. // }
  822. // };
  823. // http.request(params);
  824. // },
  825. /**
  826. * 加载热销商品列表
  827. */
  828. getHotSalesProds() {
  829. if(!this.data.shop_id||this.data.shop_id == 0){
  830. return console.log('店铺不存在');
  831. }
  832. var param = {
  833. url: "/search/searchProdPage",
  834. method: "GET",
  835. data: {
  836. current: this.data.current,
  837. size: 10,
  838. sort: 3,
  839. orderBy: 1,
  840. lat: wx.getStorageSync('LATITUDE'),
  841. lon: wx.getStorageSync('LONGITUDE'),
  842. distance: 9999999||wx.getStorageSync('DISTANCE') || 0,
  843. shopId: this.data.shop_id,
  844. channelId:wx.getStorageSync('channelId')||3
  845. },
  846. callBack: (res) => {
  847. var hotSalesList = []
  848. let img = ''
  849. res.records.map(e => {
  850. if(e.pic){
  851. img = e.pic.split(',')
  852. e.pic = img[0]
  853. }
  854. })
  855. if (this.data.current == 1) {
  856. setTimeout(() => {
  857. this.setData({
  858. hotSalesList: res.records,
  859. pages: res.pages,
  860. current: res.current
  861. });
  862. }, 500)
  863. } else {
  864. hotSalesList = this.data.hotSalesList
  865. hotSalesList.push(...res.records)
  866. this.setData({
  867. hotSalesList
  868. })
  869. if (hotSalesList.length>=res.total) {
  870. this.setData({
  871. isAll: true
  872. })
  873. }
  874. }
  875. this.setData({
  876. isHand:false
  877. })
  878. }
  879. };
  880. http.request(param);
  881. },
  882. // 触底加载下一页
  883. getNextPage() {
  884. console.log('getNextPage',this.data.current);
  885. if (this.data.pages > this.data.current) {
  886. this.setData({
  887. current: this.data.current + 1
  888. })
  889. !this.data.isHand&&this.getHotSalesProds()
  890. } else {
  891. this.setData({
  892. isAll: true
  893. })
  894. }
  895. },
  896. /**
  897. * 页面上拉触底事件的处理函数
  898. */
  899. onReachBottom: function () {
  900. this.getNextPage()
  901. },
  902. onPullDownRefresh: function () {
  903. // wx.showNavigationBarLoading() //在标题栏中显示加载
  904. //模拟加载
  905. var ths = this;
  906. this.setData({ //下拉刷新
  907. current: 1
  908. })
  909. setTimeout(function () {
  910. ths.getAllData();
  911. // wx.hideNavigationBarLoading() //完成停止加载
  912. wx.stopPullDownRefresh() //停止下拉刷新
  913. }, 100);
  914. },
  915. onShareAppMessage: function (e) {
  916. return {
  917. path: "pages/index/index"
  918. }
  919. }
  920. })