mainCtrl.js 129 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174
  1. 'use strict';
  2. /**
  3. * Clip-Two Main Controller
  4. */
  5. app.controller('AppCtrl', ['$rootScope', '$scope', '$state', '$translate', '$localStorage', '$cookieStore', '$window', '$modal', '$document', '$timeout', '$filter', '$auth', 'cfpLoadingBar', 'DDP', 'deskNotification', 'Restangular', 'api_login', 'api_text', 'api_user_data', 'api_wechatfile', 'api_bpm_data', 'api_msg', 'Myservice', '$interval', 'jry_api_bpm',
  6. function ($rootScope, $scope, $state, $translate, $localStorage, $cookieStore, $window, $modal, $document, $timeout, $filter, $auth, cfpLoadingBar, DDP, deskNotification, Restangular, api_login, api_text, api_user_data, api_wechatfile, api_bpm_data, api_msg, Myservice, $interval, jry_api_bpm) {
  7. // 未读消息数量seimin
  8. $rootScope.getMsgNum = function (id) {
  9. api_msg.msgDataList({ idx: 0, sum: 1, messageStation: { readStatus: 0, userId: id } }).then(function (data) {
  10. if (data.status == 200) {
  11. $rootScope.noReadData = data.totalNum;
  12. }
  13. return $rootScope.noReadData
  14. })
  15. }
  16. // Loading bar transition
  17. // -----------------------------------
  18. // console.log("haha");
  19. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  20. $rootScope.isFuwutai = JSON.parse(localStorage.getItem("isFuwutai")) ? true : false;
  21. console.log($rootScope.user)
  22. if ($rootScope.user) {
  23. $rootScope.getMsgNum($rootScope.user.id);
  24. }
  25. var $win = $($window);
  26. $rootScope.isMask = false;
  27. window.onbeforeunload = function () {
  28. $rootScope.statuscall = 0;
  29. $rootScope.statecall = 1;
  30. }
  31. // 所有列表自动刷新
  32. $rootScope.refreshTime = 30000;
  33. $interval(function () {
  34. $scope.jry_year = new Date().getFullYear();
  35. $scope.jry_month = new Date().getMonth() + 1;
  36. $scope.jry_data = new Date().getDate();
  37. $scope.jry_hours = new Date().getHours();
  38. $scope.jry_minute = new Date().getMinutes();
  39. $scope.jry_second = new Date().getSeconds();
  40. // console.log($scope.jry_month)
  41. }, 1000)
  42. // $win.on('beforeunload', function() { return $state.go("login.signin"); });
  43. // $auth.deleteData('auth_headers')
  44. // }
  45. // 监听路由
  46. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  47. console.log(event, toState, toParams, fromState, fromParams)
  48. // 修改密码验证
  49. // if((fromState.name != 'login.signin' || toState.name != 'login.signin') && localStorage.getItem('isSSo') === '0' && localStorage.getItem('isOverTime') === '1'){
  50. // $rootScope.changepassword(true);
  51. // }
  52. if ((toState.name == 'app.incident.chart' || toState.name == 'app.incident.editor') &&
  53. fromState.name) {
  54. console.log($rootScope.jry_state);
  55. $scope.isShixian = false;
  56. if($rootScope.jry_state == 'shixian'){
  57. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  58. //进入页面强制示忙
  59. if (tlwsa) {
  60. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  61. setTimeout(()=>{
  62. tlwsa.tlaAcw();
  63. },0)
  64. }
  65. }
  66. }
  67. if ((fromState.name == 'app.incident.chart' || fromState.name == 'app.incident.editor') &&
  68. toState.name != 'app.incident.chart' && toState.name != 'app.incident.editor'
  69. ) {
  70. console.log($rootScope.jry_state);
  71. // $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  72. //进入页面强制示闲
  73. $scope.isShixian = true;
  74. if (tlwsa) {
  75. // tlwsa.tlaForcewca($rootScope.phoneNumber);
  76. setTimeout(()=>{
  77. tlwsa.tlaWca();
  78. },0)
  79. }
  80. }
  81. if(toState.name == 'app.incident.list'){
  82. sessionStorage.removeItem('searchincident');
  83. }
  84. if (isEmpty($auth.retrieveData('auth_headers'))) {
  85. // if (toState.name != "login.signin" && toState.name != "echart") {
  86. // event.preventDefault();
  87. // $rootScope.app.isLoginFixed = true;
  88. // // $scope.lodingstyle = 'nodata';
  89. // return $state.go("login.signin");
  90. // }
  91. }
  92. // if (toState.name == "app.system.user.user") {
  93. // var isgoto = false;
  94. // if ($rootScope.user && $rootScope.user.menu) {
  95. // angular.forEach($rootScope.user.menu, function(item) {
  96. // if (item.link == toState.name) {
  97. // isgoto = true;
  98. // } else {}
  99. // })
  100. // }
  101. // if (isgoto) {
  102. // } else {
  103. // $state.go("app.dashboard");
  104. // }
  105. // }
  106. // if (toState.name != "app.incident.editor" && toState.name != "echart") {
  107. // if ($rootScope.status == 2 || $rootScope.status == 4 || $rootScope.status == 9) {
  108. // $rootScope.setidle();
  109. // }
  110. // }
  111. cfpLoadingBar.start();
  112. $auth.validateUser();
  113. });
  114. $rootScope.imUsrMap = {};
  115. $rootScope.onlineUser = [];
  116. $rootScope.offlineUser = [];
  117. $rootScope.me = undefined;
  118. $rootScope.imscope = {
  119. sessions: []
  120. }
  121. // var ws = new WebSocket('ws://192.168.3.51:8088/events');
  122. // var register= {"msgtype":"login","adn":"1001"};
  123. // ws.onopen = function() { ws.send(JSON.stringify(register));}
  124. // ws.onmessage = function(evt) { console.log(evt.data) }
  125. var ddp = new DDP('ws://115.156.150.70:3000/websocket');
  126. $rootScope.getDirectMsgRoomId = function (mdId, toId) {
  127. //me.id,to.id
  128. var rid = [mdId, toId].sort().join('');
  129. return rid;
  130. };
  131. $rootScope.sendMessage = function (rid, msg, callback, error) {
  132. ddp.call('sendMessage', [{ 'rid': rid, 'msg': msg }]).then(callback, error);
  133. };
  134. var pushNotification = function (notification) {
  135. deskNotification.showNotification(notification.title, {
  136. body: notification.body,
  137. icon: notification.icon || '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  138. onClick: notification.callback || function onNotificationClicked() {
  139. // console.log('Notification clicked.');
  140. },
  141. autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
  142. }, function onShow(error, hide) {
  143. if (error) {
  144. window.alert('Unable to show notification: ' + error.message);
  145. } else {
  146. // console.log('Notification Shown.');
  147. setTimeout(function hideNotification() {
  148. // console.log('Hiding notification....');
  149. hide(); //manually close the notification (you can skip this if you use the autoClose option)
  150. }, 5000);
  151. }
  152. });
  153. }
  154. // $rootScope.subscribeRoomMessage = function(rid){
  155. // ddp.subscribe('stream-room-messages',[rid, true]).then(function(){},function(reason){
  156. // console.log('subscribe stream-room-messages:%o', reason);
  157. // });
  158. // }
  159. $rootScope.filternotifyuser = [];
  160. $rootScope.$on('openroom', function (event, data, otheruser) {
  161. ddp.call('createDirectMessage', [otheruser]).then(function () { }, function (reason) {
  162. // console.log('createDirectMessage', reason);
  163. });
  164. ddp.subscribe('stream-room-messages', [data.rid, true]).then(function () { }, function (reason) {
  165. // console.log('subscribe stream-room-messages:%o', reason);
  166. });
  167. if ($rootScope.imUsrMap[data.from]['unread'].msgs) {
  168. $rootScope.imUsrMap[data.from]['unread'].msgs.clear;
  169. }
  170. $rootScope.filternotifyuser.push(data.from);
  171. });
  172. $rootScope.$on("clip-two.toggled", function (e, target, newState, sameGroup) {
  173. console.log(newState)
  174. if (newState == false && target == 'off-sidebar') {
  175. $rootScope.$broadcast('chatcloseroom');
  176. //$rootScope.toggle("users");
  177. //$rootScope.filternotifyuser = [];
  178. //ddp.unsubscribe('stream-room-messages');
  179. }
  180. });
  181. $rootScope.$on("closeroom", function (event, data) {
  182. $rootScope.filternotifyuser = [];
  183. ddp.unsubscribe('stream-room-messages');
  184. });
  185. var initImUser = function (email, token) {
  186. var ddpconnect = ddp.connect();
  187. ddpconnect.then(function (data) {
  188. //console.log(data);
  189. if (data.session) {
  190. // ddp.call('createDirectMessage', [data.from, data.rid]).then(function() {}, function(reason) {
  191. // console.log('subscribe createDirectMessage');
  192. // });
  193. ddp.call('login', [{ user: { email: email }, password: token }]).then(function (data) {
  194. // console.log('login data: %o', data);
  195. if (data.id) {
  196. $rootScope.me = {
  197. id: data.id,
  198. token: data.token,
  199. expiry: data.tokenExpires
  200. };
  201. //获取在线用户
  202. ddp.subscribe('activeUsers');
  203. ddp.subscribe('stream-notify-user', [$rootScope.me.id + '/notification', true]).then(function (result) {
  204. //console.log(result);
  205. }, function (reason) {
  206. // console.log('stream-notify-user error:%s', reason);
  207. });
  208. // ddp.subscribe('stream-notify-user',[$rootScope.me.id+'/message',false]).then(function(result){
  209. // console.log(result);
  210. // },function(reason){
  211. // console.log('stream-notify-user error:', reason);
  212. // });
  213. ddp.subscribe('messages', [$rootScope.me.id + '/message', true]).then(function () { }, function (reason) {
  214. // console.log('subscribe messages error:%s', reason);
  215. });
  216. //'stream-notify-user',$rootScope.me.id+'/message'
  217. // ddp.call('sendmessage', []).then(function(msg){
  218. // })
  219. //console.log('Logged in!');
  220. // ddp.subscribe('messages', [{rid:data.id,start:new Date()}]).then(function(submsg){
  221. // console.log('subscribe messages-%s', submsg);
  222. // $rootScope.rocketchat_message = ddp.getCollection('rocketchat_message');
  223. // },function(reason){
  224. // console.log(reason);
  225. // })
  226. }
  227. }, function (reason) {
  228. // console.log(reason);
  229. });
  230. } else {
  231. }
  232. ddp.watch('users', function (changedDoc, message) {
  233. //console.log('users:%o',changedDoc);
  234. // if (message == 'method') {
  235. // console.log("1111111111111111111")
  236. // }
  237. if (message == 'added') {
  238. if (changedDoc.status && ($rootScope.me.id != changedDoc._id)) {
  239. if (changedDoc.status == 'away') {
  240. $rootScope.offlineUser.push(changedDoc);
  241. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  242. } else {
  243. $rootScope.onlineUser.push(changedDoc);
  244. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  245. }
  246. } else {
  247. //self
  248. }
  249. } else if (message == 'changed') {
  250. if ($rootScope.me.id != changedDoc._id) {
  251. if (!$rootScope.imUsrMap[changedDoc._id]) {
  252. if (changedDoc.status == 'away') {
  253. $rootScope.offlineUser.push(changedDoc);
  254. $rootScope.imUsrMap[changedDoc._id] = { state: 'away', username: changedDoc.username, index: $rootScope.offlineUser.length - 1, unread: { total: 0, msgs: [] } };
  255. } else {
  256. $rootScope.onlineUser.push(changedDoc);
  257. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length - 1, unread: { total: 0, msgs: [] } };
  258. }
  259. }
  260. if (changedDoc.status == 'away') {
  261. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  262. } else {
  263. $rootScope.offlineUser.push(changedDoc);
  264. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  265. window._.map(window._.slice($rootScope.onlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  266. $rootScope.imUsrMap[item._id].index = n;
  267. })
  268. // $rootScope.onlineUser = window._.take($rootScope.onlineUser,$rootScope.imUsrMap[changedDoc._id].index).concat(window._.map(window._.slice($rootScope.onlineUser,$rootScope.imUsrMap[changedDoc._id].index+1),function(item){
  269. // item.index = item.index - 1;
  270. // }))
  271. //.splice($rootScope.imUsrMap[changedDoc.id].index,1);
  272. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.offlineUser.length };
  273. }
  274. } else {
  275. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  276. $rootScope.onlineUser.push(changedDoc);
  277. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  278. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  279. $rootScope.imUsrMap[item._id].index = n;
  280. })
  281. // $rootScope.offlineUser = window._.take($rootScope.offlineUser,$rootScope.imUsrMap[changedDoc._id].index).concat(window._.map(window._.slice($rootScope.offlineUser,$rootScope.imUsrMap[changedDoc._id].index+1),function(item){
  282. // item.index = item.index - 1;
  283. // }))
  284. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length };
  285. } else {
  286. }
  287. }
  288. }
  289. } else if (message == 'removed') {
  290. if ($rootScope.imUsrMap[changedDoc._id].state == 'away') {
  291. } else {
  292. $rootScope.onlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  293. $rootScope.offlineUser.splice($rootScope.imUsrMap[changedDoc._id].index, 1);
  294. window._.map(window._.slice($rootScope.offlineUser, $rootScope.imUsrMap[changedDoc._id].index), function (item, n) {
  295. $rootScope.imUsrMap[item._id].index = n;
  296. });
  297. $rootScope.imUsrMap[changedDoc._id] = { state: changedDoc.status, username: changedDoc.username, index: $rootScope.onlineUser.length, unread: { total: 0, msgs: [] } };
  298. }
  299. }
  300. });
  301. ddp.watch('stream-notify-user', function (changedDoc, message) {
  302. if (message == 'changed') {
  303. if (changedDoc.eventName) {
  304. if (changedDoc.eventName.indexOf('/') > -1) {
  305. var [mineId, action] = changedDoc.eventName.split('/');
  306. if (action == 'notification') {
  307. angular.forEach(changedDoc.args, function (item) {
  308. if ($rootScope.filternotifyuser.indexOf(item.payload.sender._id) > -1) {
  309. } else {
  310. // console.log("push notify message:%o", item);
  311. var r = angular.extend(item, { 'date': new Date() })
  312. $rootScope.imUsrMap[item.payload.sender._id]['unread'].msgs.push(r);
  313. $rootScope.imUsrMap[item.payload.sender._id]['unread'].total++;
  314. pushNotification({
  315. title: "您有新消息-来自" + item.payload.sender.username,
  316. body: r.text,
  317. callback: function () {
  318. window.focus();
  319. $rootScope.toggle('off-sidebar');
  320. }
  321. })
  322. //toaster.pop('info', "您有新消息-来自"+item.payload.sender.username, r.text);
  323. }
  324. })
  325. }
  326. }
  327. }
  328. } else {
  329. }
  330. //console.log('notify message %o, %o', changedDoc, message);
  331. });
  332. ddp.watch('stream-room-messages', function (changedDoc, message) {
  333. if (message == 'changed') {
  334. //angular.forEach(changedDoc.args,function(item){
  335. $rootScope.$broadcast(changedDoc.eventName + '-msgs', changedDoc.args);
  336. //};
  337. // if(changedDoc.eventName){
  338. // $rootScope.imUsrMap[eventName]=$rootScope.imUsrMap[eventName]||{};
  339. // $rootScope.imUsrMap[eventName]['msgs']=$rootScope.imUsrMap[eventName]['msgs']||[];
  340. // angular.forEach(changedDoc.args,function(item){
  341. // $rootScope.imUsrMap[eventName].msgs.push(item);
  342. // })
  343. // }
  344. } else {
  345. }
  346. // console.log('notify message %o, %o', changedDoc, message);
  347. });
  348. ddp.watch('rocketchat_message', function (changedDoc, message) {
  349. // console.log('recieve rocketchat_message: %o-%o', changedDoc, message);
  350. });
  351. });
  352. }
  353. window.onunload = function () {
  354. }
  355. $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
  356. //$auth.validateUser();
  357. //stop loading bar on stateChangeSuccess
  358. event.targetScope.$watch("$viewContentLoaded", function () {
  359. cfpLoadingBar.complete();
  360. });
  361. // scroll top the page on change state
  362. $document.scrollTo(0, 0);
  363. if (angular.element('.email-reader').length) {
  364. angular.element('.email-reader').animate({
  365. scrollTop: 0
  366. }, 0);
  367. }
  368. // Save the route title
  369. $rootScope.currTitle = $state.current.title;
  370. if (angular.isDefined($state.current.pdKey)) {
  371. $rootScope.pdKey = $state.current.pdKey;
  372. }
  373. // console.log($state.current.title);
  374. });
  375. // State not found
  376. $rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) {
  377. //$rootScope.loading = false;
  378. if (angular.isUndefined($rootScope.user.id)) {
  379. $rootScope.loading = false;
  380. }
  381. // console.log(unfoundState.to);
  382. // "lazy.state"
  383. // console.log(unfoundState.toParams);
  384. // {a:1, b:2}
  385. // console.log(unfoundState.options);
  386. // {inherit:false} + default options
  387. });
  388. $rootScope.isMousedown = false;
  389. $rootScope.changeRemoveClass = function (e) {
  390. $rootScope.isMousedown = true
  391. }
  392. $rootScope.returnRemoveClass = function (e) {
  393. $rootScope.isMousedown = false;
  394. }
  395. $rootScope.$on('auth:login-success', function (ev, data) {
  396. // $state.go('login.signin');
  397. initImUser(data.email, data.msgUuid);
  398. getMenus();
  399. //console.log(data);
  400. //$rootScope.user = data.user;
  401. //$rootScope.menus = data.menu;
  402. });
  403. //$rootScope.$watch('$auth.user')
  404. // $rootScope.$on('auth:validation-success', function(ev, user) {
  405. // // console.log(user);
  406. // initImUser(user.email, user.msgUuid);
  407. // if ($rootScope.userMenus.length == 0) {
  408. // getMenus();
  409. // }
  410. // //alert('Welcome ', user.email);
  411. // });
  412. // $rootScope.$on('auth:invalid', function(ev) {
  413. // $state.go('login.signin');
  414. // });
  415. // $rootScope.$on('auth:validation-error', function(ev) {
  416. // $state.go('login.signin');
  417. // //alert('Welcome ', user.email);
  418. // });
  419. // $rootScope.$on('auth:session-expired', function(ev) {
  420. // //alert('Welcome ', user.email);
  421. // $state.go('login.signin');
  422. // });
  423. // $rootScope.$on('auth:logout-success', function(ev) {
  424. // //alert('goodbye');
  425. // //delete $rootScope.user;
  426. // //delete $rootScope.menus;
  427. // $state.go('login.signin');
  428. // });
  429. // $rootScope.$on('auth:logout-error', function(ev) {
  430. // $state.go('login.signin');
  431. // });
  432. $rootScope.pageTitle = function () {
  433. // if($rootScope.currTitle){
  434. // return $rootScope.app.name + ' - ' + $filter('translate')($rootScope.currTitle) || $rootScope.app.description;
  435. // }else{
  436. // return $rootScope.app.name + ' - ' + $rootScope.app.description
  437. // }
  438. var perfix = "sidebar.nav.";
  439. var toTransKeypageTitle = perfix + $rootScope.currTitle;
  440. return $rootScope.app.name + ' - ' + ($filter('translate')(toTransKeypageTitle) || $rootScope.app.description);
  441. };
  442. // $auth.validateUser();
  443. // $auth.authenticate('local').then(function(resp){
  444. // }).catch(function(resp){
  445. // })
  446. // if(angular.isDefined($rootScope.nickname)){
  447. // api_login.sso($rootScope.nickname).then(function(response){
  448. // var user = Restangular.stripRestangular(response);
  449. // if (user) {
  450. // if(angular.isUndefined(user.id)){
  451. // }else{
  452. // $rootScope.user = user;
  453. // }
  454. // }
  455. // });
  456. // }else{
  457. // var user= $cookieStore.get("userObm");
  458. // if(user){
  459. // $rootScope.user = user;
  460. // $rootScope.menus = $cookieStore.get("menuObm");
  461. // }else{
  462. // if(angular.isDefined($rootScope.nickname)){
  463. // api_login.sso($rootScope.nickname).then(function(response){
  464. // var data = Restangular.stripRestangular(response);
  465. // if (data) {
  466. // if(data.user){
  467. // if(angular.isUndefined(data.user.id)){
  468. // }else{
  469. // $rootScope.user = data.user;
  470. // $rootScope.menus = data.menu;
  471. // $cookieStore.put("userObm", $rootScope.user);
  472. // $cookieStore.put("menuObm", $rootScope.menus);
  473. // $cookieStore.put("session", data.sessionId);
  474. // }
  475. // }
  476. // }
  477. // });
  478. // }else{
  479. // }
  480. // }
  481. //}
  482. //选择坐席号
  483. $scope.changeWorkId = function () {
  484. event.stopPropagation();
  485. }
  486. $rootScope.getSession = function () {
  487. if ($auth.userIsAuthenticated()) {
  488. return $auth.retrieveData('auth_headers')
  489. /*return {
  490. 'access-token':$auth.retrieveData('auth_headers')['access-token'],
  491. 'expiry':$auth.retrieveData('auth_headers')['expiry']
  492. };*/
  493. } else {
  494. return undefined;
  495. }
  496. }
  497. $scope.includes = [];
  498. $rootScope.includesState = function (state) {
  499. //for test
  500. //return true;
  501. //return includes;
  502. if ($rootScope.user) {
  503. if ($rootScope.user.menu) {
  504. angular.forEach($rootScope.user.menu, function (item) {
  505. $scope.includes[item.link] = true;
  506. });
  507. }
  508. }
  509. return $scope.includes[state];
  510. }
  511. //大屏入口
  512. $rootScope.opendashbord = function () {
  513. $state.go('echart');
  514. }
  515. // $rootScope.authority=false;
  516. // console.log($rootScope.user)
  517. // if($rootScope.user.role){
  518. // for(var i ;i<$rootScope.user.role.length;i++){
  519. // if($rootScope.user.role[i].rolecode=='call center') {
  520. // $rootScope.authority=true;
  521. // }else{$rootScope.authority=false;}
  522. // }
  523. // }
  524. /* status[已签入:1/通话中:3/来电:2],state[示闲:1,示忙:2] */
  525. // if (window.location.href && window.location.href.hash == "#/echart") {
  526. // } else {
  527. // // }
  528. // // 东经呼叫中心开始
  529. // $rootScope.statuscall = 0; //话机状态
  530. // $rootScope.statecall = 1; //示忙示闲
  531. // $scope.login = false; //签入签出
  532. // $rootScope.callout = false; //呼入呼出
  533. // $scope.group = 2000;
  534. // $scope.phone = 1500;
  535. // $rootScope.start = function(phone, group) {
  536. // api_text.start(phone, $rootScope.user.id).then(function(data) {
  537. // var token = data.token;
  538. // $rootScope.takes = token;
  539. // api_text.logout($rootScope.takes, $rootScope.user.id).then(function(data) { if (data.errno == 0) {} });
  540. // api_text.login($scope.group, token, $rootScope.user.id).then(function(data) {
  541. // if (data.errno == 0) {
  542. // $rootScope.setidle();
  543. // $scope.login = true;
  544. // $rootScope.statuscall = 1;
  545. // $rootScope.callout = false;
  546. // // function hello() {
  547. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  548. // // ws.onopen = function() { ws.send(JSON.stringify(register)); };
  549. // // };
  550. // // window.setTimeout("hello()", 1000);
  551. // // var ws = new WebSocket('ws://192.168.77.57:28088/events');
  552. // function reconnect() {
  553. // // var ws = new WebSocket('ws://192.168.3.49:28088/events');
  554. // var ws = new WebSocket('ws://115.156.150.70:28088/events');
  555. // var register = { "msgtype": "login", "adn": phone };
  556. // ws.onopen = function() {
  557. // heartCheck.start();
  558. // ws.send(JSON.stringify(register));
  559. // };
  560. // ws.onmessage = function(evt) {
  561. // heartCheck.reset();
  562. // if (evt.data == "HeartBeat") {
  563. // } else {
  564. // var mydata = JSON.parse(evt.data);
  565. // $scope.filterData = [];
  566. // if (mydata.evttype == "callincome" && mydata.uud != "misc:callback") {
  567. // $rootScope.$apply(function() {
  568. // $rootScope.statuscall = 2;
  569. // });
  570. // $rootScope.callout = false;
  571. // $rootScope.phone = mydata.ano;
  572. // var Notification = window.Notification;
  573. // Notification.requestPermission();
  574. // var n = new Notification("你有来电", {
  575. // body: "来电号码:" + mydata.ano,
  576. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  577. // // onclick: function onNotificationClicked() {
  578. // // console.log('Notification clicked.');
  579. // // }
  580. // });
  581. // } else if (mydata.evttype == "callincome" && mydata.uud == "misc:callback") {
  582. // $rootScope.callout = true;
  583. // } else if (mydata.evttype == "ringstop") {
  584. // // $rootScope.status=7;
  585. // // $rootScope.$apply(function() {
  586. // $rootScope.statuscall = 1;
  587. // // });
  588. // $rootScope.phone = ""
  589. // } else if (mydata.evttype == 'hookchanged' && $rootScope.callout) {
  590. // if (mydata.status && mydata.status == '1') {
  591. // $rootScope.$apply(function() {
  592. // $rootScope.statuscall = 1;
  593. // });
  594. // $rootScope.phone = "";
  595. // } else if (mydata.status && mydata.status != '1') {
  596. // $rootScope.$apply(function() {
  597. // $rootScope.statuscall = 3;
  598. // });
  599. // }
  600. // } else if (mydata.evttype == 'hookchanged' && !$rootScope.callout) {
  601. // if ($rootScope.phone != "") {
  602. // if (mydata.status && mydata.status == '1') { //挂机
  603. // $rootScope.$apply(function() {
  604. // $rootScope.statuscall = 1;
  605. // });
  606. // console.log("挂机");
  607. // console.log(mydata);
  608. // } else if (mydata.status && mydata.status != '1' && $rootScope.statecall != 2) { //摘机
  609. // $rootScope.statuscall = 3;
  610. // api_text.setbusy($rootScope.takes).then(function(data) {
  611. // if (data.errno == 0) {
  612. // $rootScope.statecall = 2;
  613. // $scope.busy = true;
  614. // }
  615. // })
  616. // console.log("摘机");
  617. // console.log(mydata);
  618. // api_text.getcdrid($rootScope.takes).then(function(response) {
  619. // if (response.cdrid) {
  620. // var cdrid = response.cdrid;
  621. // // var response={cdrid:'219023836'}
  622. // var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": $rootScope.phone, "telephone": $rootScope.phone, "selectType": 1 } }
  623. // api_user_data.fetchDataList('requester', filterData).then(function(data) {
  624. // var myData = Restangular.stripRestangular(data);
  625. // // $rootScope.phone="";
  626. // if (myData.list.length == 0) {
  627. // var modalInstance = $modal.open({
  628. // templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  629. // controller: function($scope, $modalInstance, api_user_data) {
  630. // $scope.title = "新增报修人";
  631. // $scope.requester = {};
  632. // $scope.onChangeadd = function(searchData) {
  633. // $scope.searchKey = searchData.account;
  634. // // $scope.searchDataadd = searchData;
  635. // var requesdata = angular.copy(searchData)
  636. // // if (requesdata.mphone) {
  637. // // delete requesdata.mphone;
  638. // // }
  639. // if (requesdata.telephone) {
  640. // delete requesdata.telephone;
  641. // }
  642. // angular.extend($scope.requester, requesdata);
  643. // }
  644. // $scope.refreshUseradd = function(searchKey) { //请求人搜索
  645. // $scope.requester.account = searchKey;
  646. // $scope.searchData = searchKey;
  647. // serchdataadd(searchKey);
  648. // }
  649. // $scope.getMydata = function(x) {
  650. // var reqestdatap = JSON.parse(x[0])
  651. // // if ($scope.requester.mphone) {
  652. // // delete reqestdatap.mphone;
  653. // // }
  654. // if ($scope.requester.telephone) {
  655. // delete reqestdatap.telephone;
  656. // }
  657. // $scope.searchField = JSON.parse(x[0]).account;
  658. // angular.extend($scope.requester, reqestdatap);
  659. // }
  660. // $scope.getMydataone = function(x) {
  661. // $scope.searchField = x;
  662. // $scope.requester.account = x;
  663. // }
  664. // serchdataadd();
  665. // function serchdataadd(searchKey) {
  666. // if (searchKey) {
  667. // var filterData = {
  668. // 'requester': {
  669. // 'searchKey': searchKey,
  670. // },
  671. // idx: 0,
  672. // sum: 10
  673. // };
  674. // } else {
  675. // var filterData = {
  676. // idx: 0,
  677. // sum: 10
  678. // };
  679. // }
  680. // // serchdataadd(searchKey)
  681. // // if ($scope.model.requester && $scope.model.requester.requesterTypeDTO) {
  682. // // angular.extend(filterData.requester, { 'requesterTypeDTO': $scope.model.requester.requesterTypeDTO })
  683. // // }
  684. // api_user_data.fetchDataList('requester', filterData).then(function(response) {
  685. // var myData = response;
  686. // $scope.myData = myData.list;
  687. // });
  688. // }
  689. // // if ((/^1[34578]\d{9}$/.test($rootScope.phone))) {
  690. // // $scope.requester = { 'mphone': $rootScope.phone };
  691. // // } else {
  692. // // $scope.requester = { 'telephone': $rootScope.phone };
  693. // // }
  694. // $scope.requester = { 'telephone': $rootScope.phone };
  695. // $scope.ok = function() {
  696. // $modalInstance.close($scope.requester);
  697. // };
  698. // $scope.cancel = function() {
  699. // $modalInstance.dismiss('cancel');
  700. // };
  701. // },
  702. // });
  703. // modalInstance.result.then(function(selectedItem) {
  704. // if (selectedItem) {
  705. // if (selectedItem.telephone && !selectedItem.mphone) {
  706. // selectedItem.telephone = angular.copy(selectedItem.mphone);
  707. // delete selectedItem.mphone;
  708. // }
  709. // var data = {
  710. // 'requester': selectedItem
  711. // };
  712. // api_user_data.addData('requester', data).then(function(response) {
  713. // if (response.status == 200) {
  714. // var data = { 'model': { 'requestershow': response.data, 'incident': { 'requester': response.data, 'area': response.areaDTO, 'place': response.placeDTO, 'houseNumber': response.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  715. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  716. // }
  717. // })
  718. // }
  719. // });
  720. // } else if (myData.list.length == 1) {
  721. // var data = { 'model': { 'requestershow': myData.list[0], 'incident': { 'requester': myData.list[0], 'area': myData.list[0].areaDTO, 'place': myData.list[0].placeDTO, 'houseNumber': myData.list[0].houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  722. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  723. // } else {
  724. // var modalInstance = $modal.open({
  725. // templateUrl: 'assets/views/createincident.html',
  726. // controller: function($scope, $modalInstance, api_user_data) {
  727. // $scope.title = "请确定报修人";
  728. // $scope.requester = myData.list;
  729. // $scope.choice = function(requester) {
  730. // $modalInstance.dismiss('cancel');
  731. // var data = { 'model': { 'requestershow': requester, 'incident': { 'requester': requester, 'area': requester.areaDTO, 'place': requester.placeDTO, 'houseNumber': requester.houseNumber, 'callID': cdrid, 'source': { 'id': 1 } } } }
  732. // $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  733. // };
  734. // $scope.cancel = function() {
  735. // $modalInstance.dismiss('cancel');
  736. // };
  737. // },
  738. // size: "lg"
  739. // });
  740. // }
  741. // });
  742. // }
  743. // })
  744. // }
  745. // }
  746. // }
  747. // }
  748. // };
  749. // var heartCheck = {
  750. // timeout: 12000, //60ms
  751. // timeoutObj: null,
  752. // serverTimeoutObj: null,
  753. // reset: function() {
  754. // clearTimeout(this.timeoutObj);
  755. // clearTimeout(this.serverTimeoutObj);
  756. // this.start();
  757. // },
  758. // start: function() {
  759. // var self = this;
  760. // this.timeoutObj = setTimeout(function() {
  761. // ws.send("HeartBeat");
  762. // self.serverTimeoutObj = setTimeout(function() {
  763. // ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
  764. // }, self.timeout)
  765. // }, this.timeout)
  766. // },
  767. // }
  768. // ws.onclose = function(evt) { reconnect(); }
  769. // ws.onerror = function(evt) { reconnect(); };
  770. // }
  771. // reconnect();
  772. // } else {
  773. // var Notification = window.Notification;
  774. // Notification.requestPermission();
  775. // var n = new Notification("签入失败!", {
  776. // body: data.errmsg,
  777. // icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  778. // // onclick: function onNotificationClicked() {
  779. // // console.log('Notification clicked.');
  780. // // }
  781. // });
  782. // }
  783. // })
  784. // })
  785. // }
  786. // // 东经呼叫中心结束
  787. //话机呼叫中心--开始
  788. // 1是老的呼叫中心
  789. // 2是2021年12月29日新增的呼叫中心
  790. $rootScope.seiminHj = 2;
  791. $rootScope.getExtnDirect = function () {
  792. $rootScope['getExtnDirect' + $rootScope.seiminHj]();
  793. }
  794. // --------------------------1------------------------------
  795. $rootScope.getExtnDirect1 = function () {
  796. var jry_data_dictionary = {
  797. key: "hjzx_cornet",
  798. type: "list"
  799. }
  800. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  801. var websocket_url = "ws://192.168.3.122:29003/ola_socket";
  802. var ola_queue = "10009"; //通话配置-队列配置-队列ID
  803. // var ola_extn = "1001"; //个人信息-座席分机号
  804. $rootScope.jry_extnNumberSelect = [];
  805. $rootScope.jry_extnNumberObj = {};
  806. $rootScope.jry_extnNumberSelect = res;
  807. $rootScope.jry_extnNumberObj.jry_extnNumber = $rootScope.jry_extnNumberSelect[0];
  808. function log(msg) {
  809. //IE has no console
  810. if ('console' in window) console.log(msg);
  811. }
  812. function websocket_connect() {
  813. ola.connect(websocket_url);
  814. ola.onConnect = onConnect;
  815. ola.onClose = onClose;
  816. ola.onMessage = onMessage;
  817. }
  818. $(document).ready(function () {
  819. // if(ola_extn!=""){
  820. if ($rootScope.jry_extnNumberObj.jry_extnNumber) {
  821. websocket_connect();
  822. }
  823. });
  824. /* callbacks */
  825. function onMessage(evt) {
  826. var phoneData = JSON.parse(evt.data);
  827. if (phoneData.event_type == "agent_state") {
  828. console.log(phoneData);
  829. if (phoneData.state == "busy") {
  830. $('#agent_state').append(" (" + phoneData.private_data + ")");
  831. // 来电
  832. if (phoneData.private_data == "ring") {
  833. console.log(phoneData);
  834. $rootScope.jry_state = "laidian";
  835. var Notification = window.Notification;
  836. Notification.requestPermission();
  837. var n = new Notification("你有来电", {
  838. body: "来电号码:" + phoneData.ani,
  839. icon: '../bower_components/HTML5-Desktop-Notifications/alert.ico',
  840. });
  841. // 摘机
  842. } else if (phoneData.private_data == "answered") {
  843. $rootScope.jry_state = "tonghuazhong";
  844. var jry_findPhone = "";
  845. if (phoneData.ani) {
  846. jry_findPhone = phoneData.ani
  847. } else if (phoneData.dnis && phoneData.other_answered) {
  848. jry_findPhone = phoneData.dnis
  849. }
  850. var filterData = {
  851. "idx": 0,
  852. "sum": 100,
  853. "requester": {
  854. "mphone": jry_findPhone,
  855. "telephone": jry_findPhone,
  856. "selectType": 1
  857. }
  858. }
  859. api_user_data.fetchDataList('requester', filterData).then(function (data) {
  860. var myData = Restangular.stripRestangular(data);
  861. // $rootScope.phone="";
  862. // 新增报修人
  863. if (myData.list.length == 0) {
  864. var modalInstance = $modal.open({
  865. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  866. controller: function ($scope, $modalInstance, api_user_data, SweetAlert, api_wechatfile) {
  867. $scope.title = "新增报修人";
  868. $scope.requester = {};
  869. $scope.onChangeadd = function (searchData) {
  870. $scope.searchKey = searchData.account;
  871. // $scope.searchDataadd = searchData;
  872. var requesdata = angular.copy(searchData)
  873. // if (requesdata.mphone) {
  874. // delete requesdata.mphone;
  875. // }
  876. if (requesdata.telephone) {
  877. delete requesdata.telephone;
  878. }
  879. angular.extend($scope.requester, requesdata);
  880. }
  881. $scope.refreshUseradd = function (searchKey) { //请求人搜索
  882. $scope.requester.account = searchKey;
  883. $scope.searchData = searchKey;
  884. serchdataadd(searchKey);
  885. }
  886. $scope.getMydata = function (x) {
  887. var reqestdatap = JSON.parse(x[0])
  888. // if ($scope.requester.mphone) {
  889. // delete reqestdatap.mphone;
  890. // }
  891. if ($scope.requester.telephone) {
  892. delete reqestdatap.telephone;
  893. }
  894. $scope.searchField = JSON.parse(x[0]).account;
  895. angular.extend($scope.requester, reqestdatap);
  896. }
  897. $scope.getMydataone = function (x) {
  898. $scope.searchField = x;
  899. $scope.requester.account = x;
  900. }
  901. serchdataadd();
  902. function serchdataadd(searchKey) {
  903. if (searchKey) {
  904. var filterData = {
  905. 'requester': {
  906. 'searchKey': searchKey,
  907. },
  908. idx: 0,
  909. sum: 10
  910. };
  911. } else {
  912. var filterData = {
  913. idx: 0,
  914. sum: 10
  915. };
  916. }
  917. api_user_data.fetchDataList('requester', filterData).then(function (response) {
  918. var myData = response;
  919. $scope.myData = myData.list;
  920. });
  921. }
  922. api_user_data.fetchDataList('area', {
  923. idx: 0,
  924. sum: 100
  925. }).then(function (response) {
  926. if (response.status == 200) {
  927. $scope.areas = response.list;
  928. }
  929. })
  930. api_wechatfile.getDictionary({
  931. "key": "requester_type",
  932. "type": "list"
  933. }).then(function (response) {
  934. // if (response.status == 200) {
  935. $scope.networktypes = response;
  936. // }
  937. })
  938. $scope.requesterAreaid = "";
  939. $scope.onChange = function (item) {
  940. $scope.requesterAreaid = item.id;
  941. $scope.requester.placeDTO = {};
  942. api_user_data.fetchDataList('place', {
  943. place: {
  944. areaId: item.id
  945. },
  946. idx: 0,
  947. sum: 1000
  948. }).then(function (response) {
  949. if (response.status == 200) {
  950. $scope.places = response.list;
  951. }
  952. })
  953. }
  954. //地点搜索
  955. $scope.refresh = function (searchVal) {
  956. var faildata = {};
  957. if ($scope.requesterAreaid) {
  958. faildata = {
  959. 'idx': 0,
  960. 'sum': 1000,
  961. 'place': {
  962. 'areaId': $scope.requesterAreaid,
  963. 'place': searchVal,
  964. 'selectType': 'pinyin_qs'
  965. }
  966. }
  967. } else {
  968. faildata = {
  969. 'idx': 0,
  970. 'sum': 1000,
  971. 'place': {
  972. 'place': searchVal,
  973. 'selectType': 'pinyin_qs'
  974. }
  975. }
  976. }
  977. api_user_data.fetchDataList('place', faildata).then(function (response) {
  978. $scope.places = response.list;
  979. delete $scope.requester.placeDTO;
  980. })
  981. }
  982. $scope.requester = {
  983. 'telephone': jry_findPhone
  984. };
  985. $scope.ok = function () {
  986. var reg1 = /^1[3456789][0-9]{9}$/; //手机号
  987. var reg2 = /^((0\d{2,3})-)*(\d{7,8})(-(\d{3,}))?$/; //座机号
  988. var flag1 = reg1.test($scope.requester.mphone);
  989. var flag2 = reg2.test($scope.requester.mphone);
  990. console.log($scope.requester)
  991. if (angular.isUndefined($scope.requester.name) || $scope.requester.name == null || $scope.requester.name == "") {
  992. SweetAlert.swal("报修人姓名未填!", "请填写报修人姓名", "error");
  993. } else if (angular.isUndefined($scope.requester.requesterType)) {
  994. SweetAlert.swal("人员类型未填!", "请填写人员类型", "error");
  995. } else if (angular.isUndefined($scope.requester.mphone) || $scope.requester.mphone == null || $scope.requester.mphone == "") {
  996. SweetAlert.swal("报修人电话未填!", "请填写报修人电话", "error");
  997. }
  998. else {
  999. $modalInstance.close($scope.requester);
  1000. }
  1001. };
  1002. $scope.cancel = function () {
  1003. $modalInstance.dismiss('cancel');
  1004. };
  1005. },
  1006. });
  1007. modalInstance.result.then(function (selectedItem) {
  1008. if (selectedItem) {
  1009. if (selectedItem.telephone && !selectedItem.mphone) {
  1010. selectedItem.telephone = angular.copy(selectedItem.mphone);
  1011. delete selectedItem.mphone;
  1012. }
  1013. var data = {
  1014. 'requester': selectedItem
  1015. };
  1016. api_user_data.addData('requester', data).then(function (response) {
  1017. if (response.status == 200) {
  1018. var data = {
  1019. 'model': {
  1020. 'requestershow': response.data,
  1021. 'incident': {
  1022. 'requester': response.data,
  1023. 'area': response.data.areaDTO,
  1024. 'place': response.data.placeDTO,
  1025. 'houseNumber': response.data.houseNumber,
  1026. // 'callID': cdrid,
  1027. 'source': {
  1028. 'id': 1547
  1029. }
  1030. }
  1031. }
  1032. }
  1033. $state.go('app.incident.title', {
  1034. 'model': JSON.stringify(data)
  1035. });
  1036. }
  1037. })
  1038. }
  1039. });
  1040. } else if (myData.list.length == 1) {
  1041. var data = {
  1042. 'model': {
  1043. 'requestershow': myData.list[0],
  1044. 'incident': {
  1045. 'requester': myData.list[0],
  1046. 'area': myData.list[0].areaDTO,
  1047. 'place': myData.list[0].placeDTO,
  1048. 'houseNumber': myData.list[0].houseNumber,
  1049. // 'callID': cdrid,
  1050. 'source': {
  1051. 'id': 1547
  1052. }
  1053. }
  1054. }
  1055. }
  1056. $state.go('app.incident.title', {
  1057. 'model': JSON.stringify(data)
  1058. });
  1059. } else {
  1060. var modalInstance = $modal.open({
  1061. templateUrl: 'assets/views/createincident.html',
  1062. controller: function ($scope, $modalInstance, api_user_data) {
  1063. $scope.title = "请确定报修人";
  1064. $scope.requester = myData.list;
  1065. $scope.choice = function (requester) {
  1066. $modalInstance.dismiss('cancel');
  1067. var data = {
  1068. 'model': {
  1069. 'requestershow': requester,
  1070. 'incident': {
  1071. 'requester': requester,
  1072. 'area': requester.areaDTO,
  1073. 'place': requester.placeDTO,
  1074. 'houseNumber': requester.houseNumber,
  1075. // 'callID': cdrid,
  1076. 'source': {
  1077. 'id': 1547
  1078. }
  1079. }
  1080. }
  1081. }
  1082. $state.go('app.incident.title', {
  1083. 'model': JSON.stringify(data)
  1084. });
  1085. };
  1086. $scope.cancel = function () {
  1087. $modalInstance.dismiss('cancel');
  1088. };
  1089. },
  1090. size: "lg"
  1091. });
  1092. }
  1093. });
  1094. }
  1095. // 挂机
  1096. } else if (phoneData.state == "login") {
  1097. go_ready()
  1098. } else if (phoneData.state == "logout") {
  1099. $rootScope.jry_state = "weiqianru";
  1100. } else if (phoneData.state == "ready") {
  1101. // 来电挂机
  1102. if (phoneData.old_state == "busy" && phoneData.private_data == "answered") {
  1103. go_break()
  1104. } else {
  1105. $rootScope.jry_state = "shixian";
  1106. }
  1107. }
  1108. // else if (data.old_state == "busy") {
  1109. // }
  1110. } else if (phoneData.event_type == "agent_caller_state") {
  1111. // special feature, never mind
  1112. if (phoneData.action == "in") {
  1113. } else {
  1114. }
  1115. } else if (phoneData.event_type == "command/reply") {
  1116. if (phoneData.phoneData && phoneData.phoneData.state) {
  1117. }
  1118. }
  1119. }
  1120. function onConnect() {
  1121. console.log("websocket connected!");
  1122. // ola._extn = ola_extn;
  1123. // ola.subscribe('ola.queue.' + ola_queue + '.' + ola_extn);
  1124. // ola.subscribe('ola.caller.' + ola_extn);
  1125. // ola.get_agent_state(ola_extn);
  1126. ola._extn = $rootScope.jry_extnNumberObj.jry_extnNumber.name;
  1127. ola.subscribe('ola.queue.' + ola_queue + '.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1128. ola.subscribe('ola.caller.' + $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1129. ola.get_agent_state($rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1130. };
  1131. function onClose() {
  1132. }
  1133. function login() {
  1134. // ola.login(ola_queue, ola_extn, {type: "onhook"});
  1135. console.log($rootScope.jry_extnNumberObj.jry_extnNumber);
  1136. ola.login(ola_queue, $rootScope.jry_extnNumberObj.jry_extnNumber.name, { type: "onhook" });
  1137. }
  1138. function logout() {
  1139. ola.logout();
  1140. }
  1141. function go_ready() {
  1142. ola.go_ready();
  1143. }
  1144. function go_break() {
  1145. ola.go_break($('#break_reason').val());
  1146. $rootScope.jry_state = "shimang";
  1147. }
  1148. function answer() {
  1149. ola.answer();
  1150. }
  1151. function dial(dst) {
  1152. ola.dial(dst);
  1153. }
  1154. $rootScope.dial = function (dst) {
  1155. ola.dial(dst);
  1156. }
  1157. function conference(dst) {
  1158. ola.conference(dst);
  1159. }
  1160. function conference_uuid(channel_uuid) {
  1161. ola.conference_uuid(channel_uuid);
  1162. }
  1163. function hangup() {
  1164. ola.hangup();
  1165. }
  1166. function take_call(uuid) {
  1167. // ola.take_call(ola_extn, uuid);
  1168. ola.take_call($rootScope.jry_extnNumberObj.jry_extnNumber.name, uuid);
  1169. }
  1170. // 签入
  1171. $rootScope.jry_qianru = function () {
  1172. login();
  1173. }
  1174. // 示闲
  1175. $rootScope.jry_shixian = function () {
  1176. go_ready()
  1177. }
  1178. // 示忙
  1179. $rootScope.jry_shimang = function () {
  1180. go_break()
  1181. }
  1182. // 签出
  1183. $rootScope.jry_qianchu = function () {
  1184. logout()
  1185. }
  1186. $rootScope.jry_bohao = function (res) {
  1187. if ($rootScope.jry_state == "weiqianru") {
  1188. // SweetAlert.swal({
  1189. // title: "拨打失败",
  1190. // text: "请先签入!",
  1191. // type: "error",
  1192. // confirmButtonColor: "#DD6B55"
  1193. // });
  1194. } else if ($rootScope.jry_state == "shimang") {
  1195. // SweetAlert.swal({
  1196. // title: "拨打失败",
  1197. // text: "请先示闲!",
  1198. // type: "error",
  1199. // confirmButtonColor: "#DD6B55"
  1200. // });
  1201. } else {
  1202. dial(res);
  1203. }
  1204. }
  1205. })
  1206. }
  1207. // ------------------------------2--------------------------
  1208. $rootScope.getExtnDirect2 = function () {
  1209. var jry_data_dictionary = {
  1210. key: "hjzx_cornet",
  1211. type: "list"
  1212. }
  1213. api_wechatfile.getDictionary(jry_data_dictionary).then(function (res) {
  1214. sessionStorage.setItem('phones',JSON.stringify(res.map(v=>v.name)));
  1215. var websocket_url = $rootScope.seiminCallIp;
  1216. $rootScope.jry_extnNumberSelect = [];
  1217. $rootScope.jry_extnNumberObj = {};
  1218. $rootScope.jry_extnNumberSelect = angular.copy(res);
  1219. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1220. var fenjiNumber = localStorage.getItem('fenjiNumber');
  1221. if(fenjiNumber){
  1222. $rootScope.jry_extnNumberSelect.forEach(ress=>{
  1223. if(ress.name == fenjiNumber){
  1224. $rootScope.jry_extnNumberObj.jry_extnNumber = ress;
  1225. }
  1226. })
  1227. }
  1228. // $rootScope.jry_extnNumberObj.jry_extnNumber = angular.copy(res[0]);//绑定分机对象
  1229. // $rootScope.jry_extnNumberObj.tel1 = angular.copy(res[0]);//目的号码对象
  1230. // $rootScope.jry_extnNumberObj.tel2 = angular.copy(res[0]);//转接坐席对象
  1231. $rootScope.preState = '';//最近一次示忙还是示闲的状态
  1232. //连接
  1233. tlwsa.tlaOpen(websocket_url);
  1234. // 强制示忙
  1235. $scope.qShimang = function(state){
  1236. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1237. //进入页面,强制示忙
  1238. // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1239. setTimeout(()=>{
  1240. tlwsa.tlaAcw();
  1241. },0)
  1242. }else{
  1243. $scope.getState(state);
  1244. }
  1245. }
  1246. // 获取状态
  1247. $scope.getState = function (state) {
  1248. // if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1249. // if(state != 2&&state != 0){
  1250. // //进入页面,强制示忙
  1251. // // tlwsa.tlaForceacw($rootScope.phoneNumber);
  1252. // setTimeout(()=>{
  1253. // tlwsa.tlaAcw();
  1254. // },3000)
  1255. // }
  1256. // }
  1257. // var agcount = tlwsa.tlaGetagentcount();
  1258. // var flag = true;
  1259. // for (var i = 0; i < agcount; i++) {
  1260. // if (tlwsa.tlaGetagentwid(i) == $rootScope.phoneNumber) {
  1261. // flag = false;
  1262. // var state = Number(tlwsa.tlaGetagentstate(i));
  1263. // console.log(state);
  1264. switch (state) {
  1265. case 0:
  1266. $rootScope.jry_state = 'weiqianru';
  1267. break;
  1268. case 1:
  1269. $rootScope.jry_state = 'shixian';
  1270. break;
  1271. case 2:
  1272. $rootScope.jry_state = 'shimang';
  1273. break;
  1274. case 3:
  1275. $rootScope.jry_state = 'laidian';
  1276. break;
  1277. case 5:
  1278. $rootScope.jry_state = 'tonghuazhong';
  1279. break;
  1280. case 6:
  1281. $rootScope.jry_state = 'zhengzaiwaihu';
  1282. break;
  1283. case 7:
  1284. $rootScope.jry_state = 'zhengzaizhuanyi';
  1285. break;
  1286. }
  1287. // }
  1288. // console.log('agnet No. ' + i + ' workid is ' + tlwsa.tlaGetagentwid(i) + ' state is ' + tlwsa.tlaGetagentstate(i) + ' ' + getStateInfo(tlwsa.tlaGetagentstate(i)))
  1289. // }
  1290. // if (flag) {
  1291. // $rootScope.jry_state = 'weiqianru';
  1292. // }
  1293. }
  1294. // 状态回调函数
  1295. // TLWSA.onStatechange = onstatechange;
  1296. // function onstatechange() {
  1297. // console.log('事件:状态变化----------------------------------------------------');
  1298. // $scope.getState();
  1299. // }
  1300. //连接呼叫中心回调函数
  1301. TLWSA.onOpenreturn = onopenreturn;
  1302. function onopenreturn(err) {
  1303. err = Number(err);
  1304. if (!err) {
  1305. console.log('呼叫中心连接成功-----seimin');
  1306. $scope.getState(0);
  1307. $.toaster({
  1308. priority: 'info',
  1309. title: '操作',
  1310. message: '呼叫中心连接成功'
  1311. });
  1312. //如果设置过话机
  1313. if (localStorage.getItem('phoneNumber')) {
  1314. //强制签出,然后签入
  1315. tlwsa.tlaKillworkid(localStorage.getItem('phoneNumber'));
  1316. }
  1317. } else {
  1318. console.log('呼叫中心连接失败-----seimin');
  1319. $scope.getState(0);
  1320. $.toaster({
  1321. priority: 'info',
  1322. title: '操作',
  1323. message: '呼叫中心连接失败'
  1324. });
  1325. }
  1326. }
  1327. //绑定分机回调函数
  1328. TLWSA.onSetphonenumberreturn = onsetphonenumberreturn;
  1329. function onsetphonenumberreturn(err) {
  1330. err = Number(err);
  1331. if (!err) {
  1332. console.log('绑定分机成功-----seimin');
  1333. $.toaster({
  1334. priority: 'info',
  1335. title: '操作',
  1336. message: '绑定分机成功'
  1337. });
  1338. localStorage.setItem('phoneNumber', $rootScope.phoneNumber);
  1339. localStorage.setItem('fenjiNumber', $rootScope.jry_extnNumberObj.jry_extnNumber.name);
  1340. $scope.qShimang(1);
  1341. } else {
  1342. console.log('绑定分机失败-----seimin');
  1343. $scope.getState(0);
  1344. $.toaster({
  1345. priority: 'info',
  1346. title: '操作',
  1347. message: '绑定分机失败'
  1348. });
  1349. }
  1350. }
  1351. //强制示忙回调函数
  1352. // TLWSA.onAcw = onacw;
  1353. // function onacw(err) {
  1354. // err = Number(err);
  1355. // if (!err) {
  1356. // console.log('强制示忙成功-----seimin');
  1357. // $scope.getState(2);
  1358. // $.toaster({
  1359. // priority: 'info',
  1360. // title: '操作',
  1361. // message: '示忙成功'
  1362. // });
  1363. // } else {
  1364. // console.log('强制示忙失败-----seimin');
  1365. // $.toaster({
  1366. // priority: 'info',
  1367. // title: '操作',
  1368. // message: '示忙失败'
  1369. // });
  1370. // }
  1371. // }
  1372. // //强制示闲回调函数
  1373. // TLWSA.onWca = onwca;
  1374. // function onwca(err) {
  1375. // console.log(err)
  1376. // err = Number(err);
  1377. // if (!err) {
  1378. // console.log('强制示闲成功-----seimin');
  1379. // $scope.getState(1);
  1380. // $.toaster({
  1381. // priority: 'info',
  1382. // title: '操作',
  1383. // message: '示闲成功'
  1384. // });
  1385. // } else {
  1386. // console.log('强制示闲失败-----seimin');
  1387. // $.toaster({
  1388. // priority: 'info',
  1389. // title: '操作',
  1390. // message: '示闲失败'
  1391. // });
  1392. // }
  1393. // }
  1394. //与服务器网络连接中断回调函数
  1395. TLWSA.onClosed = onclosed;
  1396. function onclosed() {
  1397. $scope.getState(0);
  1398. console.log('与服务器网络连接中断-----seimin');
  1399. $.toaster({
  1400. priority: 'info',
  1401. title: '操作',
  1402. message: '与服务器网络连接中断,2分钟后重连'
  1403. });
  1404. console.log('2分钟后自动重连-----seimin')
  1405. $timeout(function () {
  1406. //连接
  1407. tlwsa.tlaOpen(websocket_url);
  1408. }, 120000)
  1409. }
  1410. //签入回调函数
  1411. TLWSA.onLoginreturn = onloginreturn;
  1412. function onloginreturn(err) {
  1413. err = Number(err);
  1414. if (!err) {
  1415. console.log('签入成功-----seimin');
  1416. $.toaster({
  1417. priority: 'info',
  1418. title: '操作',
  1419. message: '签入成功'
  1420. });
  1421. setTimeout(function () {
  1422. console.log($rootScope.jry_extnNumberObj.jry_extnNumber.name,1111)
  1423. var fenjiNumber = $rootScope.jry_extnNumberObj.jry_extnNumber.name || localStorage.getItem('fenjiNumber');
  1424. console.log('开始绑定分机【' + fenjiNumber + '】-----seimin');
  1425. tlwsa.tlaSetphonenumber(fenjiNumber);
  1426. }, 0)
  1427. } else if (err == 9011) {
  1428. console.log('签入失败,该分机已登录-----seimin');
  1429. $.toaster({
  1430. priority: 'info',
  1431. title: '操作',
  1432. message: '签入失败,该分机已登录'
  1433. });
  1434. } else {
  1435. console.log('签入失败-----seimin');
  1436. $.toaster({
  1437. priority: 'info',
  1438. title: '操作',
  1439. message: '签入失败'
  1440. });
  1441. }
  1442. // tlwsa.tlaSubscribestateinfo(2);
  1443. }
  1444. // 强制签出回调函数
  1445. TLWSA.onKillreturn = onkillreturn;
  1446. function onkillreturn(err) {
  1447. err = Number(err);
  1448. if (!err) {
  1449. console.log('强制签出成功-----seimin');
  1450. $scope.getState(0);
  1451. // $.toaster({
  1452. // priority: 'info',
  1453. // title: '操作',
  1454. // message: '强制签出成功'
  1455. // });
  1456. } else {
  1457. console.log('强制签出失败,该分机不是签入状态-----seimin');
  1458. // $.toaster({
  1459. // priority: 'info',
  1460. // title: '操作',
  1461. // message: '强制签出失败'
  1462. // });
  1463. }
  1464. //如果设置过话机
  1465. if (localStorage.getItem('phoneNumber')) {
  1466. // 签入并绑定分机
  1467. $rootScope.phoneNumber = localStorage.getItem('phoneNumber');
  1468. tlwsa.tlaLogin($rootScope.phoneNumber, 1, -1);
  1469. }
  1470. }
  1471. // 签出回调函数
  1472. TLWSA.onLogoffreturn = onlogoffreturn;
  1473. function onlogoffreturn(err) {
  1474. err = Number(err);
  1475. if (!err) {
  1476. console.log('签出成功-----seimin');
  1477. $scope.getState(0);
  1478. $.toaster({
  1479. priority: 'info',
  1480. title: '操作',
  1481. message: '签出成功'
  1482. });
  1483. localStorage.removeItem('phoneNumber');
  1484. localStorage.removeItem('fenjiNumber');
  1485. $rootScope.jry_extnNumberObj.jry_extnNumber = {};
  1486. } else {
  1487. console.log('签出失败-----seimin');
  1488. $.toaster({
  1489. priority: 'info',
  1490. title: '操作',
  1491. message: '签出失败'
  1492. });
  1493. }
  1494. }
  1495. //示忙回调函数
  1496. TLWSA.onAcwreturn = onacwreturn;
  1497. function onacwreturn(err) {
  1498. err = Number(err);
  1499. if (!err) {
  1500. console.log('示忙成功-----seimin');
  1501. if (location.href.includes('app/incident/editor') || location.href.includes('app/incident/chart')) {
  1502. $scope.isShixian = false;
  1503. }else{
  1504. $scope.isShixian = true;
  1505. }
  1506. $scope.getState(2);
  1507. $rootScope.preState = 2;
  1508. $.toaster({
  1509. priority: 'info',
  1510. title: '操作',
  1511. message: '示忙成功'
  1512. });
  1513. } else {
  1514. console.log('示忙失败-----seimin');
  1515. // $.toaster({
  1516. // priority: 'info',
  1517. // title: '操作',
  1518. // message: '示忙失败'
  1519. // });
  1520. }
  1521. }
  1522. //示闲回调函数
  1523. TLWSA.onWcareturn = onwcareturn;
  1524. function onwcareturn(err) {
  1525. err = Number(err);
  1526. if (!err) {
  1527. console.log('示闲成功-----seimin');
  1528. $scope.getState(1);
  1529. $rootScope.preState = 1;
  1530. $.toaster({
  1531. priority: 'info',
  1532. title: '操作',
  1533. message: '示闲成功'
  1534. });
  1535. } else {
  1536. console.log('示闲失败-----seimin');
  1537. $.toaster({
  1538. priority: 'info',
  1539. title: '操作',
  1540. message: '示闲失败'
  1541. });
  1542. }
  1543. }
  1544. //呼叫坐席回调函数
  1545. TLWSA.onCallreturn = oncallreturn;
  1546. function oncallreturn(err) {
  1547. err = Number(err);
  1548. if (!err) {
  1549. console.log('呼叫成功,请摘机-----seimin');
  1550. $scope.getState(6);
  1551. $.toaster({
  1552. priority: 'info',
  1553. title: '操作',
  1554. message: '呼叫成功,请摘机'
  1555. });
  1556. } else {
  1557. console.log('呼叫失败-----seimin');
  1558. $.toaster({
  1559. priority: 'info',
  1560. title: '操作',
  1561. message: '呼叫失败'
  1562. });
  1563. }
  1564. }
  1565. //呼叫坐席被接听回调函数
  1566. TLWSA.onCallresult = oncallresult;
  1567. function oncallresult(jso) {
  1568. console.log(jso);
  1569. var err = Number(jso.err);
  1570. if (!err) {
  1571. console.log('呼叫被接听成功-----seimin');
  1572. $scope.getState(5);
  1573. $.toaster({
  1574. priority: 'info',
  1575. title: '操作',
  1576. message: '呼叫被接听成功'
  1577. });
  1578. } else {
  1579. console.log('呼叫被接听失败-----seimin');
  1580. $scope.qShimang(1);
  1581. $.toaster({
  1582. priority: 'info',
  1583. title: '操作',
  1584. message: '呼叫被接听失败'
  1585. });
  1586. }
  1587. }
  1588. //挂断回调函数
  1589. TLWSA.onCallend = oncallend;
  1590. function oncallend(jso) {
  1591. console.log(jso);//lmm
  1592. if (jso) {
  1593. console.log('挂断成功-----seimin');
  1594. console.log('最近一次话机状态',$rootScope.preState);
  1595. $scope.qShimang($rootScope.preState);
  1596. $.toaster({
  1597. priority: 'info',
  1598. title: '操作',
  1599. message: '挂断成功'
  1600. });
  1601. } else {
  1602. console.log('挂断失败-----seimin');
  1603. $.toaster({
  1604. priority: 'info',
  1605. title: '操作',
  1606. message: '挂断失败'
  1607. });
  1608. }
  1609. }
  1610. //呼入回调函数
  1611. TLWSA.onCallin = oncallin;
  1612. function oncallin(jso) {
  1613. console.log(jso);//lmm
  1614. $rootScope.callInPhoneNumber = jso.caller;//来电的电话
  1615. $rootScope.sockid = jso.crs;//来电的话机id
  1616. if (jso) {
  1617. console.log('呼入坐席成功,请摘机-----seimin');
  1618. $scope.getState(3);
  1619. $.toaster({
  1620. priority: 'info',
  1621. title: '操作',
  1622. message: '呼入坐席成功,请摘机'
  1623. });
  1624. console.log('来电了!电话号码是【' + $rootScope.callInPhoneNumber + '】');
  1625. } else {
  1626. console.log('呼入坐席失败-----seimin');
  1627. $.toaster({
  1628. priority: 'info',
  1629. title: '操作',
  1630. message: '呼入坐席失败'
  1631. });
  1632. }
  1633. }
  1634. //呼入摘机应答回调函数
  1635. TLWSA.onAnswer = onanswer;
  1636. function onanswer(err) {
  1637. err = Number(err);
  1638. if (!err) {
  1639. console.log('呼入摘机应答成功-----seimin');
  1640. $scope.getState(5);
  1641. $.toaster({
  1642. priority: 'info',
  1643. title: '操作',
  1644. message: '呼入摘机应答成功'
  1645. });
  1646. //根据电话号码反查报修人,如果是坐席号码,则不用
  1647. // console.log(sessionStorage.getItem('phones'));
  1648. // var phones = JSON.parse(sessionStorage.getItem('phones'));
  1649. // var isHuajihao = phones.length?phones.some(v=>v == teleno):false;
  1650. // if(isHuajihao){
  1651. // return;
  1652. // }
  1653. var postData = { "idx": 0, "sum": 10, "requester": { hjzxPhone: $rootScope.callInPhoneNumber } };
  1654. api_user_data.fetchDataList('requester', postData).then(function (result) {
  1655. if (result.status == 200) {
  1656. console.log(result.list);
  1657. var requesters = result.list;
  1658. if (requesters.length === 0) {
  1659. //未匹配到报修人,则弹窗添加报修人yeye
  1660. $state.go('app.incident.chart', {
  1661. model: JSON.stringify({
  1662. model: {
  1663. incident: {
  1664. requester: {
  1665. hjzxPhone: $rootScope.callInPhoneNumber
  1666. },
  1667. sockid: $rootScope.sockid
  1668. }
  1669. }
  1670. })
  1671. });
  1672. } else if (requesters.length === 1) {
  1673. //匹配到一个报修人
  1674. $state.go('app.incident.chart', {
  1675. model: JSON.stringify({
  1676. model: {
  1677. incident: {
  1678. requester: requesters[0],
  1679. contactsInformation: requesters[0].mphone,
  1680. sockid: $rootScope.sockid
  1681. },
  1682. }
  1683. })
  1684. });
  1685. } else {
  1686. //匹配到多个报修人
  1687. $modal.open({
  1688. templateUrl: 'assets/views/incident/tpl/tel.html',
  1689. controller: function ($scope, $modalInstance, $timeout, SweetAlert) {
  1690. $scope.list = requesters;
  1691. $scope.selectedItem = 0;
  1692. $scope.cancel = function () {
  1693. $modalInstance.dismiss('cancel');
  1694. };
  1695. $scope.changeBxr = function (id) {
  1696. $scope.selectedItem = id;
  1697. }
  1698. $scope.save = function () {
  1699. var item = $scope.list.find(v => v.id == $scope.selectedItem);
  1700. if (item) {
  1701. $scope.cancel();
  1702. $state.go('app.incident.chart', {
  1703. model: JSON.stringify({
  1704. model: {
  1705. incident: {
  1706. requester: item,
  1707. contactsInformation: item.mphone,
  1708. sockid: $rootScope.sockid
  1709. },
  1710. }
  1711. })
  1712. });
  1713. } else {
  1714. SweetAlert.swal({
  1715. title: "请选择报修人!",
  1716. type: "error"
  1717. })
  1718. }
  1719. }
  1720. }
  1721. });
  1722. }
  1723. }
  1724. })
  1725. } else {
  1726. console.log('呼入摘机应答失败-----seimin');
  1727. $.toaster({
  1728. priority: 'info',
  1729. title: '操作',
  1730. message: '呼入摘机应答失败'
  1731. });
  1732. }
  1733. }
  1734. //呼入未摘机应答回调函数
  1735. TLWSA.onMisscall = onmisscall;
  1736. function onmisscall(err) {
  1737. err = Number(err);
  1738. if (!err) {
  1739. console.log('呼入未摘机应答成功-----seimin');
  1740. $scope.getState(1);
  1741. $.toaster({
  1742. priority: 'info',
  1743. title: '操作',
  1744. message: '呼入未摘机应答成功'
  1745. });
  1746. } else {
  1747. console.log('呼入未摘机应答失败-----seimin');
  1748. $.toaster({
  1749. priority: 'info',
  1750. title: '操作',
  1751. message: '呼入未摘机应答失败'
  1752. });
  1753. }
  1754. }
  1755. //转接开始回调函数
  1756. TLWSA.onTransferreturn = ontransferreturn;//调用转移方法之后,返回该事件 如果错误码为0,仅仅表示开始转移,不代表转移目标已经接听或已经拒绝
  1757. function ontransferreturn(err) {
  1758. err = Number(err);
  1759. if (!err) {
  1760. console.log('转接坐席开始成功-----seimin');
  1761. $scope.getState(7);
  1762. $.toaster({
  1763. priority: 'info',
  1764. title: '操作',
  1765. message: '转接坐席开始成功'
  1766. });
  1767. } else {
  1768. console.log('转接坐席开始失败-----seimin');
  1769. $.toaster({
  1770. priority: 'info',
  1771. title: '操作',
  1772. message: '转接坐席开始失败'
  1773. });
  1774. }
  1775. }
  1776. //转接结果回调函数
  1777. TLWSA.onTransferresult = ontransferresult;
  1778. function ontransferresult(err) {
  1779. err = Number(err);
  1780. if (!err) {
  1781. console.log('转接坐席结果成功-----seimin');
  1782. $scope.getState(1);
  1783. $.toaster({
  1784. priority: 'info',
  1785. title: '操作',
  1786. message: '转接坐席结果成功'
  1787. });
  1788. } else {
  1789. console.log('转接坐席结果失败-----seimin');
  1790. $.toaster({
  1791. priority: 'info',
  1792. title: '操作',
  1793. message: '转接坐席结果失败'
  1794. });
  1795. }
  1796. }
  1797. // 签入
  1798. $rootScope.jry_qianru = function () {
  1799. console.log($rootScope.jry_extnNumberObj.jry_extnNumber)
  1800. if(Object.keys($rootScope.jry_extnNumberObj.jry_extnNumber).length === 0){
  1801. $.toaster({
  1802. priority: 'info',
  1803. title: '警告',
  1804. message: '绑定分机不能为空'
  1805. });
  1806. return;
  1807. }
  1808. // 签入并绑定分机
  1809. // $rootScope.jry_extnNumberObj.jry_extnNumber.name 分机号
  1810. // $rootScope.user.id 坐席号(用户id)
  1811. tlwsa.tlaLogin($rootScope.user.id, 1, -1);
  1812. $rootScope.phoneNumber = $rootScope.user.id;
  1813. }
  1814. // 示闲
  1815. $rootScope.jry_shixian = function () {
  1816. tlwsa.tlaWca();
  1817. }
  1818. // 示忙
  1819. $rootScope.jry_shimang = function () {
  1820. tlwsa.tlaAcw();
  1821. }
  1822. // 签出
  1823. $rootScope.jry_qianchu = function () {
  1824. tlwsa.tlaLogoff();
  1825. }
  1826. // 呼叫坐席
  1827. // $scope.tlaCallagc = function () {
  1828. // tlwsa.tlaCallagc($rootScope.jry_extnNumberObj.tel1)
  1829. // }
  1830. // 呼叫外线
  1831. $scope.tlaCallout = function () {
  1832. // 选择目的号码
  1833. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  1834. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  1835. if(!reg1.test($rootScope.jry_extnNumberObj.tel1)&&!reg2.test($rootScope.jry_extnNumberObj.tel1)){
  1836. $.toaster({
  1837. priority: 'info',
  1838. title: '警告',
  1839. message: '请输入正确的手机号或座机号'
  1840. });
  1841. return;
  1842. }
  1843. tlwsa.tlaCallout($rootScope.jry_extnNumberObj.tel1,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  1844. }
  1845. // // 转移坐席
  1846. // $scope.tlaTransfertoagc = function () {
  1847. // tlwsa.tlaTransfertoagc($rootScope.jry_extnNumberObj.tel2)
  1848. // }
  1849. // 转移外线
  1850. $scope.tlaTransferout = function () {
  1851. // 选择转接号码
  1852. var reg1 = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
  1853. var reg2 = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
  1854. if(!reg1.test($rootScope.jry_extnNumberObj.tel2)&&!reg2.test($rootScope.jry_extnNumberObj.tel2)){
  1855. $.toaster({
  1856. priority: 'info',
  1857. title: '警告',
  1858. message: '请输入正确的手机号或座机号'
  1859. });
  1860. return;
  1861. }
  1862. tlwsa.tlaTransferout($rootScope.jry_extnNumberObj.tel2,$rootScope.jry_extnNumberObj.jry_extnNumber.name,0)
  1863. }
  1864. })
  1865. }
  1866. $rootScope.jry_state = 'weiqianru';
  1867. window.addEventListener('load', function () {
  1868. if ($rootScope.isFuwutai) {
  1869. $rootScope.getExtnDirect();//seiminHj----1
  1870. }
  1871. })
  1872. //话机呼叫中心--结束
  1873. // 未接来电
  1874. $scope.jry_getUnanswered = function () {
  1875. var jry_data = {
  1876. idx: 0,
  1877. sum: 999,
  1878. "callRecord": {
  1879. "todayTime": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 00:00:00",
  1880. "todayTimeEnd": new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " 23:59:59",
  1881. }
  1882. }
  1883. api_bpm_data.fetchDataList("callRecord", jry_data).then(function (data) {
  1884. // fo0h
  1885. for (var i = 0; i < data.list.length; i++) {
  1886. data.list[i].createdTime = new Date(data.list[i].createdTime).getFullYear() + "-" + (new Date(data.list[i].createdTime).getMonth() + 1) + "-" + new Date(data.list[i].createdTime).getDate() + " " + new Date(data.list[i].createdTime).getHours() + ":" + new Date(data.list[i].createdTime).getMinutes() + ":" + new Date(data.list[i].createdTime).getSeconds()
  1887. }
  1888. $rootScope.jry_unansweredData = data.list;
  1889. });
  1890. }
  1891. // $scope.jry_getUnanswered();
  1892. // 来电号码回拨
  1893. $scope.jry_callBack = function (data) {
  1894. var callBackData = {
  1895. "callRecord": {
  1896. "id": data.id,
  1897. "isAnswered": "1"
  1898. }
  1899. };
  1900. api_bpm_data.updData("callRecord", callBackData).then(function (res) {
  1901. if (res) {
  1902. $scope.jry_getUnanswered();
  1903. dial(data.callerIdNumber)
  1904. }
  1905. });
  1906. if (data.department.id && data.requester) {
  1907. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'requester': data.requester, 'contacts': data.requester.name, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  1908. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1909. } else if (data.department.id) {
  1910. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  1911. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1912. } else {
  1913. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  1914. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1915. };
  1916. // ws.send("{\"type\":\"1\",\"phone\":\""+data.phone+"\"}");
  1917. }
  1918. //来电号码生成事件
  1919. $scope.jry_callToIncident = function (data) {
  1920. if (data.department.id && data.requester) {
  1921. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'requester': data.requester, 'contacts': data.requester.name, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  1922. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1923. } else if (data.department.id) {
  1924. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'dept': data.department, 'faultLocation': data.department.address, 'source': { 'id': 1 } }, 'openModel': true } }
  1925. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1926. } else {
  1927. var toData = { 'model': { 'incident': { 'contactsInformation': data.callerIdNumber, 'source': { 'id': 1 } } } }
  1928. $state.go('app.incident.title', { 'model': JSON.stringify(toData) });
  1929. }
  1930. }
  1931. $scope.onChangeadd = function (searchData) {
  1932. $scope.searchKey = searchData.account;
  1933. // $scope.searchDataadd = searchData;
  1934. var requesdata = angular.copy(searchData)
  1935. $scope.requester = requesdata;
  1936. }
  1937. $scope.refreshUseradd = function (searchKey) { //主题搜索
  1938. $scope.searchData = searchKey;
  1939. reashdata($scope.searchData);
  1940. }
  1941. $scope.getMydata = function (x) {
  1942. $scope.telephone = JSON.parse(x).phone;
  1943. $scope.searchField = $scope.telephone;
  1944. return $scope.searchField;
  1945. }
  1946. $scope.getMydataone = function (x) {
  1947. $scope.telephone = x;
  1948. $scope.searchField = $scope.telephone;
  1949. }
  1950. $scope.fildata = {
  1951. "idx": 0,
  1952. "sum": 10,
  1953. "flag": -1
  1954. }
  1955. function reashdata(item) {
  1956. if (item && item != "") {
  1957. angular.extend($scope.fildata, { 'user': { 'flag': -1, 'phone': item } })
  1958. } else {
  1959. delete $scope.fildata.user;
  1960. }
  1961. api_wechatfile.getDictionary({ "type": "list", "key": "hjzx_cornet" }).then(function (data) {
  1962. if (data.status == 200) {
  1963. $scope.myData = data.list;
  1964. }
  1965. })
  1966. // api_user_data.fetchDataList('user', $scope.fildata).then(function(response) {
  1967. // if (response) {
  1968. // if (response.status = 200) {
  1969. // var myData = response;
  1970. // $scope.myData = myData.list;
  1971. // }
  1972. // }
  1973. // })
  1974. }
  1975. if (window.location && window.location.hash == "#/echart") {
  1976. } else {
  1977. reashdata();
  1978. }
  1979. $rootScope.end = function () {
  1980. api_text.logout($rootScope.takes, $rootScope.user.id).then(function (data) {
  1981. if (data.errno == 0) {
  1982. api_text.exit($rootScope.takes).then(function (data) {
  1983. if (data.errno == 0) {
  1984. $rootScope.statuscall = 0;
  1985. $scope.login = false
  1986. // SweetAlert.swal({
  1987. // title: "登出成功",
  1988. // text: "呼叫中心登出成功!",
  1989. // type: "success"
  1990. // });
  1991. // }else{SweetAlert.swal({
  1992. // title: "登出失败",
  1993. // text: "呼叫中心登出失败!",
  1994. // type: "error"
  1995. // });
  1996. }
  1997. })
  1998. }
  1999. })
  2000. }
  2001. $rootScope.dialout = function (gid, teleno) {
  2002. var telephone = "";
  2003. if (teleno && teleno.length > 4) {
  2004. telephone = '9' + teleno;
  2005. } else {
  2006. // telephone = '*01' + teleno + '*';
  2007. telephone = teleno;
  2008. }
  2009. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  2010. if (data.errno == 0) {
  2011. // $rootScope.statuscall = 3;
  2012. $rootScope.callout = true;
  2013. // $rootScope.phone=teleno;
  2014. }
  2015. })
  2016. }
  2017. // $scope.busy=false;
  2018. $rootScope.setbusy = function () {
  2019. api_text.setbusy($rootScope.takes).then(function (data) {
  2020. if (data.errno == 0) {
  2021. $rootScope.statecall = 2;
  2022. $scope.busy = true;
  2023. }
  2024. })
  2025. }
  2026. $rootScope.setidle = function () {
  2027. api_text.setidle($rootScope.takes).then(function (data) {
  2028. if (data.errno == 0) {
  2029. $rootScope.statecall = 1;
  2030. $scope.busy = false;
  2031. }
  2032. })
  2033. }
  2034. $rootScope.inittrans = function (telephone) {
  2035. api_text.inittrans(telephone, $rootScope.takes).then(function (data) {
  2036. if (data.errno == 0) {
  2037. // $scope.status=9
  2038. }
  2039. })
  2040. }
  2041. $rootScope.comptrans = function () {
  2042. api_text.comptrans($rootScope.takes).then(function (data) {
  2043. if (data.errno == 0) {
  2044. $rootScope.statuscall = 1;
  2045. }
  2046. })
  2047. }
  2048. $rootScope.takeup = function () {
  2049. api_text.offhook($rootScope.takes).then(function (data) {
  2050. if (data.errno == 0) {
  2051. $rootScope.statuscall = 3;
  2052. }
  2053. })
  2054. }
  2055. $rootScope.takedown = function () {
  2056. api_text.onhook($rootScope.takes).then(function (data) {
  2057. if (data.errno == 0) {
  2058. $rootScope.statuscall = 1;
  2059. }
  2060. })
  2061. }
  2062. $rootScope.saveData = function (selectdata) {
  2063. var modalInstance = $modal.open({
  2064. templateUrl: 'assets/views/system/tpl/createknowledge.html',
  2065. controller: function ($scope, $modalInstance, api_bpm_data) {
  2066. $scope.worktimedata = {};
  2067. $scope.worktimedata = selectdata;
  2068. $scope.cancel = function () {
  2069. $modalInstance.dismiss('cancel');
  2070. };
  2071. $scope.savercode = function (worktimedata) {
  2072. var fildata = {
  2073. "scheduleclass": {
  2074. "id": selectdata.id,
  2075. "code": worktimedata.code,
  2076. "name": worktimedata.title,
  2077. "person": worktimedata.person,
  2078. "description": worktimedata.description,
  2079. "startTime": worktimedata.startTime,
  2080. "endTime": worktimedata.endTime,
  2081. "shiftTime": selectdata.shiftTime,
  2082. "succeedTime": selectdata.succeedTime,
  2083. "isTemplate": worktimedata.isTemplate
  2084. }
  2085. }
  2086. api_bpm_data.updData('scheduleclass', fildata).then(function (response) {
  2087. if (response) {
  2088. if (response.status == 200) {
  2089. SweetAlert.swal({
  2090. title: "修改成功!",
  2091. type: "success"
  2092. }, function () {
  2093. // $scope.refreshData('expand-right', defaultFilterData);
  2094. })
  2095. } else {
  2096. SweetAlert.swal({
  2097. title: "修改失败!",
  2098. type: "error"
  2099. })
  2100. }
  2101. }
  2102. })
  2103. $modalInstance.close();
  2104. }
  2105. }
  2106. });
  2107. }
  2108. $rootScope.changepassword = function (isNoClose = false) {
  2109. var modalInstance = $modal.open({
  2110. backdrop: !isNoClose,
  2111. templateUrl: 'assets/views/changepassword.html',
  2112. controller: function ($scope, $modalInstance, items, Restangular, SweetAlert) {
  2113. $scope.passwordnull = function (originalPwd, pwd, pwd_2) {
  2114. return originalPwd == undefined || pwd == undefined || pwd_2 == undefined || originalPwd == "" || pwd == "" || pwd_2 == "" || originalPwd == "null" || pwd == "null" || pwd_2 == "null";
  2115. }
  2116. $scope.savepassword = function (originalPwd, pwd, pwd_2) {
  2117. $modalInstance.dismiss('cancel');
  2118. // console.log('pwd=' + pwd + '+' + pwd_2);
  2119. // if(angular.isDefined(pwd)&&angular.isDefined(pwd_2)){
  2120. if (pwd != pwd_2) {
  2121. SweetAlert.swal({
  2122. title: "两次输入的新密码不相同!",
  2123. text: "输入错误,请重新输入!",
  2124. type: "error"
  2125. });
  2126. return;
  2127. }
  2128. if (pwd == pwd_2 && !(/^(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test(pwd))) {
  2129. SweetAlert.swal({
  2130. title: "密码长度8-20位,必须包含大写和小写!",
  2131. text: "输入错误,请重新输入!",
  2132. type: "error"
  2133. });
  2134. return;
  2135. }
  2136. var data2 = {};
  2137. data2["originalPwd"] = originalPwd;
  2138. data2["userid"] = $rootScope.user.id;
  2139. data2["pwd"] = pwd;
  2140. api_login.uppwd(data2).then(function (response) {
  2141. var myData = Restangular.stripRestangular(response);
  2142. if (myData.status == 200) {
  2143. SweetAlert.swal({
  2144. title: '修改成功!',
  2145. text: myData.updatePwdMonth > 0 ? "本次修改密码有效期" + myData.updatePwdMonth + "个月" : '',
  2146. type: "success",
  2147. confirmButtonColor: "#007AFF"
  2148. });
  2149. isNoClose && $state.go('app.dashboard');
  2150. } else {
  2151. SweetAlert.swal({
  2152. title: "修改失败!",
  2153. text: "输入旧密码错误,请重新输入!",
  2154. type: "error"
  2155. });
  2156. }
  2157. })
  2158. // }else{
  2159. // SweetAlert.swal({
  2160. // title: "密码不能为空!",
  2161. // text: "请输入密码!",
  2162. // type: "error"
  2163. // });
  2164. // }
  2165. }
  2166. },
  2167. resolve: {
  2168. items: function () {
  2169. return {
  2170. fetchItems: function (filterData, APIService) { }
  2171. };
  2172. },
  2173. }
  2174. });
  2175. }
  2176. // $rootScope.getnochildpending = function() {
  2177. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2178. // angular.forEach($rootScope.userMenus, function(item) {
  2179. // item.tipnum = 1;
  2180. // })
  2181. // }
  2182. // }
  2183. // $rootScope.getchildpending = function(cantdata) {
  2184. // if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2185. // angular.forEach($rootScope.userMenus, function(item) {
  2186. // item.tipnum = 1;
  2187. // angular.forEach(item, function(index) {
  2188. // index.tipnum = 18;
  2189. // })
  2190. // })
  2191. // }
  2192. // }
  2193. $rootScope.getpending = function () {
  2194. if ($rootScope.userMenus && $rootScope.userMenus.length > 0) {
  2195. if ($rootScope.user.group) {
  2196. var groupArr = [];
  2197. for (var i = 0; i < $rootScope.user.group.length; i++) {
  2198. groupArr.push($rootScope.user.group[i].id)
  2199. }
  2200. api_bpm_data.getCount({ "assignee": $rootScope.user.id, "candidateGroups": groupArr.join(), "idx": 0, "sum": 1000 }).then(function (response) {
  2201. angular.forEach($rootScope.userMenus, function (item, i) {
  2202. item.tipshow = false;
  2203. if (response) {
  2204. if (response.hjzxCount > 0 || response.wechatWarningCount > 0) {
  2205. if (item.id == 58) {
  2206. item.tipshow = true;
  2207. }
  2208. }
  2209. if (response.inspectionCount > 0) {
  2210. if (item.id == 27) {
  2211. item.tipshow = true;
  2212. }
  2213. }
  2214. if (response.incidentCount > 0) {
  2215. if (item.id == 2) {
  2216. item.tipshow = true;
  2217. }
  2218. }
  2219. if (response.releaseCount > 0) {
  2220. if (item.id == 1215) {
  2221. item.tipshow = true;
  2222. }
  2223. }
  2224. if (response.solutionCount > 0) {
  2225. if (item.id == 21) {
  2226. item.tipshow = true;
  2227. }
  2228. }
  2229. if (response.changeCount > 0) {
  2230. if (item.id == 1212) {
  2231. item.tipshow = true;
  2232. }
  2233. }
  2234. if (response.problemCount > 0) {
  2235. if (item.id == 1209) {
  2236. item.tipshow = true;
  2237. }
  2238. }
  2239. if (response.applicationForm > 0) {
  2240. if (item.id == 1221) {
  2241. item.tipshow = true;
  2242. }
  2243. }
  2244. if ((parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2245. if (item.id == 21) {
  2246. item.tipshow = true;
  2247. }
  2248. }
  2249. if (response.alarmCount > 0) {
  2250. if (item.id == 58) {
  2251. item.tipshow = true;
  2252. }
  2253. }
  2254. if (item.children) {
  2255. angular.forEach(item.children, function (index) {
  2256. if (response.hjzxCount !== null && response.hjzxCount !== undefined) {
  2257. if (index.id == 1208) {
  2258. if (response.hjzxCount < 100) {
  2259. index.tipnum = response.hjzxCount;
  2260. } else {
  2261. index.tipnum = "99+";
  2262. }
  2263. }
  2264. }
  2265. if (response.wechatWarningCount !== null && response.wechatWarningCount !== undefined) {
  2266. if (index.id == 59) {
  2267. if (response.wechatWarningCount < 100) {
  2268. index.tipnum = response.wechatWarningCount;
  2269. } else {
  2270. index.tipnum = "99+";
  2271. }
  2272. }
  2273. }
  2274. if (response.problemCount !== null && response.problemCount !== undefined) {
  2275. if (index.id == 1210) {
  2276. if (response.problemCount < 100) {
  2277. index.tipnum = response.problemCount;
  2278. } else {
  2279. index.tipnum = "99+";
  2280. }
  2281. }
  2282. }
  2283. if (response.releaseCount !== null && response.releaseCount !== undefined) {
  2284. if (index.id == 1216) {
  2285. if (response.releaseCount < 100) {
  2286. index.tipnum = response.releaseCount;
  2287. } else {
  2288. index.tipnum = "99+";
  2289. }
  2290. }
  2291. }
  2292. if (response.inspectionCount !== null && response.inspectionCount !== undefined) {
  2293. if (index.id == 147) {
  2294. if (response.inspectionCount < 100) {
  2295. index.tipnum = response.inspectionCount;
  2296. } else {
  2297. index.tipnum = "99+";
  2298. }
  2299. }
  2300. }
  2301. if (response.solutionCount !== null && response.solutionCount !== undefined) {
  2302. if (index.id == 23) {
  2303. if (response.solutionCount < 100) {
  2304. index.tipnum = response.solutionCount;
  2305. } else {
  2306. index.tipnum = "99+";
  2307. }
  2308. }
  2309. }
  2310. if (response.changeCount !== null && response.changeCount !== undefined) {
  2311. if (index.id == 1213) {
  2312. if (response.changeCount < 100) {
  2313. index.tipnum = response.changeCount;
  2314. } else {
  2315. index.tipnum = "99+";
  2316. }
  2317. }
  2318. }
  2319. if (response.incidentCount !== null && response.incidentCount !== undefined) {
  2320. if (index.id == 3) {
  2321. if (response.incidentCount < 100) {
  2322. index.tipnum = response.incidentCount;
  2323. } else {
  2324. index.tipnum = "99+";
  2325. }
  2326. }
  2327. }
  2328. if (response.applicationForm !== null && response.applicationForm !== undefined) {
  2329. if (index.id == 1231) {
  2330. if (response.applicationForm < 100) {
  2331. index.tipnum = response.applicationForm;
  2332. } else {
  2333. index.tipnum = "99+";
  2334. }
  2335. }
  2336. }
  2337. if (response.alarmCount !== null && response.alarmCount !== undefined) {
  2338. if (index.id == 1227) {
  2339. if (response.alarmCount < 100) {
  2340. index.tipnum = response.alarmCount;
  2341. } else {
  2342. index.tipnum = "99+";
  2343. }
  2344. }
  2345. }
  2346. if (response.toAuditCount && response.toReleaseCount && (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount)) > 0) {
  2347. if (index.id == 23) {
  2348. if (parseInt(response.toReleaseCount) + parseInt(response.toAuditCount) < 100) {
  2349. index.tipnum = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2350. } else {
  2351. index.tipnum = "99+";
  2352. }
  2353. }
  2354. }
  2355. })
  2356. }
  2357. }
  2358. })
  2359. // return $rootScope.userMenus;
  2360. // $scope.recordpending = response.;
  2361. // $scope.dashboardcount.knowledgedata = parseInt(response.toReleaseCount) + parseInt(response.toAuditCount);
  2362. })
  2363. } else {
  2364. // SweetAlert.swal("访问数据失败!", "该用户没有分配组", "error");
  2365. }
  2366. }
  2367. // console.log($rootScope.userMenus);
  2368. }
  2369. $rootScope.userMenus = [];
  2370. var getMenus = function () {
  2371. function convertListToTree(data, treeMap) {
  2372. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  2373. var root = null; //Initially set our loop to null
  2374. var parentNode = null;
  2375. //loop over data
  2376. for (var i = 0; i < data.length; i++) {
  2377. // data[i].id = Number(data[i].id);
  2378. var datum = data[i];
  2379. //each node will have children, so let's give it a "children" poperty
  2380. datum.children = [];
  2381. //add an entry for this node to the map so that any future children can
  2382. //lookup the parent
  2383. idToNodeMap[datum.id] = datum;
  2384. //Does this node have a parent?
  2385. if (typeof datum.parentid === "undefined" || datum.parentid == null) {
  2386. //Doesn't look like it, so this node is the root of the tree
  2387. root = datum;
  2388. treeMap[datum.id] = root;
  2389. } else {
  2390. //This node has a parent, so let's look it up using the id
  2391. parentNode = idToNodeMap[datum.parentid];
  2392. //We don't need this property, so let's delete it.
  2393. //delete datum.parentid;
  2394. //Let's add the current node as a child of the parent node.
  2395. parentNode.children.push(datum);
  2396. }
  2397. }
  2398. return root;
  2399. }
  2400. function convertParentToChildList(data) {
  2401. var treeMap = {};
  2402. var list = [];
  2403. convertListToTree(data, treeMap);
  2404. angular.forEach(treeMap, function (item) {
  2405. list.push(item);
  2406. });
  2407. list = window._.sortBy(list, function (o) {
  2408. return o.orders;
  2409. });
  2410. return list;
  2411. }
  2412. //if(userMenus.length==0){
  2413. var userMenus = [];
  2414. var idMapMenu = {};
  2415. if ($rootScope.user) {
  2416. if ($rootScope.user.menu) {
  2417. var allJurisdiction2 = $rootScope.user.menu;
  2418. var onlyMenu2 = [];
  2419. for (var i = 0; i < allJurisdiction2.length; i++) {
  2420. if (allJurisdiction2[i].event == "1") {
  2421. onlyMenu2.push(allJurisdiction2[i])
  2422. }
  2423. }
  2424. // userMenus = convertParentToChildList($rootScope.user.menu);
  2425. userMenus = convertParentToChildList(onlyMenu2);
  2426. }
  2427. }
  2428. //}
  2429. $rootScope.userMenus = userMenus;
  2430. if ($rootScope.userMenus.length > 0) {
  2431. $rootScope.getpending();
  2432. // setInterval($rootScope.getpending(), 30000);
  2433. }
  2434. return userMenus;
  2435. }
  2436. setInterval(function () {
  2437. if ($rootScope.userMenus.length > 0) {
  2438. $rootScope.getpending()
  2439. $rootScope.getMsgNum($rootScope.user.id)
  2440. }
  2441. }, 5000);
  2442. getMenus();
  2443. // console.log("$rootScope.nickname="+JSON.stringify($rootScope));
  2444. $rootScope.logout = function () {
  2445. // var userid =data.id;
  2446. // console.log(' userid='+JSON.stringify( userid));
  2447. //单点登录
  2448. if (localStorage.getItem('isSSo') === '1') {
  2449. sessionStorage.clear();
  2450. localStorage.clear();
  2451. location.href = 'http://' + location.hostname + ':8080/pc_logout.jsp'
  2452. } else {
  2453. $auth.signOut()
  2454. .then(function (resp) {
  2455. // $auth.deleteData('auth_headers')
  2456. sessionStorage.clear();
  2457. localStorage.clear();
  2458. if ($rootScope.isFuwutai) {
  2459. tlwsa.tlaClose();
  2460. $.toaster({
  2461. priority: 'info',
  2462. title: '操作',
  2463. message: '呼叫中心断开连接'
  2464. });
  2465. }
  2466. $state.go("login.signin");
  2467. })
  2468. .catch(function (resp) { });
  2469. }
  2470. //$cookieStore.remove("userObm");
  2471. //$cookieStore.remove("menuObm");
  2472. //$cookieStore.remove("session");
  2473. //$rootScope.user = undefined;
  2474. //$rootScope.menus = undefined;
  2475. //$rootScope.nickname = undefined;
  2476. //window.location = "http://www.itsm.com:8080/itsm/dev/logout.jsp";
  2477. // //logout: function(noServerLogout){
  2478. // window.sessionStorage.clear();
  2479. // window.location = "https://www.yunwei.com:8443/cas/loginout";
  2480. // //},
  2481. }
  2482. // 快速建单
  2483. $rootScope.newOrder = function () {
  2484. $state.go('app.newOrder');
  2485. }
  2486. // save settings to local storage
  2487. if (angular.isDefined($localStorage.layout)) {
  2488. $scope.app.layout = $localStorage.layout;
  2489. } else {
  2490. $localStorage.layout = $scope.app.layout;
  2491. }
  2492. $scope.$watch('app.layout', function () {
  2493. // save to local storage
  2494. $localStorage.layout = $scope.app.layout;
  2495. }, true);
  2496. //global function to scroll page up
  2497. $scope.toTheTop = function () {
  2498. $document.scrollTopAnimated(0, 600);
  2499. };
  2500. // angular translate
  2501. // ----------------------
  2502. $scope.language = {
  2503. // Handles language dropdown
  2504. listIsOpen: false,
  2505. // list of available languages
  2506. available: {
  2507. 'en': 'English',
  2508. 'it_IT': 'Italiano',
  2509. 'de_DE': 'Deutsch',
  2510. 'zh_cn': 'Chinese'
  2511. },
  2512. // display always the current ui language
  2513. init: function () {
  2514. var proposedLanguage = $translate.proposedLanguage() || $translate.use();
  2515. var preferredLanguage = $translate.preferredLanguage();
  2516. // we know we have set a preferred one in app.config
  2517. $scope.language.selected = $scope.language.available[(proposedLanguage || preferredLanguage)];
  2518. },
  2519. set: function (localeId, ev) {
  2520. $translate.use(localeId);
  2521. $scope.language.selected = $scope.language.available[localeId];
  2522. $scope.language.listIsOpen = !$scope.language.listIsOpen;
  2523. }
  2524. };
  2525. $scope.language.init();
  2526. // Function that find the exact height and width of the viewport in a cross-browser way
  2527. var viewport = function () {
  2528. var e = window,
  2529. a = 'inner';
  2530. if (!('innerWidth' in window)) {
  2531. a = 'client';
  2532. e = document.documentElement || document.body;
  2533. }
  2534. return {
  2535. width: e[a + 'Width'],
  2536. height: e[a + 'Height']
  2537. };
  2538. };
  2539. // function that adds information in a scope of the height and width of the page
  2540. $scope.getWindowDimensions = function () {
  2541. return {
  2542. 'h': viewport().height,
  2543. 'w': viewport().width
  2544. };
  2545. };
  2546. // Detect when window is resized and set some variables
  2547. $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
  2548. $scope.windowHeight = newValue.h;
  2549. $scope.windowWidth = newValue.w;
  2550. if (newValue.w >= 992) {
  2551. $scope.isLargeDevice = true;
  2552. } else {
  2553. $scope.isLargeDevice = false;
  2554. }
  2555. if (newValue.w < 992) {
  2556. $scope.isSmallDevice = true;
  2557. } else {
  2558. $scope.isSmallDevice = false;
  2559. }
  2560. if (newValue.w <= 768) {
  2561. $scope.isMobileDevice = true;
  2562. } else {
  2563. $scope.isMobileDevice = false;
  2564. }
  2565. }, true);
  2566. // Apply on resize
  2567. $win.on('resize', function () {
  2568. $scope.$apply();
  2569. });
  2570. $rootScope.app.layout.isNavbarFixed = false;
  2571. $rootScope.app.layout.isSidebarFixed = false;
  2572. $rootScope.app.layout.isFooterFixed = false;
  2573. $scope.login_signquick = function (Requesteruserinform) {
  2574. $rootScope.statuscall = 1;
  2575. $scope.loginForm = {
  2576. username: Requesteruserinform.username,
  2577. password: Requesteruserinform.password
  2578. }
  2579. $auth.submitLogin($scope.loginForm)
  2580. .then(function (resp) {
  2581. localStorage.setItem("jry_user", JSON.stringify(resp));
  2582. $rootScope.user = JSON.parse(localStorage.getItem("jry_user"));
  2583. // $rootScope.userMenus = JSON.parse(localStorage.getItem("jry_user")).menu;
  2584. var allJurisdiction = JSON.parse(localStorage.getItem("jry_user")).menu;
  2585. var onlyMenu = [];
  2586. for (var i = 0; i < allJurisdiction.length; i++) {
  2587. if (allJurisdiction[i].event == "1") {
  2588. onlyMenu.push(allJurisdiction[i])
  2589. }
  2590. };
  2591. $rootScope.userMenus = onlyMenu;
  2592. getMenus();
  2593. if (resp.error != 500) {
  2594. // $state.go('app.dashboard');
  2595. $rootScope.app.isLoginFixed = false;
  2596. } else {
  2597. resp.error = "";
  2598. $scope.loginForm.password = "";
  2599. SweetAlert.swal("用户名或者密码验证失败,请重试!", "error");
  2600. }
  2601. })
  2602. .catch(function (resp) {
  2603. $scope.loginForm.password = "";
  2604. SweetAlert.swal("系统错误,请重试!", "登录错误", "error");
  2605. });
  2606. }
  2607. var url = location.hash; //获取url中"?"符后的字串 var index=obj.lastIndexOf("\-");
  2608. var theRequest = {};
  2609. var index = url.substring(index + 1, url.length).lastIndexOf("\?");
  2610. if (url.indexOf("?") != -1 && url.indexOf("fixed_list")) {
  2611. var str = url.substr(index + 1);
  2612. var strs = str.split("&");
  2613. for (var i = 0; i < strs.length; i++) {
  2614. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  2615. }
  2616. // return theRequest;
  2617. $scope.login_signquick(theRequest)
  2618. }
  2619. // $scope.casUserId = window.location.search;
  2620. // $scope.loginForm = {
  2621. // username: theRequest[0].split("=")[1],
  2622. // password: theRequest[1].split("=")[1]
  2623. // }
  2624. // $scope.lodingstyle = 'nodata';
  2625. var userAgent = window.navigator.userAgent.toLowerCase();
  2626. var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
  2627. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
  2628. var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
  2629. var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
  2630. var isChrome = userAgent.indexOf("chrome") > -1; //判断是否Safari浏览器
  2631. if (isOpera) {
  2632. $scope.checkchrome = '当前所用浏览器是Opera浏览器,';
  2633. // return alert("访问失败,当前所用浏览器是Opera浏览器,请用Chrome浏览器访问!");
  2634. }
  2635. if (isIE) {
  2636. $scope.checkchrome = '当前所用浏览器是IE浏览器,';
  2637. // return alert("访问失败,当前所用浏览器是IE浏览器,请用Chrome浏览器访问!");
  2638. }
  2639. if (isFF) {
  2640. $scope.checkchrome = '当前所用浏览器是火狐浏览器,';
  2641. // return alert("访问失败,当前所用浏览器是火狐浏览器,请用Chrome浏览器访问!");
  2642. }
  2643. if (isSafari) {
  2644. $scope.checkchrome = '当前所用浏览器是Safari浏览器,';
  2645. // return alert("访问失败,当前所用浏览器是Safari浏览器,请用Chrome浏览器访问!");
  2646. }
  2647. if (isChrome) {
  2648. // login_sign();
  2649. $rootScope.app.isChrome = false;
  2650. // return alert("访问失败,当前所用浏览器是Chrome浏览器");
  2651. } else {
  2652. $rootScope.app.isChrome = true;
  2653. $scope.checkchrome = '';
  2654. // return alert("访问失败,请用Chrome浏览器访问!");
  2655. }
  2656. // }
  2657. // $scope.handleloginEnter = function(e) {
  2658. // if (e.keyCode == 13) {
  2659. // $scope.handleLoginClick();
  2660. // }
  2661. // };
  2662. // if (document.getElementById("isWatch").value == "true") {
  2663. // $scope.isHanderuser = true;
  2664. // } else {
  2665. // if (!JSON.parse(sessionStorage.getItem('header'))) {
  2666. // $scope.isHanderuser = false;
  2667. // $scope.login_sign();
  2668. // }
  2669. // }
  2670. // $scope.viewType = "password";
  2671. // $scope.isPassword = true;
  2672. // $scope.toggleView = function() {
  2673. // $scope.isPassword = !$scope.isPassword;
  2674. // $scope.viewType = $scope.isPassword ? "password" : "text";
  2675. // }
  2676. // $scope.handleSignOutBtnClick = function() {
  2677. // $auth.signOut()
  2678. // .then(function(resp) {
  2679. // // handle success response
  2680. // })
  2681. // .catch(function(resp) {
  2682. // // handle error response
  2683. // });
  2684. // };
  2685. // }
  2686. // }
  2687. // if (!isEmpty($auth.retrieveData('auth_headers'))) {
  2688. // } else {
  2689. // $scope.loginstart();
  2690. // }
  2691. //websocket 信息中心
  2692. console.log(atmosphere)
  2693. var socket = atmosphere;
  2694. var subSocket;
  2695. // We are now ready to cut the request
  2696. var request = {
  2697. url: 'ws://192.168.199.150:8080/messagestation/cache',
  2698. contentType: "application/json",
  2699. shared: true, // 标签共享
  2700. trackMessageLength: true, //校验数据完整性
  2701. transport: 'websocket'
  2702. };
  2703. // subSocket = socket.subscribe(request);暂时注释,不知道干啥的
  2704. request.onOpen = function (response) {
  2705. console.log(response)
  2706. subSocket.push(JSON.stringify({ login: $rootScope.user.id }));
  2707. // alert("开始连接")
  2708. };
  2709. request.onMessage = function (response) {
  2710. var message = response.responseBody;
  2711. // alert("连接成功")
  2712. console.log(message)
  2713. try {
  2714. var json = JSON.parse(message);
  2715. console.log(json.noRead)
  2716. $scope.noReadData = json.noRead
  2717. } catch (e) {
  2718. console.log('呵呵哒: ', message);
  2719. return;
  2720. }
  2721. };
  2722. request.onClose = function (response) {
  2723. // alert("连接结束")
  2724. }
  2725. request.onError = function (response) {
  2726. // alert('连接失败')
  2727. };
  2728. //信息中心模态框
  2729. var loginUser = $rootScope.user;
  2730. // if(loginUser){
  2731. // // 未读消息数量
  2732. // api_msg.msgDataList({idx: 0, sum: 1, messageStation: {readStatus: 0, userId: loginUser.id}}).then(function(data) {
  2733. // if (data.status == 200) {
  2734. // $scope.noReadData=data.totalNum
  2735. // // $rootScope.option.all = $rootScope.all;
  2736. // } else {
  2737. // $scope.noReadData=0
  2738. // }
  2739. // })
  2740. // }
  2741. // $scope.noReadData=($rootScope.noReadData||0)
  2742. // // $rootScope.all = 5;
  2743. // setTimeout(function() {
  2744. // console.log($scope.noReadData)
  2745. // }, 500)
  2746. $rootScope.wt_messages = function () {
  2747. var modalInstance = $modal.open({
  2748. templateUrl: '../../../assets/views/wt_messages.html',
  2749. controller: function ($scope, $modalInstance) {
  2750. $rootScope.msgData = {
  2751. idx: 0,
  2752. sum: 5,
  2753. messageStation: {
  2754. readStatus: 0,
  2755. userId: $rootScope.user.id
  2756. }
  2757. }
  2758. // 关闭
  2759. $scope.closeModel = function () {
  2760. modalInstance.close();
  2761. }
  2762. $scope.getMsgData = function () {
  2763. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2764. if (data) {
  2765. $rootScope.msg = data.list
  2766. $rootScope.all = data.pageCount;
  2767. $scope.wt_msgData = data
  2768. $rootScope.noReadData = data.totalNum
  2769. }
  2770. })
  2771. }
  2772. $scope.getMsgData()
  2773. $scope.message_type = 2;
  2774. $scope.message_no = function (type) { //未读1
  2775. $scope.wt_msgData = {};
  2776. $scope.message_type = type;
  2777. $rootScope.msgData.messageStation.readStatus = 0,
  2778. // $rootScope.option.curr = 1;
  2779. $rootScope.msgData.idx = 0;
  2780. // console.log($rootScope.option.curr)
  2781. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2782. $scope.msg_yesType = true;
  2783. if (data.status == 200) {
  2784. $scope.msg_yesType = false
  2785. $scope.wt_msgData = data
  2786. $rootScope.msg = data.list
  2787. $rootScope.all = data.pageCount;
  2788. $rootScope.noReadData = data.totalNum;
  2789. // $rootScope.option.all = $rootScope.all;
  2790. } else {
  2791. $scope.msg_yesType = true;
  2792. }
  2793. })
  2794. }
  2795. $scope.message_yes = function (type) { //已读0
  2796. $scope.wt_msgData = {};
  2797. $scope.message_type = type;
  2798. $rootScope.msgData.messageStation.readStatus = 1,
  2799. $rootScope.msgData.idx = 0;
  2800. // $rootScope.option.curr = 1;
  2801. // console.log($rootScope.option.curr)
  2802. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2803. $scope.msg_noType = true;
  2804. if (data.status == 200) {
  2805. $scope.msg_noType = false
  2806. $scope.wt_msgData = data
  2807. $rootScope.msg = data.list;
  2808. $rootScope.all = data.pageCount;
  2809. // $rootScope.option.all = $rootScope.all;
  2810. } else {
  2811. $scope.msg_noType = true
  2812. }
  2813. })
  2814. };
  2815. $scope.sBtn = function () {
  2816. // console.log($rootScope.msgData)
  2817. // console.log($scope.wt_msgData)
  2818. $rootScope.msgData.idx = $rootScope.msgData.idx - 1;
  2819. console.log($rootScope.msgData)
  2820. $scope.getMsgData()
  2821. }
  2822. $scope.xBtn = function () {
  2823. // console.log($rootScope.msgData)
  2824. // console.log($scope.wt_msgData)
  2825. $rootScope.msgData.idx = $rootScope.msgData.idx + 1;
  2826. console.log($rootScope.msgData)
  2827. $scope.getMsgData()
  2828. }
  2829. $scope.redIn = function (data) {
  2830. var start = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  2831. $scope.messageStation = {
  2832. messageStation: {
  2833. id: data.id,
  2834. readStatus: 1,
  2835. readTime: start
  2836. }
  2837. }
  2838. api_msg.updateDataList($scope.messageStation).then(function (data) {
  2839. console.log(data);
  2840. if (data.status == 200) {
  2841. $rootScope.msgData.messageStation.readStatus = 0,
  2842. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2843. $rootScope.msg = data.list
  2844. $rootScope.all = data.pageCount;
  2845. $rootScope.noReadData = data.totalNum;
  2846. })
  2847. }
  2848. })
  2849. };
  2850. // 一键已读
  2851. $scope.redAllIn = function () {
  2852. $rootScope.isMask = true;
  2853. api_msg.oneClickRead({userId: $rootScope.user.id}).then(function (data) {
  2854. $rootScope.isMask = false;
  2855. if (data.status == 200) {
  2856. $rootScope.msgData.messageStation.readStatus = 0,
  2857. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2858. $scope.wt_msgData = data
  2859. $rootScope.msg = data.list
  2860. $rootScope.all = data.pageCount;
  2861. $rootScope.noReadData = data.totalNum;
  2862. })
  2863. }
  2864. })
  2865. };
  2866. },
  2867. size: 'lg',
  2868. resolve: {
  2869. }
  2870. })
  2871. }
  2872. // 点击单项消息通知
  2873. $rootScope.wt_messages_onclick = function (task) {
  2874. var modalInstance = $modal.open({
  2875. templateUrl: '../../../assets/views/wt_messages_onclick.html',
  2876. controller: function ($scope, $modalInstance) {
  2877. $scope.task = angular.copy(task);
  2878. // 关闭
  2879. $scope.closeModel = function () {
  2880. modalInstance.close();
  2881. }
  2882. },
  2883. size: 'lg',
  2884. resolve: {
  2885. }
  2886. })
  2887. }
  2888. }
  2889. ]);
  2890. //消息中心分页组件
  2891. app.controller('msgCtrl', ['$scope', '$rootScope', 'api_msg', 'Myservice', function ($scope, $rootScope, api_msg, Myservice) {
  2892. $rootScope.option = {
  2893. curr: 1, //当前页数
  2894. all: $rootScope.all, //总页数
  2895. count: 5, //最多显示的页数,默认为10
  2896. //点击页数的回调函数,参数page为点击的页数
  2897. click: function (page) {
  2898. $rootScope.msgData.idx = page - 1;
  2899. //这里可以写跳转到某个页面等...
  2900. api_msg.msgDataList($rootScope.msgData).then(function (data) {
  2901. $rootScope.msg = data.list
  2902. $rootScope.all = data.pageCount;
  2903. $rootScope.option.all = $rootScope.all;
  2904. })
  2905. }
  2906. }
  2907. }]);
  2908. app.directive('myPagination', function () {
  2909. return {
  2910. restrict: 'EA',
  2911. replace: true,
  2912. rootScope: {
  2913. option: '=pageOption'
  2914. },
  2915. controller: 'msgCtrl',
  2916. template: '<ul class="pagination">' +
  2917. '<li ng-click="pageClick(p)" ng-repeat="p in page" class="{{option.curr==p?\'active\':\'\'}}">' +
  2918. '<a href="javascript:;">{{p}}</a>' +
  2919. '</li>' +
  2920. '</ul>',
  2921. link: function ($rootScope) {
  2922. //容错处理
  2923. if (!$rootScope.option.curr || isNaN($rootScope.option.curr) || $rootScope.option.curr < 1) $rootScope.option.curr = 1;
  2924. if (!$rootScope.option.all || isNaN($rootScope.option.all) || $rootScope.option.all < 1) $rootScope.option.all = 1;
  2925. if ($rootScope.option.curr > $rootScope.option.all) $rootScope.option.curr = $rootScope.option.all;
  2926. if (!$rootScope.option.count || isNaN($rootScope.option.count) || $rootScope.option.count < 1) $rootScope.option.count = 10;
  2927. //得到显示页数的数组
  2928. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  2929. //绑定点击事件
  2930. $rootScope.pageClick = function (page) {
  2931. if (page == '«') {
  2932. page = parseInt($rootScope.option.curr) - 1;
  2933. } else if (page == '»') {
  2934. page = parseInt($rootScope.option.curr) + 1;
  2935. }
  2936. if (page < 1) page = 1;
  2937. else if (page > $rootScope.option.all) page = $rootScope.option.all;
  2938. //点击相同的页数 不执行点击事件
  2939. if (page == $rootScope.option.curr) return;
  2940. if ($rootScope.option.click && typeof $rootScope.option.click === 'function') {
  2941. $rootScope.option.click(page);
  2942. $rootScope.option.curr = page;
  2943. $rootScope.page = getRange($rootScope.option.curr, $rootScope.option.all, $rootScope.option.count);
  2944. }
  2945. };
  2946. //返回页数范围(用来遍历)
  2947. function getRange(curr, all, count) {
  2948. //计算显示的页数
  2949. // console.log(curr, all, count)
  2950. curr = parseInt(curr);
  2951. all = parseInt(all);
  2952. count = parseInt(count);
  2953. var from = curr - parseInt(count / 2);
  2954. var to = curr + parseInt(count / 2) + (count % 2) - 1;
  2955. //显示的页数容处理
  2956. if (from <= 0) {
  2957. from = 1;
  2958. to = from + count - 1;
  2959. if (to > all) {
  2960. to = all;
  2961. }
  2962. }
  2963. if (to > all) {
  2964. to = all;
  2965. from = to - count + 1;
  2966. if (from <= 0) {
  2967. from = 1;
  2968. }
  2969. }
  2970. var range = [];
  2971. for (var i = from; i <= to; i++) {
  2972. range.push(i);
  2973. }
  2974. range.push('»');
  2975. range.unshift('«');
  2976. return range;
  2977. }
  2978. }
  2979. }
  2980. });
  2981. app.service('Myservice', function () {
  2982. return {
  2983. };
  2984. });
  2985. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  2986. // console.log(bh)
  2987. // if(bh>=0&&bh<=53){
  2988. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  2989. // }else{
  2990. // $('#sidebar').css('padding-bottom', 0 + 'px')
  2991. // }
  2992. window.onscroll = function () {
  2993. if (window.pageYOffset >= 0 && window.pageYOffset <= 65) {
  2994. $('#sidebar').css('padding-top', (65 - window.pageYOffset) + 'px')
  2995. } else {
  2996. $('#sidebar').css('padding-top', '0')
  2997. }
  2998. // console.log(window.pageYOffset)
  2999. // console.log(window.innerHeight)
  3000. // console.log(document.body.scrollHeight)
  3001. // 底部padding
  3002. // var bh=document.body.scrollHeight-window.innerHeight-window.pageYOffset;
  3003. // console.log(bh)
  3004. // if(bh>=0&&bh<=53){
  3005. // $('#sidebar').css('padding-bottom', (53-bh) + 'px')
  3006. // }else{
  3007. // $('#sidebar').css('padding-bottom', 0 + 'px')
  3008. // }
  3009. }