index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. const util = require('../../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. id:'',
  6. studentInfo:{
  7. studentId:''
  8. },
  9. info:{},
  10. canBuy:0,
  11. leaderRecom:0,
  12. currentIndex:0,
  13. showCode:false,
  14. headImg:'',
  15. isShare:0
  16. },
  17. onLoad: function (options) {
  18. console.log(options)
  19. if (options) {
  20. if (!util.isEmpty(options.isShare) && options.isShare==1) {
  21. this.setData({
  22. id:options.id,
  23. isShare:options.isShare
  24. })
  25. // this.getChildList()
  26. }else{
  27. this.setData({
  28. id:options.id,
  29. 'studentInfo.studentId':options.studentId,
  30. 'studentInfo.age':options.age,
  31. 'studentInfo.userNickname':app.globalData.userInfo.nickname,
  32. 'studentInfo.childName':options.childName,
  33. 'studentInfo.city':options.city,
  34. 'studentInfo.sex':options.sex,
  35. 'studentInfo.userAvatar':options.userAvatar,
  36. canBuy:options.canBuy,
  37. leaderRecom:options.leaderRecom,
  38. currentIndex:options.currentIndex,
  39. })
  40. }
  41. }
  42. },
  43. onShow:function(){
  44. if (this.data.isShare==1) {
  45. this.getChildList()
  46. }else{
  47. this.getInfo()
  48. }
  49. },
  50. // 获取儿童信息
  51. getChildList() {
  52. var self = this;
  53. util.ajax({
  54. func: "v2/gwcourse/student/list",
  55. }, function (res) {
  56. if(res.code == 0){
  57. if (res.data.length>0) {
  58. self.setData({
  59. 'studentInfo.studentId':res.data[0].id,
  60. 'studentInfo.age':res.data[0].age,
  61. 'studentInfo.userNickname':app.globalData.userInfo.nickname,
  62. 'studentInfo.childName':res.data[0].childName,
  63. 'studentInfo.city':res.data[0].city,
  64. 'studentInfo.sex':res.data[0].sex,
  65. 'studentInfo.userAvatar':res.data[0].userAvatar,
  66. canBuy:1,
  67. // leaderRecom:options.leaderRecom,
  68. // currentIndex:options.currentIndex
  69. })
  70. }else{
  71. self.setData({canBuy:0})
  72. }
  73. }else{
  74. util.showTips(res.reason)
  75. }
  76. self.getInfo()
  77. });
  78. },
  79. // 获取课程详情
  80. getInfo(){
  81. let self = this;
  82. util.ajax({
  83. func: `v2/gwcourse/course/${self.data.id}`,
  84. data:{studentId:self.data.studentInfo.studentId}
  85. }, function (res) {
  86. if (res.code==0) {
  87. self.setData({
  88. info:res.data,
  89. headImg:res.data.qrCode
  90. })
  91. self.getLeaderInfo()
  92. }else{
  93. util.showTips(res.reason)
  94. }
  95. })
  96. },
  97. // 跳转到领队简介页面
  98. jumpToLeaderDemeanor(e){
  99. let self = this;
  100. let teacherInfo = {
  101. uid:this.data.info.teacherUid,
  102. name:this.data.info.teacherName,
  103. city:this.data.info.teacherCity
  104. }
  105. wx.navigateTo({
  106. url: '/pages/account/growthCourse/leaderDemeanor/index?teacherUid='+teacherInfo.uid+'&studentId='+self.data.studentInfo.studentId+"&teacherName="+teacherInfo.name+'&teacherCity='+teacherInfo.city+'&canBuy='+this.data.canBuy+'&childName='+self.data.studentInfo.childName
  107. })
  108. },
  109. // 跳转到待反馈页面
  110. jumpToEvaluate(){
  111. let data = this.data.info;
  112. wx.navigateTo({
  113. url: '/pages/account/growthCourse/courseEvaluate/index?id='+data.id+'&studentId='+this.data.studentInfo.studentId+'&leaderName='+data.teacherName+'&courseTitle='+data.title+'&city='+data.teacherCity,
  114. })
  115. },
  116. // 预约
  117. appointment(){
  118. let self =this;
  119. if (parseInt(self.data.canBuy) ==1) {
  120. if (self.data.info.status==0) {
  121. wx.showModal({
  122. content: `确认为 ${self.data.studentInfo.childName} 小朋友预约这节成长课吗?`,
  123. success (res) {
  124. if (res.confirm) {
  125. self.appoint()
  126. } else if (res.cancel) {
  127. console.log('放弃预约')
  128. }
  129. }
  130. })
  131. } else {
  132. self.appoint()
  133. }
  134. }else {
  135. wx.showModal({
  136. content: '请先为儿童购买成长课,购买成功后即可预约课程。',
  137. success (res) {
  138. if (res.confirm) {
  139. wx.reLaunch({
  140. url: 'url',
  141. })({
  142. url:'/pages/home/index'
  143. })
  144. } else if (res.cancel) {
  145. console.log('用户点击取消')
  146. }
  147. }
  148. })
  149. }
  150. },
  151. // 预约课程接口
  152. appoint(){
  153. let self =this;
  154. util.ajax({
  155. func: `v2/gwcourse/book`,
  156. data:{
  157. studentId:self.data.studentInfo.studentId,
  158. courseId:self.data.info.id,
  159. status:self.data.info.status==0?0:1
  160. }
  161. }, function (res) {
  162. if(res.code == 0){
  163. self.setData({'info.status':self.data.info.status == 0?3:0,})
  164. if (self.data.info.status== 3) {
  165. if (!util.isEmpty(self.data.headImg)) {
  166. self.setData({
  167. methodView:0,
  168. showCode:true,
  169. })
  170. } else {
  171. wx.showModal({
  172. content: '恭喜您预约成功!请耐心等待宝大大联系。',
  173. showCancel:false,
  174. success (res) {
  175. if (res.confirm) {
  176. console.log('用户点击确定')
  177. }
  178. }
  179. })
  180. }
  181. }
  182. self.getInfo()
  183. }else{
  184. util.showTips(res.reason)
  185. }
  186. });
  187. },
  188. closeCode(e){
  189. this.setData({
  190. showCode:e.detail
  191. })
  192. },
  193. // 获取领队信息判断是否可以进入领队风采页面
  194. getLeaderInfo(){
  195. let that=this;
  196. util.ajax({
  197. func:'v2/leader/style/detail',
  198. data:{
  199. uid:that.data.info.teacherUid
  200. }
  201. },function (res) {
  202. if (res.code==0) {
  203. // if (util.isEmpty(res.data.avatar) && util.isEmpty(res.data.intro)) {
  204. // that.setData({
  205. // leaderRecom:0
  206. // })
  207. // }
  208. that.setData({leaderRecom:res.data.leaderRecom})
  209. }
  210. })
  211. },
  212. onShareAppMessage() {
  213. let self =this;
  214. return {
  215. title:'约吧,邀请你家宝贝一起参加成长课!',
  216. path:'/pages/account/growthCourse/courseDetail/index?isShare=1'+'&id='+self.data.id,
  217. imageUrl:'http://img.bbztx.com/image_test/upload/thumbs/20210223/logo/1614076819238032554.jpg'
  218. }
  219. },
  220. })