activate.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var productList = [];
  5. Page({
  6. data: {
  7. },
  8. onLoad: function (options) {
  9. this.setData({
  10. Containnerheight: common.getSystemHeight(),
  11. ProgramList: server.getProgramList(),
  12. });
  13. this.init();
  14. },
  15. onUnload:function(){
  16. productList=[];
  17. },
  18. init: function (e, isRemind) {
  19. var that = this;
  20. wx.showLoading({
  21. title: '装载中',
  22. });
  23. server.getData('GetUserActivateListByUserID500?UserID=' + app.globalData.userInfo.UserID + "&ProductID=" + app.globalData.ProgramID, function (data) {
  24. if (data && data.length > 0) {
  25. var programList = server.getProgramList();
  26. for (var i = 0; i < programList.length; i++) {
  27. for (var j = 0; j < data.length; j++) {
  28. if (programList[i].ID == data[j].ProductID) {
  29. data[j].Name = programList[i].Name;
  30. data[j].ImageUrl = programList[i].ImageUrl;
  31. data[j].appId = programList[i].appId;
  32. data[j].path = programList[i].path;
  33. //不是当前小程序不解锁
  34. if (app.globalData.ProgramID == data[j].ProductID)
  35. app.globalData.userInfo.IsMember = 1;
  36. }
  37. }
  38. }
  39. if (productList.length > 0) {
  40. for (var i = 0; i < productList.length; i++) {
  41. var b = false;
  42. for (var j = 0; j < data.length; j++) {
  43. if (productList[i].ProductID == data[j].ProductID) {
  44. b = true;
  45. break;
  46. }
  47. }
  48. if (!b) {
  49. productList[i].IsActivate = 1;
  50. data.push(productList[i]);
  51. }
  52. }
  53. }
  54. that.setData({
  55. List: data,
  56. });
  57. productList = data;
  58. if (isRemind) {
  59. wx.showModal({
  60. title: '产品未激活',
  61. content: '您有产品未激活,请立即点击红色“去激活”按钮。',
  62. showCancel: false,
  63. confirmText: "知道了",
  64. });
  65. }
  66. wx.setStorageSync("HasActivate", 1);
  67. wx.hideLoading();
  68. }
  69. else {
  70. if (isRemind) {
  71. var arr = [];
  72. for (var i = 0; i < productList.length; i++) {
  73. arr.push(productList[i].ProductID);
  74. }
  75. wx.redirectTo({
  76. url: "./activateFinish?idarr="+arr.join(","),
  77. });
  78. productList = [];
  79. wx.removeStorageSync("HasActivate");
  80. }
  81. else{
  82. for (var i = 0; i < productList.length; i++) {
  83. productList[i].IsActivate = 1;
  84. }
  85. if (productList.length>0){
  86. that.setData({
  87. List: productList,
  88. });
  89. }
  90. else{
  91. wx.removeStorageSync("HasActivate");
  92. wx.showModal({
  93. title: '提醒',
  94. content: '产品已激活。',
  95. showCancel: false,
  96. confirmText: "去首页",
  97. success:function(){
  98. wx.reLaunch({
  99. url: '../../pages/index/index',
  100. })
  101. }
  102. });
  103. }
  104. }
  105. }
  106. wx.hideLoading();
  107. });
  108. },
  109. gotoFeedback: function () {
  110. server.gotoFeedback();
  111. },
  112. gotoActive: function (e) {
  113. var that = this;
  114. var productid = e.currentTarget.dataset.id;
  115. if (productid == app.globalData.ProgramID) {
  116. server.getData('UpdateWXUsersAll500?ProductID=' + productid
  117. + "&ProductUserID=" + app.globalData.userInfo.UserID
  118. + "&CurrentProductID=" + productid
  119. + "&CurrentUserID=" + app.globalData.userInfo.UserID, function (data) {
  120. if (data) {
  121. }
  122. });
  123. }
  124. else {
  125. var appId = e.currentTarget.dataset.appid;
  126. var path = e.currentTarget.dataset.path;
  127. path += "&ProductID=" + app.globalData.ProgramID;
  128. path += "&ProductUserID=" + app.globalData.userInfo.UserID;
  129. wx.navigateToMiniProgram({
  130. appId: appId,
  131. path: path,
  132. success(res) {
  133. }
  134. });
  135. }
  136. var data = this.data.List;
  137. for (var i = 0; i < data.length; i++) {
  138. if (data[i].ProductID == productid) {
  139. data[i].IsActivate = 0;
  140. }
  141. }
  142. that.setData({
  143. List: data,
  144. });
  145. },
  146. gotoFinish: function () {
  147. this.init(null, true);
  148. },
  149. onShareAppMessage: function () {
  150. return {
  151. title: app.globalData.ShareTitle,
  152. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  153. imageUrl: app.globalData.ShareImage,
  154. }
  155. },
  156. })