student.js 7.3 KB

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