record.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. if (this.data.isGet) {
  47. this.nps();
  48. }
  49. },
  50. bindchange(e){
  51. let index= e.currentTarget.dataset.index,current=e.detail.current;
  52. this.data.datas[index].currentInx=current+1;
  53. this.setData({datas:this.data.datas})
  54. },
  55. showPoster(e){
  56. let data =e.currentTarget.dataset.item;
  57. wx.reportAnalytics('show_poster', {
  58. aid: data.aid,
  59. title: data.atitle,
  60. });
  61. data.ChildName=this.data.user[this.data.current].name;
  62. // this.setData({
  63. // showPoter:true,
  64. // posterInfo:data
  65. // })
  66. let urlData=[];
  67. urlData.push('aid='+data.aid)
  68. urlData.push('atitle='+data.atitle)
  69. urlData.push('ChildName='+data.ChildName)
  70. urlData.push('id='+data.id)
  71. if (!util.isEmpty(data.picWidthHeight)) {
  72. urlData.push('picWidthHeight='+data.picWidthHeight)
  73. }
  74. if (data.pics.length>0) {
  75. urlData.push('pic='+data.pics[0])
  76. }
  77. wx.navigateTo({
  78. // url: '/components/poster/poster?aid='+data.aid+'&atitle='+data.atitle+'&ChildName='+data.ChildName+'&id='+data.id+'&picWidthHeight='+data.picWidthHeight+'&pic='+data.pics[0],
  79. url:'/components/poster/poster?'+urlData.join('&')
  80. })
  81. },
  82. closePoster(e){
  83. this.setData({showPoter:false})
  84. },
  85. nps() {
  86. let that = this, npsData = wx.getStorageSync("nps");
  87. if (npsData.num < util.config.npsNum || util.isObjEmpty(npsData)) {
  88. util.ajax({
  89. func: "v2/order/reviews/one",
  90. }, function (res) {
  91. if (res.code == 0 && !util.isObjEmpty(res.data)) {
  92. that.setData({ npsOptons: res.data, npsStatus: true });
  93. npsData.num += 1;
  94. wx.setStorageSync("nps", npsData)
  95. }
  96. })
  97. }
  98. },
  99. selectImage(e) {
  100. this.setData({ isGet: e.detail.isGet });
  101. },
  102. close(e) {//关闭nps
  103. this.setData({ npsStatus: false });
  104. },
  105. // 查看图片
  106. showImg(e){
  107. let data = e.currentTarget.dataset;
  108. wx.previewImage({
  109. current: data.url,
  110. urls: data.item
  111. })
  112. },
  113. getUser(){
  114. let that = this;
  115. util.ajax({
  116. func:"user/childs"
  117. },function(res){
  118. if(res.code == 0){
  119. that.setData({ user: res.data || [], onshow:true});
  120. that.userData();
  121. }else
  122. util.showTips(res.reason);
  123. })
  124. },
  125. userData(aload){
  126. let that = this, user = this.data.user;
  127. if (user.length <= 0){
  128. that.setData({ noData: true });
  129. return false;
  130. }
  131. util.ajax({
  132. func:"v2/child/activity/list",
  133. data: { "cardNo": user[that.data.current].cardNo, "cardType": user[that.data.current].cardType, "pageIndex": that.data.pageIndex, "pageSize": that.data.pageSize},
  134. load: aload
  135. },function(res){
  136. if (res.data.list&&res.data.list.length>0) {
  137. res.data.list.forEach(el => {
  138. if (el.pics.length>0) {
  139. util.getImageInfo(el.pics[0]).then(res=>{
  140. el.picWidthHeight=res;
  141. })
  142. }
  143. });
  144. }
  145. let newData = res.data.list || [], isLoadMore = true, datas = !aload ? newData : [...that.data.datas, ...newData];
  146. if (newData.length < that.data.pageSize && datas.length > that.data.pageSize) {
  147. isLoadMore = false;
  148. }
  149. if(datas && datas.length > 0){
  150. let tempIndex = false;
  151. for(let i in datas){
  152. if (datas[i].status != 1 || (datas[i].status == 1 && util.isEmpty(datas[i].comment))){
  153. datas[i].isDisplay = true;
  154. datas[i].link = false;
  155. }else{
  156. datas[i].isDisplay = false;
  157. datas[i].link = true;
  158. }
  159. if (tempIndex == false && datas[i].status == 1 && !util.isEmpty(datas[i].comment)){
  160. datas[i].isDisplay = true;
  161. tempIndex = true;
  162. }
  163. datas[i].canvasId = 'radarCanvas' + i;
  164. }
  165. }
  166. var noChildData = false;
  167. if(util.isObjEmpty(datas)){
  168. noChildData = true
  169. }
  170. let timer =setTimeout(() => {
  171. that.setData({ datas, noChildData, isLoadMore, load:true});
  172. clearTimeout(timer)
  173. }, 200);
  174. that.Canvas();
  175. wx.hideLoading();
  176. })
  177. },
  178. choose(e){
  179. this.setData({ current: e.detail, pageIndex: 1, isLoadMore:true});
  180. this.userData();
  181. },
  182. Canvas(){
  183. let datas = this.data.datas;
  184. if(datas && datas.length > 0){
  185. for (let i in datas){
  186. if (datas[i].scores && datas[i].scores.length > 0){
  187. this.radar.draw(datas[i].scores, datas[i].canvasId, datas[i].grades);
  188. }
  189. }
  190. }
  191. },
  192. onPullDownRefresh() {
  193. var self = this;
  194. wx.showNavigationBarLoading();
  195. setTimeout(function () {
  196. self.setData({ pageIndex: 1 });
  197. self.userData(false);
  198. wx.hideNavigationBarLoading();
  199. wx.stopPullDownRefresh();
  200. }, 1000);
  201. },
  202. onReachBottom() {
  203. var self = this;
  204. if (self.data.isLoadMore == false) return false;
  205. setTimeout(function () {
  206. self.setData({ pageIndex: self.data.pageIndex + 1 });
  207. self.userData(true);
  208. }, 1000);
  209. },
  210. details(e){
  211. var i = parseInt(e.currentTarget.dataset.i), pics = this.data.datas[e.currentTarget.dataset.index].pics;
  212. wx.previewImage({
  213. current: pics[i], // 当前显示图片的http链接
  214. urls: pics // 需要预览的图片http链接列表
  215. });
  216. },
  217. copy(e){
  218. let index=e.currentTarget.dataset.index,activitys=this.data.datas;
  219. wx.setClipboardData({
  220. data: activitys[index].comment,
  221. success: function(res) {
  222. util.showTips('复制成功');
  223. }
  224. })
  225. },
  226. onShareAppMessage() {
  227. return {
  228. title: '儿童参加活动的成长记录',
  229. path: '/pages/account/record/record'
  230. }
  231. }
  232. })