Browse Source

弹框问题,bug修改

feature/3.1.0-小区合伙人
lfs3 6 years ago
parent
commit
0e89111f6d
4 changed files with 241 additions and 175 deletions
  1. 112
      src/models/wxLocation.js
  2. 5
      src/models/wxShare.js
  3. 59
      src/view/choose-community.vue
  4. 240
      src/view/home.vue

112
src/models/wxLocation.js

@ -2,68 +2,74 @@ import Vue from "vue";
import wx from "weixin-js-sdk";
import axios from "axios";
import wxShareModel from "../models/wxShare-model.js";
let instance = axios.create();
//引入BMap
import BMap from "BMap";
Vue.prototype.wxLocation = function () {
wxShareModel.getWXCheck().then(response => {
if (response.code != 0) {
return;
}
var jsApiSignConfig = response.response.jsApiSignConfig;
wx.config({
debug: false, // 开启调试模式,开发时可以开启
appId: jsApiSignConfig.appId, // 必填,公众号的唯一标识 由接口返回
timestamp: jsApiSignConfig.timestamp, // 必填,生成签名的时间戳 由接口返回
nonceStr: jsApiSignConfig.nonceStr, // 必填,生成签名的随机串 由接口返回
signature: jsApiSignConfig.signature, // 必填,签名 由接口返回
jsApiList: [
'checkJsApi', 'openLocation', 'getLocation'
],
});
wx.checkJsApi({
jsApiList: ['getLocation'],
success: function (res) {
if (res.checkResult.getLocation == false) {
alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!');
return;
}
return new Promise((resolve, reject) => {
wxShareModel.getWXCheck().then(response => {
if (response.code != 0) {
return;
}
});
wx.ready(() => {
// 首次进入页面进会弹窗确认地理位置
if (localStorage.getItem("latitude") == null) {
wx.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
var jsApiSignConfig = response.response.jsApiSignConfig;
wx.config({
debug: false, // 开启调试模式,开发时可以开启
appId: jsApiSignConfig.appId, // 必填,公众号的唯一标识 由接口返回
timestamp: jsApiSignConfig.timestamp, // 必填,生成签名的时间戳 由接口返回
nonceStr: jsApiSignConfig.nonceStr, // 必填,生成签名的随机串 由接口返回
signature: jsApiSignConfig.signature, // 必填,签名 由接口返回
jsApiList: [
'checkJsApi', 'openLocation', 'getLocation'
],
});
wx.checkJsApi({
jsApiList: ['getLocation'],
success: function (res) {
console.log('res:' + res);
// alert('res.latitude:' + res.latitude + '------res.longitude:' + res.longitude);
localStorage.setItem("latitude", res.latitude);
localStorage.setItem("longitude", res.longitude);
$.ajax({
url: 'http://api.map.baidu.com/geocoder/v2/?ak=a79bFu054xIbE23jlynkSXX20F9yGD4G&callback=renderReverse&location=' + res.latitude + ',' + res.longitude + '&output=json&pois=1',
type: "get",
dataType: "jsonp",
jsonp: "callback",
success: function (data) {
// alert('data.result.location.lng:' + data.result.location.lng + '-----data.result.location.lat:' + data.result.location.lat);
localStorage.setItem("latitude", data.result.location.lat);
localStorage.setItem("longitude", data.result.location.lng);
if (res.checkResult.getLocation == false) {
alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!');
return "";
}
}
});
wx.ready(() => {
// 首次进入页面进会弹窗确认地理位置
if (localStorage.getItem("latitude") == null) {
wx.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
console.log('res:' + res);
// alert('res.latitude:' + res.latitude + '------res.longitude:' + res.longitude);
// localStorage.setItem("latitude", res.latitude);
// localStorage.setItem("longitude", res.longitude);
$.ajax({
url: 'http://api.map.baidu.com/geocoder/v2/?ak=a79bFu054xIbE23jlynkSXX20F9yGD4G&callback=renderReverse&location=' + res.latitude + ',' + res.longitude + '&output=json&pois=1',
type: "get",
dataType: "jsonp",
jsonp: "callback",
success: function (data) {
// alert('data.result.location.lng:' + data.result.location.lng + '-----data.result.location.lat:' + data.result.location.lat);
localStorage.setItem("latitude", data.result.location.lat);
localStorage.setItem("longitude", data.result.location.lng);
resolve("定位成功")
}
});
},
cancel: function () {
alert("拒绝定位");
resolve("定位失败")
}
});
},
cancel: function () {
alert("拒绝定位");
} else {
resolve("已经有定位")
}
});
} else {
}
// alert("lat:" + localStorage.getItem("latitude") + ";lng:" + localStorage.getItem("longitude"));
wx.error(function (res) {
alert("wx-js初始化: " + res);
// alert("lat:" + localStorage.getItem("latitude") + ";lng:" + localStorage.getItem("longitude"));
wx.error(function (res) {
alert("wx-js初始化: " + res);
resolve("定位失败")
});
});
});
});
})
}

5
src/models/wxShare.js

@ -112,7 +112,7 @@ wxShareModel.getWXCheck().then(response =>{
localStorage.setItem("longitude", res.longitude);
},
cancel: function () {
alter("拒绝定位");
alert("拒绝定位");
}
});
} else {
@ -120,7 +120,8 @@ wxShareModel.getWXCheck().then(response =>{
}
// alert("lat:" + localStorage.getItem("latitude") + ";lng:" + localStorage.getItem("longitude"));
wx.error(function (res) {
alter("wx-js初始化: " + res);
console.log("--------wx")
alert("wx-js初始化: " + res);
});
});
});

