收藏
回答

小程序意外退出,请稍后重试

问题:如题

一个选择学校的页面,注册时和修改资料会跳转到这,部分用户出现“小程序意外退出,请稍后重试”的情况。

代码

wxml

<!--chooseSchool.wxml-->

<wxs src="../../common.wxs" module="common"></wxs>

<view class='container'>

<view class='error-tip' hidden='{{!errorText}}'>{{errorText}}</view>

<!--顶部下拉框tab  -->

<view class="ets-slide-tab flex-wrap">

<view class="tab-item {{nowSlideType==='province'?'active':''}}" bindtap="toggleSlideCon" data-type="province">

<text>{{provinceData[provinceId]?provinceData[provinceId]:'选择省份'}}</text>

<view class="icon"></view>

</view>

<view class="tab-item {{nowSlideType==='city'?'active':''}}" bindtap="toggleSlideCon" data-type="city">

<text>{{cityData[cityId]?cityData[cityId]:'选择市区'}}</text>

<view class="icon"></view>

</view>

<view class="tab-item {{nowSlideType==='area'?'active':''}}" bindtap="toggleSlideCon" data-type="area">

<text>{{areasData[areaId]?areasData[areaId]:'选择地区'}}</text>

<view class="icon"></view>

</view>

</view>

<view class="h100per" wx:if="{{areaId}}">

<!--搜索框  -->

<view class='search-con'>

<view class='float-left search-icon'></view>

<input type='text' value='{{searchKeyWord}}' placeholder='请输入关键字搜索' placeholder-class='placeholder' bindinput='changeSearchKeyWord'></input>

</view>

<!--学校选择区  -->

<scroll-view scroll-y class='school-con'>

<view class="set-items">

<view class='item' hover-class='hover' wx:for="{{schoolData}}" wx:if="{{item.type===high_school}}" wx:key="{{index}}" hidden='{{common.schoolKeyFilter(item.name, searchKeyWord)}}' data-index="{{index}}" data-type="{{item.type}}" catchtap='chooseSchool'>

<view class="float-left {{schoolId==index?'color-lightblue':''}}">{{item.name}}</view>

<view class='float-right no-mr' hidden='{{schoolId!=index}}'>

<view class="set-item-choosed"></view>

</view>

</view>

<view class='item' hover-class='hover' catchtap='goAddSchool'>

<view class="float-left color-lightblue">+ 添加学校</view>

</view>

</view>

</scroll-view>

</view>

<view class="no-task" wx:else>

<view class="white-block">

<image src="{{staticBaseUrl+'/images/teacherend/place-choose-area.png'}}" class="auto-img"></image>

</view>

<view class="center">请选择地区</view>

</view>

<view class="btn-con fix-bot">

<button id="submit" class="gra-btn" hover-class="btn-hover" catchtap="submitSave" disabled='{{addSchoolName===""&&schoolId===0}}'>{{from==='myinfo'?'保存':'确定'}}</button>

</view>

<!--省份选择区  -->

<view class="ets-slide-con {{nowSlideType==='province'?'active':''}}">

<view class="slide-item {{provinceId===index?'color-lightblue':''}}" hover-class="hover" wx:for="{{provinceData}}" wx:key="{{index}}" data-key="{{index}}" bindtap="chooseSlideItem" data-type="province">{{item}}</view>

</view>

<!--市选择区  -->

<view class="ets-slide-con {{nowSlideType==='city'?'active':''}}">

<view class="slide-item {{cityId===index?'color-lightblue':''}}" hover-class="hover" wx:for="{{cityData}}" wx:key="{{index}}" data-key="{{index}}" bindtap="chooseSlideItem" data-type="city">{{item}}</view>

</view>

<!--区域选择区  -->

<view class="ets-slide-con {{nowSlideType==='area'?'active':''}}">

<view class="slide-item {{areaId===index?'color-lightblue':''}}" hover-class="hover" wx:for="{{areasData}}" wx:key="{{index}}" data-key="{{index}}" bindtap="chooseSlideItem" data-type="area">{{item}}</view>

</view>

<view class="mask" hidden='{{maskHidden}}' catchtap='hideSlideCon'></view>  

</view>




js

// chooseSchool.js

var app = getApp();

var BMAP = require('../../utils/bmap-wx.min.js');


