index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. const util = require("../../../utils/util");
  2. const app = getApp();
  3. Page({
  4. data: {
  5. userInfo:{
  6. id:'',
  7. name:'',
  8. userAvatar:'',
  9. childName:'',
  10. age:0,
  11. city:'',
  12. sex:0,
  13. curriculum:{}
  14. },
  15. scroll:true, //用于滚动条参数
  16. showBack:false,
  17. fixTop:false,
  18. currentIndex:1,
  19. fieldIndex:1,
  20. content:'',
  21. leaderid:0, //领队默认选中
  22. SevenDaysDate:[],
  23. showDatePopup:false,
  24. showChildPopup:false,
  25. showCode:false,
  26. headImg:'',
  27. list:[],
  28. pageIndex:1,
  29. cardPageIndex:1,
  30. scrollLeft:'0',
  31. searchText:'',
  32. completedate:'',
  33. cardList:[],
  34. canBuy:0,//是否可购买成长课
  35. methodView:0,//二维码弹窗显示文案
  36. allLeader:[
  37. {
  38. uid:0,
  39. avatar:'https://img.bbztx.com/image/upload/20230105/leader.png',
  40. leaderCity:'',
  41. nickname:'全部'
  42. },
  43. ],
  44. leaderList:[],
  45. },
  46. onLoad: function (options) {
  47. // this.getList()
  48. // this.getSevenDays()
  49. },
  50. onShow:function(){
  51. this.setData({cardPageIndex:1})
  52. this.getList()
  53. // this.getCardList();
  54. // this.bindSearch(2)
  55. },
  56. setTabbar(e){
  57. let i = e.currentTarget.dataset.index;
  58. this.setData({
  59. currentIndex:i,
  60. cardList:[],
  61. cardPageIndex:1
  62. })
  63. this.getCardList();
  64. },
  65. calendarClose(e){
  66. this.setData({
  67. showDatePopup:e.detail
  68. })
  69. },
  70. personnelClose(e){
  71. this.setData({
  72. showChildPopup:e.detail
  73. })
  74. },
  75. closeCode(e){
  76. this.setData({
  77. showCode:e.detail
  78. })
  79. },
  80. // 选择领域
  81. fieldSelect(e){
  82. let data = e.currentTarget.dataset;
  83. this.setData({
  84. fieldIndex:data.index,
  85. content:data.content == '全部'?'':data.content,
  86. cardPageIndex:1
  87. })
  88. this.getCardList()
  89. },
  90. // 获取人员名单
  91. getList() {
  92. var self = this;
  93. util.ajax({
  94. func: "v2/gwcourse/student/list",
  95. }, function (res) {
  96. if(res.code == 0){
  97. if (res.data.length >0) {
  98. let arr =res.data;
  99. arr.forEach((el,i) => {
  100. el.checked =i==0?true:false;
  101. });
  102. if (util.isEmpty(self.data.userInfo.id)) {
  103. self.setData({
  104. list:arr,
  105. canBuy:arr.length>0?1:0,
  106. 'userInfo.childName':res.data[0].childName,
  107. 'userInfo.userAvatar':res.data[0].userAvatar,
  108. 'userInfo.id':res.data[0].id,
  109. 'userInfo.age':res.data[0].age,
  110. 'userInfo.city':res.data[0].city,
  111. 'userInfo.sex':res.data[0].sex,
  112. });
  113. self.getCurriculumTotal(res.data[0].id)
  114. }
  115. }
  116. }else{
  117. util.showTips(res.reason)
  118. }
  119. self.bindSearch(2)
  120. self.getCardList()
  121. self.getSevenDays()
  122. });
  123. },
  124. // 获取儿童信息
  125. getChildInfo(e){
  126. if (e.detail.id) {
  127. this.getCurriculumTotal(e.detail.id)
  128. }
  129. this.setData({
  130. showChildPopup:false,
  131. 'userInfo.childName':e.detail.childName,
  132. 'userInfo.id':e.detail.id,
  133. 'userInfo.age':e.detail.age,
  134. 'userInfo.city':e.detail.city,
  135. 'userInfo.sex':e.detail.sex,
  136. 'userInfo.userAvatar':e.detail.userAvatar,
  137. completedate:'',
  138. leaderid:0,
  139. currentIndex:'1',
  140. cardPageIndex:1,
  141. cardList:[]
  142. })
  143. // this.getCardList()
  144. this.bindSearch(2)
  145. },
  146. // 获取弹窗选中的日期
  147. getCalendarInfo(e){
  148. this.setData({
  149. showDatePopup:false,
  150. dateActived:e.detail,
  151. completedate:e.detail,
  152. cardList:[]
  153. })
  154. this.getCardList();
  155. },
  156. // 通过儿童信息获取课程信息
  157. getCurriculumTotal(id){
  158. var self = this;
  159. // let studentId = id;
  160. util.ajax({
  161. func: `v2/gwcourse/student/statinfo`,
  162. data:{studentId:id}
  163. }, function (res) {
  164. if(res.code == 0){
  165. self.setData({'userInfo.curriculum':res.data})
  166. }else{
  167. util.showTips(res.reason)
  168. }
  169. });
  170. },
  171. // 选择领队
  172. selectLeader(e){
  173. let uid = e.currentTarget.dataset.uid;
  174. if (this.data.leaderid != uid) {
  175. this.setData({
  176. leaderid:uid,
  177. cardPageIndex:1,
  178. })
  179. this.getCardList();
  180. }
  181. },
  182. // 选择日期
  183. selectDate(e){
  184. let data = e.currentTarget.dataset;
  185. this.setData({
  186. dateActived:data.completedate,
  187. completedate:data.completedate,
  188. cardList:[],
  189. cardPageIndex:1
  190. })
  191. this.getCardList();
  192. },
  193. // 搜索输入框
  194. bindinput(e){
  195. this.setData({searchText:e.detail.value})
  196. if (e.detail.value == '') {
  197. // this.setData({leaderid:0})
  198. // this.getCardList();
  199. this.bindSearch(2)
  200. }
  201. },
  202. bindSearch(bol){
  203. var self = this;
  204. let index = bol==1 ? self.data.pageIndex:1;
  205. let data ={
  206. nickname:self.data.searchText,
  207. pageIndex:index,
  208. }
  209. if (!util.isEmpty(self.data.userInfo.id)) {
  210. data.studentId=self.data.userInfo.id
  211. }
  212. util.ajax({
  213. func: `v2/gwcourse/teacher/list`,
  214. data:data
  215. }, function (res) {
  216. if(res.code == 0){
  217. if (res.data.list&&res.data.list.length>0) {
  218. let arr =bol==1?self.data.leaderList.concat(res.data.list):self.data.allLeader.concat(res.data.list);
  219. self.setData({
  220. leaderList:arr,
  221. leaderid:(bol==2 || (self.data.searchText==''&& bol!=1))?0: bol==1? self.data.leaderid: res.data.list[0].uid
  222. })
  223. if (bol!=1) {
  224. self.getCardList();
  225. self.setData({scrollLeft:0})
  226. }
  227. }else{
  228. let arr =bol==1?self.data.leaderList:self.data.allLeader;
  229. self.setData({leaderList:arr})
  230. if (bol!=1) {
  231. self.setData({scrollLeft:0})
  232. }
  233. }
  234. }else{
  235. util.showTips(res.reason)
  236. }
  237. });
  238. },
  239. // 获取卡片列表信息
  240. getCardList(bol){
  241. let self = this,data={};
  242. if (self.data.currentIndex==1) {
  243. data.date = '';
  244. data.field = '';
  245. data.leaderUid=self.data.leaderid==0?'':self.data.leaderid;
  246. } else if (self.data.currentIndex==2) {
  247. data.leaderUid = '';
  248. data.date = self.data.dateActived;
  249. } else if (self.data.currentIndex==3){
  250. data.leaderUid = '';
  251. data.date = '';
  252. data.field = '';
  253. } else{
  254. data.leaderUid = '';
  255. data.date = '';
  256. data.field = self.data.content;
  257. }
  258. data.studentId= self.data.userInfo.id;
  259. data.book=self.data.currentIndex=='3'?1:0;
  260. data.pageIndex=self.data.cardPageIndex;
  261. util.ajax({
  262. func: `v2/gwcourse/list`,
  263. data:data
  264. }, function (res) {
  265. if(res.code == 0){
  266. if (res.data.list&&res.data.list.length>0) {
  267. let arr = self.data.cardList.concat(res.data.list)
  268. self.setData({cardList:bol==1?arr:res.data.list})
  269. }else{
  270. self.setData({cardList:bol==1?self.data.cardList:[]})
  271. }
  272. }else{
  273. util.showTips(res.reason)
  274. }
  275. });
  276. },
  277. // 跳转到课程详情页
  278. jumpToDetail(e){
  279. let data = e.currentTarget.dataset
  280. let info = this.data.userInfo
  281. wx.navigateTo({
  282. url: '/pages/account/growthCourse/courseDetail/index?id='+data.id+'&studentId='+info.id+'&childName='+info.childName+'&age='+info.age+'&city='+info.city+'&sex='+info.sex+'&userAvatar='+info.userAvatar+'&canBuy='+this.data.canBuy+'&leaderRecom='+data.leaderrecom+'&currentIndex='+this.data.currentIndex
  283. })
  284. },
  285. // 立即购买
  286. jumpToHome(bol){
  287. wx.reLaunch({
  288. url:'/pages/home/index'
  289. })
  290. },
  291. // 跳转到待反馈页面
  292. jumpToEvaluate(e){
  293. let data = e.currentTarget.dataset;
  294. wx.navigateTo({
  295. url: '/pages/account/growthCourse/courseEvaluate/index?id='+data.id+'&studentId='+this.data.userInfo.id+'&leaderName='+data.leadername+'&courseTitle='+data.coursetitle+'&city='+data.city,
  296. })
  297. },
  298. // 预约
  299. appointment(e){
  300. let data = e.currentTarget.dataset;
  301. let self =this;
  302. if (self.data.list.length>0) {
  303. if (data.status==0) {
  304. wx.showModal({
  305. content: `确认为 ${self.data.userInfo.childName} 小朋友预约这节成长课吗?`,
  306. success (res) {
  307. if (res.confirm) {
  308. self.appoint(data)
  309. } else if (res.cancel) {
  310. console.log('放弃预约')
  311. }
  312. }
  313. })
  314. }else{
  315. self.appoint(data)
  316. }
  317. }else {
  318. wx.showModal({
  319. content: '请先为儿童购买成长课,购买成功后即可预约课程。',
  320. success (res) {
  321. if (res.confirm) {
  322. wx.reLaunch({
  323. url: '/pages/home/index'
  324. })
  325. } else if (res.cancel) {
  326. console.log('用户点击取消')
  327. }
  328. }
  329. })
  330. }
  331. },
  332. // 无儿童信息的提示
  333. tip(){
  334. wx.showModal({
  335. content: '请先为儿童购买成长课,购买成功后预约课程即可在此查看记录。',
  336. confirmText:'前往购买',
  337. success (res) {
  338. if (res.confirm) {
  339. wx.reLaunch({
  340. url: '/pages/home/index'
  341. })
  342. } else if (res.cancel) {
  343. console.log('用户点击取消')
  344. }
  345. }
  346. })
  347. },
  348. // 预约课程接口
  349. appoint(data){
  350. let self = this;
  351. util.ajax({
  352. func: `v2/gwcourse/book`,
  353. data:{
  354. studentId:self.data.userInfo.id,
  355. courseId:data.item.id,
  356. status:data.status
  357. }
  358. }, function (res) {
  359. if(res.code == 0){
  360. self.data.cardList.forEach((el,i) => {
  361. if (el.id == data.item.id) {
  362. let STASTUS = 'cardList['+i+'].status';
  363. let STU = 'cardList['+i+'].students';
  364. let num='userInfo.curriculum.courseReservedNum',num1= 'userInfo.curriculum.courseActnum';
  365. if (data.status == 0) {
  366. let arr = {
  367. id:self.data.userInfo.id,
  368. userAvatar:self.data.userInfo.userAvatar
  369. };
  370. self.data.cardList[i].students.push(arr)
  371. self.setData({
  372. [STASTUS]:3,
  373. [STU]:self.data.cardList[i].students,
  374. [num]:self.data.userInfo.curriculum.courseReservedNum+1,
  375. [num1]:self.data.userInfo.curriculum.courseActnum-1
  376. })
  377. } else {
  378. self.data.cardList[i].students.forEach((el,index) => {
  379. if (el.id == self.data.userInfo.id) {
  380. self.data.cardList[i].students.splice(index,1)
  381. }
  382. });
  383. self.setData({
  384. [STASTUS]:0,
  385. [STU]:self.data.cardList[i].students,
  386. [num]:self.data.userInfo.curriculum.courseReservedNum-1,
  387. [num1]:self.data.userInfo.curriculum.courseActnum+1
  388. })
  389. }
  390. if (data.status== 0) {
  391. if (!util.isEmpty(data.item.qrCode)) {
  392. self.setData({
  393. showCode:true,
  394. headImg:data.item.qrCode,
  395. methodView:0
  396. })
  397. } else {
  398. wx.showModal({
  399. content: '恭喜您预约成功!请耐心等待宝大大联系。',
  400. showCancel:false,
  401. success (res) {
  402. if (res.confirm) {
  403. console.log('用户点击确定')
  404. }
  405. }
  406. })
  407. }
  408. }
  409. }
  410. });
  411. }else{
  412. util.showTips(res.reason)
  413. }
  414. });
  415. },
  416. // 进群上课
  417. groupCodeView(e){
  418. let data = e.currentTarget.dataset.item;
  419. if (!util.isEmpty(data.qrCode)) {
  420. this.setData({
  421. showCode:true,
  422. headImg:data.qrCode,
  423. methodView:1
  424. })
  425. } else {
  426. wx.showModal({
  427. content: '您已预约!请耐心等待宝大大联系。',
  428. showCancel:false,
  429. success (res) {
  430. if (res.confirm) {
  431. console.log('用户点击确定')
  432. }
  433. }
  434. })
  435. }
  436. },
  437. // 横向滑动滚动条
  438. pageLoad(){
  439. this.data.pageIndex++;
  440. this.setData({pageIndex:this.data.pageIndex})
  441. this.bindSearch(1)
  442. },
  443. // 下拉懒加载
  444. cardListLoad(){
  445. this.data.cardPageIndex++;
  446. this.setData({cardPageIndex:this.data.cardPageIndex});
  447. this.getCardList(1);
  448. },
  449. // 打开日历弹窗
  450. getDatepopup(){
  451. this.setData({showDatePopup:true})
  452. },
  453. // 获取当前时间后七天
  454. getSevenDays(){
  455. let date = new Date(),timeNow=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate(),arr=[];
  456. for (let index = 0; index < 7; index++) {
  457. var NewDate = new Date(date);
  458. NewDate.setDate(date.getDate()+index);
  459. var time = NewDate.getFullYear()+"-"+this.changeDate(NewDate.getMonth()+1)+"-"+this.changeDate(NewDate.getDate());
  460. let date1 = (NewDate.getMonth()+1)+"."+NewDate.getDate(),week = "日一二三四五六".charAt(new Date(time).getDay());
  461. let dateInfo = {
  462. date:date1,
  463. week:week,
  464. completeDate:time,
  465. num:0
  466. }
  467. if (index==0) {
  468. this.setData({
  469. dateActived:time
  470. })
  471. }
  472. arr.push(dateInfo);
  473. }
  474. this.getDateActivited(arr).then(res=>{
  475. if (res && res.length>0) {
  476. arr.forEach((el,i) => {
  477. res.forEach(item => {
  478. if (el.completeDate == item.date) {
  479. el.num = item.num
  480. }
  481. });
  482. });
  483. }
  484. this.setData({
  485. SevenDaysDate:arr
  486. })
  487. })
  488. },
  489. // 获取每日活动详情
  490. getDateActivited(date){
  491. return new Promise(function (resolve, reject) {
  492. util.ajax({
  493. func: "v2/gwcourse/schedule",
  494. data: { "startDate": date[0].completeDate, "endDate": date[date.length-1].completeDate}
  495. }, function (res) {
  496. if (res.code == 0) {
  497. resolve(res.data)
  498. }else{
  499. // reject()
  500. util.showTips(res.reason);
  501. }
  502. })
  503. }
  504. )
  505. },
  506. // 日期转换
  507. changeDate(date){
  508. let str = date>=10?date:'0'+date;
  509. return str;
  510. },
  511. selectChilds(){
  512. this.setData({showChildPopup:true})
  513. },
  514. // 页面上拉触底事件的处理函数
  515. onReachBottom: function () {
  516. this.cardListLoad();
  517. },
  518. toTop() {
  519. wx.pageScrollTo({
  520. scrollTop: 0,
  521. duration: 300
  522. })
  523. },
  524. onPageScroll(e) {
  525. let query = wx.createSelectorQuery(),self =this;
  526. query.select('.content').boundingClientRect();
  527. query.select('.tabSelect').boundingClientRect();
  528. query.exec(function (res) {
  529. self.setData({showBack :res[0].top<=0 ? true:false})
  530. // self.setData({fixTop:res[1].top<=0 ? (res[0].top<=0?true:false): false})
  531. self.setData({fixTop:res[0].top<0 ? true: false})
  532. })
  533. },
  534. onShareAppMessage() {
  535. return {
  536. title:'让爱和快乐延续,小黄人成长课在线等你来约!',
  537. path:'/pages/account/growthCourse/index',
  538. imageUrl:'http://img.bbztx.com/image_test/upload/thumbs/20210223/logo/1614076819238032554.jpg'
  539. }
  540. },
  541. })