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.

239 lines
6.2 KiB

//index.js
//获取应用实例
const app = getApp()
var bmap = require('../../libs/bmap-wx.min.js');
Page({
data: {
sugData: '',
items: [
{ top: 58, title: '联系人', note:'您的姓名', page: 'Name' ,box:'',typeFlag:'text'},
{ top: 1, title: '手机号码', note: '请填写手机号码', page: 'Mobile', box: '', typeFlag: 'number'},
{ top: 1, title: '服务地址', note: '搜索您的小区/大厦/学校', page: 'Area', box: 'show', typeFlag: 'text'},
{ top: 1, title: '详细地址', note: '填写街道门牌信息', page: 'Address', box: '', typeFlag: 'text'},
{ top: 1, title: '服务面积', note: '选择您的服务面积', page: 'ServiceArea', box: '', typeFlag: 'text'}
],
addrItems:[],
img: '../../images/addr.png',
area:'',
name:'',
mobile:'',
addr:'',
serviceArea:'',
show:false
},
// 绑定input输入
inputArea: function (e) {
var that = this;
// 新建百度地图对象
var BMap = new bmap.BMapWX({
ak: '7nj5S5ZHqOaqcwom3m6zh1bWagseiSXD'
});
var fail = function (data) {
console.log(data)
};
var success = function (data) {
// var sugData = '';
let addr=[];
for (var i = 0; i < data.result.length; i++) {
// sugData = sugData + data.result[i].name + '\n';
addr[i] = data.result[i].name;
}
// that.setData({
// sugData: sugData
// });
that.setData({
addrItems: addr,
show: true,
area: e.detail.value
});
console.log(that.data.addrItems);
}
// 发起suggestion检索请求
BMap.suggestion({
query: e.detail.value,
region: '广州',
city_limit: true,
fail: fail,
success: success
});
},
inputName:function(e){
this.setData({
name: e.detail.value
})
},
inputMobile: function (e) {
this.setData({
mobile: e.detail.value
})
},
inputAddr: function (e) {
this.setData({
addr: e.detail.value
})
},
chooseAddr:function(e){
var that=this;
let str = e.currentTarget.dataset.item;
console.log(str);
that.setData({
addrItems:[],
area:str,
show:false
})
console.log(that.data.addrItems);
},
showClear: function (e) {
var that = this;
console.log(that.data.area);
if (that.data.area!=''){
that.setData({
show: true
})
}else{
that.setData({
show: false
})
}
},
clear: function (e) {
var that = this;
that.setData({
addrItems: [],
area:''
})
},
hideAll: function (e) {
var that = this;
that.setData({
addrItems: [],
show: false
})
},
save: function (e) {
let that = this;
let name = this.data.name;
let mobile = this.data.mobile;
let area = this.data.area;
let addr = this.data.addr;
let serviceArea = this.data.serviceArea;
let checkName = this.checkForm(name, '姓名','name');
console.log(checkName);
if(checkName !=false){
let checkMobile = this.checkForm(mobile, '手机号','mobile');
if (checkMobile!=false){
let checkArea = this.checkForm(area, '服务地址','area');
if (checkArea != false) {
let checkAddr = this.checkForm(addr, '详细地址','area');
if (checkAddr != false) {
this.checkForm(serviceArea, '服务面积','serviceArea');
}
}
}
}
if (this.data.mobile_lock === 0) {
this.setData({
mobile_lock: 1
});
let that = this;
wx.request({
url: app.gw.hostUrl + '/sms/code',
data: { mobileNumber: that.data.mobile, codeType: 1, clientType: 10 },
header: { "Content-Type": "application/json" },
method: 'GET',
dataType: 'json',
responseType: 'text',
success: function (res) {
if (res.data.code == 0) {
that.setData({
mobile_count: 60
});
wx.showToast({
title: '验证码发送成功',
icon: 'success',
duration: 2000
})
that.btnCount();
} else {
that.setData({
mobile_lock: 0
});
that.setData(
{ popErrorMsg: res.data.msg }
);
that.ohShitfadeOut();
return;
}
},
fail: function (res) { },
complete: function (res) { },
})
}
},
checkForm: function (sign,title,flag){
let that = this;
if (sign == '') {
that.setData(
{ popErrorMsg: title+"不能为空" }
);
that.ohShitfadeOut();
return false;
}else if(flag=='mobile'){
if (!(/^1[345678]\d{9}$/.test(sign))) {
that.setData(
{ popErrorMsg: title+"格式错误,请重填" }
);
that.ohShitfadeOut();
return false;
}
}
},
ohShitfadeOut() {//错误提示显示3秒后消失,清空计时器
var fadeOutTimeout = setTimeout(() => {
this.setData({ popErrorMsg: '' });
clearTimeout(fadeOutTimeout);
}, 3000);
},
onLoad: function (options) {
let item = JSON.parse(options.jsonStr);
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true,
price: item.price,
title: item.name,
product: item,
})
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo: function (e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})