日照项目的居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

519 lines
11 KiB

import request from "@config/rerquest";
import {
wxRequestPost,
wxGetSetting,
wxGetUserProfile,
} from "@utils/promise-wx-api";
import getLocation from "@utils/location";
const app = getApp();
Component({
properties: {
isNovice: {
type: Boolean,
value: false,
},
},
data: {
hasChose: false,
isShowHouseList: true,
selectedarea: false,
region: ["山东省", "青岛市", "市北区"],
// region: ["", "", ""],
currentAddress: "",
contact: "",
qrUrl: "",
gridList: [],
params: {
pageNo: 1,
pageSize: 20,
isNone: false,
isAuthorized: 1, // 0 1 是否首次位置授权
areaCode: "",
selectedAreaCode: "",
province: "",
city: "",
area: "",
},
idCard: "",
buildingName: "",
},
observers: {
buildingName() {
this.resetGridList();
this.getList();
},
},
methods: {
async onLoad() {
this.getContactPhone();
wx.showLoading({ title: "请求中" });
await this.getLocation();
wx.hideLoading();
},
getContactPhone() {
request({
method: "POST",
url: "resi/guide/stranger/marketcontactinfo",
ifToken: false,
}).then((res) => {
console.log(res.data);
this.setData({
contact: res.data.phone,
qrUrl: res.data.qrUrl,
});
});
},
// 获取地理位置信息
async getLocation(isQuiet = true) {
const st = await wxGetSetting();
let isAuthorized = 0;
if (
st.msg == "success" &&
st.data.authSetting["scope.userLocation"]
) {
isAuthorized = 1;
}
const { msg, data } = await getLocation(isQuiet);
console.log(msg, data);
if (msg === "success") {
this.setData({
selectedarea: true,
currentAddress: data.address,
"params.isAuthorized": isAuthorized,
"params.province": data.province,
"params.city": data.city,
"params.area": data.district,
"params.selectedAreaCode": data.adcode,
"params.areaCode": data.adcode,
});
this.resetGridList();
this.getList();
}
},
async reLocation() {
console.log("重新获取定位");
this.getLocation(false);
},
bindRegionChange: function (e) {
console.log("picker发送选择改变,携带值为", e.detail.value[0]);
let province = e.detail.value[0];
let city = e.detail.value[1];
let area = e.detail.value[2];
let adcode = e.detail.code[2];
this.setData({
selectedarea: true,
region: e.detail.value,
// currentAddress: "",
"params.province": province,
"params.city": city,
"params.area": area,
"params.areaCode": adcode,
"params.selectedAreaCode": adcode,
});
this.resetGridList();
this.getList();
},
// 到底部自动加载
onReachBottom() {
console.log("========onReachBottom");
this.getList();
},
handleBlur(e) {
const { value } = e.detail;
if (!this.identityCodeValid(value)) {
return wx.showToast({
title: "证件号格式错误",
icon: "none",
duration: 1500,
});
}
},
async handleBlur_new(e) {
console.log(JSON.stringify(e));
const { value } = e.detail;
// if (value.length > 0) {
// this.setData({
// buildingName: value,
// isShowHouseList: true
// })
// this.getNeighborhoodlist('bind')
// } else {
// this.setData({
// buildingName: '',
// isShowHouseList: false
// })
// this.resetGridList();
// await this.getList();
// }
console.log("value:", value);
// if(!this.identityCodeValid(value)) {
// return wx.showToast({
// title: '证件号格式错误',
// icon: 'none',
// duration: 1500
// })
// }
},
handleInput(e) {
const { value } = e.detail;
this.setData({
idCard: value,
});
},
handleInput_new(e) {
const { value } = e.detail;
this.setData({
buildingName: value,
isShowHouseList: true,
});
},
identityCodeValid(idcode) {
// 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
return /^(\d{15}$)|(^\d{17}([0-9]|X)$)|(^[a-zA-Z]{2}\d{7}$|^[a-zA-Z]{1}\d{8}$)/.test(
idcode
);
},
// handleCancle() {
// this.setData({
// idCard: ''
// })
// this.reLocation()
// },
handleCancle_new() {
this.setData({
buildingName: "",
// isShowHouseList: false
});
this.resetGridList();
this.getList();
},
async handleItem(e) {
console.log("eeee----", e.currentTarget.dataset.index);
const { index } = e.currentTarget.dataset;
const { gridList } = this.data;
let item = gridList[index];
if (item.showItem) {
item.showItem = false;
this.setData({
gridList,
});
return;
}
const {
msg,
data: {
data: { code, data },
},
} = await wxRequestPost(
"gov/org/icneighborhood/open/list",
{
gridId: item.gridId,
},
{
isQuiet: false,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
console.log("data----", data);
if (data.total > 0) {
item.showItem = true;
item.village = data.list
.map((n) => n.neighborHoodName)
.join("、");
this.setData({
gridList,
});
} else {
wx.showToast({
title: "还没有小区哦",
icon: "none",
duration: 1500,
});
}
} else {
wx.showToast({
title: msg,
icon: "none",
duration: 1500,
});
}
},
async handleSearch() {
if (!this.data.idCard) {
wx.showToast({
title: "请输入证件号",
icon: "none",
duration: 1500,
});
return;
}
const url = "epmetuser/icresiuser/icUserMatchGrid";
const extAppid = wx.getStorageSync("extAppid");
wx.showLoading({ title: "" });
const {
msg,
data: {
data: { code, data },
},
} = await wxRequestPost(
url,
{
appId: extAppid,
idCard: this.data.idCard,
},
{
isQuiet: false,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
this.resetGridList();
let { gridList } = this.data;
gridList = [];
gridList.push({ ...data, showItem: false });
this.setData({
gridList,
});
console.log("data-sssss", data);
} else {
wx.showToast({
title: msg,
icon: "none",
duration: 1500,
});
}
},
async handleFocus() {
this.setData({
isShowHouseList: true,
});
this.getList();
},
getList() {
const { isShowHouseList } = this.data;
if (isShowHouseList) {
this.getNeighborhoodlist();
} else {
this.getGridList();
}
},
// 重置网格列表
resetGridList() {
this.setData({
// gridList: [],
"params.pageNo": 1,
"params.isNone": false,
});
},
async getNeighborhoodlist22222() {
const url = "gov/org/icneighborhood/neighborhoodlist";
// wx.showLoading({ title: "" });
const {
msg,
data: {
data: { code, data },
},
} = await wxRequestPost(
url,
{
buildingName: this.data.buildingName,
},
{
isQuiet: false,
}
);
// wx.hideLoading();
if (msg === "success" && code === 0) {
this.resetGridList();
let { gridList } = this.data;
gridList = [];
let _data =
data &&
data.map((item) => {
return {
...item,
showItem: false,
};
});
gridList = _data;
this.setData({
gridList,
});
// console.log('data-sssss', JSON.stringify(this.data.gridList))
} else {
wx.showToast({
title: msg,
icon: "none",
duration: 1500,
});
}
},
// 获取网格列表
async getNeighborhoodlist() {
const { params } = this.data;
if (params.isNone) return console.log("没有更多了");
const url = "gov/org/icneighborhood/neighborhoodlist";
wx.showLoading({ title: "" });
const {
msg,
data: {
data: { code, data },
},
} = await wxRequestPost(
url,
{
buildingName: this.data.buildingName,
pageNo: params.pageNo,
pageSize: params.pageSize,
},
{
isQuiet: false,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
let { gridList } = this.data;
let _data =
data &&
data.map((item) => {
return {
...item,
showItem: false,
};
});
if (params.pageNo == 1) {
gridList = _data;
} else {
gridList.push(..._data);
}
this.setData({
gridList,
hasChose: true,
"params.pageNo": params.pageNo + 1,
"params.isNone": data.length < params.pageSize,
});
return false;
}
},
// 获取网格列表
async getGridList() {
const { params } = this.data;
if (params.isNone) return console.log("没有更多了");
const extAppid = wx.getStorageSync("extAppid");
const url = extAppid
? "resi/guide/stranger/publiclocationgridlist"
: "resi/guide/stranger/getlocationcustomergridlist";
wx.showLoading({ title: "" });
const {
msg,
data: {
data: { code, data },
},
} = await wxRequestPost(
url,
{
...params,
appId: extAppid,
isNovice: this.data.isNovice,
},
{
isQuiet: false,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
let { gridList } = this.data;
let _data =
data &&
data.map((item) => {
return {
...item,
showItem: false,
};
});
if (params.pageNo == 1) {
gridList = _data;
} else {
gridList.push(..._data);
}
this.setData({
gridList,
hasChose: true,
"params.pageNo": params.pageNo + 1,
"params.isNone": data.length < params.pageSize,
});
return false;
}
},
// 点击网格登录
async loginGrid(e) {
let gid = e.currentTarget.dataset.gid;
let cid = e.currentTarget.dataset.cid;
app.globalData.customerId = cid;
app.globalData.gridId = gid;
wx.showLoading({ title: "" });
await app.enterGridData();
wx.hideLoading();
app.setAccountInfo({ isLogined: true });
if (
wx.getStorageSync("isFromQr") &&
wx.getStorageSync("isFromQr") == "1"
) {
wx.reLaunch({
url: "/subpages/points/pages/fangyi/xinxi/create/index",
});
wx.removeStorageSync("isFromQr");
} else {
wx.reLaunch({
url: "/pages/main/index",
});
}
},
},
});