123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // pages/shopinfo/shopinfo.js
- import storeApi from '../../api/store'
- import productApi from '../../api/product'
- import commentsApi from '../../api/comments'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- shopInfo: {},
- commentsList: [],
- productList: [],
- shopId: 0,
- pageNo: 1,
- pageSum: '',
- loadingEnd: false,
- commentsNum: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- this.setData({
- shopId: options.id
- })
- await this.getShopInfo();
- await this.getCommentsList()
- },
- getCommentsList: async function () {
- var page = this.data.pageNo;
- var shopId = this.data.shopId;
- var comments = await commentsApi.getCommentsByStore(page, 2, shopId);
- //对返回的评论列表进行处理
- var commList = this.standardCommentsList(comments.list);
- var commentsList = this.data.commentsList;
- var list = commentsList.concat(commList)
- this.setData({
- commentsList: list,
- pageSum: comments.pageCount,
- commentsNum: comments.count
- })
- },
- standardCommentsList: function (list) {
- list.forEach(function (item, i, array) {
- let urls = item.imgUrls;
- let imgs = urls.split(',');
- item.imgs = imgs;
- let time = item.createTime.trim().split(" ")[0];
- item.commentTime = time
- })
- return list;
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- var self = this;
- var pageNo = self.data.pageNo;
- pageNo += 1;
- if (self.data.pageNo <= self.data.pageSum) {
- self.setData({
- pageNo
- })
- self.getCommentsList()
- return
- }
- self.setData({
- loadingEnd: true
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- getShopInfo: async function () {
- const self = this;
- var shopId = self.data.shopId;
- const productList = await productApi.getProductList(1, 100);
- const shopInfo = await storeApi.getStoreById(shopId);
- console.log(productList)
- self.setData({
- productList,
- shopInfo: shopInfo.info
- })
- },
- showProduct: function (e) {
- console.log(e.currentTarget.dataset.productid)
- var productId = e.currentTarget.dataset.productid;
- var shopId = this.data.shopInfo.id;
- // console.log('shop='+shopId)
- wx.navigateTo({
- url: '../product/product?shopId=' + shopId + '&productId=' + productId,
- })
- },
- guide: function(e){
- const self = this;
- var lat = parseFloat(self.data.shopInfo.latitude);
- var lon = parseFloat(self.data.shopInfo.longitude);
- wx.getSetting({
- success: async (res) => {
- let authSetting = res.authSetting
- if (authSetting['scope.userLocation']) {
- console.log('已授权地理位置')
- wx.openLocation({
- latitude:lat,
- longitude: lon,
- })
- // 已授权
- } else {
- // 未授权
- console.log('未授权地理位置');
- wx.getLocation({
- type: 'wgs84',
- async success(res) {
- console.log(res)
- const latitude = res.latitude
- const longitude = res.longitude
- wx.setStorageSync('lon', longitude)
- wx.setStorageSync('lat', latitude)
- wx.openLocation({
- latitude:lat,
- longitude: lon,
- })
- }
- })
- }
- }
- })
- }
- })
|