student.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. shareImg: 'https://app.schoolwisdoms.com/static/app/student/imgs/share-bill.png',
  14. inviteConfig: {},
  15. count: 0,
  16. enroll: 0,
  17. coin: '0',
  18. invitations: [],
  19. showShareImg: false,
  20. showCodeImg: false,
  21. posterConfig: {
  22. 'width': 700,
  23. 'height': 900,
  24. 'backgroundColor': '#fff',
  25. 'debug': false,
  26. 'preload': true,
  27. 'hide-loading': true,
  28. images: [{
  29. x: 0,
  30. y: 0,
  31. url: 'https://app.schoolwisdoms.com/static/app/student/imgs/share-bill.png',
  32. width: 700,
  33. height: 900
  34. }, {
  35. x: 250,
  36. y: 640,
  37. url: 'https://app.schoolwisdoms.com/static/app/student/imgs/share-bill.png',
  38. width: 200,
  39. height: 200
  40. }],
  41. },
  42. qrCodeImg: '',
  43. sid: null,
  44. oid: null,
  45. },
  46. onPosterSuccess(e) {
  47. let that = this;
  48. let {
  49. detail
  50. } = e;
  51. wx.saveImageToPhotosAlbum({
  52. filePath: detail,
  53. success(res) {
  54. wx.showToast({
  55. title: '图片已保存到本地相册',
  56. icon: 'none'
  57. })
  58. that.setData({
  59. showShareImg: false
  60. })
  61. that.triggerEvent("callMethod")
  62. }, fail(res) {
  63. console.log(res)
  64. that.getSetting()
  65. }
  66. })
  67. },
  68. getSetting: function () {
  69. // 相册授权
  70. wx.getSetting({
  71. success(res) {
  72. // 进行授权检测,未授权则进行弹层授权
  73. if (!res.authSetting["scope.writePhotosAlbum"]) {
  74. wx.showModal({
  75. title: '提示',
  76. content: '您未授权相册使用权限,是否重新授权?',
  77. success: function (res) {
  78. if (res.confirm) {
  79. wx.openSetting({
  80. success(settingdata) {
  81. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  82. console.log("获取权限成功,再次点击图片保存到相册")
  83. } else {
  84. console.log("获取权限失败")
  85. }
  86. }, fail(res) {
  87. console.log(res)
  88. }
  89. })
  90. }
  91. }
  92. })
  93. }
  94. },
  95. fail(res) {
  96. console.log(res);
  97. }
  98. });
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options) {
  104. if (options.sid && options.oid) {
  105. this.setData({ sid: options.sid, oid: options.oid })
  106. } else {
  107. let stu = wx.getStorageSync('student');
  108. this.setData({ sid: stu.studentId, oid: stu.orgId })
  109. }
  110. wx.getSystemInfo({
  111. success: (result) => {
  112. this.setData({
  113. height: result.windowHeight
  114. })
  115. },
  116. })
  117. this.queryInvitation(null);
  118. let t = this;
  119. setTimeout(() => {
  120. t.doSearch();
  121. }, 1000);
  122. },
  123. showCodeImg: function () {
  124. this.setData({
  125. showCodeImg: true
  126. })
  127. },
  128. closeImg: function () {
  129. this.setData({
  130. showShareImg: false,
  131. showCodeImg: false
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. return {
  169. title: '邀请有礼',
  170. path: '/pages/student/student?sid=' + this.data.sid + '&oid=' + this.data.oid,
  171. image: this.data.qrCodeImg
  172. }
  173. },
  174. queryInvitation: function (methodName) {
  175. let urls = urlDef.urls
  176. let inviteConfig = {}
  177. util.apiPost(urls.get_activity_share + '&q.orgId=' + this.data.oid).then((rs) => {
  178. if (rs && rs.length > 0) {
  179. let r = rs[0];
  180. inviteConfig.title = (r.name ? r.name : '邀请有礼');
  181. inviteConfig.description = (r.remark ? r.remark : '邀请新学员,赢得奖励');
  182. inviteConfig.imageUrl = r.imgUrl;
  183. if (r.activityUrl && r.activityUrl.length > 0) {
  184. inviteConfig.url = r.activityUrl + (r.activityUrl.indexOf('?') === -1 ? '?' : '&') + 'studentId=' + this.data.sid + '&orgId=' + this.data.oid;
  185. }
  186. let qrCodeImg = urls.get_qr_code + '?content=' + encodeURIComponent(inviteConfig.url)
  187. this.setData({ 'posterConfig.images[1].url': qrCodeImg })
  188. this.setData({ qrCodeImg: qrCodeImg })
  189. this.setData({ inviteConfig: inviteConfig })
  190. if ('billShare' === methodName) {
  191. this.billShare();
  192. }
  193. if ('share' === methodName) {
  194. this.share();
  195. }
  196. if ('codeInvite' === methodName) {
  197. this.codeInvite();
  198. }
  199. }
  200. });
  201. },
  202. doSearch: function () {
  203. let urls = urlDef.urls
  204. util.apiPost(urls.get_invitation_count + '&q.introducer=' + this.data.sid).then(rs => {
  205. if (rs) {
  206. this.setData({ count: rs.num })
  207. }
  208. });
  209. util.apiPost(urls.get_invitation_enroll + '&q.introducer=' + this.data.sid).then(rs => {
  210. if (rs) {
  211. this.setData({ enroll: rs.num })
  212. }
  213. });
  214. util.apiPost(urls.get_invitation_coin + '&q.introducer=' + this.data.sid).then(rs => {
  215. if (rs && rs.length > 0) {
  216. let i = 0;
  217. let coin = ''
  218. rs.forEach(r => {
  219. coin += (r.amount + '<view class=\'unit\'>' + (r.type === 1 ? '元' : '课时') + '</view>');
  220. if (i < rs.length - 1) {
  221. coin += '<view class=\'sl\'>/</view>';
  222. }
  223. i++;
  224. });
  225. this.setData({ coin: coin })
  226. }
  227. });
  228. util.apiPost(urls.query_invitation_list + '&q.introducer=' + this.data.sid).then(rs => {
  229. if (rs) {
  230. rs.map(o => {
  231. o.name = o.studentName ? o.studentName : o.clientName
  232. o.statusText = this.getStatus(o)
  233. o.face = this.getHead(o)
  234. })
  235. this.setData({ invitations: rs })
  236. }
  237. });
  238. },
  239. getHead(item) {
  240. let urls = urlDef.urls
  241. return item.imageUrl ? urls.oss_file + 'image/' + item.imageUrl : '/images/head.png';
  242. },
  243. getStatus(item) {
  244. if (item.orderCount > 0) { // 有已付款的订单
  245. return '已报名';
  246. } else {
  247. if (item.isAudition === 0) { // 未试听
  248. return '已注册';
  249. }
  250. return '已试听';
  251. }
  252. },
  253. billShare: function () {
  254. if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
  255. this.setData({
  256. showShareImg: true
  257. })
  258. } else {
  259. this.queryInvitation('billShare');
  260. }
  261. },
  262. codeInvite: function () {
  263. this.setData({
  264. showCodeImg: true
  265. })
  266. }
  267. })