scoreline.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. var canPage=true;
  6. Page({
  7. data: {
  8. PageType:"scoreline",
  9. DistrictID:1,
  10. ScoreTypeID:1,
  11. Years:constant.arrYear,
  12. YearIndex:0,
  13. IsSearch:false,
  14. Accommodation:constant.arrAccommodation,
  15. TailScore:constant.arrTailScore,
  16. PublicOrPrivate:constant.arrPublicOrPrivate,
  17. LocalOrNolocal:constant.arrLocalOrNolocal,
  18. },
  19. onLoad: function (options) {
  20. var that = this;
  21. that.setData({
  22. Containnerheight: main.getWindowHeight(),
  23. IsShow:app.globalData.userInfo.IsShow,
  24. ScoreTypeID:options.ScoreTypeID,
  25. DistrictID:options.DistrictID,
  26. YearIndex:options.YearIndex,
  27. PageType:options.PageType,
  28. SchoolType1:options.SchoolType1,
  29. IsSearch:false,
  30. IsFocus:false,
  31. PageCount:app.globalData.PageCount,//翻页数
  32. });
  33. var b=true;
  34. var title="";
  35. if (options.PageType=="collect"){
  36. var collectSchool=wx.getStorageSync('CollectList');
  37. var schoolCount=0;
  38. if (options.SchoolType1=="高中")
  39. schoolCount=collectSchool.收藏的高中.length;
  40. else
  41. schoolCount=collectSchool.收藏的初中.length;
  42. that.setData({
  43. SchoolCount:schoolCount,
  44. });
  45. if (schoolCount==0){
  46. that.setData({
  47. List:[],
  48. });
  49. b=false;
  50. }
  51. else{
  52. var arr=[];
  53. var name="";
  54. for(var i=0;i<constant.arrDistrict.length;i++){
  55. var obj={};
  56. obj.ID=Number(constant.arrDistrict[i].ID);
  57. obj.Name=constant.arrDistrict[i].Name.substr(0,2);
  58. obj.CSS="";
  59. arr.push(obj);
  60. }
  61. that.setData({
  62. SchoolType1:options.SchoolType1,
  63. District:arr,
  64. DistrictName:name,
  65. });
  66. }
  67. //debugger;
  68. //title="对比·"+options.SchoolType1+"·"+that.data.District[that.data.DistrictID-1].Name;
  69. title="对比·"+options.SchoolType1;
  70. }
  71. else{
  72. title=constant.arrScoreType[that.data.ScoreTypeID-1].Name+'·'+constant.arrDistrict[that.data.DistrictID-1].Name;
  73. }
  74. wx.setNavigationBarTitle({
  75. title: title,
  76. });
  77. that.setData({
  78. Title: title,
  79. });
  80. if (b)
  81. that.init();
  82. },
  83. onPullDownRefresh: function () {
  84. var that=this;
  85. //debugger;
  86. wx.redirectTo({
  87. url: 'scoreline?PageType='+that.data.PageType+'&ScoreTypeID='+that.data.ScoreTypeID+'&SchoolType1='+that.data.SchoolType1+'&DistrictID='+that.data.DistrictID+"&YearIndex="+that.data.YearIndex,
  88. })
  89. wx.stopPullDownRefresh();
  90. },
  91. init:function(){
  92. var that = this;
  93. var districtID=Number(that.data.DistrictID);
  94. var year=that.data.Years[that.data.YearIndex].Name;
  95. for(var i=0;i<that.data.Years.length;i++){
  96. that.data.Years[i].CSS="";
  97. }
  98. that.data.Years[that.data.YearIndex].CSS="Selected";
  99. that.setData({
  100. IsSearch:false,
  101. IsFocus:false,
  102. SearchNull:false,
  103. ContrastNull:false,
  104. InputValue:"",
  105. Years:that.data.Years,
  106. });
  107. var url="";
  108. var canSelect=true;
  109. if (that.data.PageType=="collect"){
  110. if (districtID==-1 && that.data.SchoolType1=="高中")
  111. canSelect=false;
  112. url="GetMPSScoreByCollect?SchoolType1="+that.data.SchoolType1+"&UserID="+app.globalData.userInfo.UserID+"&ScoreYear="+year+"&DistrictID="+districtID;
  113. }
  114. else{
  115. canSelect=true;
  116. var scoreTypeID=constant.arrScoreType[that.data.ScoreTypeID-1].Name;
  117. url="GetMPSScore?ScoreYear="+year+"&ScoreType="+scoreTypeID+"&DistrictID="+districtID;
  118. }
  119. if (canSelect){
  120. wx.showLoading({
  121. title: '加载中',
  122. });
  123. main.getData(url, function (data) {
  124. if (data) {
  125. for(var i=0;i<data.length;i++){
  126. var item=data[i];
  127. item.IsAccommodation=true;
  128. item.IsPublicOrPrivate=true;
  129. item.IsLocalOrNolocal=true;
  130. item.IsSearchResult=true;
  131. }
  132. // 是否住宿全部选中
  133. for(var i=0;i<constant.arrAccommodation.length;i++)
  134. constant.arrAccommodation[i].CSS="Selected";
  135. //若是高中收藏对比
  136. data=realData2(that,data);
  137. //名额到校将收藏初中提前显示
  138. data=realData(that,data);
  139. //将保存的用户习惯(显示列表样式)提取出来
  140. var isListAll=wx.getStorageSync('TailScore');
  141. if (isListAll){
  142. that.data.TailScore[0].CSS="Selected";
  143. }
  144. var pageCount=data.length;
  145. if (that.data.ScoreTypeID==3)
  146. pageCount=app.globalData.PageCount;
  147. //debugger;
  148. var isContrastNull=false;
  149. if (data.length==0 && that.data.SchoolCount>0)
  150. isContrastNull=true;
  151. that.setData({
  152. Accommodation:constant.arrAccommodation,
  153. List:data,
  154. IsSearch:false,
  155. IsListAll:isListAll,
  156. TailScore:that.data.TailScore,
  157. PageCount:pageCount,
  158. PageFilterCount:data.length,
  159. ContrastNull:isContrastNull,
  160. });
  161. }
  162. var timeTimeout=2000;
  163. if (that.data.ScoreTypeID==3 && that.data.DistrictID==11){
  164. timeTimeout=3000;
  165. if (app.globalData.IsAndroid)
  166. timeTimeout=4000;
  167. }
  168. setTimeout(function(){
  169. wx.hideLoading();
  170. },timeTimeout);
  171. });
  172. }
  173. function realData(obj,data){
  174. //名额到校将收藏初中提前显示
  175. if (obj.data.ScoreTypeID==3){
  176. //debugger;
  177. var schoolList=wx.getStorageSync('CollectList')["收藏的初中"];
  178. if (schoolList && schoolList.length>0){
  179. var arr=[];
  180. for(var i=0;i<data.length;i++){
  181. var item=data[i];
  182. for(var j=0;j<schoolList.length;j++){
  183. if (item.SchoolOfGraduation==schoolList[j].ID){
  184. item.IsCollect=true;
  185. arr.push(item);
  186. data.splice(i,1);
  187. i--;
  188. break;
  189. }
  190. }
  191. }
  192. if (arr.length>0){
  193. for(var i=arr.length-1;i>=0;i--){
  194. data.unshift(arr[i]);
  195. }
  196. }
  197. }
  198. }
  199. return data;
  200. }
  201. function realData2(obj,data){
  202. //若是高中收藏对比
  203. if (obj.data.SchoolType1=='高中' && obj.data.PageType=="collect"){
  204. var schoolList=wx.getStorageSync('CollectList')["收藏的高中"];
  205. for(var i=0;i<data.length;i++){
  206. var item=data[i];
  207. for(var j=0;j<schoolList.length;j++){
  208. if (item.ID==schoolList[j].ID){
  209. item.SchoolFullName=schoolList[j].SchoolFullName;
  210. item.District=schoolList[j].District;
  211. item.SchoolType2Short=schoolList[j].SchoolType2Short;
  212. item.PublicOrPrivate=schoolList[j].PublicOrPrivate;
  213. schoolList[j].IsExist=true;
  214. }
  215. }
  216. }
  217. var arr=[];
  218. for(var i=0;i<schoolList.length;i++){
  219. if (!schoolList[i].IsExist)
  220. arr.push(schoolList[i]);
  221. }
  222. obj.setData({
  223. ListNullData:arr,
  224. });
  225. var title="对比·"+obj.data.SchoolType1+"·"+obj.data.District[that.data.DistrictID-1].Name;
  226. wx.setNavigationBarTitle({
  227. title: title,
  228. });
  229. }
  230. return data;
  231. }
  232. },
  233. onPage: function (e) {
  234. var that=this;
  235. var count=that.data.PageCount;
  236. if (canPage && count<that.data.List.length){
  237. canPage=false
  238. count+=app.globalData.PageCount;
  239. that.setData({
  240. PageCount:count,
  241. });
  242. setTimeout(function(){
  243. canPage=true;
  244. },2000);
  245. }
  246. },
  247. onSelect:function(event){
  248. var that=this;
  249. main.onSelect(that,event,function(obj,e,result){
  250. //显示大图列表还是全部列表
  251. if (e.currentTarget.dataset.object=="TailScore"){
  252. wx.showLoading({
  253. title:"加载中",
  254. mask:true,
  255. });
  256. that.setData({
  257. IsListAll: result,
  258. });
  259. setTimeout(function(){
  260. wx.hideLoading();
  261. },2000);
  262. wx.setStorageSync('TailScore', result);
  263. }
  264. //选择年份
  265. else if (e.currentTarget.dataset.object=="Years"){
  266. if (that.data.PageType=="collect")
  267. that.data.DistrictID=-1;
  268. wx.redirectTo({
  269. url: 'scoreline?PageType='+that.data.PageType+'&SchoolType1='+that.data.SchoolType1+'&ScoreTypeID='+that.data.ScoreTypeID+'&DistrictID='+that.data.DistrictID+"&YearIndex="+e.currentTarget.dataset.index,
  270. });
  271. }
  272. //选择公办和民办
  273. else if (e.currentTarget.dataset.object=="PublicOrPrivate"){
  274. var selectIndex=e.currentTarget.dataset.index;
  275. var selectText=that.data.PublicOrPrivate[selectIndex].Name;
  276. var isSelect=that.data.PublicOrPrivate[selectIndex].CSS=="Selected";
  277. var isNull=true;
  278. for(var i=0;i<that.data.List.length;i++){
  279. var item=that.data.List[i];
  280. if (selectText==item.PublicOrPrivate)
  281. item.IsPublicOrPrivate=isSelect;
  282. if (item.IsPublicOrPrivate)
  283. isNull=false;
  284. }
  285. that.setData({
  286. List:that.data.List,
  287. SearchNull:isNull,
  288. });
  289. }
  290. //选择本地和非本地
  291. else if (e.currentTarget.dataset.object=="LocalOrNolocal"){
  292. var selectIndex=e.currentTarget.dataset.index;
  293. var isNull=true;
  294. for(var i=0;i<that.data.List.length;i++){
  295. var item=that.data.List[i];
  296. item.IsLocalOrNolocal=false;
  297. if (selectIndex==0)
  298. item.IsLocalOrNolocal=true;
  299. else if (selectIndex==1 && item.DistrictNameArea==constant.arrDistrict[that.data.DistrictID-1].Name)
  300. item.IsLocalOrNolocal=true;
  301. else if (selectIndex==2 && item.DistrictNameArea!=constant.arrDistrict[that.data.DistrictID-1].Name)
  302. item.IsLocalOrNolocal=true;
  303. }
  304. that.setData({
  305. List:that.data.List,
  306. });
  307. }
  308. //选择寄宿
  309. else if (e.currentTarget.dataset.object=="Accommodation"){
  310. var selectIndex=e.currentTarget.dataset.index;
  311. var selectText=that.data.Accommodation[selectIndex].Name;
  312. var isSelect=that.data.Accommodation[selectIndex].CSS=="Selected";
  313. var isNull=true;
  314. for(var i=0;i<that.data.List.length;i++){
  315. var item=that.data.List[i];
  316. if (selectText==item.Accommodation)
  317. item.IsAccommodation=isSelect;
  318. if (item.IsAccommodation)
  319. isNull=false;
  320. }
  321. that.setData({
  322. List:that.data.List,
  323. SearchNull:isNull,
  324. });
  325. }
  326. //选择区
  327. else if (e.currentTarget.dataset.object=="District"){
  328. that.setData({
  329. DistrictID:e.currentTarget.dataset.index+1,
  330. DistrictName:constant.arrDistrict[e.currentTarget.dataset.index].Name,
  331. });
  332. that.init();
  333. }
  334. });
  335. },
  336. showSearch:function(){
  337. var that=this;
  338. that.setData({
  339. IsSearch:true,
  340. IsFocus:true,
  341. });
  342. },
  343. clearInput:function(){
  344. var that=this;
  345. that.bindKeyInput({detail:{value:""}});
  346. that.setData({
  347. IsSearch:false,
  348. IsFocus:false,
  349. SearchNull:false,
  350. ContrastNull:false,
  351. });
  352. },
  353. clearInput2:function(){
  354. var that=this;
  355. that.bindKeyInput({detail:{value:""}});
  356. that.setData({
  357. IsSearch:true,
  358. IsFocus:true,
  359. });
  360. },
  361. bindKeyInput:function(e){
  362. var inputValue=e.detail.value;
  363. var that=this;
  364. var isNull=true;
  365. var count=0;
  366. for(var i=0;i<that.data.List.length;i++){
  367. var item=that.data.List[i];
  368. if (inputValue){
  369. if (item.SchoolFullNameJunior.indexOf(e.detail.value)>=0){
  370. item.IsSearchResult=true;
  371. count++;
  372. isNull=false;
  373. }
  374. else
  375. item.IsSearchResult=false;
  376. }
  377. else{
  378. item.IsSearchResult=true;
  379. count++;
  380. }
  381. }
  382. that.setData({
  383. List:that.data.List,
  384. SearchNull:isNull,
  385. InputValue:inputValue,
  386. PageFilterCount:count,
  387. });
  388. },
  389. goto: function (e) {
  390. main.goto(e);
  391. },
  392. returnTop:function(){
  393. main.returnTop();
  394. },
  395. onShareTimeline: function () {
  396. return this.onShareAppMessage();
  397. },
  398. onShareAppMessage: function () {
  399. var that=this;
  400. var title="上海中招"+that.data.Title;
  401. var path=app.globalData.SharePath+'?UserID=' + app.globalData.userInfo.UserID+'&type=scoreline&ScoreTypeID='+that.data.ScoreTypeID+'&ID=' + that.data.DistrictID+"&YearIndex="+that.data.YearIndex;
  402. if (that.data.PageType=="collect"){
  403. title=app.globalData.ShareTitle;
  404. path=app.globalData.SharePath+'?UserID=' + app.globalData.userInfo.UserID;
  405. }
  406. return {
  407. title: title,
  408. path: path,
  409. }
  410. }
  411. })