|
|
@ -2,89 +2,83 @@ Page({ |
|
|
|
data: { |
|
|
|
statusBarHeight: 44, // 导航高度
|
|
|
|
modalY: 0, // 楼栋选择top值
|
|
|
|
addressList:[ |
|
|
|
{buildingId:'1', descr: '世界大厦1#1-1-1'}, |
|
|
|
{buildingId:'2', descr: '世界大厦1#1-1-2'}, |
|
|
|
{buildingId:'3', descr: '世界大厦1#1-1-3'}, |
|
|
|
{buildingId:'4', descr: '世界大厦1#1-2-1'}, |
|
|
|
{buildingId:'5', descr: '世界大厦1#1-2-2'}, |
|
|
|
{buildingId:'6', descr: '世界大厦1#1-2-3'}, |
|
|
|
{buildingId:'7', descr: '世界大厦1#1-3-1'}, |
|
|
|
{buildingId:'8', descr: '世界大厦1#1-3-2'}, |
|
|
|
{buildingId:'9', descr: '世界大厦1#1-3-3'}, |
|
|
|
{buildingId:'10', descr: '世界大厦1#1-4-1'}, |
|
|
|
{buildingId:'11', descr: '世界大厦1#1-4-2'}, |
|
|
|
{buildingId:'12', descr: '世界大厦1#1-4-3'} |
|
|
|
unitModalY: 0, // 单元选择top值
|
|
|
|
addressList: [{ |
|
|
|
buildingId: '1', |
|
|
|
descr: '世界大厦A座' |
|
|
|
}, |
|
|
|
{ |
|
|
|
buildingId: '2', |
|
|
|
descr: '世界大厦B座' |
|
|
|
}, |
|
|
|
{ |
|
|
|
buildingId: '3', |
|
|
|
descr: '其他' |
|
|
|
} |
|
|
|
], // 楼栋列表
|
|
|
|
addressSelectIndex:'', // 当前选择楼栋对应下标, 用下标解决第一个被选中时样式特殊处理
|
|
|
|
addressSelectItem:{}, // 当道选择的楼栋对象
|
|
|
|
addressOne: "", // 第一个地址输入框的值
|
|
|
|
addressTwo: "", // 第二个地址输入框的值
|
|
|
|
addressOneLength: 0, // 第一个地址输入框可输入字符个数
|
|
|
|
focusNumber: 0, // 地址输入框获得焦点时的位置
|
|
|
|
focusIndex: '', // 确定第几个地址输入获得光标 one-第一个, two-第二个
|
|
|
|
unitList: [{ |
|
|
|
buildingId: '1', |
|
|
|
descr: '1单元' |
|
|
|
}, |
|
|
|
{ |
|
|
|
buildingId: '2', |
|
|
|
descr: '2单元' |
|
|
|
}, |
|
|
|
{ |
|
|
|
buildingId: '3', |
|
|
|
descr: '其他' |
|
|
|
} |
|
|
|
], // 楼栋列表
|
|
|
|
addressSelectItem: {}, // 当道选择的楼栋对象
|
|
|
|
unitItem: {}, // 单元号
|
|
|
|
houseNumber: "", // 门牌号
|
|
|
|
}, |
|
|
|
// 更新当前选择的楼栋
|
|
|
|
setAddressItem(e){ |
|
|
|
const index=e.currentTarget.dataset['index']; |
|
|
|
// 更新当前选择的单元
|
|
|
|
setunitItem(e){ |
|
|
|
const index = e.currentTarget.dataset['index']; |
|
|
|
this.setData({ |
|
|
|
addressSelectIndex:index, // 当前选择楼栋对应下标, 用下标解决第一个被选中时样式特殊处理
|
|
|
|
addressSelectItem:this.data.addressList[index], // 当道选择的楼栋对象
|
|
|
|
modalY: 0, // 楼栋选择top值
|
|
|
|
unitItem: this.data.unitList[index], |
|
|
|
unitModalY: 0, // 单元选择top值
|
|
|
|
}) |
|
|
|
}, |
|
|
|
// 更新第一个输入框的值
|
|
|
|
bindKeyAddressOne(e) { |
|
|
|
// 去空格,拼接字符串,拼接做特殊处理,防止字符串拼接错乱
|
|
|
|
const value = (e.detail.value.substring(0, this.data.addressOneLength) + this.data.addressTwo + e.detail.value.substring(this.data.addressOneLength)).replace(/\s/g, ""); |
|
|
|
let focusNumber = 0; |
|
|
|
if (value.substring(this.data.addressOneLength).length) { |
|
|
|
focusNumber = value.substring(this.data.addressOneLength).length |
|
|
|
} |
|
|
|
// 更新当前选择的楼栋
|
|
|
|
setAddressItem(e) { |
|
|
|
const index = e.currentTarget.dataset['index']; |
|
|
|
this.setData({ |
|
|
|
addressOne: value.substring(0, this.data.addressOneLength), |
|
|
|
addressTwo: value.substring(this.data.addressOneLength), |
|
|
|
focusNumber, |
|
|
|
focusIndex: value.substring(0, this.data.addressOneLength).length>=this.data.addressOneLength?'two':'one' |
|
|
|
addressSelectItem: this.data.addressList[index], |
|
|
|
modalY: 0, // 楼栋选择top值
|
|
|
|
}) |
|
|
|
}, |
|
|
|
// 更新第二个输入框的值
|
|
|
|
bindKeyAddressTwo(e) { |
|
|
|
// 去空格,拼接字符串
|
|
|
|
const value = this.data.addressOne + e.detail.value.replace(/\s/g, ""); |
|
|
|
let focusNumber = 0; |
|
|
|
if (e.detail.value.replace(/\s/g, "").length) { |
|
|
|
focusNumber = e.detail.value.replace(/\s/g, "").length |
|
|
|
} else { |
|
|
|
focusNumber = this.data.addressOne.length |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
addressOne: value.substring(0, this.data.addressOneLength), |
|
|
|
addressTwo: value.substring(this.data.addressOneLength), |
|
|
|
focusNumber, |
|
|
|
focusIndex: e.detail.value.replace(/\s/g, "").length?'two':'one' |
|
|
|
}) |
|
|
|
// 更新门牌号的值
|
|
|
|
bindKeyHouseNumber(e) { |
|
|
|
|
|
|
|
}, |
|
|
|
// 获取元素信息
|
|
|
|
showSelectAddress(e) { |
|
|
|
// 获取单元元素信息
|
|
|
|
showSelectUnit(){ |
|
|
|
const _this = this; |
|
|
|
wx.createSelectorQuery().selectAll('#information-address-btn-wrap').boundingClientRect(function (rect) { |
|
|
|
wx.createSelectorQuery().selectAll('#information-unit-btn-wrap').boundingClientRect(function (rect) { |
|
|
|
// console.log(rect[0])
|
|
|
|
// 根据按钮位置计算下拉框top值
|
|
|
|
_this.setData({ |
|
|
|
modalY: _this.data.modalY ? 0 : parseInt(rect[0].top) + parseInt(rect[0].height) |
|
|
|
unitModalY: _this.data.unitModalY ? 0 : parseInt(rect[0].top) + parseInt(rect[0].height), |
|
|
|
modalY:0 |
|
|
|
}) |
|
|
|
}).exec() |
|
|
|
}, |
|
|
|
onLoad() { |
|
|
|
const _this=this; |
|
|
|
// 计算第一个地址输入框可视范围内能输入字符串的个数
|
|
|
|
wx.createSelectorQuery().selectAll('.information-title-input').boundingClientRect(function (rect) { |
|
|
|
// 获取楼栋元素信息
|
|
|
|
showSelectAddress(e) { |
|
|
|
const _this = this; |
|
|
|
wx.createSelectorQuery().selectAll('#information-address-btn-wrap').boundingClientRect(function (rect) { |
|
|
|
// console.log(rect[0])
|
|
|
|
// 根据按钮位置计算下拉框top值
|
|
|
|
_this.setData({ |
|
|
|
addressOneLength: parseInt(rect[0].width/16) |
|
|
|
modalY: _this.data.modalY ? 0 : parseInt(rect[0].top) + parseInt(rect[0].height), |
|
|
|
unitModalY:0 |
|
|
|
}) |
|
|
|
}).exec(); |
|
|
|
}).exec() |
|
|
|
}, |
|
|
|
onLoad() { |
|
|
|
const _this = this; |
|
|
|
// 获取设备的信息
|
|
|
|
let systemInfo = wx.getSystemInfoSync(); |
|
|
|
// 获取信号区高度, 并设置标题高度
|
|
|
|