add_student.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // pages/child_list/child_list.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { pinyin } from '../../utils/hz2py_full.js'
  4. import { StudentList, ChangeClass} from '../../utils/api.js'
  5. const { navigateTo, redirectTo, navigateBack } = routers()
  6. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  7. const { baseImgUrl, thumbnail } = globalData
  8. const app = getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. baseImgUrl,
  15. thumbnail,
  16. statusBar: app.globalData.statusBar,
  17. isLoaded: false,
  18. isChild:false,
  19. searchKey: '',
  20. checkNum:0,
  21. isCheck:false,
  22. pageNo: 1,
  23. pageSize: 10,
  24. isAll: false,
  25. isAllType:2,
  26. isType:1,
  27. hiddenModel:false,
  28. HOT_NAME: '#',
  29. toView: 'A',
  30. scrollTop: 10,
  31. nodata: [
  32. {
  33. text: '暂无学生'
  34. }
  35. ],
  36. list: [
  37. // {
  38. // "teacherId": "asdasd",
  39. // "teacherTypeList": ["2", "3"],
  40. // "subject": "语文,数学",
  41. // "name": "王的大",
  42. // "imgUrl": "",
  43. // "phone": "",
  44. // "classSum": 10
  45. // }
  46. ]
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. var windowHeight = wx.getSystemInfoSync().windowHeight - 170;
  53. var scrollHeight_ = windowHeight +"px";
  54. this.setData({scrollHeight_})
  55. this.setData(options)
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  62. for (const i in obj) {
  63. this[i] = obj[i]
  64. }
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. this.getData();
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. this.setData({ pageNo: 1 })
  87. this.getData(res => {
  88. wx.stopPullDownRefresh()
  89. })
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom: function () {
  95. const { isAll} = this.data
  96. if (isAll) {
  97. return
  98. }
  99. this.getData()
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage: function () {
  105. if (app.sharePageDefaultCtl) {
  106. return app.sharePageDefaultCtl()
  107. }
  108. },
  109. /**
  110. * 跳转
  111. */
  112. navigateCtl:function(e){
  113. // const { parentVipList } = this.data
  114. var parentVipList = wx.getStorageSync('parentVipList')
  115. if (parentVipList.length>0) {
  116. app.navigateCtl(e);
  117. } else {
  118. wx.showToast({
  119. title: '请勾选孩子后再试',
  120. icon: 'none'
  121. })
  122. }
  123. },
  124. /**
  125. * 底部导航跳转
  126. */
  127. redirectCtl: app.redirectCtl,
  128. /**
  129. * 提示框隐藏
  130. */
  131. allShowModel: function () {
  132. this.setData({ hiddenModel: false})
  133. },
  134. /**
  135. * 添加学生更换班级确认
  136. */
  137. addStudentShow:function(){
  138. this.setData({ isAdd: true, isAllType: 2, isLoaded: false, pageNo: 1, list: [], searchKey:''})
  139. this.getData();
  140. },
  141. /**
  142. * 添加学生更换班级确认
  143. */
  144. addStudent: function (cb) {
  145. const continuousFn = { fn: this.addStudent, param: { ...arguments } }
  146. const { classId, vipIds=[], className}=this.data
  147. if (vipIds.length == 0) {
  148. wx.showToast({
  149. title: '请添加学生',
  150. icon: 'none'
  151. })
  152. return
  153. }
  154. ChangeClass({ data: { vipIds, classId}, continuousFn }).then(res => {
  155. wx.showToast({
  156. title: '添加学生成功',
  157. icon: 'none',
  158. duration:1000
  159. })
  160. // redirectTo({ url: 'pages/child_list/child_list', paras: {classId} }, true)
  161. setTimeout((function callback() {
  162. wx.navigateBack({
  163. delta: 1
  164. })
  165. }).bind(this), 500);
  166. if (isFn(cb)) cb()
  167. }).catch(res => {
  168. if (isFn(cb)) cb()
  169. })
  170. },
  171. /**
  172. * 选择续费学生
  173. */
  174. selectPay:function(){
  175. this.setData({ isChild: true, isAllType: 1, pageNo: 1, searchKey:''});
  176. this.getData();
  177. },
  178. /**
  179. * 续费搜索学生列表
  180. */
  181. payBlurCtl: function () {
  182. const { searchKey } = this.data
  183. if (!searchKey) {
  184. wx.showToast({
  185. title: '搜索内容不能为空',
  186. icon: 'none'
  187. })
  188. return
  189. }
  190. this.setData({ pageNo: 1, isAllType:1 });
  191. this.getData()
  192. },
  193. /**
  194. * 重新搜索学生列表
  195. */
  196. cancel:function(){
  197. this.setData({ isAllType: 0, isChild: false, pageNo: 1 })
  198. this.getData();
  199. },
  200. /**
  201. * 保存学生姓名
  202. */
  203. inputCtl: function (e) {
  204. const { value } = e.detail
  205. const { searchKey } = this.data
  206. if (searchKey == value) {
  207. return
  208. }
  209. this.setData({ searchKey: value })
  210. },
  211. /**
  212. * 重新搜索学生列表
  213. */
  214. blurCtl: function () {
  215. const { searchKey } = this.data
  216. this.setData({ pageNo: 1 });
  217. this.getData()
  218. },
  219. /**
  220. * 选择学生
  221. */
  222. selectLiCtl: function (e) {
  223. const { index,key} = e.currentTarget.dataset
  224. const { list, isCheck,navIdx,teacherList } = this.data
  225. list[index]['isCheck'] = list[index].isCheck == '' ? 'active' : '';
  226. this.setData({ list})
  227. this.studentCaculate(list)
  228. },
  229. /**
  230. * 计算学生总数和vip列表
  231. */
  232. studentCaculate: function (list) {
  233. let checkNum = 0
  234. const vipIds = [];
  235. for (let i in list) {
  236. if (list[i]['isCheck'] =='active') {
  237. checkNum++
  238. vipIds.push(list[i]['vipId'])
  239. }
  240. }
  241. this.setData({ checkNum, vipIds})
  242. },
  243. /**
  244. * 计算教师总数和vip列表
  245. */
  246. caculate: function (list) {
  247. let checkNum = 0
  248. const vipIds = [];
  249. const teacherIdList = [];
  250. for (let i in list) {
  251. // for (let j in list[i].items){
  252. if (list[i]['isCheck'] =='active') {
  253. checkNum++
  254. vipIds.push(list[i]['vipId'])
  255. // teacherIdList.push(list[i].items[j]['teacherId'])
  256. }
  257. // }
  258. }
  259. this.setData({ checkNum, vipIds, teacherIdList})
  260. },
  261. /**
  262. * 获取学生数据
  263. */
  264. getData: function (cb) {
  265. const continuousFn = { fn: this.getData, param: { ...arguments } }
  266. const { searchKey, isAllType, pageNo, pageSize, list=[], isAdd, classId}=this.data;
  267. StudentList({ data: { searchKey, type: isAllType,classId,pageNo,pageSize}, continuousFn }).then(res => {
  268. wx.hideLoading();
  269. const {isCheck } = this.data;
  270. const temp = res.data.list;
  271. const tempList = (res => {
  272. for (let i in res) {
  273. res[i]['isCheck'] = ''
  274. // res[i]['index'] = pinyin.go(res[i].childName).slice(0, 1).toUpperCase()
  275. if (res[i].childName.length>5){
  276. res[i].childName = res[i].childName.slice(0, 5)+ '...'
  277. }else{
  278. res[i].childName = res[i].childName
  279. }
  280. }
  281. return res
  282. })(temp || [])
  283. let arr = []
  284. if (pageNo == 1) {
  285. arr = [...tempList]
  286. } else {
  287. arr = [...list, ...tempList]
  288. }
  289. this.setData({
  290. list: arr,
  291. pageNo: tempList.length == pageSize ? Number(pageNo) + 1 : pageNo,
  292. isAll: tempList.length < pageSize,
  293. isLoaded: true
  294. })
  295. if (isFn(cb)) cb()
  296. }).catch(res => {
  297. this.setData({ isLoaded: true })
  298. if (isFn(cb)) cb()
  299. })
  300. }
  301. })