scoreline.js 15 KB

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