Customer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. MWF.xApplication.CRM = MWF.xApplication.CRM || {};
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xDesktop.requireApp("CRM", "Template", null,false);
  4. MWF.xDesktop.requireApp("Template", "Explorer", null,false);
  5. MWF.require("MWF.widget.Identity", null,false);
  6. /*MWF.xDesktop.requireApp("Forum", "Actions.RestActions", null, false);*/
  7. MWF.xApplication.CRM.Customer = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default"
  12. },
  13. initialize: function (node, app, actions, options) {
  14. this.setOptions(options);
  15. this.app = app;
  16. this.lp = app.lp.customer;
  17. this.path = "/x_component_CRM/$Customer/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. debugger
  22. },
  23. loadCss: function () {
  24. this.cssPath = "/x_component_CRM/$Customer/" + this.options.style + "/css.wcss";
  25. this._loadCss();
  26. },
  27. load: function () {
  28. //this.testActions = new MWF.xApplication.Forum.Actions.RestActions();
  29. if(this.formContentArr)this.formContentArr.empty();
  30. this.formContentArr = [];
  31. if(this.formMarkArr)this.formMarkArr.empty();
  32. this.formMarkArr = [];
  33. this.rightContentDiv = this.app.rightContentDiv;
  34. this.createHeadContent();
  35. //this.createToolBarContent();
  36. this.createCustomerContent();
  37. this.resizeWindow();
  38. this.app.addEvent("resize", function(){
  39. this.resizeWindow();
  40. }.bind(this));
  41. },
  42. reload:function(){
  43. this.createCustomerContent();
  44. this.resizeWindow();
  45. },
  46. createHeadContent:function(){
  47. debugger
  48. if(this.headContentDiv) this.headContentDiv.destroy();
  49. this.headContentDiv = new Element("div.headContentDiv",{"styles":this.css.headContentDiv}).inject(this.rightContentDiv);
  50. this.headTitleDiv = new Element("div.headTitleDiv",{
  51. "styles":this.css.headTitleDiv,
  52. "text":this.lp.head.headTitle
  53. }).inject(this.headContentDiv);
  54. //search
  55. this.headSearchDiv = new Element("div.headSearchDiv",{"styles":this.css.headSearchDiv}).inject(this.headContentDiv);
  56. this.headSearchTextDiv = new Element("div.headSearchTextDiv",{"styles":this.css.headSearchTextDiv}).inject(this.headSearchDiv);
  57. this.headSearchImg = new Element("img.headSearchImg",{
  58. "styles":this.css.headSearchImg,
  59. "src": this.path+"default/icons/search.png"
  60. }).inject(this.headSearchTextDiv);
  61. this.headSearchInput = new Element("input.headSearchInput",{
  62. "styles":this.css.headSearchInput,
  63. "placeholder":this.lp.head.searchText
  64. }).inject(this.headSearchTextDiv);
  65. this.headSearchInput.addEvents({
  66. "keyup":function(){
  67. if(this.headSearchInput.get("value")!=""){
  68. this.headSearchRemoveImg.setStyles({"display":"inline-block"})
  69. }
  70. }.bind(this)
  71. });
  72. this.headSearchRemoveImg = new Element("img.headSearchRemoveImg",{
  73. "styles":this.css.headSearchRemoveImg,
  74. "src": this.path+"default/icons/remove.png"
  75. }).inject(this.headSearchTextDiv);
  76. this.headSearchRemoveImg.addEvents({
  77. "click":function(){
  78. this.headSearchInput.set("value","")
  79. }.bind(this)
  80. });
  81. this.headSearchBottonDiv = new Element("div.headSearchBottonDiv",{
  82. "styles":this.css.headSearchBottonDiv,
  83. "text":this.lp.head.search
  84. }).inject(this.headSearchDiv);
  85. this.headBottonDiv = new Element("div.headBottonDiv",{"styles":this.css.headBottonDiv}).inject(this.headContentDiv);
  86. this.headNewBottonDiv = new Element("div.headNewBottonDiv",{
  87. "styles":this.css.headNewBottonDiv,
  88. "text" :this.lp.head.create
  89. }).inject(this.headBottonDiv);
  90. this.headNewBottonDiv.addEvents({
  91. "click":function(){
  92. MWF.xDesktop.requireApp("CRM", "CustomerEdit", function(){
  93. this.explorer = new MWF.xApplication.CRM.CustomerEdit(this, this.actions,{},{
  94. "isEdited":true,
  95. "isNew":true,
  96. "onReloadView" : function( ){
  97. //alert(JSON.stringify(data))
  98. //this.reload();
  99. }.bind(this)
  100. });
  101. this.explorer.load();
  102. }.bind(this))
  103. }.bind(this)
  104. });
  105. this.headMoreBottonDiv = new Element("div.headMoreBottonDiv",{
  106. "styles":this.css.headMoreBottonDiv,
  107. "text" :this.lp.head.moreAction
  108. }).inject(this.headBottonDiv);
  109. this.headMoreBottonDiv.addEvents({
  110. "click":function(){
  111. }.bind(this)
  112. });
  113. this.headMoreImg = new Element("img.headMoreImg",{
  114. "styles": this.css.headMoreImg,
  115. "src" : this.path+"default/icons/arrow.png"
  116. }).inject(this.headMoreBottonDiv);
  117. },
  118. createToolBarContent:function(){
  119. },
  120. createCustomerContent:function(){
  121. if(this.contentListDiv) this.contentListDiv.destroy();
  122. this.contentListDiv = new Element("div.contentListDiv",{"styles":this.css.contentListDiv}).inject(this.rightContentDiv);
  123. if(this.contentListInDiv) this.contentListInDiv.destroy();
  124. this.contentListInDiv = new Element("div.contentListInDiv",{"styles":this.css.contentListInDiv}).inject(this.contentListDiv);
  125. var size = this.rightContentDiv.getSize();
  126. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-8)+"px"});
  127. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":this.contentListDiv.getHeight()+"px","width":"100%"});
  128. if(this.customerView) delete this.customerView;
  129. var templateUrl = this.path+"customerView.json";
  130. var filter = {};
  131. ////this.customerView = new MWF.xApplication.CRM.Customer.View(this.contentListInDiv, this.app, {lp : this.app.lp.curtomerView, css : this.css, actions : this.actions }, { templateUrl : templateUrl,filterData:filter} );
  132. this.customerView = new MWF.xApplication.CRM.Customer.View(
  133. this.contentListInDiv,
  134. this.openDiv,
  135. this.app,
  136. this,
  137. { templateUrl : templateUrl,filterData:filter},
  138. {
  139. lp:this.app.lp.customerView,
  140. isAdmin:this.options.isAdmin
  141. }
  142. );
  143. this.customerView.load();
  144. },
  145. resizeWindow:function(){
  146. var size = this.rightContentDiv.getSize();
  147. var rSize = this.headTitleDiv.getSize();
  148. var lSize = this.headBottonDiv.getSize();
  149. if(this.headSearchDiv){
  150. var x = this.headSearchDiv.getSize().x;
  151. this.headSearchDiv.setStyles({"margin-left":(size.x-rSize.x-lSize.x)/2-(x/2)+"px"});
  152. }
  153. //alert(JSON.stringify(size))
  154. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-8)+"px"});
  155. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":this.contentListDiv.getHeight()+"px"});
  156. }
  157. });
  158. MWF.xApplication.CRM.Customer.View = new Class({
  159. Extends: MWF.xApplication.CRM.Template.ComplexView,
  160. _createDocument: function(data){
  161. return new MWF.xApplication.CRM.Clue.Document(this.viewNode, data, this.explorer, this);
  162. },
  163. _getCurrentPageData: function(callback, count, page, searchText,searchType){
  164. var category = this.category = this.options.category;
  165. if (!count)count = 15;
  166. if (!page)page = 1;
  167. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  168. //if(id=="(0)")this.app.createShade();
  169. var filter = this.options.filterData || {};
  170. filter={key: searchText?searchText.trim():"",
  171. orderFieldName: "updateTime",
  172. orderType: "desc"
  173. };
  174. if (!searchType)searchType = "全部客户";
  175. if(!this.isAdmin){
  176. debugger
  177. if(searchType=="我负责的客户"){
  178. this.actions.ListMyDuty_customer(page, count, filter, function (json) {
  179. if (callback)callback(json);
  180. }.bind(this));
  181. }
  182. if(searchType=="下属负责的客户"){
  183. this.actions.ListNestedSubPerson_customer(page, count, filter, function (json) {
  184. if (callback)callback(json);
  185. }.bind(this));
  186. }
  187. if(searchType=="我参与的客户"){
  188. this.actions.ListMyParticipate_customer(page, count, filter, function (json) {
  189. if (callback)callback(json);
  190. }.bind(this));
  191. }
  192. if(searchType=="全部客户"){
  193. this.actions.ListAllMy_customer(page, count, filter, function (json) {
  194. if (callback)callback(json);
  195. }.bind(this));
  196. }
  197. }else{
  198. this.actions.getCustomerListPage(page, count, filter, function (json) {
  199. if (callback)callback(json);
  200. }.bind(this));
  201. }
  202. },
  203. _create: function(){
  204. },
  205. _openDocument: function(openId ,openName){
  206. /*MWF.xDesktop.requireApp("CRM", "ClueEdit", function(){
  207. this.explorer = new MWF.xApplication.CRM.ClueEdit(this, this.actions,{},{
  208. "clueId":clueId,
  209. "onReloadView" : function( ){
  210. //alert(JSON.stringify(data))
  211. this.reload();
  212. }.bind(this)
  213. });
  214. this.explorer.load();
  215. }.bind(this))*/
  216. MWF.xDesktop.requireApp("CRM", "CustomerOpen", function(){
  217. this.explorer = new MWF.xApplication.CRM.CustomerOpen(this, this.actions,{},{
  218. "openId":openId,
  219. "openName":openName,
  220. "openType":"single",
  221. "onReloadView" : function( ){
  222. //alert(JSON.stringify(data))
  223. this.reload();
  224. }.bind(this)
  225. });
  226. this.explorer.load();
  227. }.bind(this))
  228. },
  229. _queryCreateViewNode: function(){
  230. },
  231. _postCreateViewNode: function( viewNode ){
  232. },
  233. _queryCreateViewHead:function(){
  234. },
  235. _postCreateViewHead: function( headNode ){
  236. }
  237. });
  238. MWF.xApplication.CRM.Customer.Document = new Class({
  239. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  240. _queryCreateDocumentNode:function( itemData ){
  241. },
  242. _postCreateDocumentNode: function( itemNode, itemData ){
  243. this.view.template.items.each(function (item,i) {
  244. if(item.head.width){
  245. itemNode.getElements("td")[i].set("width",item.head.width);
  246. }
  247. if(i == itemNode.getElements("td").length-1){
  248. itemNode.getElements("td")[i].set("width",this.view.lastTdWidth);
  249. }
  250. }.bind(this));
  251. },
  252. open: function (e) {
  253. this.view._openDocument(this.data, this.index);
  254. },
  255. edit : function(){
  256. var appId = "ForumDocument"+this.data.id;
  257. if (this.app.desktop.apps[appId]){
  258. this.app.desktop.apps[appId].setCurrent();
  259. }else {
  260. this.app.desktop.openApplication(null, "ForumDocument", {
  261. "sectionId" : this.data.sectionId,
  262. "id" : this.data.id,
  263. "appId": appId,
  264. "isEdited" : true,
  265. "isNew" : false,
  266. "index" : this.index
  267. });
  268. }
  269. }
  270. })
  271. //
  272. //MWF.xApplication.CRM.Customer.View = new Class({
  273. // Extends: MWF.xApplication.Template.Explorer.ComplexView,
  274. //
  275. // _createDocument: function(data){
  276. // return new MWF.xApplication.CRM.Customer.Document(this.viewNode, data, this.explorer, this);
  277. // },
  278. //
  279. // _getCurrentPageData: function(callback, count){
  280. // var category = this.category = this.options.category;
  281. //
  282. // if (!count)count = 20;
  283. // var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  284. //
  285. // if(id=="(0)")this.app.createShade();
  286. //
  287. // var filter = this.options.filterData || {};
  288. //
  289. // this.actions.getCustomerListNext(id, count, filter, function (json) {
  290. // if (callback)callback(json);
  291. // this.app.destroyShade();
  292. // }.bind(this));
  293. //
  294. // },
  295. // _create: function(){
  296. //
  297. // },
  298. // _openDocument: function( documentData ){
  299. //
  300. // //if(this.customerRead){
  301. // // this.customerRead.load(documentData)
  302. // //}else{
  303. // MWF.xDesktop.requireApp("CRM", "CustomerRead", function(){
  304. // this.customerRead = new MWF.xApplication.CRM.CustomerRead(this.explorer.contentListDiv,this.app, this.explorer,this.actions,{
  305. // "width":1000,
  306. // "onReloadView" : function(){
  307. // this.explorer.reloadCustomerView();
  308. // }.bind(this)
  309. // } );
  310. // this.customerRead.load(documentData);
  311. // this.explorer.formContentArr.push(this.customerRead);
  312. // this.explorer.formMarkArr.push(this.customerRead.formMaskNode);
  313. //
  314. // }.bind(this));
  315. // //}
  316. //
  317. // },
  318. // _queryCreateViewNode: function(){
  319. //
  320. // },
  321. // _postCreateViewNode: function( viewNode ){
  322. //
  323. // },
  324. // _queryCreateViewHead:function(){
  325. //
  326. // },
  327. // _postCreateViewHead: function( headNode ){
  328. //
  329. // }
  330. //
  331. //});
  332. //
  333. //MWF.xApplication.CRM.Customer.Document = new Class({
  334. // Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  335. //
  336. // "viewActionReturn":function(){
  337. // return false
  338. // }
  339. //
  340. //});