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.
408 lines
10 KiB
JavaScript
408 lines
10 KiB
JavaScript
9 months ago
|
const app = getApp();
|
||
|
const cartOrder = require("../../utils/cartOrder.js");
|
||
|
const utils = require("../../utils/utils.js")
|
||
|
const util = require("../../utils/util.js")
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
hidden: false,
|
||
|
longitude: null,
|
||
|
latitude: null,
|
||
|
keyword: null,
|
||
|
pageNumber: 1,
|
||
|
pageSize: 10,
|
||
|
address: "",
|
||
|
busMode: 1,
|
||
|
list: [], // 门店
|
||
|
flag: false,
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function(options) {
|
||
|
this.setData({busMode:options.busMode,color:app.globalData.color})
|
||
|
wx.setNavigationBarTitle({
|
||
|
title: options.title,
|
||
|
});
|
||
|
|
||
|
this.cy_tapGetLocation();
|
||
|
},
|
||
|
getLocationHandler: function(e) {
|
||
|
if (e.detail.authSetting["scope.userLocation"]) {
|
||
|
this.cy_tapGetLocation();
|
||
|
} else {
|
||
|
util.showWaring("请授权获取地址位置")
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* 扫码点餐
|
||
|
*/
|
||
|
scanOrder: function() {
|
||
|
if (app.scene) {
|
||
|
var params = app.scene.split("&");
|
||
|
app.scene = null;
|
||
|
var storeNo = params[1];
|
||
|
var index = 0;
|
||
|
for (var i = 0; i < this.data.list.length; i++) {
|
||
|
var store = this.data.list[i];
|
||
|
if (storeNo == store.no) {
|
||
|
index = i;
|
||
|
}
|
||
|
}
|
||
|
var store = this.data.list[index];
|
||
|
app.orderTicket = cartOrder.getDefaultOrderTicket();
|
||
|
app.orderTicket.tableNo = params[2];
|
||
|
app.orderTicket.id = store.id;
|
||
|
app.orderTicket.storeId = store.storeId;
|
||
|
app.orderTicket.storeName = store.name;
|
||
|
app.orderTicket.storeAddress = store.address;
|
||
|
app.orderTicket.storeNo = store.storeNo;
|
||
|
app.orderTicket.distance = store.distance;
|
||
|
app.orderTicket.deliverFee = store.deliverFee;
|
||
|
app.orderTicket.busMode = this.data.busMode;
|
||
|
app.orderTicket.phone = app.globalData.phone;
|
||
|
var url = "../list/shopList";
|
||
|
wx.navigateTo({
|
||
|
url: url,
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 获取门店信息列表
|
||
|
*/
|
||
|
cy_getStoreList: function() {
|
||
|
var that = this;
|
||
|
var params = {
|
||
|
"method": "program.store.list",
|
||
|
"programId": app.globalData.programId,
|
||
|
"longitude": that.data.longitude,
|
||
|
"latitude": that.data.latitude,
|
||
|
"pageNumber": that.data.pageNumber,
|
||
|
"pageSize": that.data.pageSize,
|
||
|
}
|
||
|
if( that.data.busMode==3){
|
||
|
params.busMode=that.data.busMode;
|
||
|
}
|
||
|
if (that.data.keyword != null && that.data.keyword != "") {
|
||
|
params.keyword = that.data.keyword;
|
||
|
}
|
||
|
// 忽略签名参数
|
||
|
var ignores = ["keyword", "pageNumber", "pageSize"];
|
||
|
ignores.push("keyword");
|
||
|
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret,app.globalData.serverUrl).ajax(params, ignores,
|
||
|
function(json) {
|
||
|
console.log(json);
|
||
|
that.data.flag = true;
|
||
|
wx.stopPullDownRefresh();
|
||
|
var result = json.data;
|
||
|
if (result.status == 1) {
|
||
|
var tempList = [];
|
||
|
var temStoreNotBusiness=[];
|
||
|
if (that.data.pageNumber != 1) {
|
||
|
tempList = that.data.list;
|
||
|
}
|
||
|
|
||
|
for (var store of result.list) {
|
||
|
store.distance = utils.getOne(store.distance / 1000);
|
||
|
|
||
|
if (that.data.busMode == 1) {
|
||
|
if (store.busModes.indexOf(0) != -1 || store.busModes.indexOf(1) != 1) {
|
||
|
tempList.push(store);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (that.data.busMode == 3) {
|
||
|
if (store.busModes.indexOf(that.data.busMode) != -1) {
|
||
|
tempList.push(store);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (that.data.busMode == 0) {
|
||
|
if (tempList.length == 0) {
|
||
|
wx.showToast({
|
||
|
title: '暂无堂食门店',
|
||
|
icon: "none",
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
else if (that.data.busMode == 3) {
|
||
|
if (tempList.length == 0) {
|
||
|
wx.showToast({
|
||
|
title: '暂无外卖门店',
|
||
|
icon: "none",
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
//在这里整体循环的是为了处理分页未营业还在最后
|
||
|
var temStoreIsBusiness=[];
|
||
|
if(tempList.length>0){
|
||
|
for(var store of tempList){
|
||
|
if(store.isOpen==0){
|
||
|
temStoreNotBusiness.push(store);
|
||
|
}else {
|
||
|
temStoreIsBusiness.push(store);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(temStoreNotBusiness.length>0){
|
||
|
temStoreIsBusiness=temStoreIsBusiness.concat(temStoreNotBusiness);
|
||
|
}
|
||
|
that.setData({
|
||
|
list: temStoreIsBusiness,
|
||
|
hidden: true,
|
||
|
});
|
||
|
//
|
||
|
//that.scanOrder();
|
||
|
} else {
|
||
|
that.setData({
|
||
|
list: [],
|
||
|
hidden: true,
|
||
|
})
|
||
|
app.msg.showMsg("提示", result.message);
|
||
|
}
|
||
|
|
||
|
},
|
||
|
function(error) {
|
||
|
that.setData({
|
||
|
list: [],
|
||
|
hidden: true,
|
||
|
flag: true
|
||
|
})
|
||
|
app.msg.showMsg("提示", "网络中断,操作失败");
|
||
|
}
|
||
|
);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 联系商家
|
||
|
*/
|
||
|
cy_makeiPhone: function(e) {
|
||
|
console.log(e);
|
||
|
var phoneNumber = e.currentTarget.dataset.iphone;
|
||
|
if (phoneNumber == "") {
|
||
|
wx.showToast({
|
||
|
title: '暂无商家联系电话,敬请期待',
|
||
|
icon: 'none',
|
||
|
})
|
||
|
return;
|
||
|
}
|
||
|
wx.makePhoneCall({
|
||
|
phoneNumber: phoneNumber,
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 去点单
|
||
|
*/
|
||
|
cy_storeShop: function(e) {
|
||
|
var index = e.currentTarget.dataset.index;
|
||
|
var store = this.data.list[index];
|
||
|
wx.setStorageSync("store", store);
|
||
|
app.globalData.store = store;
|
||
|
console.log("=============store:",store);
|
||
|
|
||
|
app.orderTicket = cartOrder.getDefaultOrderTicket();
|
||
|
app.orderTicket.storeId = store.storeId;
|
||
|
app.orderTicket.storeName = store.storeName;
|
||
|
app.orderTicket.storeAddress = store.address;
|
||
|
app.orderTicket.storeNo = store.storeNo;
|
||
|
app.orderTicket.distance = store.distance;
|
||
|
app.orderTicket.deliverFee = store.deliverFee;
|
||
|
app.orderTicket.busMode = this.data.busMode;
|
||
|
app.orderTicket.phone = app.globalData.phone;
|
||
|
app.orderTicket.tableName = "选择餐桌";
|
||
|
|
||
|
app.globalData.deductionRate = store.deductionRate;
|
||
|
app.globalData.memberDeductionRate = store.memberDeductionRate;
|
||
|
app.globalData.memberPriceEnabled = store.memberPriceEnabled;
|
||
|
app.globalData.memberPayEnabled=store.memberPayEnabled;
|
||
|
app.globalData.takeOutBoxFeeFlag=store.takeOutBoxFeeFlag;
|
||
|
console.error(" takeOutBoxFeeFlag ",store.takeOutBoxFeeFlag)
|
||
|
var url = "../list/shopList?shopRate=" + store.deductionRate;
|
||
|
if (this.data.busMode == '3') {
|
||
|
app.globalData.deliverMoney = store.deliverMoney;
|
||
|
var distance = app.utils.getDistance(store.latitude, store.longitude, this.data.latitude, this.data.longitude);
|
||
|
|
||
|
var deliverKilometre = 5;
|
||
|
if (store.deliverKilometre) {
|
||
|
deliverKilometre = parseFloat(store.deliverKilometre);
|
||
|
}
|
||
|
if (distance > deliverKilometre) {
|
||
|
var title = '注意:超过' + deliverKilometre + "公里不支持配送",
|
||
|
url = url+"&isDeliverKilometreWarn=true&warn=" + title;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
wx.navigateTo({
|
||
|
url: url,
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
cy_callPhone: function(e) {
|
||
|
var index = e.currentTarget.dataset.index;
|
||
|
var store = this.data.list[index];
|
||
|
if (store.isOpen == 0) {
|
||
|
wx.showToast({
|
||
|
title: '门店休息中,暂停营业',
|
||
|
icon: "none",
|
||
|
})
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wx.makePhoneCall({
|
||
|
phoneNumber: store.orderTel,
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
cy_storeLocation: function(e) {
|
||
|
var index = e.currentTarget.dataset.index;
|
||
|
var store = this.data.list[index];
|
||
|
wx.openLocation({
|
||
|
latitude: store.latitude,
|
||
|
longitude: store.longitude,
|
||
|
})
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* cy-addStore
|
||
|
*/
|
||
|
cy_addStore: function() {
|
||
|
if (this.data.flag) {
|
||
|
this.cy_getStoreList();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
|
||
|
/******************************
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
cy_tapGetLocation: function() {
|
||
|
var that = this;
|
||
|
console.log("获取地理位置");
|
||
|
wx.getLocation({
|
||
|
isHighAccuracy:true,
|
||
|
type:"",
|
||
|
success: res => {
|
||
|
console.log(res)
|
||
|
if (res.errMsg == "getLocation:ok") {
|
||
|
that.setData({
|
||
|
longitude: res.longitude,
|
||
|
latitude: res.latitude
|
||
|
});
|
||
|
var location = {};
|
||
|
location.latitude = res.latitude;
|
||
|
location.longitude = res.longitude;
|
||
|
that.setData({
|
||
|
location: location
|
||
|
})
|
||
|
console.log(app)
|
||
|
app.qqmapsdk.reverseGeocoder({
|
||
|
location: {
|
||
|
latitude: res.latitude,
|
||
|
longitude: res.longitude,
|
||
|
},
|
||
|
success: function(res) {
|
||
|
|
||
|
that.setData({
|
||
|
address: res.result.address
|
||
|
})
|
||
|
},
|
||
|
fail: function(err) {
|
||
|
console.log(err);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
that.cy_getStoreList();
|
||
|
}
|
||
|
},
|
||
|
fail: res => {
|
||
|
console.log(res);
|
||
|
that.setData({
|
||
|
longitude: res.longitude,
|
||
|
latitude: res.latitude,
|
||
|
hidden: true,
|
||
|
})
|
||
|
},
|
||
|
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 搜索
|
||
|
*/
|
||
|
cy_search: function(e) {
|
||
|
// console.log(e);
|
||
|
var that = this;
|
||
|
that.data.keyword = e.detail.value;
|
||
|
if (e.type == "input") {
|
||
|
that.cy_getStoreList();
|
||
|
} else if (e.type == "input") {
|
||
|
if (that.data.keyword == "") {
|
||
|
that.cy_getStoreList();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 定位
|
||
|
*/
|
||
|
cy_tapChooseLocation: function() {
|
||
|
var that = this;
|
||
|
wx.chooseLocation({
|
||
|
success: function(res) {
|
||
|
console.log(res);
|
||
|
if (res.errMsg == "chooseLocation:ok") {
|
||
|
that.setData({
|
||
|
longitude: res.longitude,
|
||
|
latitude: res.latitude,
|
||
|
address: res.address
|
||
|
});
|
||
|
that.cy_getStoreList();
|
||
|
}
|
||
|
},
|
||
|
fail: function(res) {
|
||
|
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function() {
|
||
|
this.data.pageNumber = 1;
|
||
|
this.cy_getStoreList();
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
onReachBottom: function(e) {
|
||
|
console.log("加载更多")
|
||
|
this.data.pageNumber++;
|
||
|
this.cy_getStoreList();
|
||
|
}
|
||
|
|
||
|
})
|