record.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. import { radar } from '../../../components/radar/radar';
  4. Page({
  5. radar,
  6. data: {
  7. datas:{},
  8. current:0,
  9. radarData:[],
  10. load:false,
  11. user:[],
  12. userData:{},
  13. currentPages:0,
  14. noData:false,
  15. noChildData:false,
  16. onshow:false,
  17. cardNo:'',
  18. cardType:'',
  19. avatar:'',
  20. name:'',
  21. npsOptons: {},
  22. npsStatus: false,//nps组件是否显示
  23. isGet: true,
  24. pageIndex:1,
  25. pageSize: 20,
  26. isLoadMore: true,
  27. showPoter:false,
  28. posterInfo:{}
  29. },
  30. onShow:function(){
  31. let currentPages = getCurrentPages().length;
  32. if(!this.data.onshow){
  33. this.setData({current:0})
  34. let that = this,rid = this.data.rid;
  35. if (currentPages == 1){
  36. // var getLocation = util.promise();
  37. // getLocation.then(function(value) {
  38. that.getUser();
  39. that.setData({currentPages});
  40. // }, function(error) {
  41. // });
  42. }else{
  43. that.getUser();
  44. }
  45. }
  46. },
  47. bindchange(e){
  48. let index= e.currentTarget.dataset.index,current=e.detail.current;
  49. this.data.datas[index].currentInx=current+1;
  50. this.setData({datas:this.data.datas})
  51. },
  52. showPoster(e){
  53. let data =e.currentTarget.dataset.item;
  54. wx.reportAnalytics('show_poster', {
  55. aid: data.aid,
  56. title: data.atitle,
  57. });
  58. data.ChildName=this.data.user[this.data.current].name;
  59. // this.setData({
  60. // showPoter:true,
  61. // posterInfo:data
  62. // })
  63. let urlData=[];
  64. urlData.push('aid='+data.aid)
  65. urlData.push('atitle='+data.atitle)
  66. urlData.push('ChildName='+data.ChildName)
  67. urlData.push('id='+data.id)
  68. if (!util.isEmpty(data.picWidthHeight)) {
  69. urlData.push('picWidthHeight='+data.picWidthHeight)
  70. }
  71. if (data.pics.length>0) {
  72. urlData.push('pic='+data.pics[0])
  73. }
  74. wx.navigateTo({
  75. // url: '/components/poster/poster?aid='+data.aid+'&atitle='+data.atitle+'&ChildName='+data.ChildName+'&id='+data.id+'&picWidthHeight='+data.picWidthHeight+'&pic='+data.pics[0],
  76. url:'/components/poster/poster?'+urlData.join('&')
  77. })
  78. },
  79. closePoster(e){
  80. this.setData({showPoter:false})
  81. },
  82. selectImage(e) {
  83. this.setData({ isGet: e.detail.isGet });
  84. },
  85. close(e) {//关闭nps
  86. this.setData({ npsStatus: false });
  87. },
  88. // 查看图片
  89. showImg(e){
  90. let data = e.currentTarget.dataset;
  91. wx.previewImage({
  92. current: data.url,
  93. urls: data.item
  94. })
  95. },
  96. getUser(){
  97. let that = this;
  98. util.ajax({
  99. func:"user/childs"
  100. },function(res){
  101. if(res.code == 0){
  102. that.setData({ user: res.data || [], onshow:true});
  103. that.userData();
  104. }else
  105. util.showTips(res.reason);
  106. })
  107. },
  108. userData(aload){
  109. let that = this, user = this.data.user;
  110. if (user.length <= 0){
  111. that.setData({ noData: true });
  112. return false;
  113. }
  114. util.ajax({
  115. func:"v2/child/activity/list",
  116. data: { "cardNo": user[that.data.current].cardNo, "cardType": user[that.data.current].cardType, "pageIndex": that.data.pageIndex, "pageSize": that.data.pageSize},
  117. load: aload
  118. },function(res){
  119. if (res.data.list&&res.data.list.length>0) {
  120. res.data.list.forEach(el => {
  121. if (el.pics.length>0) {
  122. util.getImageInfo(el.pics[0]).then(res=>{
  123. el.picWidthHeight=res;
  124. })
  125. }
  126. });
  127. }
  128. let newData = res.data.list || [], isLoadMore = true, datas = !aload ? newData : [...that.data.datas, ...newData];
  129. if (newData.length < that.data.pageSize && datas.length > that.data.pageSize) {
  130. isLoadMore = false;
  131. }
  132. if(datas && datas.length > 0){
  133. let tempIndex = false;
  134. for(let i in datas){
  135. if (datas[i].status != 1 || (datas[i].status == 1 && util.isEmpty(datas[i].comment))){
  136. datas[i].isDisplay = true;
  137. datas[i].link = false;
  138. }else{
  139. datas[i].isDisplay = false;
  140. datas[i].link = true;
  141. }
  142. if (tempIndex == false && datas[i].status == 1 && !util.isEmpty(datas[i].comment)){
  143. datas[i].isDisplay = true;
  144. tempIndex = true;
  145. }
  146. datas[i].canvasId = 'radarCanvas' + i;
  147. }
  148. }
  149. var noChildData = false;
  150. if(util.isObjEmpty(datas)){
  151. noChildData = true
  152. }
  153. let timer =setTimeout(() => {
  154. that.setData({ datas, noChildData, isLoadMore, load:true});
  155. clearTimeout(timer)
  156. }, 200);
  157. that.Canvas();
  158. wx.hideLoading();
  159. })
  160. },
  161. choose(e){
  162. this.setData({ current: e.detail, pageIndex: 1, isLoadMore:true});
  163. this.userData();
  164. },
  165. Canvas(){
  166. let datas = this.data.datas;
  167. if(datas && datas.length > 0){
  168. for (let i in datas){
  169. if (datas[i].scores && datas[i].scores.length > 0){
  170. this.radar.draw(datas[i].scores, datas[i].canvasId, datas[i].grades);
  171. }
  172. }
  173. }
  174. },
  175. onPullDownRefresh() {
  176. var self = this;
  177. wx.showNavigationBarLoading();
  178. setTimeout(function () {
  179. self.setData({ pageIndex: 1 });
  180. self.userData(false);
  181. wx.hideNavigationBarLoading();
  182. wx.stopPullDownRefresh();
  183. }, 1000);
  184. },
  185. onReachBottom() {
  186. var self = this;
  187. if (self.data.isLoadMore == false) return false;
  188. setTimeout(function () {
  189. self.setData({ pageIndex: self.data.pageIndex + 1 });
  190. self.userData(true);
  191. }, 1000);
  192. },
  193. details(e){
  194. var i = parseInt(e.currentTarget.dataset.i), pics = this.data.datas[e.currentTarget.dataset.index].pics;
  195. wx.previewImage({
  196. current: pics[i], // 当前显示图片的http链接
  197. urls: pics // 需要预览的图片http链接列表
  198. });
  199. },
  200. copy(e){
  201. let index=e.currentTarget.dataset.index,activitys=this.data.datas;
  202. wx.setClipboardData({
  203. data: activitys[index].comment,
  204. success: function(res) {
  205. util.showTips('复制成功');
  206. }
  207. })
  208. },
  209. onShareAppMessage() {
  210. return {
  211. title: '儿童参加活动的成长记录',
  212. path: '/pages/account/record/record'
  213. }
  214. }
  215. })