Chance.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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.xApplication.CRM.Chance = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default"
  9. },
  10. initialize: function (container, app, actions, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_CRM/$Chance/";
  13. this.cssPath = "../x_component_CRM/$Chance/"+this.options.style+"/css.wcss";
  14. this.lpPath = "../x_component_CRM/$Chance/"+this.options.style+"/zh-cn.js?v="+o2.version.v;
  15. this._loadCss();
  16. /*COMMON.AjaxModule.loadCss( this.path+this.options.style+"/main.css",function(){
  17. console.log("main.css,load complete");
  18. })*/
  19. this.app = app;
  20. this.container = $(container);
  21. this.lp={};//this.app.lp.chance;
  22. if(!this.lp.head){
  23. console.log("this.lp:::",this.lpPath);
  24. this.loadLP();
  25. this.lp = MWF.xApplication.CRM.Chance.LP.chance;
  26. }else{
  27. //console.log("222222222222");
  28. }
  29. console.log("this is Chance init()");
  30. this.actions = actions;
  31. },
  32. loadLP:function(){
  33. MWF.xDesktop.requireApp("CRM", "$Chance.default.nzh-cn", null, false);
  34. /*if(!MWF.xApplication.CRM.Chance.LP){
  35. MWF.xDesktop.requireApp("CRM", "$Chance.default."+o2.language, {
  36. "failure": function(){
  37. MWF.xDesktop.requireApp("CRM", "$Chance.default.nzh-cn", null, false);
  38. }.bind(this)
  39. }, false);
  40. }*/
  41. },
  42. load: function(){
  43. if(this.formContentArr)this.formContentArr.empty();
  44. this.formContentArr = [];
  45. if(this.formMarkArr)this.formMarkArr.empty();
  46. this.formMarkArr = [];
  47. this.rightContentDiv = this.app.rightContentDiv;
  48. this.createHeadContent();
  49. this.createToolBarContent();
  50. this.createChanceContent();
  51. this.resizeWindow();
  52. this.app.addEvent("resize", function(){
  53. this.resizeWindow();
  54. }.bind(this));
  55. },
  56. reload:function(){
  57. this.createChanceContent();
  58. this.resizeWindow();
  59. },
  60. createHeadContent:function(){
  61. if(this.headContentDiv) this.headContentDiv.destroy();
  62. console.log(this.css);
  63. this.headContentDiv = new Element("div.headContentDiv",{"styles":this.css.headContentDiv}).inject(this.rightContentDiv);
  64. this.headTitleDiv = new Element("div.headTitleDiv",{
  65. "styles":this.css.headTitleDiv,
  66. "text":this.lp.head.headTitle
  67. }).inject(this.headContentDiv);
  68. console.log("111111");
  69. //search
  70. this.headSearchDiv = new Element("div.headSearchDiv",{"styles":this.css.headSearchDiv}).inject(this.headContentDiv);
  71. this.headSearchTextDiv = new Element("div.headSearchTextDiv",{"styles":this.css.headSearchTextDiv}).inject(this.headSearchDiv);
  72. this.headSearchInput = new Element("input.headSearchInput",{
  73. "styles":this.css.headSearchInput,
  74. "placeholder":this.lp.head.searchText
  75. }).inject(this.headSearchTextDiv);
  76. this.headSearchInput.addEvents({
  77. "keyup":function(){
  78. if(this.headSearchInput.get("value")!=""){
  79. this.headSearchRemoveImg.setStyles({"display":"inline-block"});
  80. }
  81. }.bind(this)
  82. });
  83. this.headSearchRemoveImg = new Element("img.headSearchRemoveImg",{
  84. "styles":this.css.headSearchRemoveImg,
  85. "src": this.path+"default/icons/remove.png"
  86. }).inject(this.headSearchTextDiv);
  87. this.headSearchRemoveImg.addEvents({
  88. "click":function(){
  89. this.headSearchInput.set("value","");
  90. this.headSearchRemoveImg.setStyles({"display":"none"});
  91. }.bind(this)
  92. });
  93. this.headSearchButtonDiv = new Element("div.headSearchBottonDiv",{
  94. "styles":this.css.headSearchButtonDiv,
  95. //"text":this.lp.head.search
  96. }).inject(this.headSearchDiv);
  97. this.headSearchheadSearchButton= new Element("button.headSearchButton",{
  98. "styles":this.css.headSearchButton
  99. }).inject(this.headSearchButtonDiv);
  100. this.headSearchImg = new Element("img.headSearchImg",{
  101. "styles":this.css.headSearchImg,
  102. "src": this.path+"default/icons/search.png"
  103. }).inject(this.headSearchheadSearchButton);
  104. this.headButtonDiv = new Element("div.headButtonDiv",{"styles":this.css.headButtonDiv}).inject(this.headContentDiv);
  105. this.headNewButtonDiv = new Element("div.headNewButtonDiv",{
  106. "styles":this.css.headNewButtonDiv,
  107. "text" :this.lp.head.create
  108. }).inject(this.headButtonDiv);
  109. this.headNewButtonDiv.addEvents({
  110. "click":function(){
  111. MWF.xDesktop.requireApp("CRM", "ChanceEdit", function(){
  112. console.log("this.lp",this.lp);
  113. var editForm = new MWF.xApplication.CRM.ChanceEdit(null,{},null, {
  114. app: this.app,
  115. container : this.app.content,
  116. lp : this.lp,
  117. actions : this.actions,
  118. css : {},
  119. callback : function () {
  120. editForm.create();
  121. }
  122. });
  123. editForm.create();
  124. }.bind(this))
  125. }.bind(this)
  126. });
  127. },
  128. createToolBarContent:function(){
  129. },
  130. createChanceContent:function(){
  131. if(this.contentListDiv) this.contentListDiv.destroy();
  132. this.contentListDiv = new Element("div.contentListDiv",{"styles":this.css.contentListDiv}).inject(this.rightContentDiv);
  133. if(this.contentListInDiv) this.contentListInDiv.destroy();
  134. this.contentListInDiv = new Element("div.contentListInDiv",{"styles":this.css.contentListInDiv}).inject(this.contentListDiv);
  135. var size = this.rightContentDiv.getSize();
  136. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-8)+"px","width":(size.x)+"px"});
  137. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":this.contentListDiv.getHeight()+"px","width":(this.contentListDiv.getWidth())+"px"});
  138. if(this.chanceView) delete this.chanceView;
  139. var templateUrl = this.path+"chanceView.json";
  140. var filter = {};
  141. ////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} );
  142. this.chanceView = new MWF.xApplication.CRM.Chance.View(
  143. this.contentListInDiv,
  144. {},
  145. this.app,
  146. this,
  147. { templateUrl : templateUrl,filterData:filter},
  148. {
  149. isAdmin:this.options.isAdmin
  150. }
  151. );
  152. this.chanceView.load();
  153. //this.app.setScrollBar(this.contentListInDiv.getElement(".contentTableNode"),this.customerView,"crm");
  154. },
  155. resizeWindow:function(){
  156. var size = this.rightContentDiv.getSize();
  157. var rSize = this.headTitleDiv.getSize();
  158. var lSize = this.headButtonDiv.getSize();
  159. if(this.headSearchDiv){
  160. var x = this.headSearchDiv.getSize().x;
  161. this.headSearchDiv.setStyles({"margin-left":(size.x-rSize.x-lSize.x)/2-(x/2)+"px"});
  162. }
  163. //alert(JSON.stringify(size))
  164. if(this.contentListDiv)this.contentListDiv.setStyles({"height":(size.y-this.headContentDiv.getHeight()-8)+"px","width":(size.x)+"px"});
  165. if(this.contentListInDiv)this.contentListInDiv.setStyles({"height":this.contentListDiv.getHeight()+"px","width":(this.contentListDiv.getWidth())+"px"});
  166. }
  167. });
  168. MWF.xApplication.CRM.Chance.View = new Class({
  169. Extends: MWF.xApplication.CRM.Template.ComplexView,
  170. initialize: function (container, data, app, explorer, options, para) {
  171. this.container = container;
  172. this.data = data||{};
  173. this.explorer = explorer;
  174. if( para ){
  175. this.app = app || para.app || this.explorer.app;
  176. this.lp = para.lp || this.explorer.lp || this.app.lp;
  177. this.css = para.css || this.explorer.css || this.app.css;
  178. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  179. this.isAdmin = para.isAdmin;
  180. }else{
  181. this.app = app || this.explorer.app;
  182. this.lp = this.explorer.lp || this.app.lp;
  183. this.css = this.explorer.css || this.app.css;
  184. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  185. }
  186. /*template 外边传进来*/
  187. if (!options.templateUrl) {
  188. options.templateUrl = this.explorer.path + "listItem.json"
  189. } else if (options.templateUrl.indexOf("/") == -1) {
  190. options.templateUrl = this.explorer.path + options.templateUrl;
  191. }
  192. this.setOptions(options);
  193. },
  194. _createDocument: function(data){
  195. return new MWF.xApplication.CRM.Chance.Document(this.viewNode, data, this.explorer, this);
  196. },
  197. ayalyseTemplate: function () {
  198. MWF.getJSON(this.options.templateUrl, function (json) {
  199. this.template = json;
  200. console.log("this is template,",json);
  201. }.bind(this), false)
  202. },
  203. _getCurrentPageData: function(callback, count, page, searchText,searchType){
  204. var category = this.category = this.options.category;
  205. if (!count)count = 10;
  206. if (!page)page = 1;
  207. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  208. //if(id=="(0)")this.app.createShade();
  209. var filter = this.options.filterData || {};
  210. /*if(searchText){
  211. filter = {
  212. key:searchText
  213. };
  214. }
  215. this.actions.getChanceByPage(page, count, filter, function (json) {
  216. if (callback)callback(json);
  217. //this.app.destroyShade();
  218. }.bind(this));*/
  219. filter={key: searchText?searchText.trim():"",
  220. orderFieldName: "updateTime",
  221. orderType: "desc"
  222. };
  223. if (!searchType)searchType = "全部商机";
  224. if(!this.isAdmin||searchType!="全部商机"){
  225. if(searchType=="我负责的商机"){
  226. this.actions.ListMyDuty_chance(page, count, filter, function (json) {
  227. if (callback)callback(json);
  228. }.bind(this));
  229. }
  230. if(searchType=="下属负责的商机"){
  231. this.actions.ListNestedSubPerson_chance(page, count, filter, function (json) {
  232. if (callback)callback(json);
  233. }.bind(this));
  234. }
  235. if(searchType=="我参与的商机"){
  236. this.actions.ListMyParticipate_chance(page, count, filter, function (json) {
  237. if (callback)callback(json);
  238. }.bind(this));
  239. }
  240. if(searchType=="全部商机"){
  241. this.actions.ListAllMy_chance(page, count, filter, function (json) {
  242. if (callback)callback(json);
  243. }.bind(this));
  244. }
  245. }else{
  246. this.actions.getChanceByPage(page, count, filter, function (json) {
  247. if (callback)callback(json);
  248. }.bind(this));
  249. }
  250. },
  251. useTablePlugins: function (cpage,searchText,searchType) {
  252. console.log("this is useTablePlugins page:"+cpage+";;;;text:"+searchText);
  253. if(jQuery(".laytable-box").length > 0) jQuery(".laytable-box").remove();
  254. var that = this;
  255. var cdata = [];
  256. var cols = [];
  257. var col = [];
  258. var sortField = "";
  259. var sortType = "";
  260. var chanceViewObject = this.template;
  261. var count = 15;
  262. sortField = chanceViewObject.sortField;
  263. sortType = chanceViewObject.sortType;
  264. var csize = this.container.getSize();
  265. var hsize = this.headTableNode.getSize();
  266. var tHeight = csize.y-hsize.y-80;
  267. if (!cpage)cpage = 1;
  268. /*for ( i in chanceListObject){
  269. cols.push(chanceListObject[i]);
  270. }*/
  271. cols = chanceViewObject.field;
  272. //cols.push(col);
  273. this._getCurrentPageData(function (json) {
  274. json.data.each(function (data ) {
  275. if(data.owneruser){
  276. var owneruser = data.owneruser;
  277. var createuser = data.createuser;
  278. data.owneruser = owneruser.split("@")[0];
  279. data.createuser = createuser.split("@")[0];
  280. }else{
  281. data.owneruser = "";
  282. data.createuser = "";
  283. }
  284. cdata.push(data);
  285. }.bind(this));
  286. cdata = json.data;
  287. layui.config({
  288. base: '../x_component_CRM/$Template/plugins/table2/'
  289. }).use(['table2', "table2"], function () {
  290. var table = layui.table2;
  291. console.log(cols);
  292. var tableIns = table.render({
  293. elem: "#contentTable",
  294. data: cdata,
  295. height: tHeight,
  296. width: '100%',
  297. page: {
  298. align: 'right',
  299. groups: 5,//显示连续页码数量
  300. curr:1,
  301. count: json.count,//总条数
  302. limit:10,
  303. limits:[10, 20, 30, 40, 50, 60, 70, 80, 90]
  304. },
  305. initSort: {
  306. sortField: sortField,
  307. sortType: sortType
  308. },
  309. cols:[cols]
  310. });
  311. that.container.getElements(".chanceId").forEach(
  312. function (e,i) {
  313. //console.log("this is chanceId click fun:::::",e,i);
  314. e.addEvent("click",function(){
  315. console.log(this);
  316. that._openDocument(this.get("id"),this.text);
  317. }.bind(e))
  318. }
  319. );
  320. that.container.getElements(".customerId").forEach(
  321. function (e,i) {
  322. //console.log("this is customerid click fun:::::",e,i);
  323. e.addEvent("click",function(){
  324. console.log(this);
  325. that._openCustomer(this.get("id"),this.text);
  326. }.bind(e))
  327. }
  328. );
  329. jQuery(".laytable-page-pagination").find("a").each(function(index,element){
  330. jQuery(element).on("click", function () {
  331. //cpage = parseInt(jQuery(element).attr("value"))+cpage;
  332. var topage = 1;
  333. if(jQuery(element).attr("value")=="-1" || jQuery(element).attr("value")=="+1"){
  334. topage = parseInt(jQuery(element).attr("value"))+topage;
  335. }else{
  336. topage = parseInt(jQuery(element).text());
  337. }
  338. if(jQuery(element).attr("class")!="page-item page-last rayui-disabled" && jQuery(element).attr("class")!="page-item page-prev rayui-disabled"){
  339. //that.useTablePlugins(topage);
  340. var searchText = jQuery(".headSearchInput").val();
  341. var searchType ="";
  342. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  343. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  344. }
  345. if(searchText!=""){
  346. that.useTablePlugins(topage,searchText,searchType);
  347. }else{
  348. that.useTablePlugins(topage,"",searchType);
  349. }
  350. }
  351. });
  352. }
  353. );
  354. jQuery(".laytable-page-btnok").on("click", function () {
  355. var cpage = parseInt(jQuery(".laytable-page-input").val());
  356. var searchText = jQuery(".headSearchInput").val();
  357. var searchType ="";
  358. if(jQuery(".headTableNode").find(".se-select-name").length > 0){
  359. searchType = jQuery(".headTableNode").find(".se-select-name").text();
  360. }
  361. if(searchText!=""){
  362. that.useTablePlugins(cpage,searchText,searchType);
  363. }else{
  364. that.useTablePlugins(cpage,"",searchType);
  365. }
  366. });
  367. jQuery(".page-item").each(function(index,element){
  368. if(jQuery(element).attr("value")==(cpage+"")){
  369. jQuery(element).attr("class","page-item page-active");
  370. }else{
  371. if(jQuery(element).attr("value")!="-1" && jQuery(element).attr("value")!="+1"){
  372. jQuery(element).attr("class","page-item");
  373. }
  374. }
  375. });
  376. var cCount = jQuery(".page-active").attr("value");
  377. var firstObj = jQuery(".page-prev").parent().next().find("a")[0];
  378. var lastObj = jQuery(".page-last").parent().prev().find("a")[0];
  379. if(parseInt(cCount)>parseInt(jQuery(firstObj).attr("value"))){
  380. jQuery(".page-prev").attr("class","page-item page-prev");
  381. }else{
  382. jQuery(".page-prev").attr("class","page-item page-prev rayui-disabled");
  383. }
  384. if(parseInt(cCount)==parseInt(jQuery(lastObj).attr("value"))){
  385. jQuery(".page-last").attr("class","page-item page-last rayui-disabled");/////
  386. }else{
  387. jQuery(".page-last").attr("class","page-item page-last");
  388. }
  389. jQuery(".laytable-page-input").attr("value",cpage+"");
  390. });
  391. }.bind(this),count, cpage,searchText,searchType);
  392. },
  393. _openDocument: function( id , name ){
  394. //if(this.customerRead){
  395. // this.customerRead.load(documentData)
  396. //}else{
  397. MWF.xDesktop.requireApp("CRM", "ChanceOpen", function(){
  398. this.explorer = new MWF.xApplication.CRM.ChanceOpen(this, this.actions,{},{
  399. "openId":id,
  400. "openName":name,
  401. "openType":"single",
  402. "lp":this.lp,
  403. "onReloadView" : function( ){
  404. //alert(JSON.stringify(data))
  405. this.reload();
  406. }.bind(this)
  407. });
  408. this.explorer.load();
  409. }.bind(this))
  410. },
  411. _openCustomer: function(openId ,openName){
  412. MWF.xDesktop.requireApp("CRM", "CustomerOpen", function(){
  413. this.explorer = new MWF.xApplication.CRM.CustomerOpen(this, this.actions,{},{
  414. "openId":openId,
  415. "openName":openName,
  416. "openType":"single",
  417. "onReloadView" : function( ){
  418. //alert(JSON.stringify(data))
  419. this.reload();
  420. }.bind(this)
  421. });
  422. this.explorer.load();
  423. }.bind(this))
  424. },
  425. });
  426. MWF.xApplication.CRM.Chance.Document = new Class({
  427. Extends: MWF.xApplication.CRM.Template.ComplexDocument,
  428. "viewActionReturn":function(){
  429. return false
  430. }
  431. });