angular.app.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. app.controller('AppCtrl', [ '$rootScope', '$scope', '$http', '$localStorage', '$location', '$q', '$timeout', '$sce', function($rootScope, $scope, $http, $localStorage, $location, $q, $timeout, $sce) {
  2. $scope.StdReg = {};
  3. $scope.result = {};
  4. $scope.param = {};
  5. /***************************************************************************
  6. * Frame参数
  7. */
  8. $rootScope.frame = {
  9. CompanyName : '',
  10. FrameVersion : '2.0.0',
  11. WaitWindow : false
  12. };
  13. $rootScope.ArtStdReg = undefined;
  14. // 设置cookeis
  15. $rootScope.setLocalStorage = function(name, value) {
  16. $localStorage[name] = value;
  17. };
  18. // 获取cookies
  19. $rootScope.getLocalStorage = function(name) {
  20. return $localStorage[name];
  21. };
  22. // 内部跳转
  23. $rootScope.goLocation = function(url) {
  24. $location.path('app/' + url);
  25. };
  26. // 到首页
  27. $rootScope.goWechat = function(url) {
  28. window.location = './wechat.jsp';
  29. };
  30. $scope.closeWechat = function() {
  31. WeixinJSBridge.call('closeWindow');
  32. }
  33. $rootScope.showHtml = function(html) {
  34. var value = html.replace(/ /g, '&nbsp;').replace(/\n/g, '<br />');
  35. return $sce.trustAsHtml(value);
  36. }
  37. // Ajax统一请求函数
  38. $rootScope.ajaxRequest = function(params, fn) {
  39. if (params == undefined)
  40. params = {};
  41. if (params.data == undefined)
  42. params.data = {};
  43. if ($rootScope.ArtStdReg != undefined)
  44. params.data.std_id = $rootScope.ArtStdReg.std_id;
  45. var params = angular.extend({
  46. method : 'post'
  47. }, params);
  48. $http(params).then(function onSuccess(response) {
  49. // $.hideLoading();
  50. if (response == undefined)
  51. console.log(params);
  52. fn.call(undefined, response.data);
  53. });
  54. };
  55. // 将date转换成长时间串
  56. $rootScope.isAfterTime = function(date, now) {
  57. if (now == undefined)
  58. now = new Date();
  59. if (!angular.isDate(date))
  60. date = $rootScope.parseLongString(date);
  61. console.log(date.getTime() - now.getTime());
  62. return date.getTime() > now.getTime();
  63. };
  64. // 将date转换成长时间串
  65. $rootScope.longDateString = function(date) {
  66. if (date == undefined)
  67. date = new Date();
  68. if (angular.isDate(date))
  69. return date.toJSON();
  70. return "";
  71. };
  72. // 将date转换成长时间串
  73. $rootScope.longMinuteString = function(date) {
  74. return $rootScope.longDateString(date).substr(0, 15);
  75. };
  76. // 将日期转换成短时间串
  77. $rootScope.shortDateString = function(date) {
  78. if (date == undefined)
  79. return "";
  80. if (angular.isDate(date))
  81. date = date.toJSON();
  82. if (date.length > 10)
  83. return date.substr(0, 10);
  84. return date;
  85. };
  86. // 获取日期的时间串
  87. $rootScope.shortTimeString = function(date) {
  88. if (date == undefined)
  89. return "";
  90. if (angular.isDate(date))
  91. date = date.toJSON();
  92. if (date.length > 10)
  93. return date.substr(11, 5);
  94. return date;
  95. }
  96. // 将短日期时间串转换成日期
  97. $rootScope.parseShortString = function(date) {
  98. if (date == undefined)
  99. date = new Date();
  100. var str = $rootScope.shortDateString(date);
  101. return new Date(Date.parse(str.replace(/-/g, "/")));
  102. }
  103. // 将长时间串转化成日期
  104. $rootScope.parseLongString = function(date) {
  105. if (angular.isDate(date))
  106. return date;
  107. if (date == undefined || date.length != 19)
  108. return undefined;
  109. return new Date(Date.parse(date.replace(/-/g, "/")));
  110. }
  111. // 获取url参数
  112. $rootScope.GetQueryString = function(name) {
  113. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  114. var r = window.location.search.substr(1).match(reg);
  115. if (r != null)
  116. return unescape(r[2]);
  117. return null;
  118. };
  119. $rootScope.initWinxinApi = function() {
  120. $rootScope.ajaxRequest({
  121. url : '../enrol/wx/config.htm',
  122. data : {
  123. url : location.href.split('#')[0]
  124. }
  125. }, function(data) {
  126. var obj = angular.extend({
  127. debug : false
  128. }, data.entity, {
  129. jsApiList : [ 'checkJsApi', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'translateVoice', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'onVoicePlayEnd', 'pauseVoice', 'stopVoice', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard' ]
  130. });
  131. wx.error(function(res) {
  132. // 加载直到成功为止
  133. $rootScope.initWinxinApi();
  134. return false;
  135. });
  136. wx.config(obj);
  137. wx.ready(function() {
  138. wx.hideOptionMenu();
  139. wx.hideAllNonBaseMenuItem();
  140. });
  141. });
  142. };
  143. $rootScope.getParamValue = function(paran_name, default_value) {
  144. if ($rootScope.FrameParam[paran_name] == undefined)
  145. return default_value;
  146. return $rootScope.FrameParam[paran_name];
  147. }
  148. $rootScope.checkParamValue = function(param_name, default_value, check_value) {
  149. var value = $rootScope.getParamValue(param_name, default_value);
  150. if ((value + '') == (check_value + ''))
  151. return true;
  152. return false;
  153. }
  154. $rootScope.InitStatus = false;
  155. $rootScope.loginSuccess = false;
  156. $rootScope.getUserInfo = function() {
  157. // 请求用户信息
  158. $.ajax({
  159. url : '../enrol/wx/user/info.htm',
  160. async : false,
  161. type : "POST",
  162. dataType : "json",
  163. data : {
  164. code : $rootScope.GetQueryString('code')
  165. },
  166. success : function(data) {
  167. $.hideLoading();
  168. if (data.success == false) {
  169. $.alert(data.errorMsg, function() {
  170. WeixinJSBridge.call('closeWindow');
  171. });
  172. // if(data.login == false) {
  173. // $.alert("微信加载出现问题,请退出重新进入公众号!", function() {
  174. // WeixinJSBridge.call('closeWindow');
  175. // });
  176. // return;
  177. // }else {
  178. // $.alert(data.errorMsg, function() {
  179. // WeixinJSBridge.call('closeWindow');
  180. // });
  181. // return;
  182. // }
  183. return;
  184. }
  185. // 初始化成功
  186. $rootScope.InitStatus = true;
  187. $rootScope.loginSuccess = true;
  188. // 初始化参数信息
  189. $rootScope.FrameParam = {};
  190. angular.forEach(data.map.FrameParamArray, function(param) {
  191. $rootScope.FrameParam[param.param_name] = param.param_value;
  192. });
  193. $rootScope.StdTypeArray = data.map.StdTypeArray;
  194. // 设置微信抬头
  195. if ($rootScope.FrameParam.EnrolTitle) {
  196. document.title = $rootScope.FrameParam.EnrolTitle;
  197. }
  198. // 判断当前考务状态
  199. if ($rootScope.FrameParam.ArtStatus == 'Config') {
  200. // 未开放报名,
  201. $rootScope.InitStatus = false;
  202. WeixinJSBridge.call('closeWindow');
  203. return;
  204. }
  205. $rootScope.ArtStdReg = data.map.StdReg;
  206. $rootScope.WxUser = data.map.WxUser;
  207. // --std_info
  208. if (data.map.StdReg != undefined) {
  209. // 处理考生信息
  210. if (data.map.StdReg.reg_status == 'IdCard') {
  211. // 上传了证件照片
  212. $rootScope.goLocation('std/reg');
  213. } else if (data.map.StdReg.reg_status == 'NoCrownPhoto') {
  214. // 上传免冠照片
  215. $rootScope.goLocation('std/reg');
  216. } else if (data.map.StdReg.std_score_file == 'firstLogin') {
  217. $rootScope.goLocation('std/info');
  218. } else {
  219. $rootScope.goLocation('main');
  220. }
  221. } else {
  222. if ($rootScope.FrameParam.AllowStdReg == 'InActive') {
  223. // 不允许考生自行注册
  224. if($rootScope.FrameParam.GeneralExam == 'Active') {
  225. $rootScope.goLocation('std/wybinding');
  226. } else {
  227. $rootScope.goLocation('std/binding');
  228. }
  229. } else {
  230. $rootScope.goLocation('std/reg');
  231. }
  232. return;
  233. }
  234. },
  235. error : function(data) {
  236. }
  237. });
  238. }
  239. $rootScope.getJudgerInfo = function() {
  240. $.ajax({
  241. url : '../judge/wx/judger/info.htm',
  242. async : false,
  243. type : "POST",
  244. dataType : "json",
  245. data : {
  246. code : $rootScope.GetQueryString('code')
  247. },
  248. success : function(data) {
  249. $.hideLoading();
  250. if (data.success == false) {
  251. $.alert(data.errorMsg, function() {
  252. WeixinJSBridge.call('closeWindow');
  253. });
  254. return;
  255. }
  256. // 初始化成功
  257. $rootScope.InitStatus = true;
  258. $rootScope.loginSuccess = true;
  259. // 初始化参数信息
  260. $rootScope.FrameParam = {};
  261. angular.forEach(data.map.FrameParamArray, function(param) {
  262. $rootScope.FrameParam[param.param_name] = param.param_value;
  263. });
  264. $rootScope.WxUser = data.map.WxUser;
  265. if (data.map.WxUser) {
  266. $rootScope.goLocation('judge');
  267. }
  268. /*
  269. * else{ $rootScope.goLocation('judge/binding'); }
  270. */
  271. },
  272. error : function(data) {
  273. }
  274. });
  275. }
  276. // $rootScope.initWinxinApi();
  277. // if (location.search.indexOf('?judge') != -1) {
  278. // $rootScope.getJudgerInfo();
  279. // } else {
  280. // $rootScope.getUserInfo();
  281. // }
  282. $rootScope.isProvinceStd = function() {
  283. if ($rootScope.ArtStdReg.std_province == $rootScope.FrameParam.SchoolProvince)
  284. return true;
  285. return false;
  286. }
  287. $rootScope.getTimeName = function(time_type) {
  288. if (time_type + '' == '1')
  289. return '上午';
  290. else if (time_type + '' == '2')
  291. return '下午';
  292. if (time_type + '' == '3')
  293. return '晚上';
  294. else
  295. return time_type;
  296. }
  297. $rootScope.uploadStdMaterial = function(material_type, fn, enrol_id) {
  298. wx.chooseImage({
  299. count : 1, // 默认9
  300. sizeType : [ 'compressed' ], // 可以指定是原图还是压缩图,默认二者都有'original',
  301. sourceType : [ 'album', 'camera' ], // 可以指定来源是相册还是相机,默认二者都有
  302. success : function(res) {
  303. var localIds = res.localIds;
  304. wx.uploadImage({
  305. localId : localIds[0], // 需要上传的图片的本地ID,由chooseImage接口获得
  306. isShowProgressTips : 1, // 默认为1,显示进度提示
  307. success : function(serverRes) {
  308. var serverId = serverRes.serverId; // 返回图片的服务器端ID
  309. $.showLoading("考生材料上传中,请稍候...")
  310. // 上传成功,去服务器取图片
  311. var vData = {
  312. std_id : $rootScope.ArtStdReg.std_id,
  313. media_id : serverId,
  314. material_type : material_type
  315. };
  316. if (enrol_id)
  317. vData.enrol_id = enrol_id;
  318. $rootScope.ajaxRequest({
  319. url : '../enrol/std/material/upload.htm',
  320. method : 'post',
  321. data : vData
  322. }, function(data) {
  323. $.hideLoading();
  324. $rootScope[material_type] = data.entity;
  325. if (material_type == 'NoCrownPhoto') {
  326. $rootScope.ArtStdReg.std_image = data.entity.material_file;
  327. }
  328. if (fn)
  329. fn.call(undefined, data);
  330. });
  331. },
  332. fail : function(error) {
  333. $.alert('图片服务器暂时无法访问,请稍侯再试', '错误提示');
  334. }
  335. });
  336. }
  337. });
  338. }
  339. $rootScope.getParam = function() {
  340. $rootScope.ajaxRequest({
  341. url: '../wish/std/get/param.htm',
  342. method: 'post'
  343. },function(data) {
  344. $scope.param = data;
  345. });
  346. }
  347. $rootScope.getParam();
  348. $rootScope.searchStd = function() {
  349. var url = '../wish/std/search/all.htm';
  350. if($scope.param.map.schoolCode === '10331') {
  351. url = 'wish/std/searchNy.htm';
  352. }
  353. $rootScope.ajaxRequest({
  354. url : url,
  355. method : 'post',
  356. data : $scope.StdReg
  357. },function(data) {
  358. if(!data.map) {
  359. $scope.currStep = "noAdmis";
  360. $scope.result.std_name = $scope.StdReg.std_name;
  361. } else {
  362. $scope.currStep = "admis";
  363. $scope.result = data.map;
  364. }
  365. });
  366. }
  367. } ]);