shopinfo.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // pages/shopinfo/shopinfo.js
  2. import storeApi from '../../api/store'
  3. import productApi from '../../api/product'
  4. import commentsApi from '../../api/comments'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. shopInfo: {},
  11. commentsList: [],
  12. productList: [],
  13. shopId: 0,
  14. pageNo: 1,
  15. pageSum: '',
  16. loadingEnd: false,
  17. commentsNum: 0
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: async function (options) {
  23. this.setData({
  24. shopId: options.id
  25. })
  26. await this.getShopInfo();
  27. await this.getCommentsList()
  28. },
  29. getCommentsList: async function () {
  30. var page = this.data.pageNo;
  31. var shopId = this.data.shopId;
  32. var comments = await commentsApi.getCommentsByStore(page, 2, shopId);
  33. //对返回的评论列表进行处理
  34. var commList = this.standardCommentsList(comments.list);
  35. var commentsList = this.data.commentsList;
  36. var list = commentsList.concat(commList)
  37. this.setData({
  38. commentsList: list,
  39. pageSum: comments.pageCount,
  40. commentsNum: comments.count
  41. })
  42. },
  43. standardCommentsList: function (list) {
  44. list.forEach(function (item, i, array) {
  45. let urls = item.imgUrls;
  46. let imgs = urls.split(',');
  47. item.imgs = imgs;
  48. let time = item.createTime.trim().split(" ")[0];
  49. item.commentTime = time
  50. })
  51. return list;
  52. },
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. var self = this;
  83. var pageNo = self.data.pageNo;
  84. pageNo += 1;
  85. if (self.data.pageNo <= self.data.pageSum) {
  86. self.setData({
  87. pageNo
  88. })
  89. self.getCommentsList()
  90. return
  91. }
  92. self.setData({
  93. loadingEnd: true
  94. })
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {
  100. },
  101. getShopInfo: async function () {
  102. const self = this;
  103. var shopId = self.data.shopId;
  104. const productList = await productApi.getProductList(1, 100);
  105. const shopInfo = await storeApi.getStoreById(shopId);
  106. console.log(productList)
  107. self.setData({
  108. productList,
  109. shopInfo: shopInfo.info
  110. })
  111. },
  112. showProduct: function (e) {
  113. console.log(e.currentTarget.dataset.productid)
  114. var productId = e.currentTarget.dataset.productid;
  115. var shopId = this.data.shopInfo.id;
  116. // console.log('shop='+shopId)
  117. wx.navigateTo({
  118. url: '../product/product?shopId=' + shopId + '&productId=' + productId,
  119. })
  120. },
  121. guide: function(e){
  122. const self = this;
  123. var lat = parseFloat(self.data.shopInfo.latitude);
  124. var lon = parseFloat(self.data.shopInfo.longitude);
  125. wx.getSetting({
  126. success: async (res) => {
  127. let authSetting = res.authSetting
  128. if (authSetting['scope.userLocation']) {
  129. console.log('已授权地理位置')
  130. wx.openLocation({
  131. latitude:lat,
  132. longitude: lon,
  133. })
  134. // 已授权
  135. } else {
  136. // 未授权
  137. console.log('未授权地理位置');
  138. wx.getLocation({
  139. type: 'wgs84',
  140. async success(res) {
  141. console.log(res)
  142. const latitude = res.latitude
  143. const longitude = res.longitude
  144. wx.setStorageSync('lon', longitude)
  145. wx.setStorageSync('lat', latitude)
  146. wx.openLocation({
  147. latitude:lat,
  148. longitude: lon,
  149. })
  150. }
  151. })
  152. }
  153. }
  154. })
  155. }
  156. })