myPage.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. var util = require('../../utils/util.js');
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. stars: [],
  9. score: 80,
  10. headIcon:null,
  11. nick:'',
  12. workfordo:0,
  13. working:0,
  14. postList:[],
  15. openId:''
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function(options) {
  21. try {
  22. var headIcon = wx.getStorageSync('headIcon');
  23. var nick = wx.getStorageSync('nick');
  24. var star = wx.getStorageSync('star');
  25. var score = wx.getStorageSync('score');
  26. const openid = wx.getStorageSync('openid');
  27. this.setData({
  28. headIcon: app.globalData.imageBase + "/"+headIcon,
  29. nick: nick,
  30. stars: util.convertToStarsArray(star),
  31. score: score,
  32. openId:openid
  33. })
  34. this.getWorkStream();
  35. } catch (e) {
  36. }
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function() {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function() {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function() {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function() {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function() {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function() {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function() {
  72. },
  73. refreshList:function(e){
  74. this.getWorkStream();
  75. },
  76. moreinfoEvent:function(e){
  77. var id = e.currentTarget.dataset.id;
  78. wx.navigateTo({
  79. url: "/pages/myPage/detail/reportDetail?id="+id
  80. })
  81. },
  82. modifyPersonInfo: function (e) {
  83. wx.navigateTo({
  84. url: "/pages/account/account"
  85. })
  86. },
  87. getWorkStream:function(){
  88. //var openid = this.data.openId;// wx.getStorageSync('openid');
  89. var that = this;
  90. var url = app.globalData.cloudBase + "/Wx/Work/List/"+ this.data.openId;
  91. wx.request({
  92. url: url,
  93. method: 'GET',
  94. header: {
  95. "Content-Type": "json"
  96. },
  97. // data: {
  98. // openid: openid
  99. // }
  100. // ,
  101. success: function (res) {
  102. console.debug(res.data);
  103. if (res.data.code === "0") {
  104. that.processWorkStream(res.data.data);
  105. }
  106. },
  107. fail: function (error) {
  108. console.log(error)
  109. }
  110. })
  111. },
  112. processWorkStream:function(list){
  113. if (null === list || list.length <= 0) {
  114. return;
  115. }
  116. var postList = [];
  117. var date = new Date();
  118. //年
  119. var NY = '' + date.getFullYear();
  120. //月
  121. var NM = this.PrefixInteger(date.getMonth() + 1, 2);// < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  122. //日
  123. var ND = this.PrefixInteger(date.getDate(), 2);// < 10 ? '0' + date.getDate() : date.getDate();
  124. for (var index = 0; index < list.length; index++) {
  125. var post = list[index];
  126. // var cdate = new Date(post.updateTime);
  127. // var cy = '' + cdate.getFullYear();
  128. // var cm = this.PrefixInteger(cdate.getMonth() + 1, 2);// (cdate.getMonth() + 1 < 10 ? '0' + (cdate.getMonth() + 1) : cdate.getMonth() + 1);
  129. // var cd = this.PrefixInteger(cdate.getDate(), 2);// < 10 ? '0' + cdate.getDate() : cdate.getDate();
  130. //var time = post['time'];
  131. // if (cy === NY && cm === NM && cd === ND) {
  132. // var ch = this.PrefixInteger(date.getHours(), 2);
  133. // var cm = this.PrefixInteger(cdate.getMinutes(), 2);
  134. // var cs = this.PrefixInteger(cdate.getSeconds(), 2);
  135. // time = '' + ch + ':' + cm + ':' + cs;
  136. // } else {
  137. // time = '' + cy + '-' + cm + '-' + cd;
  138. // }
  139. // var replys = [];
  140. // for (var i = 0; i < post.replys.length && i < 2; i++) {
  141. // var item = post.replys[i];
  142. // var reply = {
  143. // id: item.id,
  144. // openid: item.openid,
  145. // showBoxId: item.showBoxId,
  146. // content: item.content,
  147. // name: item.nick
  148. // }
  149. // replys.push(reply);
  150. // }
  151. // var photos = [];
  152. // for (var j = 0; j < post.photos.length; j++) {
  153. // var item = post.photos[j];
  154. // var photo = {
  155. // id: item.id,
  156. // showBoxId: item.showBoxId,
  157. // photo: item.photo,
  158. // large: app.globalData.imageBase + "/" + item.photo,
  159. // middle: app.globalData.imageBase + "/mid_" + item.photo,
  160. // small: app.globalData.imageBase + "/thumb_" + item.photo
  161. // }
  162. // photos.push(photo);
  163. // }
  164. var temp = {
  165. id: post.id,
  166. // nick: post.nick,
  167. // headIcon: app.globalData.imageBase + "/" + post.headIcon,
  168. time: post.time,
  169. info: post.info,
  170. orgName: post.orgName
  171. // stars: util.convertToStarsArray("" + post.star),
  172. // score: post.score,
  173. //replyList: replys,
  174. //photoList: photos,
  175. // replySize: post.replys.length
  176. }
  177. postList.push(temp);
  178. }
  179. this.setData({
  180. postList: postList
  181. })
  182. }
  183. ,
  184. PrefixInteger: function (num, length) {
  185. return (Array(length).join('0') + num).slice(-length);
  186. }
  187. })