123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- // pages/child_list/child_list.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
- import { pinyin } from '../../utils/hz2py_full.js'
- import { StudentList, ChangeClass} from '../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
- const { baseImgUrl, thumbnail } = globalData
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- thumbnail,
- statusBar: app.globalData.statusBar,
- isLoaded: false,
- isChild:false,
- searchKey: '',
- checkNum:0,
- isCheck:false,
- pageNo: 1,
- pageSize: 10,
- isAll: false,
- isAllType:2,
- isType:1,
- hiddenModel:false,
- HOT_NAME: '#',
- toView: 'A',
- scrollTop: 10,
- nodata: [
- {
- text: '暂无学生'
- }
- ],
- list: [
- // {
- // "teacherId": "asdasd",
- // "teacherTypeList": ["2", "3"],
- // "subject": "语文,数学",
- // "name": "王的大",
- // "imgUrl": "",
- // "phone": "",
- // "classSum": 10
- // }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var windowHeight = wx.getSystemInfoSync().windowHeight - 170;
- var scrollHeight_ = windowHeight +"px";
- this.setData({scrollHeight_})
- this.setData(options)
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getData();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.setData({ pageNo: 1 })
- this.getData(res => {
- wx.stopPullDownRefresh()
- })
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll} = this.data
- if (isAll) {
- return
- }
- this.getData()
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (app.sharePageDefaultCtl) {
- return app.sharePageDefaultCtl()
- }
- },
- /**
- * 跳转
- */
- navigateCtl:function(e){
- // const { parentVipList } = this.data
- var parentVipList = wx.getStorageSync('parentVipList')
- if (parentVipList.length>0) {
- app.navigateCtl(e);
- } else {
- wx.showToast({
- title: '请勾选孩子后再试',
- icon: 'none'
- })
- }
- },
- /**
- * 底部导航跳转
- */
- redirectCtl: app.redirectCtl,
-
-
- /**
- * 提示框隐藏
- */
- allShowModel: function () {
- this.setData({ hiddenModel: false})
- },
-
-
-
- /**
- * 添加学生更换班级确认
- */
- addStudentShow:function(){
-
- this.setData({ isAdd: true, isAllType: 2, isLoaded: false, pageNo: 1, list: [], searchKey:''})
- this.getData();
- },
- /**
- * 添加学生更换班级确认
- */
- addStudent: function (cb) {
- const continuousFn = { fn: this.addStudent, param: { ...arguments } }
- const { classId, vipIds=[], className}=this.data
- if (vipIds.length == 0) {
- wx.showToast({
- title: '请添加学生',
- icon: 'none'
- })
- return
- }
- ChangeClass({ data: { vipIds, classId}, continuousFn }).then(res => {
- wx.showToast({
- title: '添加学生成功',
- icon: 'none',
- duration:1000
- })
- // redirectTo({ url: 'pages/child_list/child_list', paras: {classId} }, true)
- setTimeout((function callback() {
- wx.navigateBack({
- delta: 1
- })
- }).bind(this), 500);
- if (isFn(cb)) cb()
- }).catch(res => {
- if (isFn(cb)) cb()
- })
- },
-
- /**
- * 选择续费学生
- */
- selectPay:function(){
- this.setData({ isChild: true, isAllType: 1, pageNo: 1, searchKey:''});
- this.getData();
- },
-
- /**
- * 续费搜索学生列表
- */
- payBlurCtl: function () {
- const { searchKey } = this.data
- if (!searchKey) {
- wx.showToast({
- title: '搜索内容不能为空',
- icon: 'none'
- })
- return
- }
- this.setData({ pageNo: 1, isAllType:1 });
- this.getData()
- },
- /**
- * 重新搜索学生列表
- */
- cancel:function(){
- this.setData({ isAllType: 0, isChild: false, pageNo: 1 })
- this.getData();
- },
- /**
- * 保存学生姓名
- */
- inputCtl: function (e) {
- const { value } = e.detail
- const { searchKey } = this.data
- if (searchKey == value) {
- return
- }
- this.setData({ searchKey: value })
- },
- /**
- * 重新搜索学生列表
- */
- blurCtl: function () {
- const { searchKey } = this.data
- this.setData({ pageNo: 1 });
- this.getData()
- },
- /**
- * 选择学生
- */
- selectLiCtl: function (e) {
- const { index,key} = e.currentTarget.dataset
- const { list, isCheck,navIdx,teacherList } = this.data
- list[index]['isCheck'] = list[index].isCheck == '' ? 'active' : '';
- this.setData({ list})
- this.studentCaculate(list)
- },
- /**
- * 计算学生总数和vip列表
- */
- studentCaculate: function (list) {
- let checkNum = 0
- const vipIds = [];
- for (let i in list) {
- if (list[i]['isCheck'] =='active') {
- checkNum++
- vipIds.push(list[i]['vipId'])
- }
- }
- this.setData({ checkNum, vipIds})
- },
- /**
- * 计算教师总数和vip列表
- */
- caculate: function (list) {
- let checkNum = 0
- const vipIds = [];
- const teacherIdList = [];
- for (let i in list) {
- // for (let j in list[i].items){
- if (list[i]['isCheck'] =='active') {
- checkNum++
- vipIds.push(list[i]['vipId'])
- // teacherIdList.push(list[i].items[j]['teacherId'])
- }
- // }
- }
- this.setData({ checkNum, vipIds, teacherIdList})
- },
- /**
- * 获取学生数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { searchKey, isAllType, pageNo, pageSize, list=[], isAdd, classId}=this.data;
- StudentList({ data: { searchKey, type: isAllType,classId,pageNo,pageSize}, continuousFn }).then(res => {
- wx.hideLoading();
- const {isCheck } = this.data;
- const temp = res.data.list;
- const tempList = (res => {
- for (let i in res) {
- res[i]['isCheck'] = ''
- // res[i]['index'] = pinyin.go(res[i].childName).slice(0, 1).toUpperCase()
- if (res[i].childName.length>5){
- res[i].childName = res[i].childName.slice(0, 5)+ '...'
- }else{
- res[i].childName = res[i].childName
- }
- }
- return res
- })(temp || [])
- let arr = []
- if (pageNo == 1) {
- arr = [...tempList]
- } else {
- arr = [...list, ...tempList]
- }
- this.setData({
- list: arr,
- pageNo: tempList.length == pageSize ? Number(pageNo) + 1 : pageNo,
- isAll: tempList.length < pageSize,
- isLoaded: true
- })
- if (isFn(cb)) cb()
- }).catch(res => {
- this.setData({ isLoaded: true })
- if (isFn(cb)) cb()
- })
- }
- })
|