Main.js 13 KB

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