storeList.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // pages/groupmeallist/storeList/storeList.js
  2. import StoreApi from '../../../api/storeList'
  3. const cache = require('../../../utils/cache.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. phoneshow:false,
  10. isShowConfirmPannel:false,
  11. idx:'',
  12. page:1,
  13. pageSize:8,
  14. longitude:"",
  15. latitude:"",
  16. keyword:"",
  17. storeList:[],
  18. selectStoreInfo:null,
  19. id:0,
  20. isClicked:false, //是否已经点击过了,默认没有
  21. pageSource:"",
  22. storePhone:'',
  23. store:null
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. },
  30. /**
  31. * 获取门店列表
  32. */
  33. async getNearbyStoreList(step='init') {
  34. let _self = this;
  35. try {
  36. let storeRes = await StoreApi.getNearbyStoreList(
  37. _self.data.page,
  38. _self.data.pageSize,
  39. _self.data.keyword,
  40. _self.data.longitude,
  41. _self.data.latitude);
  42. if(storeRes.code==200 && storeRes.msg=='success') {
  43. let list = storeRes.data;
  44. if(list.length!=0) {
  45. list.map((item,index)=>{
  46. if(item.distance!==null){
  47. let distance = parseFloat(item.distance);
  48. item.distance = (distance).toFixed(2);
  49. }
  50. if(item.id==_self.data.id && _self.data.isClicked == false){
  51. item.active = true;
  52. _self.setData({
  53. selectStoreInfo:item,
  54. })
  55. }else {
  56. item.active = false;
  57. }
  58. })
  59. }
  60. if(step=='init') { //初始化
  61. _self.setData({
  62. storeList:list
  63. })
  64. console.log(list.length)
  65. } else {
  66. if(list.length==0) {
  67. _self.setData({
  68. page:_self.data.page-1
  69. })
  70. } else {
  71. //分页
  72. _self.setData({
  73. storeList:_self.data.storeList.concat(list),
  74. })
  75. }
  76. }
  77. }
  78. } catch(error) {
  79. console.log(error);
  80. }
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. let _self = this;
  92. //获取最近的经纬度
  93. let locationPosition = cache.getNearLocation()
  94. if(locationPosition!=null) {
  95. _self.setData({
  96. longitude:locationPosition.longitude,
  97. latitude:locationPosition.latitude
  98. })
  99. }
  100. _self.getNearbyStoreList();
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. let _self = this;
  122. _self.setData({
  123. page:_self.data.page+1
  124. })
  125. //获取门店列表
  126. _self.getNearbyStoreList('pull')
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. },
  133. // 拉出电话面板
  134. showPhoneTab(e){
  135. let idx = e.currentTarget.dataset.idx;
  136. var that = this;
  137. let storePhone=this.data.storeList[idx].phone
  138. this.setData({
  139. storePhone:storePhone,
  140. phoneshow : !this.data.phoneshow
  141. })
  142. },
  143. // 确认门店拉出
  144. confirmstore(){},
  145. confirmtPannel: function (e) {
  146. this.setData({
  147. phoneshow : false
  148. })
  149. if (this.data.isShowConfirmPannel) {
  150. this.closeConfirmPannel()
  151. return
  152. }
  153. this.showConfirmPannel(e);
  154. },
  155. //关闭购物车面板
  156. closeConfirmPannel: function() {
  157. this.setData({
  158. isShowConfirmPannel: false,
  159. phoneshow : false
  160. })
  161. },
  162. //显示对话框
  163. showConfirmPannel (e) {
  164. // 显示遮罩层
  165. let idx = e.currentTarget.dataset.idx;
  166. var that = this;
  167. let store=this.data.storeList[idx]
  168. var animation = wx.createAnimation({
  169. duration: 100,
  170. timingFunction: "linear",
  171. delay: 0
  172. })
  173. this.animation = animation
  174. animation.translateY(300).step()
  175. this.setData({
  176. animationData: animation.export(),
  177. isShowConfirmPannel: true,
  178. store:store,
  179. idx:idx
  180. })
  181. setTimeout(function () {
  182. animation.translateY(0).step()
  183. this.setData({
  184. animationData: animation.export()
  185. })
  186. }.bind(this), 100)
  187. },
  188. // 确定门店跳回商品列表
  189. confirmStoreGoToStoreGoods(e){
  190. let way = e.currentTarget.dataset.way;
  191. //缓存门店取餐方式
  192. cache.setStoreWay(way)
  193. console.log(this.data.storeList[this.data.idx])
  194. cache.setCurrStore(this.data.storeList[this.data.idx]);
  195. wx.switchTab({
  196. url:'/pages/groupmeallist/storeGoods/storeGoods'
  197. });
  198. },
  199. /**
  200. * 选择门店
  201. */
  202. sureStore() {
  203. let _self = this;
  204. //存储选中的地址
  205. console.log(_self.data.pageSource);
  206. if(_self.data.pageSource == "storeGoods"){
  207. console.log(999999);
  208. wx.redirectTo({
  209. url: '/pages/storeGoods/storeGoods'
  210. })
  211. }else{
  212. wx.reLaunch({
  213. url: '/pages/index/index?step=storeSelect'
  214. })
  215. }
  216. },
  217. })