scoreline.js 12 KB

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