scoreline.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. if (that.data.DistrictID==11)//浦东太特殊,减少加载数量
  147. pageCount=50;
  148. else
  149. pageCount=app.globalData.PageCount;
  150. }
  151. //debugger;
  152. var isContrastNull=false;
  153. if (data.length==0 && that.data.SchoolCount>0)
  154. isContrastNull=true;
  155. if (data.length>0){
  156. that.setData({
  157. Accommodation:constant.arrAccommodation,
  158. List:data,
  159. IsSearch:false,
  160. IsListAll:isListAll,
  161. TailScore:that.data.TailScore,
  162. PageCount:pageCount,
  163. PageFilterCount:data.length,
  164. ContrastNull:isContrastNull,
  165. });
  166. }
  167. else{
  168. // wx.showModal({
  169. // title: '暂无公布',
  170. // showCancel:false,
  171. // content: '教育局暂未公布2024年1-15志愿信息,正式数据一般在7月公布,敬请期待。',
  172. // confirmText: '知道了',
  173. // complete: (res) => {
  174. // if (res.confirm) {
  175. // wx.redirectTo({
  176. // url: 'scoreline?PageType='+that.data.PageType+'&SchoolType1='+that.data.SchoolType1+'&ScoreTypeID='+that.data.ScoreTypeID+'&DistrictID='+that.data.DistrictID+"&YearIndex=1",
  177. // });
  178. // }
  179. // }
  180. // })
  181. }
  182. }
  183. var timeTimeout=2000;
  184. if (that.data.ScoreTypeID==3 && that.data.DistrictID==11){
  185. timeTimeout=3000;
  186. if (app.globalData.IsAndroid)
  187. timeTimeout=4000;
  188. }
  189. setTimeout(function(){
  190. wx.hideLoading();
  191. },timeTimeout);
  192. });
  193. }
  194. function realData(obj,data){
  195. //名额到校将收藏初中提前显示
  196. if (obj.data.ScoreTypeID==3){
  197. //debugger;
  198. var schoolList=wx.getStorageSync('CollectList')["收藏的初中"];
  199. if (schoolList && schoolList.length>0){
  200. var arr=[];
  201. for(var i=0;i<data.length;i++){
  202. var item=data[i];
  203. for(var j=0;j<schoolList.length;j++){
  204. if (item.SchoolOfGraduation==schoolList[j].ID){
  205. item.IsCollect=true;
  206. arr.push(item);
  207. data.splice(i,1);
  208. i--;
  209. break;
  210. }
  211. }
  212. }
  213. if (arr.length>0){
  214. for(var i=arr.length-1;i>=0;i--){
  215. data.unshift(arr[i]);
  216. }
  217. }
  218. }
  219. }
  220. return data;
  221. }
  222. function realData2(obj,data){
  223. //若是高中收藏对比
  224. if (obj.data.SchoolType1=='高中' && obj.data.PageType=="collect"){
  225. var schoolList=wx.getStorageSync('CollectList')["收藏的高中"];
  226. for(var i=0;i<data.length;i++){
  227. var item=data[i];
  228. for(var j=0;j<schoolList.length;j++){
  229. if (item.ID==schoolList[j].ID){
  230. item.SchoolFullName=schoolList[j].SchoolFullName;
  231. item.District=schoolList[j].District;
  232. item.SchoolType2Short=schoolList[j].SchoolType2Short;
  233. item.PublicOrPrivate=schoolList[j].PublicOrPrivate;
  234. schoolList[j].IsExist=true;
  235. }
  236. }
  237. }
  238. var arr=[];
  239. for(var i=0;i<schoolList.length;i++){
  240. if (!schoolList[i].IsExist)
  241. arr.push(schoolList[i]);
  242. }
  243. obj.setData({
  244. ListNullData:arr,
  245. });
  246. var title="对比·"+obj.data.SchoolType1+"·"+obj.data.District[that.data.DistrictID-1].Name;
  247. wx.setNavigationBarTitle({
  248. title: title,
  249. });
  250. }
  251. return data;
  252. }
  253. },
  254. onPage: function (e) {
  255. var that=this;
  256. var count=that.data.PageCount;
  257. if (canPage && count<that.data.List.length){
  258. canPage=false
  259. count+=app.globalData.PageCount;
  260. that.setData({
  261. PageCount:count,
  262. });
  263. setTimeout(function(){
  264. canPage=true;
  265. },2000);
  266. }
  267. },
  268. onSelect:function(event){
  269. var that=this;
  270. main.onSelect(that,event,function(obj,e,result){
  271. //显示大图列表还是全部列表
  272. if (e.currentTarget.dataset.object=="TailScore"){
  273. wx.showLoading({
  274. title:"加载中",
  275. mask:true,
  276. });
  277. that.setData({
  278. IsListAll: result,
  279. });
  280. setTimeout(function(){
  281. wx.hideLoading();
  282. },2000);
  283. wx.setStorageSync('TailScore', result);
  284. }
  285. //选择年份
  286. else if (e.currentTarget.dataset.object=="Years"){
  287. if (that.data.PageType=="collect")
  288. that.data.DistrictID=-1;
  289. wx.redirectTo({
  290. url: 'scoreline?PageType='+that.data.PageType+'&SchoolType1='+that.data.SchoolType1+'&ScoreTypeID='+that.data.ScoreTypeID+'&DistrictID='+that.data.DistrictID+"&YearIndex="+e.currentTarget.dataset.index,
  291. });
  292. }
  293. //选择公办和民办
  294. else if (e.currentTarget.dataset.object=="PublicOrPrivate"){
  295. var selectIndex=e.currentTarget.dataset.index;
  296. var selectText=that.data.PublicOrPrivate[selectIndex].Name;
  297. var isSelect=that.data.PublicOrPrivate[selectIndex].CSS=="Selected";
  298. var isNull=true;
  299. for(var i=0;i<that.data.List.length;i++){
  300. var item=that.data.List[i];
  301. if (selectText==item.PublicOrPrivate)
  302. item.IsPublicOrPrivate=isSelect;
  303. if (item.IsPublicOrPrivate)
  304. isNull=false;
  305. }
  306. that.setData({
  307. List:that.data.List,
  308. SearchNull:isNull,
  309. });
  310. }
  311. //选择本地和非本地
  312. else if (e.currentTarget.dataset.object=="LocalOrNolocal"){
  313. var selectIndex=e.currentTarget.dataset.index;
  314. var isNull=true;
  315. for(var i=0;i<that.data.List.length;i++){
  316. var item=that.data.List[i];
  317. item.IsLocalOrNolocal=false;
  318. if (selectIndex==0)
  319. item.IsLocalOrNolocal=true;
  320. else if (selectIndex==1 && item.DistrictNameArea==constant.arrDistrict[that.data.DistrictID-1].Name)
  321. item.IsLocalOrNolocal=true;
  322. else if (selectIndex==2 && item.DistrictNameArea!=constant.arrDistrict[that.data.DistrictID-1].Name)
  323. item.IsLocalOrNolocal=true;
  324. }
  325. that.setData({
  326. List:that.data.List,
  327. });
  328. }
  329. //选择寄宿
  330. else if (e.currentTarget.dataset.object=="Accommodation"){
  331. var selectIndex=e.currentTarget.dataset.index;
  332. var selectText=that.data.Accommodation[selectIndex].Name;
  333. var isSelect=that.data.Accommodation[selectIndex].CSS=="Selected";
  334. var isNull=true;
  335. for(var i=0;i<that.data.List.length;i++){
  336. var item=that.data.List[i];
  337. if (selectText==item.Accommodation)
  338. item.IsAccommodation=isSelect;
  339. if (item.IsAccommodation)
  340. isNull=false;
  341. }
  342. that.setData({
  343. List:that.data.List,
  344. SearchNull:isNull,
  345. });
  346. }
  347. //选择区
  348. else if (e.currentTarget.dataset.object=="District"){
  349. that.setData({
  350. DistrictID:e.currentTarget.dataset.index+1,
  351. DistrictName:constant.arrDistrict[e.currentTarget.dataset.index].Name,
  352. });
  353. that.init();
  354. }
  355. });
  356. },
  357. showSearch:function(){
  358. var that=this;
  359. app.globalData.TempParam=that.data.PageCount;
  360. that.setData({
  361. IsSearch:true,
  362. IsFocus:true,
  363. });
  364. },
  365. clearInput:function(){
  366. var that=this;
  367. that.bindKeyInput({detail:{value:""}});
  368. that.setData({
  369. IsSearch:false,
  370. IsFocus:false,
  371. SearchNull:false,
  372. ContrastNull:false,
  373. PageCount:app.globalData.TempParam,
  374. });
  375. },
  376. clearInput2:function(){
  377. var that=this;
  378. that.bindKeyInput({detail:{value:""}});
  379. that.setData({
  380. IsSearch:true,
  381. IsFocus:true,
  382. PageCount:app.globalData.TempParam,
  383. });
  384. },
  385. bindKeyInput:function(e){
  386. var inputValue=e.detail.value;
  387. var that=this;
  388. var isNull=true;
  389. var count=0;
  390. //debugger;
  391. for(var i=0;i<that.data.List.length;i++){
  392. var item=that.data.List[i];
  393. if (inputValue){
  394. if (item.SchoolFullNameJunior.indexOf(e.detail.value)>=0){
  395. item.IsSearchResult=true;
  396. count++;
  397. isNull=false;
  398. }
  399. else
  400. item.IsSearchResult=false;
  401. }
  402. else{
  403. item.IsSearchResult=true;
  404. count++;
  405. }
  406. }
  407. console.log("pagecount:"+that.data.PageCount);
  408. that.setData({
  409. List:that.data.List,
  410. SearchNull:isNull,
  411. InputValue:inputValue,
  412. PageFilterCount:count,
  413. PageCount:10000,
  414. });
  415. },
  416. goto: function (e) {
  417. if (e.currentTarget.dataset.url=="school?PageType=scoreline&ID="
  418. || e.currentTarget.dataset.url=="school?PageType=scoreline&ID=0")
  419. return null;
  420. else{
  421. app.globalData.FeedbackUrl="scoreline?PageType="+this.data.PageType+"&ScoreTypeID="+this.data.ScoreTypeID+"&DistrictID="+this.data.DistrictID;
  422. main.goto(e);
  423. }
  424. },
  425. returnTop:function(){
  426. main.returnTop();
  427. },
  428. onShareTimeline: function () {
  429. return this.onShareAppMessage();
  430. },
  431. onShareAppMessage: function () {
  432. var that=this;
  433. var title="上海中招"+that.data.Title;
  434. var path=app.globalData.SharePath+'?UserID=' + app.globalData.userInfo.UserID+'&type=scoreline&ScoreTypeID='+that.data.ScoreTypeID+'&ID=' + that.data.DistrictID+"&YearIndex="+that.data.YearIndex;
  435. if (that.data.PageType=="collect"){
  436. title=app.globalData.ShareTitle;
  437. path=app.globalData.SharePath+'?UserID=' + app.globalData.userInfo.UserID;
  438. }
  439. return {
  440. title: title,
  441. path: path,
  442. }
  443. }
  444. })