scoreline.js 13 KB

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