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.

506 lines
14 KiB
JavaScript

2 years ago
// pages/jobDetail/editAddress/index.js
const { isNotEmptyCheck } = require("../../../utils/commonUtil.js");
var QQMapWX = require("../../../utils/qqmap-wx-jssdk.min.js");
var qqmapsdk;
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
array: ['河南', '日薪', '补贴', '返费', '计件', '保底', '面议', '月薪'],
index: 0,
jobDetail: {},
cqDz: '暂无详细地址',
cqName:'无',
cqAddress: '暂无详细地址',
cqLat: '',
cpLng: '',
msDz: '暂无详细地址',
msName:"上海昌硕科技有限公司",
msAddress:"上海市浦东新区秀沿路3668号",
msLat: '',
msLng: '',
ssDz: '暂无详细地址',
ssName:'无',
ssLat: '',
ssLng: '',
district: '',
show1:false,
storeId:'',
storeName:'',
jobId:'',
jobName:'',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var that = this;
qqmapsdk = new QQMapWX({
key: "5PTBZ-YI7C6-MZGS3-ES7QN-4T5O2-EJFVR",
});
new Promise(function (resolve, reject) {
that.setData({
jobDetail: wx.getStorageSync('jobDetail')
})
resolve();
}).then(function () {
that.setData({
cqDz: that.data.jobDetail.poses.store.detailPosition,
cqLat: that.data.jobDetail.poses.store.latitude,
cqLng: that.data.jobDetail.poses.store.longitude,
msDz: that.data.jobDetail.jobPoses.interview.posContent,
msLat: that.data.jobDetail.jobPoses.interview.latitude,
msLng: that.data.jobDetail.jobPoses.interview.longitude,
ssDz: that.data.jobDetail.jobPoses.room.posContent,
ssLat: that.data.jobDetail.jobPoses.room.latitude,
ssLng: that.data.jobDetail.jobPoses.room.longitude,
storeId:that.data.jobDetail.store.id,
storeName:that.data.jobDetail.store.storeName,
jobId:that.data.jobDetail.storeJob.id,
jobName:that.data.jobDetail.storeJob.jobName,
})
})
console.log(that.data.jobDetail)
},
getDistrictStr(lat, lng) {
return new Promise(function(reslove, reject) {
qqmapsdk.reverseGeocoder({
location: {
latitude: lat,
longitude: lng
},
success: function (res1) {
reslove(res1.result.address_component.province + "," + res1.result.address_component.city + "," + res1.result.address_component.district);
},
fail: function() {
reslove('');
}
})
});
},
chooseMap2(e) {
var that = this;
console.log(e)
let name = e.currentTarget.dataset['name'];
let id = e.currentTarget.dataset['id'];
let record = {};
let tmp = that.data.jobDetail;
console.log(tmp, that.data)
console.log(id == "");
wx.chooseLocation({
success(res) {
console.log(res);
that.getDistrictStr(res.latitude, res.longitude).then((dis) => {
if(name == "others") {
let others = tmp.poses[name];
for(var i = 0; i != others.length; ++i) {
if(others[i].id == id) {
tmp.poses[name][i].posTitle = res.name;
tmp.poses[name][i].posContent = res.address;
tmp.poses[name][i].latitude = res.latitude;
tmp.poses[name][i].longitude = res.longitude;
tmp.poses[name][i].district = dis;
tmp.poses[name].fkName = that.data.storeName;
tmp.poses[name].fkId = that.data.storeId;
tmp.poses[name].posType = 2;
}
}
} else if(name == "store"){
tmp.poses[name].posTitle = res.name;
tmp.poses[name].posContent = res.address;
tmp.poses[name].latitude = res.latitude;
tmp.poses[name].longitude = res.longitude;
tmp.poses[name].district = dis;
tmp.poses[name].fkName = that.data.storeName;
tmp.poses[name].fkId = that.data.storeId;
tmp.poses[name].posType = 2;
if(id != ""){
tmp.poses[name].id = id;
}
}else{
tmp.poses[name].posTitle = res.name;
tmp.poses[name].posContent = res.address;
tmp.poses[name].latitude = res.latitude;
tmp.poses[name].longitude = res.longitude;
tmp.poses[name].district = dis;
tmp.poses[name].fkName = that.data.jobName;
tmp.poses[name].fkId = that.data.jobId;
tmp.poses[name].posType = 4;
tmp.jobPoses[name].posTitle = res.name;
tmp.jobPoses[name].posContent = res.address;
tmp.jobPoses[name].latitude = res.latitude;
tmp.jobPoses[name].longitude = res.longitude;
tmp.jobPoses[name].district = dis;
tmp.jobPoses[name].fkName = that.data.jobName;
tmp.jobPoses[name].fkId = that.data.jobId;
tmp.jobPoses[name].posType = 4;
if(id != ""){
tmp.poses[name].id = id;
}
}
that.setData({
jobDetail: tmp,
})
console.log(res, tmp);
})
}
})
// }
},
formSubmit(e) {
var that = this;
wx.showLoading({
title: '提交中...',
})
console.log(that.data.jobDetail.poses);
let data = {
storeId: '',
posJsonStr: '',
};
data.storeId = that.data.jobDetail.store.id;
data.storeJobId = that.data.jobDetail.storeJob.id;
data.posJsonStr = JSON.stringify(that.data.jobDetail.poses);
console.log(data)
wx.request({
url: app.globalData.ip + "/store/updatePos",
header: app.globalData.header,
data: data,
method: "POST",
success: function (res) {
wx.hideLoading({
success: (res) => {},
})
wx.showToast({
title: '修改成功',
icon: 'success',
duration: 1000
})
setTimeout(function () {
wx.navigateBack({
delta: 1,
})
}, 1000)
},
fail: function (res) {
console.log(res);
},
});
},
shrink(){
wx.navigateBack({
delta: 1,
})
},
push(filedName, filedValue) {
let currData = {};
let that = this;
currData["id"] = that.data.jobDetail.storeJob.id;
currData["fieldName"] = filedName;
currData["value"] = filedValue;
return new Promise(function (resolve, reject) {
wx.request({
url: app.globalData.ip + "/store/job/updateJobField",
header: app.globalData.header,
data: currData,
method: "POST",
success: function (res) {
resolve(res);
// debugger;
},
fail: function (res) {
reject(res);
console.log(res);
},
});
})
},
cn(){
console.log("cn");
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
var that = this;
let addPos = wx.getStorageSync('otherPos');
let tmp = that.data.jobDetail;
if(addPos) {
console.log(JSON.parse(addPos));
tmp.poses['others'].push(JSON.parse(addPos));
wx.removeStorageSync('otherPos');
that.setData({
jobDetail: tmp,
})
}
this.setData({
slideButtons: [{
data:1,
text: '清空',
src: 'http://matripe.oss-cn-beijing.aliyuncs.com/yishoudan/cla.png', // icon的路径
}],
slideButtons2: [{
data:1,
text: '清空',
src: 'http://matripe.oss-cn-beijing.aliyuncs.com/yishoudan/cla.png', // icon的路径
}],
slideButtons1: [{
data:1,
text: '清空',
src: 'http://matripe.oss-cn-beijing.aliyuncs.com/yishoudan/cla.png', // icon的路径
}, {
data:2,
text: '删除',
extClass: 'test',
src: 'http://matripe.oss-cn-beijing.aliyuncs.com/yishoudan/del.png', // icon的路径
}],
})
// that.getMap();
// that.setData({
// cqDz: that.data.jobDetail.store.detailPosition,
// cqLat: that.data.jobDetail.store.lat,
// cqLng: that.data.jobDetail.store.lng,
// msDz: that.data.jobDetail.storeJob.interviewAddr,
// ssDz: that.data.jobDetail.storeJob.meettingAddr,
// })
},
bindbuttontap(e){
console.log(e);
this.setData({
show1:true
})
},
slideButtonTap(e) {
console.log(e)
var that = this;
let name = e.currentTarget.dataset['name'];
let id = e.currentTarget.dataset['id'];
let record = {};
let tmp = that.data.jobDetail;
that.setData({
show1:true
})
console.log(e.detail)
if(e.detail.index == 0){
wx.showModal({
content: '确定要清空该地址吗?',
confirmColor:"#00bebe",
success (res) {
if (res.confirm) {
console.log('用户点击确定')
if("others" == name) {
let others = tmp.poses[name];
for(var i = 0; i != others.length; ++i) {
if(others[i].id == id) {
tmp.poses[name][i].posTitle = "";
tmp.poses[name][i].posContent = "";
tmp.poses[name][i].latitude = "";
tmp.poses[name][i].longitude = "";
}
}
} else {
tmp.poses[name].posTitle = "";
tmp.poses[name].posContent = "";
tmp.poses[name].latitude = "";
tmp.poses[name].longitude = "";
}
that.setData({
jobDetail: tmp,
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}else{
wx.showModal({
content: '确定要删除该地址吗?',
confirmColor:"#00bebe",
success (res) {
if (res.confirm) {
wx.request({
url: app.globalData.ip + "/lbs/position/del/" + id,
header: app.globalData.header,
method: "get",
success: function (res) {
if("others" == name) {
let others = tmp.poses[name];
let arr = [];
for(var i = 0; i != others.length; ++i) {
if(others[i].id != id) {
arr.push(tmp.poses[name][i]);
}
}
tmp.poses[name] = arr;
}
that.setData({
jobDetail: tmp,
})
wx.showToast({
title: '已删除',
icon: 'success',
duration: 1500
})
wx.setStorageSync('jobDetail', that.data.jobDetail)
// debugger;
},
fail: function (res) {
reject(res);
console.log(res);
},
});
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
},
slideButtonTap2(e) {
var that = this;
console.log(e.detail)
if(e.detail.index == 0){
wx.showModal({
content: '确定要清空该地址吗?',
confirmColor:"#00bebe",
success (res) {
if (res.confirm) {
that.setData({
msName:'无',
msAddress:"暂无详细地址"
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}else{
wx.showModal({
content: '确定要删除该地址吗?',
confirmColor:"#00bebe",
success (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
},
getMap(){
var _this = this;
qqmapsdk.direction({
mode: 'bicycling',//可选值:'driving'(驾车)、'walking'(步行)、'bicycling'(骑行),不填默认:'driving',可不填
//from参数不填默认当前地址
from: {
latitude: 39.984060,
longitude: 116.306361
},
to: {
latitude: 39.984060,
longitude: 116.288868
},
success: function (res) {
console.log(res);
var ret = res;
var coors = ret.result.routes[0].polyline, pl = [];
//坐标解压(返回的点串坐标,通过前向差分进行压缩)
var kr = 1000000;
for (var i = 2; i < coors.length; i++) {
coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
}
//将解压后的坐标放入点串数组pl中
for (var i = 0; i < coors.length; i += 2) {
pl.push({ latitude: coors[i], longitude: coors[i + 1] })
}
console.log(pl)
//设置polyline属性将路线显示出来,将解压坐标第一个数据作为起点
_this.setData({
latitude:pl[0].latitude,
longitude:pl[0].longitude,
polyline: [{
points: pl,
color: '#ff0000bf',
width: 4
}]
})
},
fail: function (error) {
console.error(error);
},
complete: function (res) {
console.log(res);
}
});
},
goAdd(){
wx.setStorageSync('jobDetail', this.data.jobDetail)
wx.navigateTo({
url: '../addAddressNew/index',
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})