ChanceEdit.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  2. MWF.xApplication.CRM.ChanceEdit = new Class({
  3. Extends: MPopupForm,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "width": "800",
  8. "height": "600",
  9. "hasTop": true,
  10. "hasIcon": false,
  11. "hasTopIcon" : false,
  12. "hasTopContent" : false,
  13. "draggable": true,
  14. "maxAction" : true,
  15. "closeAction": true,
  16. "isFull" : false,
  17. "startTime" : null,
  18. "endTime" : null,
  19. "isWholeday" : false,
  20. "title" : "新建商机",
  21. "defaultCalendarId" : ""
  22. },
  23. load: function(){
  24. this.lp = this.lp.chanceEdit||{};
  25. this.cssPath = "/x_component_CRM/$ChanceEdit/"+this.options.style+"/css.wcss";
  26. this.path = "/x_component_CRM/$ChanceEdit/";
  27. this.type ={};
  28. this._loadCss();
  29. this.loadData();
  30. },
  31. create: function () {
  32. this.fireEvent("queryCreate");
  33. this.isNew = true;
  34. this.loadResource(function(){
  35. this._open();
  36. }.bind(this));
  37. this.fireEvent("postCreate");
  38. },
  39. edit: function(){
  40. this.fireEvent("queryCreate");
  41. this.isEdited = true;
  42. this.loadResource(function(){
  43. this._open();
  44. }.bind(this));
  45. this.fireEvent("postCreate");
  46. },
  47. loadData: function(){
  48. this.Customer = this.data&&this.data.customer?this.data.customer:{};
  49. if(!this.types){
  50. this.actions.getTypes(function(json){
  51. this.types=json.data;
  52. }.bind(this));
  53. if(this.types&&this.types.length){
  54. //var self = this;
  55. for(i = 0 ; i < this.types.length ; i ++){
  56. this.actions.getStatusByTypeid(this.types[i].id,function (json) {
  57. //this.statusid[type.id]=json.data;
  58. this.types[i].statusid = json.data;
  59. // console.log("this is complete statusid===>>>>",this.data.statusid,"======",json.data.id)
  60. json.data.forEach(function(e,i){
  61. if(this.data.statusid==e.id){
  62. this.statusid = e;
  63. }
  64. }.bind(this))
  65. }.bind(this))
  66. if(this.data.typeid==this.types[i].id){
  67. this.type=this.types[i];
  68. }
  69. }
  70. }
  71. }
  72. //console.log(this.types);
  73. },
  74. loadResource: function ( callback ) {
  75. callback();
  76. /*var baseUrls = [
  77. "/x_component_CRM/$Template/assets/js/jquery.min.js",
  78. ];
  79. var fullcalendarUrl = "/x_component_CRM/$Template/assets/js/notifyme.js";
  80. var confirmUrl = "/x_component_CRM/$Template/assets/js/showBo.js";
  81. //var confirmUrl = "/x_component_CRM/$Main/laydate/laydate.js";
  82. COMMON.AjaxModule.loadCss("/x_component_CRM/$Template/assets/css/notifyme.css",function(){
  83. COMMON.AjaxModule.load(baseUrls, function(){
  84. jQuery.noConflict();
  85. COMMON.AjaxModule.load(fullcalendarUrl, function(){
  86. COMMON.AjaxModule.load(confirmUrl, function(){
  87. //if(callback)callback();
  88. }.bind(this))
  89. }.bind(this));
  90. }.bind(this))
  91. }.bind(this));
  92. COMMON.AjaxModule.loadCss("/x_component_CRM/$Template/date/css/jquery-ui.css",function(){
  93. COMMON.AjaxModule.load(baseUrls, function(){
  94. jQuery.noConflict();
  95. COMMON.AjaxModule.load("/x_component_CRM/$Template/date/jquery-ym-datePlugin-0.1.js", function(){
  96. if(callback)callback();
  97. /!* COMMON.AjaxModule.load("/x_component_CRM/$Template/date/js/datepicker.all.js", function(){
  98. if(callback)callback();
  99. }.bind(this))*!/
  100. }.bind(this));
  101. }.bind(this))
  102. }.bind(this));*/
  103. },
  104. _createTableContent: function(){
  105. this.formTableArea.set("html", this.getHtml());
  106. //this.formTableArea.setClassName("notify-content");
  107. this.formTableArea.getElements(".conent-value").forEach(function(e,i){
  108. var cobj = e.getChildren()[0];
  109. var stype = cobj.getAttribute("stype");
  110. var sid = cobj.getAttribute("id");
  111. if(stype=="datetime"&&(this.isNew||this.isEdited)){
  112. this.loadTimeContainer(cobj);
  113. }
  114. if(sid=="typeid"&&(this.isNew||this.isEdited)){
  115. var self = this;
  116. var valueArr = this.types;
  117. if(valueArr.length>0){
  118. var selectHtml = '<ul class="el-dropdown-type" style="display: none;" tid="'+sid+'">'
  119. for(var n=0;n<valueArr.length;n++){
  120. selectHtml = selectHtml+'<li class="el-dropdown-menu__item" index="'+n+'">'+valueArr[n].opportunitytypename+'</li>'
  121. }
  122. jQuery(self.formTableArea).append(selectHtml+'<div class="popper__arrow"></div></ul>');
  123. jQuery(cobj).click(function(){
  124. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).css({"left":jQuery(cobj).offset().left,"top":jQuery(cobj).offset().top+30})
  125. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).toggle(100);
  126. }.bind(this));
  127. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).children().click(function(){
  128. debugger
  129. jQuery(cobj).text(jQuery(this).text());
  130. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).toggle(100);
  131. var newTypeid = self.types[jQuery(this).attr("index")];
  132. if(!self.type||newTypeid.id!=self.type.id){
  133. self.type = newTypeid;
  134. self.statusid = {};
  135. self.changeType();
  136. }
  137. });
  138. }
  139. }else if(sid=="statusid"&&(this.isNew||this.isEdited)){
  140. this.changeType = function(){
  141. var cobj = this.formTableArea.getElement("#statusid");
  142. var self = this;
  143. // console.log("this is statusid=====>>>",this.statusid);
  144. var valueArr = this.type.statusid;
  145. jQuery("[tid=statusid]").remove();
  146. if(!self.statusid||!self.statusid.id){
  147. jQuery(cobj).text("");
  148. }
  149. if(valueArr&&valueArr.length>0){
  150. var selectHtml = '<ul class="el-dropdown-type" style="display: none;" tid="statusid">'
  151. for(var n=0;n<valueArr.length;n++){
  152. selectHtml = selectHtml+'<li class="el-dropdown-menu__item" index="'+n+'">'+valueArr[n].opportunitystatusname+'</li>'
  153. }
  154. jQuery(self.formTableArea).append(selectHtml+'<div class="popper__arrow"></div></ul>');
  155. jQuery(cobj).unbind().click(function(){
  156. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).css({"left":jQuery(cobj).offset().left,"top":jQuery(cobj).offset().top+30})
  157. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).toggle(100);
  158. });
  159. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).children().click(function(){
  160. var newStatusid = self.type.statusid[jQuery(this).attr("index")];
  161. self.statusid = newStatusid;
  162. jQuery(cobj).text(jQuery(this).text());
  163. jQuery(self.formTableArea.getElement("[tid="+sid+"]")).toggle(100);
  164. });
  165. }
  166. }.bind(this);
  167. this.changeType();
  168. }else if(sid=="customer"&&(this.isNew||this.isEdited)){
  169. cobj.setAttribute("readOnly","true");
  170. jQuery(cobj).click(function(){
  171. this.selectCustomer = new MWF.xApplication.CRM.ChanceEdit.selectForm (null,{},null, {
  172. app: this,
  173. container: this.formTableArea,
  174. lp: this.lp,
  175. actions: this.actions,
  176. css: {},
  177. }
  178. );
  179. this.selectCustomer.create();
  180. }.bind(this));
  181. }
  182. }.bind(this));
  183. },
  184. getHtml: function(){
  185. var section_header = '<div class="section-header"><div class="section-mark" style="border-left-color: rgb(70, 205, 207);"></div> '+
  186. '<div data-v-ec8f8850="" class="section-title">基本信息</div></div>';
  187. var itemTemplateObject = this.getItemTemplate(this.lp );
  188. var section_conent = '<div class="section-conent">';
  189. for ( i in itemTemplateObject){
  190. var stype = itemTemplateObject[i].type;
  191. var innerHtml = '<input type="text" class="inline-input" '+(this.isEdited||this.isNew?'':'readOnly')+' value="'+itemTemplateObject[i].value+'" name="'+i+'" id="'+i+'" stype="'+stype+'">';
  192. if(stype=="textarea"){
  193. innerHtml = '<textarea rows="6" class="el-textarea__inner" '+(this.isEdited||this.isNew?'':'readOnly')+' id="'+i+'" stype="'+stype+'" style="resize: none; min-height: 30.6px;">'+itemTemplateObject[i].value+'</textarea>';
  194. }
  195. if(stype=="select"){
  196. innerHtml = '<div class="inline-input" style="display: inline-block;cursor:pointer;" '+(this.isEdited||this.isNew?'':'readOnly')+' id="'+i+'" stype="'+stype+'" >'+itemTemplateObject[i].value+'</div><div class="el-icon-arrow-down el-icon--right" style="margin-left: -20px; display: inline-block;"><img src="/x_component_CRM/$ChanceEdit/default/icons/arrow.png"></div>';
  197. }
  198. section_conent = section_conent+'<div class="conent-inline"><div class="conent-title" lable="'+i+'">'+itemTemplateObject[i].text+'</div>' +
  199. '<div class="conent-value">'+innerHtml+'</div></div>';
  200. }
  201. section_conent = section_conent + '</div>';
  202. var section_button = '<div class="section_button"><button class="el-button handle-button el-button-cancle"><span>取消</span></button>'+
  203. '<button class="el-button handle-button el-button-primary"><span>保存</span></button></div>';
  204. var htmlstr = section_header+section_conent;
  205. return htmlstr;
  206. },
  207. loadTimeContainer: function(obj){
  208. jQuery(obj).ymdateplugin({
  209. showTimePanel: true
  210. });
  211. },
  212. getItemTemplate: function( lp ){
  213. _self = this;
  214. return {
  215. name: {
  216. text: lp.name,
  217. type: "text",
  218. //attr : {placeholder:lp.name},
  219. notEmpty:true,
  220. value:this.data&&this.data.opportunityname?this.data.opportunityname:""
  221. },
  222. customer:{
  223. type: "text",
  224. text: lp.customer,
  225. value:this.data && this.data.customer&&this.data.customer.customername?this.data.customer.customername:""
  226. },
  227. typeid: {
  228. type: "select",
  229. text: lp.typeid,
  230. value:this.data && this.data.opportunityType&&this.data.opportunityType.opportunitytypename?this.data.opportunityType.opportunitytypename:""
  231. },
  232. statusid: {
  233. type: "select",
  234. text: lp.statusid,
  235. value:this.data && this.data.opportunityStatus&&this.data.opportunityStatus.opportunitystatusname?this.data.opportunityStatus.opportunitystatusname:""
  236. },
  237. money:{
  238. type: "text",
  239. text: lp.money,
  240. value: this.data && this.data.money?this.data.money:""
  241. },
  242. dealdate: {
  243. text: lp.dealdate,
  244. name:"dealdate",
  245. attr : {id:"dealdate"},
  246. type: "datetime",
  247. value:this.data && this.data.dealdate?this.data.dealdate:""
  248. },
  249. remark: {
  250. text: lp.remark,
  251. name:"remark",
  252. type: "textarea",
  253. value:this.data && this.data.remark?this.data.remark:""
  254. }
  255. }
  256. },
  257. ok: function(){
  258. this.fireEvent("queryOk");
  259. var data = this.getResult();
  260. //console.log("this is change create data:::",data)
  261. if (data) {
  262. this._ok(data, function (json) {
  263. if (json.type == "error") {
  264. if( this.app && this.app.notice )this.app.notice(json.message, "error");
  265. } else {
  266. if( this.formMaskNode )this.formMaskNode.destroy();
  267. if( this.formAreaNode )this.formAreaNode.destroy();
  268. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  269. if( this.app && this.app.notice)this.app.notice(this.isNew ? this.lp.createSuccess : this.lp.updateSuccess, "success");
  270. this.fireEvent("postOk");
  271. }
  272. }.bind(this))
  273. }
  274. },
  275. getResult: function(){
  276. var json = {};
  277. var data = {};
  278. json.type = "success";
  279. //console.log(this);
  280. try{
  281. data.opportunityname = this.formTableArea.getElement("#name").get("value");
  282. data.customerid = this.Customer.id;
  283. data.typeid = this.type.id;
  284. data.statusid = this.statusid.id;
  285. data.money = this.formTableArea.getElement("#money").get("value");
  286. data.dealdate = this.formTableArea.getElement("#dealdate").get("value");
  287. data.remark = this.formTableArea.getElement("#remark").get("value");
  288. if(this.isEdited){
  289. data.id = this.data.id;
  290. }
  291. //data.remark = this.formTableArea.getElement("#remark").get("value");
  292. }catch (e) {
  293. json.type="error";
  294. data = {};
  295. data.reson = e;
  296. }
  297. json.data = data;
  298. return json;
  299. },
  300. _ok: function (data, callback) {
  301. if(data.type="success") {
  302. if(this.isNew){
  303. this.actions.createChance(data.data, function (json) {
  304. //console.log("this is createChange result:::",json);
  305. callback(json);
  306. })
  307. }else{
  308. this.actions.updateChance(data.id,data.data, function (json) {
  309. //console.log("this is createChange result:::",json);
  310. callback(json);
  311. })
  312. }
  313. }else{
  314. // console.log("这里需要提示,请填完表单!!",data);
  315. }
  316. }
  317. });
  318. MWF.xApplication.CRM.ChanceEdit.selectForm = new Class({
  319. Extends : MPopupForm,
  320. options: {
  321. "style": "default",
  322. "width": "700",
  323. "height": "400",
  324. "hasTop": true,
  325. "hasIcon": false,
  326. "hasTopIcon" : false,
  327. "hasTopContent" : false,
  328. "draggable": true,
  329. "maxAction" : true,
  330. "closeAction": true,
  331. "isFull" : false,
  332. "startTime" : null,
  333. "endTime" : null,
  334. "isWholeday" : false,
  335. "title" : "选择客户",
  336. "defaultCalendarId" : "",
  337. "callback": function(){
  338. // console.log("you can do something when is ok");
  339. }.bind(this)
  340. },
  341. load: function(){
  342. //console.log(this.container);
  343. //this.lp = this.lp.chanceEdit||{};
  344. this.cssPath = "/x_component_CRM/$ChanceEdit/"+this.options.style+"/css.wcss";
  345. this.path = "/x_component_CRM/$ChanceEdit/";
  346. this.type ={};
  347. this._loadCss();
  348. this.loadData();
  349. },
  350. _createTableContent: function () {
  351. //this.formTableArea.set("html", this.getHtml());
  352. var templateUrl = this.path+"customerSelect.json";
  353. var filter = {};
  354. this.form = new MWF.xApplication.CRM.ChanceEdit.SelectCustomer(
  355. this.formTableArea,
  356. null,
  357. this.app,
  358. this,
  359. { templateUrl : templateUrl,filterData:filter,listPageName:"getCustomerListPage"},
  360. {
  361. lp:{}
  362. }
  363. )
  364. this.form.load();
  365. },
  366. _ok: function (data, callback) {
  367. if(!data){
  368. }else{
  369. if(typeof this.options.callback == "function"){
  370. this.options.callback();
  371. }
  372. this.container.getElement("#customer").setAttribute("value",data.customername);
  373. this.app.Customer = data;
  374. if( this.formMaskNode )this.formMaskNode.destroy();
  375. if( this.formAreaNode )this.formAreaNode.destroy();
  376. this.fireEvent("postOk");
  377. }
  378. },
  379. loadData:function(){
  380. }
  381. });
  382. MWF.xApplication.CRM.ChanceEdit.SelectCustomer = new Class({
  383. Extends: MWF.xApplication.CRM.Template.SelectForm,
  384. //一般需要重写分页方法
  385. _getCurrentPageData: function(callback, count, page, searchText){
  386. var category = this.category = this.options.category;
  387. if (!count)count = 10;
  388. if (!page)page = 1;
  389. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  390. //if(id=="(0)")this.app.createShade();
  391. var filter = this.options.filterData || {};
  392. if(searchText){
  393. filter = {
  394. key:searchText
  395. };
  396. }
  397. this.actions.getCustomerListPage(page, count, filter, function (json) {
  398. if (callback)callback(json);
  399. }.bind(this));
  400. }
  401. });