12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- const app = getApp();
- const api = require('../../api/api');
- import countryCodeData from '../../mocks/countryCode';
- import {
- throttle
- } from '../../utils/util';
- Page({
- data: {
- navbarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '区号列表', //导航栏 中间的标题
- capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
- },
- countryCodeList: [],
- allCode: [],
- intoPosition: '',
- clickIndex: 0,
- topVal: '',
- titleHeight: 0,
- contentHeight: 0,
- height: 0
- },
- onLoad() {
- this.setData({
- height: app.globalData.height
- })
- let newCountryData = countryCodeData.map(item => {
- if (item.data && item.data.length) {
- return {
- ...item
- }
- }
- }).filter(item => item);
- this.setData({
- countryCodeList: newCountryData,
- allCode: newCountryData.map(item => item.key)
- })
- },
- onReady() {
- let totalTop = 0;
- const query = wx.createSelectorQuery()
- query.select('.title').boundingClientRect()
- query.select('.ind_content').boundingClientRect()
- query.selectViewport().scrollOffset()
- query.exec((res) => {
- let titleHeight = res[0].height;
- let contentHeight = res[1].height;
- this.data.countryCodeList.map(item => {
- let height = (item.data.length * contentHeight) + titleHeight;
- item.distance = totalTop;
- totalTop += height;
- return {
- ...item
- }
- })
- this.setData({
- countryCodeList: this.data.countryCodeList
- })
- })
- },
- jumpItemPosition(e) {
- let tip = e.currentTarget.dataset.info;
- let one = tip.split("-")[0];
- let two = tip.split("-")[1];
- this.setData({
- intoPosition: one,
- clickIndex: two,
- topVal: one
- })
- },
- handleScroll: throttle(function (e) {
- for (let i = 0; i < this.data.countryCodeList.length; i++) {
- if (i > 0 && e.detail.scrollTop < this.data.countryCodeList[i].distance) {
- this.setData({
- topVal: this.data.countryCodeList[i - 1].key,
- clickIndex: i - 1,
- })
- return;
- }
- }
- }),
- backInputPhone(e) {
- let code = e.currentTarget.dataset.code;
- let pages = getCurrentPages();
- let prevPage = pages[pages.length - 2]; //上一个页面
- wx.navigateBack({
- delta: 1
- })
- prevPage.setData({
- phoneCode: code
- })
- }
- })
|