batch_renew.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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 { RenewStudentList, ClassList,MyInfo2} 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: true,
  18. isChild:false,
  19. searchKey: '',
  20. checkNum:0,
  21. classCheckNum:0,
  22. isCheck:0,
  23. classIsCheck:0,
  24. pageNo: 1,
  25. pageSize: 20,
  26. isAll: false,
  27. isAllType:1,
  28. isType:1,
  29. isAdd:false,
  30. isAddTeacher:false,
  31. hiddenModel:false,
  32. navList: ['学生续费','班级续费'],
  33. navIdx:0,
  34. HOT_NAME: '#',
  35. toView: 'A',
  36. scrollTop: 10,
  37. nodata: [
  38. {
  39. text: '暂无学生续费'
  40. },
  41. {
  42. text: '暂无班级续费'
  43. },
  44. ],
  45. list: []
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. var windowHeight = wx.getSystemInfoSync().windowHeight - 120;
  52. var scrollHeight_ = windowHeight +"px";
  53. this.setData({scrollHeight_})
  54. this.setData(options)
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {
  60. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  61. for (const i in obj) {
  62. this[i] = obj[i]
  63. }
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. this.getDataNumber()
  70. const { navIdx } = this.data;
  71. this.setData({checkNum:0,classCheckNum:0,selectStudentList:[],classIdList:[]})
  72. if (navIdx == 0) {
  73. this.getData();
  74. } else {
  75. this.getClassList()
  76. }
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function () {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. const { navIdx} = this.data
  93. if (navIdx==0){
  94. this.setData({ pageNo: 1 })
  95. this.getData(res => {
  96. wx.stopPullDownRefresh()
  97. })
  98. }
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. const { isAll, pageNo, navIdx, isAddTeacher } = this.data
  105. if (isAll) {
  106. return
  107. }
  108. wx.showLoading({
  109. title: '加载中',
  110. })
  111. if (navIdx==0){
  112. this.getData()
  113. }
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function () {
  119. if (app.sharePageDefaultCtl) {
  120. return app.sharePageDefaultCtl()
  121. }
  122. },
  123. /**
  124. * 跳转
  125. */
  126. navigateCtl:function(e){
  127. const { navIdx,selectStudentList=[],classIdList=[]} = this.data
  128. if(navIdx==0){
  129. if (selectStudentList.length>0) {
  130. app.navigateCtl(e);
  131. } else {
  132. wx.showToast({
  133. title: '请勾选学生后再试',
  134. icon: 'none'
  135. })
  136. }
  137. }else{
  138. if (classIdList.length>0) {
  139. app.navigateCtl(e);
  140. } else {
  141. wx.showToast({
  142. title: '请勾选班级后再试',
  143. icon: 'none'
  144. })
  145. }
  146. }
  147. },
  148. /**
  149. * 底部导航跳转
  150. */
  151. redirectCtl: app.redirectCtl,
  152. /**
  153. * 选择老师
  154. */
  155. selectTeacher:function(e){
  156. const { idx } = e.currentTarget.dataset
  157. const { navIdx } = this.data
  158. this.setData({ pageNo: 1, pageSize: 10, navIdx: idx,checkNum:0,classCheckNum:0})
  159. wx.showLoading({
  160. title: '加载中',
  161. })
  162. if(idx==0){
  163. this.getData()
  164. }else{
  165. this.getClassList()
  166. }
  167. },
  168. /**
  169. * 获取币数
  170. */
  171. getDataNumber: function (cb) {
  172. const continuousFn = { fn: this.getDataNumber, param: { ...arguments } }
  173. var that=this
  174. MyInfo2({ data: {}, continuousFn }).then(res => {
  175. const { libService, platformService, libId} = res.data;
  176. that.setData({ libService, platformService, libId,isLoaded: true})
  177. if (isFn(cb)) cb()
  178. }).catch(res => {
  179. that.setData({ isLoaded: true })
  180. if (isFn(cb)) cb()
  181. })
  182. },
  183. /**
  184. * 选择学生
  185. */
  186. selectLiCtl: function (e) {
  187. const { index,key} = e.currentTarget.dataset
  188. const { list, isCheck,navIdx,classList } = this.data
  189. // console.log(index,classList)
  190. if(navIdx==0){
  191. list[index].items[key]['isCheck'] = list[index].items[key].isCheck == '' ? 'active' : '';
  192. this.setData({ list})
  193. this.caculate(list)
  194. }else{
  195. classList[index]['isCheck'] = classList[index].isCheck == '' ? 'active' : '';
  196. this.setData({ classList})
  197. this.classCaculate(classList)
  198. }
  199. },
  200. /**
  201. * 选择全部学生和班级续费
  202. */
  203. checkAllCtl:function () {
  204. const { list, isCheck,navIdx,classList,classIsCheck} = this.data
  205. const temp = {}
  206. var that=this
  207. if(navIdx==0){
  208. for (let i in list) {
  209. for (let j in list[i].items){
  210. list[i].items[j].isCheck= isCheck != 1 ? 'active' : ''
  211. }
  212. }
  213. that.setData({list})
  214. this.caculate(list)
  215. }else{
  216. for (let i in classList) {
  217. temp[`classList[${i}].isCheck`] = classIsCheck != 1 ? 'active' :''
  218. }
  219. that.setData(temp)
  220. this.classCaculate(classList)
  221. }
  222. },
  223. /**
  224. * 计算学生总数和vip列表
  225. */
  226. caculate: function (list) {
  227. const { studentList=[]}=this.data
  228. let checkNum = 0
  229. const selectStudentList = [];
  230. const vipIdList = [];
  231. for (let i in list) {
  232. for (let j in list[i].items){
  233. if (list[i].items[j]['isCheck'] =='active') {
  234. checkNum++
  235. vipIdList.push(list[i].items[j]['vipId'])
  236. selectStudentList.push(list[i].items[j])
  237. }
  238. }
  239. }
  240. this.setData({ checkNum, vipIdList,selectStudentList,isCheck:studentList.length==selectStudentList.length})
  241. },
  242. /**
  243. * 计算班级总数和vip列表
  244. */
  245. classCaculate: function (list) {
  246. const { classList}=this.data
  247. let classCheckNum = 0
  248. const selectClassList = [];
  249. const classIdList = [];
  250. for (let i in list) {
  251. if (list[i]['isCheck'] =='active') {
  252. classCheckNum++
  253. classIdList.push(classList[i]['classId'])
  254. selectClassList.push(classList[i])
  255. }
  256. }
  257. this.setData({ classCheckNum, selectClassList, classIdList,classIsCheck:classList.length==selectClassList.length})
  258. },
  259. /**
  260. * 获取学生续费数据
  261. */
  262. getData: function (cb) {
  263. const continuousFn = { fn: this.getData, param: { ...arguments } }
  264. const { pageNo, pageSize, list=[],studentList=[], libId}=this.data;
  265. var that=this;
  266. RenewStudentList({ data: { libId, pageNo, pageSize}, continuousFn }).then(res => {
  267. wx.hideLoading();
  268. const {isCheck } = this.data;
  269. const temp = res.data.list;
  270. const tempList = (res => {
  271. for (let i in res) {
  272. res[i]['isCheck'] = ''
  273. res[i]['index'] = pinyin.go(res[i].childName).slice(0, 1).toUpperCase()
  274. if (res[i].childName.length>5){
  275. res[i].childName = res[i].childName.slice(0, 3)+ '...'
  276. }else{
  277. res[i].childName = res[i].childName
  278. }
  279. }
  280. return res
  281. })(temp || [])
  282. let arr = []
  283. if (pageNo == 1) {
  284. arr = [...tempList]
  285. } else {
  286. arr = [...studentList, ...tempList]
  287. }
  288. this.setData({
  289. studentList:arr,
  290. list: that.normalizeSinger(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. /**
  302. * 获取班级续费
  303. */
  304. getClassList: function (cb) {
  305. const continuousFn = { fn: this.getClassList, param: { ...arguments } }
  306. const { list = [],classId } = this.data;
  307. var that=this;
  308. ClassList({ data: {}, continuousFn }).then(res => {
  309. wx.hideLoading();
  310. const { isCheck } = this.data;
  311. const temp = res.data.list;
  312. const tempList = (res => {
  313. for (let i in res) {
  314. res[i]['isCheck'] = ''
  315. }
  316. return res
  317. })(temp || [])
  318. this.setData({
  319. classList:tempList,
  320. isLoaded: true
  321. })
  322. if (isFn(cb)) cb()
  323. }).catch(res => {
  324. this.setData({ isLoaded: true })
  325. if (isFn(cb)) cb()
  326. })
  327. },
  328. /**
  329. * 字母导航
  330. */
  331. normalizeSinger(list) {
  332. let map = {
  333. hot: {
  334. title: this.data.HOT_NAME,
  335. items: []
  336. }
  337. }
  338. list.forEach((item, index) => {
  339. var parent = /^[A-Za-z]+$/;
  340. if (!parent.test(item.index)) {
  341. map.hot.items.push({
  342. childName: item.childName,
  343. className: item.className,
  344. endDate:item.endDate,
  345. grade: item.grade,
  346. imgUrl: item.imgUrl,
  347. serviceType: item.serviceType,
  348. vipId: item.vipId,
  349. isCheck:''
  350. })
  351. }
  352. const key = item.index
  353. if (!map[key]) {
  354. map[key] = {
  355. title: key,
  356. items: []
  357. }
  358. }
  359. map[key].items.push({
  360. childName: item.childName,
  361. className: item.className,
  362. endDate:item.endDate,
  363. grade: item.grade,
  364. imgUrl: item.imgUrl,
  365. serviceType: item.serviceType,
  366. vipId: item.vipId,
  367. isCheck: ''
  368. })
  369. })
  370. // console.log(map)
  371. // 为了得到有序列表,我们需要处理 map
  372. let ret = []
  373. let hot = []
  374. for (let key in map) {
  375. let val = map[key]
  376. if (val.title.match(/[a-zA-Z]/)) {
  377. ret.push(val)
  378. } else if (val.title === this.data.HOT_NAME) {
  379. hot.push(val)
  380. }
  381. }
  382. ret.sort((a, b) => {
  383. return a.title.charCodeAt(0) - b.title.charCodeAt(0)
  384. })
  385. // console.log(hot, ret)
  386. if (hot[0].items.length == 0) {
  387. return ret
  388. } else {
  389. return ret.concat(hot)
  390. }
  391. },
  392. // 点击首字母
  393. scrollToview(e) {
  394. const { id, idx } = e.currentTarget.dataset
  395. console.log(id, idx)
  396. this.setData({ currentIndex: idx, toView: id })
  397. wx.showToast({
  398. title: `${id}`,
  399. icon: 'none',
  400. duration: 500
  401. })
  402. },
  403. // 滚动时触发事件
  404. viewScroll: function (e) {
  405. var newY = e.detail.scrollTop;
  406. // this.scrollY(newY);
  407. },
  408. scrollY(newY) {
  409. const listHeight = this.data.listHeight
  410. // console.log(listHeight)
  411. // 当滚动到顶部,newY>0
  412. if (newY == 0 || newY < 0) {
  413. this.setData({
  414. currentIndex: 0,
  415. })
  416. return
  417. }
  418. // 在中间部分滚动
  419. for (let i = 0; i < listHeight.length - 1; i++) {
  420. // debugger
  421. let height1 = listHeight[i]
  422. let height2 = listHeight[i + 1]
  423. // console.log(listHeight, i)
  424. if (newY >= height1 && newY < height2) {
  425. // console.log(i)
  426. this.setData({
  427. currentIndex: i,
  428. })
  429. return
  430. }
  431. }
  432. // 当滚动到底部,且-newY大于最后一个元素的上限
  433. this.setData({
  434. currentIndex: listHeight.length - 2,
  435. })
  436. },
  437. /**
  438. * 返回孩子信息
  439. */
  440. blockInfo:function(){
  441. const { classId} = this.data
  442. this.redirectCtl({ url: 'main', method: { classId} }, true)
  443. },
  444. calculateHeight() {
  445. var lHeight = [],
  446. that = this;
  447. let height = 0;
  448. lHeight.push(height);
  449. var query = wx.createSelectorQuery();
  450. query.selectAll('.list-group').boundingClientRect(function (rects) {
  451. var rect = rects,
  452. len = rect.length;
  453. for (let i = 0; i < len; i++) {
  454. height += rect[i].height;
  455. lHeight.push(height)
  456. }
  457. }).exec();
  458. var calHeight = setInterval(function () {
  459. if (lHeight != [0]) {
  460. that.setData({
  461. listHeight: lHeight
  462. });
  463. clearInterval(calHeight);
  464. }
  465. }, 1000)
  466. }
  467. })