Main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. MWF.xApplication.CRM = MWF.xApplication.CRM || {};
  2. MWF.require("MWF.widget.Identity", null,false);
  3. MWF.xDesktop.requireApp("CRM", "Actions.RestActions", null, false);
  4. MWF.xApplication.CRM.options = {
  5. multitask: false,
  6. executable: true
  7. };
  8. MWF.xApplication.CRM.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "CRM",
  14. "icon": "icon.png",
  15. "width": "1400",
  16. "height": "700",
  17. "isResize": true,
  18. "isMax": true,
  19. "title": MWF.xApplication.CRM.LP.title
  20. },
  21. onQueryLoad: function(){
  22. this.lp = MWF.xApplication.CRM.LP;
  23. if(!this.inBrowser){
  24. this.openInNewBrowserX();
  25. }else{
  26. COMMON.AjaxModule.loadCss( this.path+this.options.style+"/main.css",function(){
  27. console.log("main.css,load complete");
  28. })
  29. }
  30. },
  31. openInNewBrowserX: function(){
  32. this.desktop.openBrowserApp = this.options.name;
  33. this.desktop.openBrowserStatus = (this.recordStatus) ? this.recordStatus() : null;
  34. var status = (this.desktop.openBrowserStatus) ? JSON.encode(this.desktop.openBrowserStatus) : "";
  35. var url = "app.html?app="+this.options.name+"&status="+status;
  36. window.open(url, "_blank");
  37. if (!this.inBrowser)
  38. try{
  39. this.close();
  40. }catch(e){
  41. this.taskitem.destroy();
  42. this.window = null;
  43. this.taskitem = null;
  44. this.desktop.closeApp(this);
  45. this.fireAppEvent("postClose");
  46. o2.release(this);
  47. }
  48. },
  49. load: function(isCurrent){
  50. this.fireAppEvent("queryLoad");
  51. if (!this.inBrowser){
  52. this.loadWindow(isCurrent);
  53. }else{
  54. this.loadInBrowser(isCurrent);
  55. }
  56. },
  57. onPostLoad:function(){
  58. this.resizeWindow();
  59. },
  60. loadApplication: function(callback){
  61. this.maxSize(function () {
  62. this.user = layout.desktop.session.user.name;
  63. this.userGender = layout.desktop.session.user.genderType;
  64. //this.restActions = new MWF.xApplication.CRM.Actions.RestActions();
  65. this.actions = new MWF.xApplication.CRM.Actions.RestActions();
  66. //this.identites = this.getIdentityies();
  67. if( !this.container ){
  68. this.content.setStyle("overflow", "hidden");
  69. this.container = new Element("div.container",{"styles":this.css.container}).inject(this.content)
  70. }
  71. this.createTopContent();
  72. this.createMiddleContent();
  73. //this.resizeWindow();
  74. this.addEvent("c", function(){
  75. this.resizeWindow();
  76. }.bind(this));
  77. MWF.xDesktop.requireApp("CRM", "BaiduMap", function(){
  78. window.BMap_loadScriptTime = (new Date).getTime();
  79. var apiPath = "http://api.map.baidu.com/getscript?v=2.0&ak=Qac4WmBvHXiC87z3HjtRrbotCE3sC9Zg&services=&t=20161219171637";
  80. if( !window.BDMapApiLoaded ){
  81. COMMON.AjaxModule.loadDom(apiPath, function () {
  82. window.BDMapApiLoaded = true;
  83. if( !window.BDMarkerToolLoaded ){
  84. COMMON.AjaxModule.load( "/x_component_CRM/BDMarkerTool.js", function(){
  85. window.BDMarkerToolLoaded = true;
  86. });
  87. }else{
  88. }
  89. });
  90. }
  91. }.bind(this));
  92. if(callback) callback();
  93. }.bind(this));
  94. },
  95. reload:function(){
  96. this.createMiddleContent();
  97. this.resizeWindow();
  98. },
  99. createMiddleContent:function(){
  100. if(this.middleContentDiv) this.middleContentDiv.destroy();
  101. this.middleContentDiv = new Element("div.middleContentDiv",{"styles":this.css.middleContentDiv}).inject(this.container);
  102. this.createLeftContent();
  103. //this.createRightContent();
  104. },
  105. ////////////////////Top//////////////////////////////////////
  106. createTopContent:function(){
  107. if(this.topContentDiv) this.topContentDiv.destroy();
  108. this.topContentDiv = new Element("div.topContentDiv",{"styles":this.css.topContentDiv}).inject(this.container);
  109. this.logoDiv = new Element("div.logoDiv",{"styles":this.css.logoDiv}).inject(this.topContentDiv);
  110. this.logoImg = new Element("img.logoImg",{
  111. "styles":this.css.logoImg,
  112. "src":this.path+"default/icons/crm.png"
  113. }).inject(this.logoDiv);
  114. this.logoTitleDiv = new Element("div.logoTitleDiv",{
  115. "styles":this.css.logoTitleDiv,
  116. "text":this.lp.main.title
  117. }).inject(this.logoDiv);
  118. this.topLeftDiv = new Element("div.topLeftDiv",{"styles":this.css.topLeftDiv}).inject(this.topContentDiv);
  119. var topLeftLi = new Element("li.topLeftLi",{"styles":this.css.topLeftLi}).inject(this.topLeftDiv);
  120. var tmpDiv = new Element("div.topLeftLiDiv",{"styles":this.css.topLeftLiDiv,"text":this.user}).inject(topLeftLi);
  121. var tmpImg = new Element("img.topLeftLiImg",{
  122. "styles":this.css.topLeftLiImg,
  123. "src":this.path+"default/icons/arrow.png"
  124. }).inject(topLeftLi);
  125. },
  126. isAdmin: function(){
  127. return MWF.AC.isCMSManager() || MWF.AC.isAdministrator()
  128. },
  129. ////////////////////Top//////////////////////////////////////
  130. ////////////////////left//////////////////////////////////////
  131. createLeftContent:function(){
  132. this.leftContentDiv = new Element("div.leftContentDiv",{"styles":this.css.leftContentDiv}).inject(this.middleContentDiv);
  133. this.quickStartDiv = new Element("div.quickStartDiv",{"styles":this.css.quickStartDiv}).inject(this.leftContentDiv);
  134. //this.quickStartDiv.toggle();
  135. this.quickStartImg = new Element("img.quickStartImg",{
  136. "styles":this.css.quickStartImg,
  137. "src":this.path+"default/icons/add.png"
  138. }).inject(this.quickStartDiv);
  139. this.quickStartTextDiv = new Element("div.quickStartTextDiv",{
  140. "styles":this.css.quickStartTextDiv,
  141. "text":this.lp.main.quickStart
  142. }).inject(this.quickStartDiv);
  143. this.createNavi();
  144. },
  145. createNavi:function(){
  146. var _self = this;
  147. this.naviDiv = new Element("div.naviDiv",{
  148. "styles" : this.css.naviDiv
  149. }).inject(this.leftContentDiv);
  150. var jsonUrl = this.path+"navi.json";
  151. MWF.getJSON(jsonUrl, function(json){
  152. json.each(function(d){ //menu
  153. if(d.type=="menu"){
  154. var naviMenuLi = new Element("div.naviMenuLi",{
  155. "styles":this.css.naviMenuLi
  156. }).inject(this.naviDiv);
  157. var naviMenuImg = new Element("img.naviMenuImg",{
  158. "styles" : this.css.naviMenuImg,
  159. "src" : this.path + d.icon
  160. }).inject(naviMenuLi);
  161. var naviMenuTxtDiv = new Element("div.naviMenuTxtDiv",{
  162. "styles" : this.css.naviMenuTxtDiv,
  163. "text" : d.title
  164. }).inject(naviMenuLi);
  165. d.items.each(function(dd){
  166. var naviItemLi = new Element("div.naviItemLi",{
  167. "styles":this.css.naviItemLi,
  168. "id":dd.action,
  169. "action":dd.action
  170. }).inject(this.naviDiv);
  171. var naviItemImg = new Element("img.naviItemImg",{
  172. "styles" : this.css.naviItemImg,
  173. "src" : this.path + dd.icon,
  174. "df":dd.icon,
  175. "dfFill":dd.iconFill
  176. }).inject(naviItemLi);
  177. var naviItemTxtDiv = new Element("div.naviItemTxtDiv",{
  178. "styles" : this.css.naviItemTxtDiv,
  179. "text" : dd.title
  180. }).inject(naviItemLi);
  181. naviItemLi.addEvents({
  182. "mouseover":function(){
  183. if(this.get("action") != _self.curModule){
  184. this.setStyles({"color":"#ff8e31"});
  185. var tmp = this.getElement("img");
  186. if(tmp)tmp.set("src",_self.path + tmp.get("dfFill"))
  187. }
  188. },
  189. "mouseout":function(){
  190. if(this.get("action") != _self.curModule){
  191. this.setStyles({"color":"#ffffff"});
  192. var tmp = this.getElement("img");
  193. if(tmp)tmp.set("src",_self.path + tmp.get("df"))
  194. }
  195. },
  196. "click":function(){
  197. //if(_self.curModule != this.get("action")){
  198. _self.curModule = this.get("action");
  199. var allLi = _self.naviDiv.getElements(".naviItemLi");
  200. allLi.setStyles({"color":"#ffffff"});
  201. allLi.getElement("img").each(function(ddd){
  202. ddd.set("src",_self.path + ddd.get("df"))
  203. });
  204. this.setStyles({"color":"#ff8e31"});
  205. var tmp = this.getElement("img");
  206. if(tmp) tmp.set("src",_self.path + tmp.get("dfFill"));
  207. _self.openModule(this.get("action"))
  208. //}
  209. }
  210. })
  211. }.bind(this))
  212. }
  213. }.bind(this));
  214. }.bind(this),false);
  215. //this.naviDiv.getElementById("homePage").click()
  216. this.naviDiv.getElements(".naviItemLi").each(function(d){
  217. if(d.get("action") == "homePage"){
  218. _self.curModule = "homePage";
  219. d.setStyles({"color":"#ff8e31"});
  220. var tmp = d.getElement("img");
  221. if(tmp)tmp.set("src",_self.path + tmp.get("dfFill"));
  222. _self.openHomePage();
  223. }
  224. })
  225. },
  226. openModule:function(action){
  227. if(action == "homePage"){
  228. this.openHomePage();
  229. }else if(action == "message"){
  230. this.openMessage()
  231. }else if(action == "clue"){
  232. this.openClue();
  233. }else if(action == "customer"){
  234. this.openCustomer()
  235. }else if(action == "publicseas"){
  236. this.openPublicseas()
  237. } else if(action == "contact"){
  238. this.openContact()
  239. }else if(action == "chance"){
  240. this.openChance()
  241. }else if(action == "stat"){
  242. this.openStat()
  243. }
  244. },
  245. openHomePage:function(){
  246. //首页
  247. //if(this.rightContentDiv)this.rightContentDiv.empty();
  248. if(this.indexModule) delete this.indexModule;
  249. MWF.xDesktop.requireApp("CRM","Index",function(){
  250. if(this.rightContentDiv) this.rightContentDiv.destroy();
  251. this.rightContentDiv = new Element("div.rightContentDiv#rightContentDiv",{"styles":this.css.rightContentDiv}).inject(this.middleContentDiv);
  252. this.resizeWindow();
  253. this.indexModule = new MWF.xApplication.CRM.Index(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  254. this.indexModule.load();
  255. }.bind(this));
  256. },
  257. openMessage:function(){
  258. //信息
  259. if(this.rightContentDiv)this.rightContentDiv.empty();
  260. if(this.messageModule) delete this.messageModule;
  261. MWF.xDesktop.requireApp("CRM", "Message", function(){
  262. this.messageModule = new MWF.xApplication.CRM.Message(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  263. this.messageModule.load();
  264. }.bind(this))
  265. },
  266. openClue:function(){
  267. //线索
  268. if(this.rightContentDiv)this.rightContentDiv.empty();
  269. if(this.clueModule) delete this.clueModule;
  270. MWF.xDesktop.requireApp("CRM","Clue",function(){
  271. this.clueModule = new MWF.xApplication.CRM.Clue(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  272. this.clueModule.load();
  273. }.bind(this));
  274. },
  275. openCustomer:function(){
  276. //客户
  277. if(this.rightContentDiv)this.rightContentDiv.empty();
  278. if(this.customerModule) delete this.customerModule;
  279. MWF.xDesktop.requireApp("CRM", "Customer", function(){
  280. this.customerModule = new MWF.xApplication.CRM.Customer(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  281. this.customerModule.load();
  282. }.bind(this))
  283. },
  284. openPublicseas:function(){
  285. //客户
  286. if(this.rightContentDiv)this.rightContentDiv.empty();
  287. if(this.publicseasModule) delete this.publicseasModule;
  288. MWF.xDesktop.requireApp("CRM", "Publicseas", function(){
  289. this.publicseasModule = new MWF.xApplication.CRM.Publicseas(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  290. this.publicseasModule.load();
  291. }.bind(this))
  292. },
  293. openContact:function(){
  294. if(this.rightContentDiv)this.rightContentDiv.empty();
  295. if(this.contactsModule) delete this.contactsModule;
  296. MWF.xDesktop.requireApp("CRM", "Contacts", function(){
  297. this.contactsModule = new MWF.xApplication.CRM.Contacts(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  298. this.contactsModule.load();
  299. }.bind(this))
  300. },
  301. openChance: function(){
  302. //商机
  303. if(this.rightContentDiv)this.rightContentDiv.empty();
  304. if(this.chanceModule) delete this.chanceModule;
  305. MWF.xDesktop.requireApp("CRM", "Chance", function(){
  306. this.chanceModule = new MWF.xApplication.CRM.Chance(this.rightContentDiv,this,this.actions,{"isAdmin":this.isAdmin()});
  307. this.chanceModule.load();
  308. }.bind(this))
  309. },
  310. openStat: function(){
  311. },
  312. ////////////////////left//////////////////////////////////////
  313. ////////////////////right//////////////////////////////////////
  314. createRightContent:function(){
  315. if(this.rightContentDiv) this.rightContentDiv.destroy();
  316. this.rightContentDiv = new Element("div.rightContentDiv",{"styles":this.css.rightContentDiv}).inject(this.middleContentDiv);
  317. },
  318. ////////////////////right//////////////////////////////////////
  319. //////////////////////////////////////公用方法///////////////////////////////////////////////
  320. resizeWindow:function(){
  321. var size = this.content.getSize();
  322. if(this.middleContentDiv) this.middleContentDiv.setStyles({"height":(size.y-this.topContentDiv.getSize().y)+"px"});
  323. if(this.middleContentDiv) var midSize = this.middleContentDiv.getSize();
  324. if(this.leftContentDiv) this.leftContentDiv.setStyles({"height":midSize.y+"px"});
  325. if(this.rightContentDiv) this.rightContentDiv.setStyles({
  326. "height":midSize.y+"px",
  327. "width":(midSize.x-this.leftContentDiv.getSize().x)+"px",
  328. "margin-left":this.leftContentDiv.getSize().x+"px"
  329. })
  330. },
  331. recordStatus: function(){
  332. var status;
  333. status = {
  334. identity: this.identity
  335. };
  336. return status;
  337. },
  338. createShade: function(obj,t){
  339. var defaultObj = this.content;
  340. var obj = obj || defaultObj;
  341. var txt;
  342. txt = t || "loading...";
  343. if(this.shadeDiv){ this.shadeDiv.destroy()}
  344. if(this.shadeTxtDiv) this.shadeTxtDiv.destroy();
  345. this.shadeDiv = new Element("div.shadeDiv").inject(obj);
  346. this.inforDiv = new Element("div.inforDiv",{
  347. styles:{"height":"16px","display":"inline-block","position":"absolute","background-color":"#336699","border-radius":"3px","padding":"5px 10px"}
  348. }).inject(this.shadeDiv);
  349. this.loadImg = new Element("img.loadImg",{
  350. styles:{"width":"16px","height":"16px","float":"left"},
  351. src:"/x_component_CRM/$Main/default/icons/loading.gif"
  352. }).inject(this.inforDiv);
  353. this.shadeTxtSpan = new Element("span.shadeTxtSpan").inject(this.inforDiv);
  354. this.shadeTxtSpan.set("text",txt);
  355. this.shadeDiv.setStyles({
  356. "width":"100%","height":"100%","position":"absolute","opacity":"0.7","background-color":"#cccccc","z-index":"999"
  357. });
  358. this.shadeTxtSpan.setStyles({"color":"#ffffff","font-size":"12px","display":"inline-block","line-height":"16px","padding-left":"5px"});
  359. var x = obj.getSize().x;
  360. var y = obj.getSize().y;
  361. this.shadeDiv.setStyles({
  362. "left":(obj.getLeft()-defaultObj.getLeft())+"px",
  363. "top":(obj.getTop()-defaultObj.getTop())+"px",
  364. "width":x+"px",
  365. "height":y+"px"
  366. });
  367. if(obj.getStyle("position")=="absolute"){
  368. this.shadeDiv.setStyles({
  369. "left":"0px",
  370. "top":"0px"
  371. })
  372. }
  373. this.inforDiv.setStyles({
  374. "left":(x/2)+"px",
  375. "top":(y/2)+"px"
  376. })
  377. },
  378. destroyShade : function(){
  379. if(this.shadeDiv) this.shadeDiv.destroy();
  380. //if(this.shadeDiv) this.shadeDiv.destroy()
  381. },
  382. setScrollBar: function(node, view, style, offset, callback){
  383. if (!style) style = "default";
  384. if (!offset){
  385. offset = {
  386. "V": {"x": 0, "y": 0},
  387. "H": {"x": 0, "y": 0}
  388. };
  389. }
  390. MWF.require("MWF.widget.ScrollBar", function(){
  391. if(this.scrollbar && this.scrollbar.scrollVAreaNode){
  392. this.scrollbar.scrollVAreaNode.destroy();
  393. delete this.scrollbar;
  394. }
  395. this.scrollbar = new MWF.widget.ScrollBar(node, {
  396. "style": style||"default",
  397. "offset": offset,
  398. "indent": false,
  399. "distance": 50,
  400. "onScroll": function (y) {
  401. var scrollSize = node.getScrollSize();
  402. var clientSize = node.getSize();
  403. var scrollHeight = scrollSize.y - clientSize.y;
  404. //var view = this.baseView || this.centerView;
  405. if (y + 20 > scrollHeight && view && view.loadElementList) {
  406. if (! view.isItemsLoaded)view.loadElementList();
  407. }
  408. }.bind(this)
  409. });
  410. if (callback) callback();
  411. }.bind(this));
  412. return false;
  413. },
  414. showErrorMessage:function(xhr,text,error){
  415. var errorText = error;
  416. if (xhr) errorMessage = xhr.responseText;
  417. if(errorMessage!=""){
  418. var e = JSON.parse(errorMessage);
  419. if(e.message){
  420. this.notice( e.message,"error");
  421. }else{
  422. this.notice( errorText,"error");
  423. }
  424. }else{
  425. this.notice(errorText,"error");
  426. }
  427. }
  428. //////////////////////////////////////公用方法///////////////////////////////////////////////
  429. });