library.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. Menu1Array:[{ID:0,Name:"语文",CSS:"Selected"},{ID:1,Name:"English",CSS:""}],
  7. Menu2Array1:[{ID:0,Name:"全部",CSS:"Selected"},{ID:1,Name:"小学",CSS:""},{ID:2,Name:"初中",CSS:""},{ID:3,Name:"高中",CSS:""},{ID:4,Name:"大学",CSS:""}],
  8. Menu2Array2:[{ID:0,Name:"全部",CSS:"Selected"},{ID:1,Name:"课本",CSS:""},{ID:2,Name:"课外拓展",CSS:""}],
  9. IsShowMenu:false,
  10. Menu2Name1:"学段",
  11. Menu2Name2:"类型",
  12. },
  13. onPullDownRefresh: function () {
  14. wx.stopPullDownRefresh();
  15. },
  16. onLoad: function (options) {
  17. var that = this;
  18. that.setData({
  19. Containnerheight: main.getWindowHeight(),
  20. ImagePath: app.globalData.uploadImageUrl,
  21. });
  22. that.init(options);
  23. },
  24. init:function(options){
  25. var that=this;
  26. main.getData('GetMiaoguoTestLibrary', function (data) {
  27. if (data) {
  28. that.setData({
  29. List:data,
  30. });
  31. let index=0;
  32. if (options.Category=="English")
  33. index=1;
  34. that.setMenu({currentTarget:{dataset:{type:1,index:index}}});
  35. that.filterList();
  36. }
  37. });
  38. },
  39. setMenu:function(e){
  40. let that=this;
  41. let index=e.currentTarget.dataset.index;
  42. let type1=e.currentTarget.dataset.type;
  43. let arr=[];
  44. if (type1==1){
  45. arr=that.data.Menu1Array;
  46. that.data.Menu2Name1="学段";
  47. that.data.Menu2Name2="类型";
  48. that.data.Menu2Array1[0].CSS="Selected";
  49. for(let i=1;i<that.data.Menu2Array1.length;i++)
  50. that.data.Menu2Array1[i].CSS="";
  51. that.data.Menu2Array2[0].CSS="Selected";
  52. for(let i=1;i<that.data.Menu2Array2.length;i++)
  53. that.data.Menu2Array2[i].CSS="";
  54. }
  55. else if (type1==2){
  56. arr=that.data.Menu2Array1;
  57. that.data.Menu2Name1="学段";
  58. }
  59. else if (type1==3){
  60. arr=that.data.Menu2Array2;
  61. that.data.Menu2Name2="类型";
  62. }
  63. for(let i=0;i<arr.length;i++){
  64. arr[i].CSS="";
  65. if (index==i){
  66. arr[i].CSS="Selected";
  67. if (type1==2 && index>0)
  68. that.data.Menu2Name1=arr[i].Name;
  69. else if (type1==3 && index>0)
  70. that.data.Menu2Name2=arr[i].Name;
  71. }
  72. }
  73. that.setData({
  74. IsShowMenu:false,
  75. Menu1Array:that.data.Menu1Array,
  76. Menu2Array1:that.data.Menu2Array1,
  77. Menu2Array2:that.data.Menu2Array2,
  78. Menu2Name1:that.data.Menu2Name1,
  79. Menu2Name2:that.data.Menu2Name2,
  80. });
  81. that.filterList();
  82. },
  83. filterList:function(e){
  84. let that=this;
  85. let arr=this.data.List;
  86. let count=0;
  87. for(let i=0;i<arr.length;i++){
  88. arr[i].GradeSelected1=0;
  89. for(let j=0;j<that.data.Menu1Array.length;j++){
  90. if (that.data.Menu1Array[j].CSS=="Selected"){
  91. if (arr[i].Category==that.data.Menu1Array[j].Name)
  92. arr[i].GradeSelected1=1;
  93. break;
  94. }
  95. }
  96. arr[i].GradeSelected2=0;
  97. for(let j=0;j<that.data.Menu2Array1.length;j++){
  98. if (that.data.Menu2Array1[j].CSS=="Selected"){
  99. if (that.data.Menu2Array1[j].Name=="全部" || arr[i].Grade.indexOf(that.data.Menu2Array1[j].Name)>=0)
  100. arr[i].GradeSelected2=1;
  101. break;
  102. }
  103. }
  104. arr[i].GradeSelected3=0;
  105. for(let j=0;j<that.data.Menu2Array2.length;j++){
  106. if (that.data.Menu2Array2[j].CSS=="Selected"){
  107. if (that.data.Menu2Array2[j].Name=="全部" || arr[i].Category2==that.data.Menu2Array2[j].Name)
  108. arr[i].GradeSelected3=1;
  109. break;
  110. }
  111. }
  112. if (arr[i].GradeSelected1==1 && arr[i].GradeSelected2==1 && arr[i].GradeSelected3==1)
  113. count++;
  114. }
  115. that.setData({
  116. List:arr,
  117. Count:count,
  118. });
  119. },
  120. showMenu:function(e){
  121. let index=e.currentTarget.dataset.index;
  122. let menu2Array=this.data.Menu2Array1;
  123. if (index==3)
  124. menu2Array=this.data.Menu2Array2;
  125. this.setData({
  126. IsShowMenu:true,
  127. Menu2Index:index,
  128. Menu2Array:menu2Array,
  129. })
  130. },
  131. goto: function (e) {
  132. var url = e.currentTarget.dataset.url;
  133. wx.navigateTo({
  134. url: url,
  135. });
  136. },
  137. catchTouchMove:function(e) {
  138. // 这个函数不需要做任何事情,只需要捕获事件防止冒泡
  139. return false;
  140. },
  141. onShareAppMessage: function () {
  142. return {
  143. title: app.globalData.ShareTitle,
  144. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  145. imageUrl: app.globalData.ShareImage,
  146. }
  147. },
  148. })