59
src/view/choose-community.vue

@ -124,8 +124,8 @@ export default {
if (data.addressComponents) {
const result = data.addressComponents;
const location = {
creditLongitude: r.point.lat, //
creditLatitude: r.point.lng, //
creditLongitude: r.point.lng, //
creditLatitude: r.point.lat, //
creditProvince: result.province || "", //
creditCity: result.city || "", //
creditArea: result.district || "", //
@ -173,8 +173,8 @@ export default {
},
//
confirm(list) {
console.log("list:" + list);
// let addressArr = list.split(",");
console.log("list:" + list);
// let addressArr = list.split(",");
let arr = list[2].split("&") || "";
this.districtId = arr[0];
this.defaultCity = arr[1];
@ -182,7 +182,7 @@ export default {
console.log("arr:" + this.defaultCity);
// localStorage.setItem("cityName", list);
this.show = false;
this.pageNum = 1;
this.pageNum = 0;
this.busy = false;
this.loadMoreHide = false;
this.loadMoreTips = false;
@ -266,26 +266,27 @@ export default {
item.cityId + "&" + item.cityName,
item.districtId + "&" + item.districtName + "&" + item.merchantNo
];
if (isEmpty(this.templateNo)) {
localStorage.setItem("cityName", this.addressValue.slice());
localStorage.setItem(
"estate",
item.housingEstateId + "&" + item.housingEstateName
);
this.estateId = item.housingEstateId;
countPartner();
this.$router.push({
name: "首页"
});
} else {
this.$vux.confirm.show({
title: "选择小区",
content: "确定选择" + item.housingEstateName,
confirmText: "确定",
cancelText: "取消",
onCancel: () => {},
onConfirm: () => {
this.$vux.confirm.show({
title: "选择小区",
content: "确定选择:" + item.cityName+item.districtName +"【" + item.housingEstateName + "】",
confirmText: "确定",
cancelText: "取消",
onCancel: () => {},
onConfirm: () => {
this.estateId = item.housingEstateId;
if (isEmpty(this.templateNo)) {
localStorage.setItem("cityName", this.addressValue.slice());
localStorage.setItem(
"estate",
item.housingEstateId + "&" + item.housingEstateName
);
this.estateId = item.housingEstateId;
countPartner();
this.$router.push({
name: "首页"
});
} else {
chooseCommunityApi
.getGoodsTemlate({
templateNo: this.templateNo,
@ -309,7 +310,10 @@ export default {
content: item.housingEstateName + "暂无提供此商品服务",
confirmText: "确定",
onConfirm: () => {
localStorage.setItem("cityName", this.addressValue.slice());
localStorage.setItem(
"cityName",
this.addressValue.slice()
);
localStorage.setItem(
"estate",
item.housingEstateId + "&" + item.housingEstateName
@ -325,8 +329,9 @@ export default {
this.showLoading = false;
});
}
});
}
}
});
// this.$router.push({
// name: ""
// });

240
src/view/home.vue

@ -171,7 +171,8 @@ export default {
show: false,
location: {},
uniqueId: "",
defaultCity: "天河区", //
defaultDistrict: "天河区",
defaultCity: "广州市", //
defaultCommunity: "请选择小区",
merchantNo: 2, //
districtId: "440106000", //id
@ -319,11 +320,12 @@ export default {
lng: this.lng
})
.then(res => {
console.log("----------getAddressInfo");
if (res.response.allAddress && res.response.userAddress) {
this.addressData = res.response.allAddress;
this.flag = true;
let data = res.response;
//type:1-0-1-2-
//type:-10-1-2-3-
if (data.userAddress.type == 1) {
this.address =
data.userAddress.cityName +
@ -332,54 +334,23 @@ export default {
: "");
this.alertShow = true;
} else if (data.userAddress.type == 2) {
return new Promise((resolve, reject) => {
chooseCommunityApi
.getEstateList({
draw: 0,
lat: this.lat,
lng: this.lng,
num: 1
})
.then(res => {
//
if (res.dataList.length > 0) {
var addreRes = res.dataList[0];
this.$vux.confirm.show({
title: "自动定位小区:",
content: addreRes.housingEstateName,
cancelText: "切换地址",
onCancel: () => {
this.chooseCommunity();
},
onConfirm: () => {
this.defaultLocalEstate(addreRes);
this.getGoodsList();
}
});
} else {
this.$vux.confirm.show({
title: "自动定位地址:",
content:
data.userAddress.cityName +
(data.userAddress.districtName
? data.userAddress.districtName
: ""),
confirmText: "选择小区",
cancelText: "切换地址",
onCancel: () => {
this.chooseCommunity();
},
onConfirm: () => {
this.defaultLocalEstate(data.estateInfo);
this.chooseCommunity();
}
});
}
this.showLoading = false;
})
.catch(error => {
this.showLoading = false;
});
this.showLoading = false;
this.$vux.confirm.show({
title: "自动定位小区",
content:
data.estateInfo.cityName +
data.estateInfo.districtName +
"【" +
data.estateInfo.housingEstateName +
"】",
cancelText: "切换",
onCancel: () => {
this.chooseCommunity();
},
onConfirm: () => {
this.defaultLocalEstate(data.estateInfo);
this.getGoodsList();
}
});
} else if (data.userAddress.type == 0) {
this.getGoodsList();
@ -393,6 +364,20 @@ export default {
this.chooseCommunity();
}
});
} else if (data.userAddress.type == 3) {
localStorage.removeItem("estate");
this.$vux.alert.show({
title:
this.defaultCity +
this.defaultDistrict +
"【" +
this.defaultCommunity +
"】" +
"暂无开通服务",
onHide: () => {
this.chooseCommunity();
}
});
}
resolve();
}
@ -413,9 +398,10 @@ export default {
this.addressValue = arr;
this.provinceId = arr[0].split("&")[0];
this.cityId = arr[1].split("&")[0];
let cityNameArr = arr[2].split("&");
this.districtId = cityNameArr[0];
this.defaultCity = cityNameArr[1];
this.defaultCity = arr[1].split("&")[1];
let districtArr = arr[2].split("&");
this.districtId = districtArr[0];
this.defaultDistrict = districtArr[1];
// this.merchantNo = cityNameArr[2];
this.merchantNo = 2;
}
@ -428,6 +414,7 @@ export default {
},
getData() {
let get = async () => {
this.getId();
await this.getAddressInfo();
// await this.getGoodsList();
};
@ -438,19 +425,33 @@ export default {
this.chooseCommunity();
},
getLocation() {
// let get = async () => {
//
var ua = window.navigator.userAgent.toLowerCase();
//uaMicroMessenger
let _this = this;
if (ua.match(/MicroMessenger/i) == "micromessenger") {
//
this.wxLocation({});
this.wxLocation().then(result => {
console.log("wxLocationresult:" + result);
this.getId();
this.getAddressInfo();
});
// this.getData().then(result => {
// this.wxLocation({})
// });
} else {
// TODO api
this.getCity();
}
// };
// return get();
},
getWXLocation() {
let get = async () => {
await this.wxLocation({});
};
return get();
},
getCity() {
let _this = this;
var geolocation = new BMap.Geolocation();
@ -467,8 +468,8 @@ export default {
if (data.addressComponents) {
const result = data.addressComponents;
const location = {
creditLongitude: r.point.lat, //
creditLatitude: r.point.lng, //
creditLongitude: r.point.lng, //
creditLatitude: r.point.lat, //
creditProvince: result.province || "", //
creditCity: result.city || "", //
creditArea: result.district || "", //
@ -480,20 +481,22 @@ export default {
localStorage.setItem("longitude", location.creditLongitude);
_this.lat = location.creditLatitude;
_this.lng = location.creditLongitude;
// alert(
// "-" +
// location.creditProvince +
// ";-" +
// location.creditCity +
// ";-" +
// location.creditArea +
// ";-" +
// location.creditStreet +
// ";lat-" +
// location.creditLatitude +
// ";lng-" +
// location.creditLongitude
// );
alert(
"省-" +
location.creditProvince +
";市-" +
location.creditCity +
";区-" +
location.creditArea +
";街道-" +
location.creditStreet +
";lat-" +
location.creditLatitude +
";lng-" +
location.creditLongitude
);
_this.getId();
_this.getAddressInfo();
}
});
// }
@ -505,12 +508,15 @@ export default {
? estateRes.provinceId
: this.provinceId;
this.cityId = estateRes.cityId ? estateRes.cityId : this.cityId;
this.cityName = estateRes.cityName
? estateRes.cityName
: this.defaultCity;
this.districtId = estateRes.districtId
? estateRes.districtId
: this.districtId;
this.defaultCity = estateRes.districtName
this.defaultDistrict = estateRes.districtName
? estateRes.districtName
: this.defaultCity;
: this.defaultDistrict;
this.merchantNo = estateRes.merchantNo;
this.addressValue = [
this.provinceId + "&" + estateRes.provinceName,
@ -542,6 +548,12 @@ export default {
// this.getdefaultAddress();
// this.getAddress();
// this.getLocation();
// this.$vux.confirm.show({
// content: "",
// confirmText: "",
// onConfirm: () => {}
// });
this.getId();
let eId = this.$route.query.estateId;
console.log("eId----" + eId + "estateId---" + this.estateId);
@ -568,20 +580,36 @@ export default {
this.showLoading = false;
if (isEmpty(res.response)) {
//
this.chooseCommunity();
this.$vux.alert.show({
title:
this.defaultCity +
this.defaultDistrict +
"【" +
this.defaultCommunity +
"】" +
"暂无开通服务",
onHide: () => {
this.chooseCommunity();
}
});
} else {
//
var linkEstate = res.response;
this.$vux.confirm.show({
title: "当前小区",
content: linkEstate.housingEstateName,
confirmText: "确定",
cancelText: "切换",
content:
linkEstate.cityName +
linkEstate.districtName +
"【" +
linkEstate.housingEstateName +
"】",
confirmText: "切换",
cancelText: "确定",
onCancel: () => {
this.chooseCommunity();
this.defaultLocalEstate(linkEstate);
},
onConfirm: () => {
this.defaultLocalEstate(linkEstate);
this.chooseCommunity();
}
});
}
@ -590,8 +618,19 @@ export default {
this.showLoading = false;
});
} else {
this.showLoading = false;
this.chooseCommunity();
this.$vux.alert.show({
title:
this.defaultCity +
this.defaultDistrict +
"【" +
this.defaultCommunity +
"】" +
"暂无开通服务",
onHide: () => {
this.showLoading = false;
this.chooseCommunity();
}
});
}
} else {
var loclEstate = res.response;
@ -617,10 +656,20 @@ export default {
//
var linkEstate = res.response;
this.$vux.confirm.show({
title: "切换小区",
content: linkEstate.housingEstateName,
content:
"当前小区为:" +
this.defaultCity +
this.defaultDistrict +
"【" +
this.defaultCommunity +
"】,是否切换为:" +
linkEstate.cityName +
linkEstate.districtName +
"【" +
linkEstate.housingEstateName +
"】,是否切换为:",
confirmText: "不切换",
cancelText: "切换",
cancelText: "确定",
onCancel: () => {
this.defaultLocalEstate(linkEstate);
this.getGoodsList();
@ -661,16 +710,21 @@ export default {
var linkEstate = res.response;
this.$vux.confirm.show({
title: "当前小区",
content: linkEstate.housingEstateName,
confirmText: "确定",
cancelText: "切换",
content:
linkEstate.cityName +
linkEstate.districtName +
"【" +
linkEstate.housingEstateName +
"】",
confirmText: "切换",
cancelText: "确定",
onCancel: () => {
this.chooseCommunity();
},
onConfirm: () => {
this.defaultLocalEstate(linkEstate);
this.getGoodsList();
countPartner()
countPartner();
},
onConfirm: () => {
this.chooseCommunity();
}
});
}
@ -680,8 +734,8 @@ export default {
});
}
} else {
//this.getData();
this.getLocation();
this.getData();
}
var uuniqueId = this.$route.query.uniqueId;

Loading…
Cancel
Save