student.js 7.0 KB

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