You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
5.5 KiB
JavaScript

// pages/card/cardSuitStore.js
const card = require('../../utils/card.js');
const app = getApp();
var firstLoad = true;
Page({
/**
* 页面的初始数据
*/
data: {
hidden: false,
pageNum: 1,
pageSize:15,
totalPage: 0,
totalCount: 0,
dataList: [],
inputShowed: false,
inputVal: "",
inputFlag: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.cy_getUseStore();
},
/**
* 获取门店信息
*/
cy_getUseStore: function() {
var that = this;
var hide = that.data.hidden;
var dataList = that.data.dataList;
var showLength = dataList.length;
var totalCount = that.data.totalCount;
if (!firstLoad && (showLength >= totalCount)) {
return;
}
that.setData({
hidden: hide
});
// 当前位置
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
that.cy_queryShops(longitude, latitude);
},
fail: function() {
queryShops(0, 0);
}
});
},
cy_queryShops: function(longitude, latitude) {
var that = this;
var hide = that.data.hidden;
var dataList = that.data.dataList;
var pageNum = that.data.pageNum;
var pageSize = that.data.pageSize;
var keyword = that.data.inputVal;
var property = "name";
var keyword = that.data.inputVal;
var params = {
'groupNo': app.groupNo,
'pageNum': pageNum,
'pageSize': pageSize,
'property': property,
'keyword': keyword,
'longitude': longitude,
'latitude': latitude,
'method': 'group.shop.distance.list'
};
var ignores = ["property", "keyword"];
app.jsapi.memberApi(app.globalData.appMemberKey, app.globalData.appMemberSecret, app.globalData.serverMemberUrl).ajax(params, ignores,
function(res) {
var resData = res.data;
if (resData.status == 1) {
var totalNum = resData.totalCount;
if (dataList.length != 0 && dataList.length >= totalNum) {
that.setData({
hidden: hide
});
return;
}
var totalPage = resData.pageCount;
var shopList = resData.list;
var shopLength = shopList.length;
for (var value of shopList) {
value.distance = (parseFloat(value.distance) / 1000).toFixed(2);
dataList.push(value);
}
pageNum = pageNum + 1;
that.setData({
hidden: true,
totalCount: totalNum,
totalPage: totalPage,
pageNum: pageNum,
dataList: dataList
});
} else {
that.setData({
hidden: hide
});
}
},
function(error) {
console.log(error);
}
);
},
/**
*
*/
showInput: function () {
this.setData({
inputShowed: true
});
},
/**
*
*/
hideInput: function () {
this.resetSearch();
this.setData({
inputVal: "",
inputShowed: false,
inputFlag: 0
});
},
/**
*
*/
clearInput: function () {
this.resetSearch();
this.setData({
inputVal: "",
inputFlag: 0
});
},
/**
*
*/
inputTyping: function (e) {
var inputFlag = 1;
var inputVal = e.detail.value;
this.setData({
inputVal: inputVal,
inputFlag: inputFlag
});
this.resetSearch();
if (inputVal == "") {
inputFlag = 0;
this.setData({
inputFlag: inputFlag
});
}
},
/**
*
*/
resetSearch: function () {
var inputFlag = this.data.inputFlag;
var that = this;
var hide = that.data.hidden = true;
if (inputFlag == 1) {
this.setData({
hidden: hide,
pageNum: 1,
totalPage: 0,
totalCount: 0,
dataList: []
});
this.cy_getUseStore();
}
},
/**
*
*/
onLocation: function (e) {
var latitude = e.currentTarget.dataset.latitude;
var longitude = e.currentTarget.dataset.longitude;
if (latitude != "" && longitude != "") {
wx.openLocation({
latitude: Number(latitude),
longitude: Number(longitude),
scale: 28
})
} else {
// 当前位置
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
wx.openLocation({
latitude: latitude,
longitude: longitude,
scale: 28
})
}
});
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
wx.showNavigationBarLoading() //在标题栏中显示加载
this.cy_getUseStore();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
this.cy_getUseStore();
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})