大数据平台的小程序版本

index.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. safeAreaTop:50+app.data.safeAreaTop,
  8. claimTaskFlag:false,
  9. authorizeFlag:false,
  10. userList:[],
  11. token:'',
  12. user_id:'',
  13. isReset:false,
  14. isOneFalg:true,
  15. timeType:1,
  16. minute: 600,
  17. timeMsg:'',
  18. timer:1,
  19. isIOS:false,
  20. deleteTaskFlag:false,
  21. delete_user_id:''
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. this.uploadClaim()
  28. var info = wx.getSystemInfoSync()
  29. if (info.platform === 'android') {
  30. this.setData({isIOS:false})
  31. } else {
  32. this.setData({isIOS:true})
  33. }
  34. },
  35. onShow: function () {
  36. this.uploadClaim()
  37. },
  38. switchPlatform(){//日期切换
  39. var _this = this;
  40. wx.showActionSheet({
  41. itemList: ['昨天', '近7天', '近30天'],
  42. success (res) {
  43. _this.setData({
  44. timeType:res.tapIndex == 0 ? 1 : res.tapIndex == 1 ? 7 : res.tapIndex == 2 ? 30 : 1
  45. })
  46. },
  47. fail (res) {
  48. }
  49. })
  50. },
  51. goUserDetail(e){
  52. var data = e.currentTarget.dataset.data;
  53. if(data.no_user){
  54. this.setData({
  55. claimTaskFlag:true,
  56. user_id:data.user_id
  57. })
  58. }else{
  59. wx.navigateTo({
  60. url: '/pages/claim/claimDetail/index?user_id='+data.user_id,
  61. })
  62. }
  63. },
  64. uploadClaim(){//更新数据
  65. this.setData({authorizeFlag:false})
  66. if(wx.getStorageSync('claim_token')&&wx.getStorageSync('claim_token')!=''){
  67. wx.showLoading({
  68. title: '加载中',
  69. })
  70. app.func.req('/api/sphClaim/getData', 'get', {
  71. user_id:this.data.user_id,
  72. token:wx.getStorageSync('claim_token')
  73. }, (res) => {
  74. wx.hideLoading()
  75. if(res && res.errno == 0){
  76. var data = wx.getStorageSync('claim')
  77. if(!data||data==''){data={}}
  78. data[res.rst.user_id] = res.rst;
  79. wx.setStorageSync('claim', data)
  80. wx.setStorageSync('claim_token', '')
  81. this.init()
  82. }else{
  83. this.init()
  84. // wx.showToast({
  85. // title: res.err,
  86. // icon: 'none',
  87. // duration: 2000
  88. // })
  89. }
  90. },()=>{
  91. this.init()
  92. wx.hideLoading()
  93. })
  94. }else{
  95. this.init()
  96. }
  97. },
  98. init(){
  99. wx.showLoading({
  100. title: '加载中',
  101. })
  102. app.func.req('/api/sphClaimInfo/list', 'get', {}, (res) => {
  103. wx.hideLoading()
  104. wx.stopPullDownRefresh()
  105. if(res && res.errno == 0){
  106. var user_arr = res.rst;
  107. var local_claim = wx.getStorageSync('claim')
  108. user_arr.forEach((item)=>{
  109. if(local_claim[item.user_id]){
  110. item.post = local_claim[item.user_id].indicator.post;
  111. }else{
  112. item.no_user = true
  113. }
  114. })
  115. this.setData({
  116. isOneFalg:false,
  117. userList:user_arr,
  118. })
  119. }else{
  120. wx.showToast({
  121. title: res.err,
  122. icon: 'none',
  123. duration: 2000
  124. })
  125. }
  126. },()=>{
  127. wx.stopPullDownRefresh()
  128. wx.hideLoading()
  129. })
  130. },
  131. claimButtonEvent(){//添加视频号
  132. this.setData({claimTaskFlag:true,isReset:false,user_id:''})
  133. },
  134. againActivationEvent(e){//重新激活
  135. var user_id = e.currentTarget.dataset.user_id
  136. this.setData({isReset:true,user_id:user_id})
  137. this.getToken()
  138. },
  139. cancelTask(){
  140. this.setData({claimTaskFlag:false,authorizeFlag:false,deleteTaskFlag:false})
  141. },
  142. closeClaimMask(){
  143. this.setData({
  144. authorizeFlag:false
  145. })
  146. this.uploadClaim()
  147. },
  148. getToken(){
  149. this.setData({
  150. claimTaskFlag:false,
  151. authorizeFlag:true,
  152. })
  153. },
  154. deleteEvent(e){
  155. var user_id = e.currentTarget.dataset.user_id;
  156. this.setData({
  157. delete_user_id:user_id,
  158. deleteTaskFlag:true
  159. })
  160. },
  161. deleteVideoNum(){//删除视频号
  162. wx.showLoading({
  163. title: '加载中',
  164. })
  165. app.func.req('/api/sphClaim/delete', 'post', {
  166. uid:this.data.delete_user_id
  167. }, (res) => {
  168. wx.hideLoading()
  169. if(res && res.errno == 0){
  170. var local_claim = wx.getStorageSync('claim'),obj={}
  171. if(local_claim&&local_claim!=''){
  172. for(var i in local_claim){
  173. if(i!=this.data.delete_user_id){
  174. obj[i] = local_claim[i]
  175. }
  176. }
  177. wx.setStorageSync('claim', obj)
  178. }
  179. this.setData({deleteTaskFlag:false})
  180. this.init()
  181. }else{
  182. wx.showToast({
  183. title: res.err,
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. }
  188. },()=>{
  189. wx.hideLoading()
  190. })
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面隐藏
  199. */
  200. onHide: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面卸载
  204. */
  205. onUnload: function () {
  206. clearInterval(this.data.timer);
  207. },
  208. /**
  209. * 页面相关事件处理函数--监听用户下拉动作
  210. */
  211. onPullDownRefresh: function () {
  212. this.uploadClaim()
  213. },
  214. /**
  215. * 页面上拉触底事件的处理函数
  216. */
  217. onReachBottom: function () {
  218. },
  219. /**
  220. * 用户点击右上角分享
  221. */
  222. onShareAppMessage: function () {
  223. }
  224. })