Page({

/**

  * 页面的初始数据

  */

data: {

nowSlideType: '',

provinceId: '',

cityId: '',

areaId: '',

schoolId: 0,

maskHidden: true,

searchKeyWord: '',

addSchoolName: '',

errorText: '',

staticBaseUrl: app.globalData.staticBaseUrl,

cityData: {},

areasData: {}

},


/**

  * 生命周期函数--监听页面加载

  */

onLoad: function (options) {

var that = this;

var from = options.from;

var high_school = Number(options.high_school);

wx.showLoading({

title: ' ',

mask: true,

})

this.setData({

from: from,

high_school: high_school

})

if (from === 'myinfo' || from == 'myset') {

var token = wx.getStorageSync('ets_token');

that.setData({

token: token,

})

//调用应用实例的方法获取全局数据

app.getUserInfo(function (userInfo) {

var class_province = userInfo.class_province; // 限制修改的省份

var class_city = userInfo.class_city;   //限制修改的市区

var school_id = '';

if(from == 'myinfo'){

school_id = userInfo.school_id;

high_school = userInfo.high_school;

}

var param = {};

param.high_school = high_school;

param.province_id = userInfo.province_id;

param.city_id = userInfo.city_id;

param.area_id = userInfo.area_id;

param.school_id = school_id;

param.school_name = '';

//更新数据

that.setData({

param: param,

class_province: class_province,

class_city: class_city,

high_school: high_school

})

that.getArea(function (data) {

that.setData({

areaData: data,

provinceData: data[1],

cityData: data[userInfo.province_id],

areasData: data[userInfo.city_id],

provinceId: userInfo.province_id,

cityId: userInfo.city_id,

areaId: userInfo.area_id,

schoolId: school_id

})

that.getSchool(userInfo.area_id)

});

})

}else{

var schoolId = app.globalData.regData ? app.globalData.regData.school_id : '';

var areaId = app.globalData.regData ? app.globalData.regData.area_id : '';

if (areaId){

var provinceId = app.globalData.regData.province_id;

var cityId = app.globalData.regData.city_id;

that.getArea(function (data) {

that.setData({

areaData: data,

provinceData: data[1],

cityData: data[provinceId],

areasData: data[cityId],

provinceId: provinceId,

cityId: cityId,

areaId: areaId,

schoolId: schoolId

})

that.getSchool(areaId)

});

}else{

var Bmap = new BMAP.BMapWX({

ak: '百度地图ak码'

})

Bmap.regeocoding({

fail: function (data) {

that.getArea(function (data) {

that.setData({

areaData: data,

provinceData: data[1],

})

});

wx.hideLoading()

},

success: function (data) {

// console.log(data);

var province = data.originalData.result.addressComponent.province;

var city = data.originalData.result.addressComponent.city;

wx.request({

url: app.globalData.ajaxBaseUrl + '/column/area-id-map?area_search_str=' + province + ',' + city,

header: {

'content-type': 'application/x-www-form-urlencoded'

},

method: 'GET',

dataType: 'json',

success: function (res) {

var data = res.data;

// 获取定位后自动选择地区

that.getArea(function (d) {

var p = data.data.province != 0 ? data.data.province : '';

var c = '', a = '';

var cityData = {}, areasData = {};

if (p) {

cityData = d[p];

if (data.data.city != 0) {

c = data.data.city

} else {

c = d[p] ? Object.keys(d[p])[0] : ''

}

}

if (c) {

a = d[c] ? Object.keys(d[c])[0] : '';

areasData = d[c]

}

// if (a) {

//   that.getSchool(a)

// }

that.setData({

provinceData: d[1],

cityData: cityData,

areasData: areasData,

provinceId: p,

cityId: c || '',

// areaId: a || ''

nowSlideType: 'area',

maskHidden: false

})

});

},

complete: function () {

wx.hideLoading();

}

})

},

})

}

}

},

onShow: function(){

},

// 获取地区

getArea: function (cb) {

var that = this;

wx.request({

url: app.globalData.ajaxBaseUrl + '/column/areas',

data: {

token: that.data.token

},

header: {

'content-type': 'application/x-www-form-urlencoded'

},

method: 'GET',

dataType: 'json',

success: function (res) {

var data = res.data;

app.globalData.etsAreaData = data;

// console.log(data);

cb(data)

}

})

},

// 获取学校

getSchool: function (id) {

var that = this;

wx.showLoading()

wx.request({

url: app.globalData.ajaxBaseUrl + '/column/schools',

data: {

area_id: id,

token: that.data.token

},

header: {

'content-type': 'application/x-www-form-urlencoded'

},

method: 'GET',

dataType: 'json',

success: function (res) {

var data = res.data;

// console.log(data);

that.setData({

schoolData: data

})

},

complete: function(){

wx.hideLoading()

}

})

},

// 下拉框选择

toggleSlideCon: function (event) {

var _type = event.currentTarget.dataset.type;

var maskHidden = false;

if (_type == 'area' && !this.data.cityId) {

wx.showToast({

title: '请先选择市区',

icon: 'none',

duration: 2000,

mask: true,

})

return

}

if (_type === this.data.nowSlideType) {

_type = '';

maskHidden = true;

}

this.setData({

nowSlideType: _type,

maskHidden: maskHidden

})

},

hideSlideCon: function () {

this.setData({

nowSlideType: '',

maskHidden: true

})

},

// 选择省、市、区

chooseSlideItem: function (event) {

var _type = event.currentTarget.dataset.type;

var key = event.currentTarget.dataset.key;

var from = this.data.from;

var that = this;

var areaData = app.globalData.etsAreaData;

if (from == 'myinfo') {

var param = that.data.param;

param.school_id = 0;

param.school_name = '';

}

if (_type === 'province') {

if (from == 'myinfo') {

param.province_id = key;

param.city_id = '';

param.area_id = '';

}

that.setData({

provinceId: key,

cityId: '',

areaId: '',

cityData: areaData[key],

areasData: []

})

} else if (_type === 'city') {

if (from == 'myinfo') {

param.city_id = key;

param.area_id = '';

}

that.setData({

cityId: key,

areaId: '',

areasData: areaData[key]

})

} else if (_type === 'area') {

if (from == 'myinfo') {

param.area_id = key;

}

that.setData({

areaId: key,

})

this.getSchool(key);

}

if (from == 'myinfo') {

that.setData({

param: param

})

}

this.setData({

schoolId: 0,

})

this.hideSlideCon();

},

// 关键字搜索

changeSearchKeyWord: function (event) {

var value = event.detail.value;

this.setData({

searchKeyWord: value

})

},

// 选择学校

chooseSchool: function (event) {

var id = event.currentTarget.dataset.index;

var _type = event.currentTarget.dataset.type;

this.setData({

schoolId: id,

})

},

// 跳转到添加学校

goAddSchool: function () {

var provinceId = this.data.provinceId;

var cityId = this.data.cityId;

var areaId = this.data.areaId;

var allArea = app.globalData.etsAreaData;

if(allArea[cityId]&&!allArea[cityId][areaId]){

areaId = Object.keys(allArea[cityId])[0]

}

var from = this.data.from;

wx.navigateTo({

url: '/pages/addSchool/addSchool?p_id=' + provinceId + '&c_id=' + cityId + '&a_id=' + areaId + '&from=' + from,

})

},

// 跳转到班级选择

submitSave: function () {

var from = this.data.from;

var param = this.data.param;

var high_school = this.data.high_school;

var provinceId = this.data.provinceId;

var cityId = this.data.cityId;

var areaId = this.data.areaId;

var schoolData = this.data.schoolData;

var schoolId = this.data.schoolId;

var schoolName = this.data.addSchoolName;

if (from === 'myinfo' || from == 'myset') {

if (schoolName) {

param.school_name = schoolName;

param.school_id = 0;

} else {

param.school_name = '';

param.school_id = schoolId;

}

this.sendInfo(param);

}  else {

app.globalData.regData.province_id = provinceId;

app.globalData.regData.city_id = cityId;

app.globalData.regData.area_id = areaId;

app.globalData.regData.school_id = schoolId;

app.globalData.regData.school_name = schoolData[schoolId]['name'];

wx.navigateBack({

delta: 1,

})

}

},

// 修改资料request

sendInfo: function (obj) {

var that = this;

var from = this.data.from;

obj.token = this.data.token;

app.changeUserInfo({

scope: that,

prama: obj,

success: function(res){

var data = res.data;

if (data.code === 0) {

app.globalData.myInfoNeedReload = true;

app.globalData.myNeedReload = true;

var delta = 1;

if (from == 'myset'){

delta = 2

}

wx.showToast({

title: '修改成功',

icon: 'none',

duration: 2000,

mask: true,

success: function(res) {

setTimeout(function(){

wx.navigateBack({

delta: delta,

})

}, 2000)

},

})

} else {

var errorText = '';

switch (data.code) {

case 70009:

case 70010:

wx.showModal({

title: '修改学校',

// content: '修改学校之前,需要先在班级管理中转让或删除班级。',

content: '修改学校之前,需要先在班级管理中删除班级。',

showCancel: true,

cancelText: '取消',

cancelColor: '#1CB0F6',

confirmText: '去设置',

confirmColor: '#a4aab3',

success: function (res) {

console.log(res)

if (res.confirm) {

wx.switchTab({

url: '/pages/class/class',

})

}

},

fail: function (res) { },

complete: function (res) { },

})

// errorText = '您选择的学校与您不在同个区域';

break

default:

errorText: data.msg

break

}

if(errorText){

that.setData({

errorText: errorText

})

app.hideTip({

scope: that,

key: 'errorText',

time: 5000,

});

}

}

}

})

},

/**

 * 用户点击右上角分享

 */

onShareAppMessage: function () {

return app.shareOption

},

})


最后一次编辑于  2018-09-30
回答关注问题邀请回答
收藏

1 个回答

  • 🙈
    🙈
    2018-09-30


    好像大部分都是iPhone上出的问题

    2018-09-30
    有用
    回复
登录 后发表内容