student.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // pages/student/student.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. height: 0,
  11. animation: {},
  12. left: 750,
  13. inviteConfig: {},
  14. count: 0,
  15. enroll: 0,
  16. coin: '0',
  17. invitations: []
  18. },
  19. closeCamera: function () {
  20. this.animation = wx.createAnimation({
  21. timingFunction: 'linear',
  22. duration: 400
  23. })
  24. const left = 750
  25. this.animation.translateX(left).step()
  26. this.setData({
  27. animation: this.animation.export()
  28. })
  29. },
  30. showCamaer: function () {
  31. this.animation = wx.createAnimation({
  32. timingFunction: 'linear',
  33. duration: 100
  34. })
  35. const left = 0
  36. this.animation.translateX(left).step()
  37. this.setData({
  38. animation: this.animation.export(),
  39. left
  40. })
  41. },
  42. scanCode: function (e) {
  43. console.log(JSON.stringify(e))
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. wx.getSystemInfo({
  50. success: (result) => {
  51. this.setData({
  52. height: result.windowHeight
  53. })
  54. },
  55. })
  56. this.queryInvitation(null);
  57. let t = this;
  58. setTimeout(() => {
  59. t.doSearch();
  60. }, 1000);
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. },
  97. queryInvitation: function (methodName) {
  98. let urls = urlDef.urls
  99. let stu = wx.getStorageSync('student');
  100. let inviteConfig = {}
  101. util.apiPost(urls.get_activity_share + '&q.orgId=' + stu.orgId).then((rs) => {
  102. if (rs && rs.length > 0) {
  103. let r = rs[0];
  104. inviteConfig.title = (r.name ? r.name : '邀请有礼');
  105. inviteConfig.description = (r.remark ? r.remark : '邀请新学员,赢得奖励');
  106. inviteConfig.imageUrl = r.imgUrl;
  107. if (r.activityUrl && r.activityUrl.length > 0) {
  108. inviteConfig.url = r.activityUrl + (r.activityUrl.indexOf('?') === -1 ? '?' : '&') + 'studentId=' + stu.studentId + '&orgId=' + stu.orgId;
  109. }
  110. this.setData({ inviteConfig: inviteConfig })
  111. if ('billShare' === methodName) {
  112. this.billShare();
  113. }
  114. if ('share' === methodName) {
  115. this.share();
  116. }
  117. if ('codeInvite' === methodName) {
  118. this.codeInvite();
  119. }
  120. }
  121. });
  122. },
  123. doSearch: function () {
  124. let urls = urlDef.urls
  125. let stu = wx.getStorageSync('student');
  126. util.apiPost(urls.get_invitation_count + '&q.introducer=' + stu.studentId).then(rs => {
  127. if (rs) {
  128. this.setData({ count: rs.num })
  129. }
  130. });
  131. util.apiPost(urls.get_invitation_enroll + '&q.introducer=' + stu.studentId).then(rs => {
  132. if (rs) {
  133. this.setData({ enroll: rs.num })
  134. }
  135. });
  136. util.apiPost(urls.get_invitation_coin + '&q.introducer=' + stu.studentId).then(rs => {
  137. if (rs && rs.length > 0) {
  138. let i = 0;
  139. let coin = ''
  140. rs.forEach(r => {
  141. coin += (r.amount + '<view class=\'unit\'>' + (r.type === 1 ? '元' : '课时') + '</view>');
  142. if (i < rs.length - 1) {
  143. coin += '<view class=\'sl\'>/</view>';
  144. }
  145. i++;
  146. });
  147. this.setData({ coin: coin })
  148. }
  149. });
  150. util.apiPost(urls.query_invitation_list + '&q.introducer=' + stu.studentId).then(rs => {
  151. if (rs) {
  152. rs.map(o => {
  153. o.name = o.studentName ? o.studentName : o.clientName
  154. o.statusText = this.getStatus(o)
  155. o.face = this.getHead(o)
  156. })
  157. this.setData({ invitations: rs })
  158. }
  159. });
  160. },
  161. getHead(item) {
  162. let urls = urlDef.urls
  163. return item.imageUrl ? urls.oss_file + 'image/' + item.imageUrl : '/images/head.png';
  164. },
  165. getStatus(item) {
  166. if (item.orderCount > 0) { // 有已付款的订单
  167. return '已报名';
  168. } else {
  169. if (item.isAudition === 0) { // 未试听
  170. return '已注册';
  171. }
  172. return '已试听';
  173. }
  174. },
  175. billShare: function () {
  176. if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
  177. console.log('弹出海报分享页面')
  178. // this.modal = this.modalCtrl.create('BillSharePage', { item: this.inviteConfig });
  179. // this.modal.present();
  180. } else {
  181. this.queryInvitation('billShare');
  182. }
  183. },
  184. share: function () {
  185. if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
  186. // this.modal = this.modalCtrl.create('SharePage', { item: this.inviteConfig });
  187. // this.modal.present();
  188. console.log('弹出享页面')
  189. } else {
  190. this.queryInvitation('share');
  191. }
  192. },
  193. codeInvite: function () {
  194. let urls = urlDef.urls
  195. if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
  196. let regUrl = this.data.inviteConfig.url;
  197. let imgUrl = urls.get_qr_code + '?content=' + encodeURIComponent(regUrl);
  198. this.openModal(imgUrl);
  199. } else {
  200. this.queryInvitation('codeInvite');
  201. }
  202. },
  203. openModal: function (imgUrl) {
  204. // 弹出页面
  205. console.log('...' + imgUrl)
  206. }
  207. })