index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. const util = require('../../../utils/util.js');
  2. import * as echarts from '../../../components/ec-canvas/echarts.js';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. indexs:{
  7. child:0,
  8. activity:0,
  9. video: null,
  10. videoParent: null
  11. },
  12. noData: false,
  13. childs:[],
  14. activity:[],
  15. actives: [],
  16. list: [],
  17. ec: {
  18. lazyLoad: true // 延迟加载
  19. }
  20. },
  21. onShow() {
  22. this.getChild();
  23. },
  24. getChild(){
  25. let that = this;
  26. util.ajax({
  27. func: "user/childs",
  28. load: false
  29. }, function (res) {
  30. if (res.code == 0) {
  31. that.setData({ childs: res.data, noData: res.data.length > 0 ? true : false });
  32. if (!util.isObjEmpty(that.data.childs)) that.getActivity();
  33. }else {
  34. util.showTips(res.reason);
  35. }
  36. });
  37. },
  38. getActivity() {
  39. let that = this;
  40. util.ajax({
  41. func: "v2/child/camps",
  42. data: { "cardNo": that.data.childs[that.data.indexs.child].cardNo, "cardType": that.data.childs[that.data.indexs.child].cardType },
  43. load: false
  44. }, function (res) {
  45. if (res.code == 0) {
  46. if (!util.isObjEmpty(res.data)){
  47. that.setData({ activity: res.data, noData: true });
  48. that.getInfo();
  49. }else{
  50. that.setData({ activity: res.data, info: null, list: [], noData: false });
  51. }
  52. that.jsonDataArr();
  53. } else {
  54. util.showTips(res.reason);
  55. }
  56. });
  57. },
  58. jsonDataArr() {
  59. let self = this, arr = [];
  60. for (var i = 0; i < self.data.activity.length; i++) {
  61. arr.push(self.data.activity[i].sname + " " + self.data.activity[i].ptitle);
  62. }
  63. this.setData({ actives: arr });
  64. },
  65. getCourseList(load){
  66. let that = this;
  67. util.ajax({
  68. func:'v2/course/list',
  69. data: { "playerId": that.data.info.playerId, 'id': that.data.info.id},
  70. load: load
  71. },function(res){
  72. if(res.code == 0){
  73. that.setData({ list: res.data });
  74. }else
  75. util.showTips(res.reason);
  76. });
  77. },
  78. getInfo(){
  79. let that = this;
  80. util.ajax({
  81. func:"v2/course/center",
  82. data: { "cardNo": that.data.childs[that.data.indexs.child].cardNo, "cardType": that.data.childs[that.data.indexs.child].cardType, "aid": that.data.activity[that.data.indexs.activity].aid, "campId": that.data.activity[that.data.indexs.activity].campId},
  83. load: false
  84. },function(res){
  85. if(res.code == 0){
  86. if (!util.isObjEmpty(res.data)) {
  87. that.setData({ info: res.data, noData: res.data.courseNum });
  88. if (res.data.courseNum > 0){
  89. that.getCourseList(false);
  90. if (!util.isObjEmpty(res.data.xarr)) that.chartInit(res.data.show);
  91. }
  92. }else{
  93. that.setData({ noData: false, info: null, list: [] });
  94. }
  95. } else if (res.statusCode != 200) {
  96. that.setData({ noData: false });
  97. } else
  98. util.showTips(res.reason);
  99. })
  100. },
  101. bindChildChange(e) {
  102. this.setData({
  103. indexs: { child: e.detail.value, activity: 0},
  104. activity:[],
  105. info:null,
  106. noData: true
  107. });
  108. this.getActivity();
  109. },
  110. bindActivityChange(e) {
  111. this.data.indexs.activity = e.detail.value;
  112. this.setData({
  113. indexs: this.data.indexs,
  114. info: null,
  115. noData: true
  116. });
  117. this.getInfo();
  118. },
  119. updateHead(){
  120. let that = this;
  121. wx.chooseImage({
  122. count: 1,
  123. sizeType: ['compressed'],
  124. sourceType: ['album', 'camera'],
  125. success(res) {
  126. wx.uploadFile({
  127. url: util.config.apiServer +'v2/child/avatar.do', // 仅为示例,非真实的接口地址
  128. filePath: res.tempFilePaths[0],
  129. name: 'avatarFile',
  130. formData: {
  131. childId: that.data.info.childId,
  132. rid: app.globalData.userInfo ? app.globalData.userInfo.rid : ''
  133. },
  134. success(res) {
  135. let data = JSON.parse(res.data);
  136. if (res.statusCode==200&&data.code == 0){
  137. that.data.info.avatar = data.data;
  138. that.setData({info : that.data.info });
  139. }else
  140. util.showTips(res.reason);
  141. }
  142. })
  143. }
  144. })
  145. },
  146. playEnd(event){
  147. this.data.indexs.video = null;
  148. this.data.indexs.videoParent = null;
  149. this.setData({
  150. indexs: this.data.indexs
  151. })
  152. },
  153. videoPlay(event){
  154. let e = event.currentTarget, parentIndex = e.dataset.parentindex, index = e.dataset['index'];
  155. if (!this.data.indexs.video && !this.data.indexs.videoParent) {
  156. this.data.indexs.video = index;
  157. this.data.indexs.videoParent = parentIndex;
  158. this.setData({
  159. indexs: this.data.indexs
  160. });
  161. this.videoContext = wx.createVideoContext('video_' + parentIndex+'_'+ index)
  162. this.videoContext.play();
  163. this.videoContext.requestFullScreen();
  164. } else {
  165. this.videoContext = wx.createVideoContext('video_' + this.data.indexs.videoParent + '_' + this.data.indexs.video)
  166. this.videoContext.stop();
  167. this.videoContext.exitFullScreen();
  168. this.data.indexs.video = index;
  169. this.data.indexs.videoParent = parentIndex;
  170. this.setData({
  171. indexs: this.data.indexs
  172. })
  173. this.videoContext = wx.createVideoContext('video_' + parentIndex + '_' + index);
  174. this.videoContext.play();
  175. this.videoContext.requestFullScreen();
  176. }
  177. },
  178. fullscreen(e){
  179. if (!e.detail.fullScreen){
  180. this.videoContext.stop();
  181. this.data.indexs.video = null;
  182. this.data.indexs.videoParent = null;
  183. this.setData({
  184. indexs: this.data.indexs
  185. })
  186. }
  187. },
  188. navigatorUrl(e){
  189. let data = e.currentTarget.dataset;
  190. util.navigator(data.url);
  191. },
  192. chartInit(type){
  193. if (util.isObjEmpty(this.data.info.xarr)) return false;
  194. let columns = [], that = this;
  195. for (let i in this.data.info.xarr){
  196. columns.push({
  197. value: this.data.info.xarr[i],
  198. textStyle: {
  199. color: '#908f90'
  200. }
  201. });
  202. }
  203. this.selectComponent('#mychart').init((canvas, width, height) => {
  204. // 初始化图表
  205. var Chart = echarts.init(canvas, null, {
  206. width: width,
  207. height: height
  208. });
  209. Chart.clear();
  210. let options = {
  211. xAxis: {
  212. type: 'category',
  213. axisLine: {
  214. show: false
  215. },
  216. axisTick: {
  217. show: false
  218. },
  219. axisLabel: {
  220. interval: 0,
  221. rotate: 40
  222. },
  223. data: columns
  224. },
  225. yAxis: {
  226. show: false
  227. },
  228. grid: {
  229. left: '0',
  230. right: '0',
  231. bottom: '12%'
  232. },
  233. series: [{
  234. type: 'bar',
  235. barWidth: 38,
  236. label: {
  237. show: true,
  238. position: 'top',
  239. formatter: '{c}分',
  240. color: '#ee3a43'
  241. },
  242. itemStyle: {
  243. color:'#ffccd3'
  244. },
  245. data: that.data.info.yarr
  246. }]
  247. };
  248. if(type == 0){
  249. options.grid = {
  250. left: '5%',
  251. right: '5%',
  252. bottom: '40%'
  253. };
  254. options.dataZoom = [{
  255. type:'inside',
  256. start: 0,
  257. end: 30
  258. },{
  259. type: 'slider',
  260. showDetail:false,
  261. showDataShadow:false,
  262. handleStyle:{
  263. borderColor:'#ee3a43'
  264. },
  265. backgroundColor:'#fff0f3',
  266. handleSize:'60%',
  267. handleIcon:'path://M30.9,53.2c-14.1,0-25.6-11.5-25.6-25.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z'
  268. }];
  269. }
  270. Chart.setOption(options);
  271. return Chart;
  272. });
  273. },
  274. onShareAppMessage() {
  275. return {
  276. title: '活动营前课',
  277. path: '/pages/account/course/index'
  278. }
  279. }
  280. })