ClueEdit.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. MWF.xApplication.CRM.ClueEdit = new Class({
  2. Extends: MWF.xApplication.CRM.Template.PopupForm,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "width": "800",
  7. "height": "100%",
  8. "top" : 0,
  9. "left" : 0,
  10. "hasTop": true,
  11. "hasIcon": false,
  12. "hasBottom": true,
  13. "title": "",
  14. "draggable": false,
  15. "closeAction": true
  16. },
  17. initialize: function (explorer, actions, data, options) {
  18. this.setOptions(options);
  19. this.explorer = explorer;
  20. this.app = explorer.app;
  21. this.lp = this.app.lp.clue.clueEdit;
  22. this.path = "../x_component_CRM/$ClueEdit/";
  23. this.cssPath = this.path + this.options.style + "/css.wcss";
  24. this._loadCss();
  25. this.options.title = this.lp.title;
  26. this.data = data || {};
  27. this.actions = actions;
  28. debugger
  29. },
  30. load: function () {
  31. this.loadResource(function(){
  32. this.appArea = jQuery("body").children(":first");
  33. this.createForm();
  34. }.bind(this))
  35. },
  36. loadResource: function ( callback ) {
  37. if(callback)callback();
  38. },
  39. createForm:function(){
  40. _self = this;
  41. jQuery(_self.appArea).next().attr("style","");
  42. jQuery(_self.appArea).next().attr("class","mask");
  43. var section_header = '<div class="section-header"><div class="section-mark" style="border-left-color: rgb(70, 205, 207);"></div> '+
  44. '<div data-v-ec8f8850="" class="section-title">基本信息</div></div>';
  45. //var itemTemplateObject = _self.getItemTemplate(_self.lp );
  46. var itemTemplateObject = _self.lp;
  47. debugger
  48. var section_conent = '<div class="section-conent">';
  49. for ( i in itemTemplateObject){
  50. var stype = itemTemplateObject[i].type;
  51. //var innerHtml = '<input type="text" class="inline-input" name="'+i+'" id="'+i+'" stype="'+stype+'">';
  52. var notEmpty = itemTemplateObject[i].notEmpty?itemTemplateObject[i].notEmpty:"false";
  53. var innerHtml = '<input type="text" class="inline-input" name="'+i+'" id="'+i+'" notEmpty="'+notEmpty+'" stype="'+stype+'">';
  54. if(stype=="textarea"){
  55. innerHtml = '<textarea rows="6" class="el-textarea__inner" id="'+i+'" notEmpty="'+notEmpty+'" stype="'+stype+'" style="resize: none; min-height: 30.6px;"></textarea>';
  56. }
  57. if(stype=="select"){
  58. innerHtml = '<div class="inline-input" style="display: inline-block;cursor:pointer;" id="'+i+'" notEmpty="'+notEmpty+'" stype="'+stype+'" ></div><div class="el-icon-arrow-down el-icon--right" style="margin-left: -20px;height:34px; display: inline-block;"><img src="../x_component_CRM/$Clue/default/icons/arrow.png"></div>';
  59. }
  60. section_conent = section_conent+'<div class="conent-inline"><div class="conent-title" lable="'+i+'">'+itemTemplateObject[i].text+'</div>' +
  61. '<div class="conent-value">'+innerHtml+'</div></div>';
  62. }
  63. section_conent = section_conent + '</div>';
  64. var section_button = '<div class="section_button"><div><button class="el-button handle-button el-button-cancle"><span>取消</span></button>'+
  65. '<button class="el-button handle-button el-button-primary"><span>保存</span></button></div></div>';
  66. var htmlstr = section_header+section_conent+section_button;
  67. jQuery(".headMoreImg").notifyMe(
  68. 'left',
  69. 'default',
  70. '新建线索',
  71. '',
  72. '',
  73. htmlstr,
  74. 'notifyEdit',
  75. 50
  76. );
  77. jQuery(".conent-value").each(function(index,element){
  78. var cobj = jQuery(element).children().eq(0)
  79. var stype = jQuery(cobj).attr("stype");
  80. if(stype=="datetime"){
  81. _self.loadTimeContainer(jQuery(cobj).attr("id"));
  82. }
  83. if(stype=="select"){
  84. var selectObjects = _self.app.lp.clue;
  85. for ( j in selectObjects){
  86. if(j==jQuery(cobj).attr("id")){
  87. var clp = itemTemplateObject[j];
  88. var valueList = clp.value;
  89. var valueArr = valueList.split(",");
  90. if(valueArr.length>0){
  91. var selectHtml = '<ul class="el-dropdown-type" style="display: none;" tid="'+jQuery(cobj).attr("id")+'">'
  92. for(var n=0;n<valueArr.length;n++){
  93. selectHtml = selectHtml+'<li class="el-dropdown-menu__item">'+valueArr[n]+'</li>'
  94. }
  95. jQuery(".notify-content").append(selectHtml+'<div class="popper__arrow"></div></ul>');
  96. jQuery(cobj).click(function(){
  97. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").css({"left":jQuery(cobj).offset().left-50,"top":jQuery(cobj).offset().top+30,"width":282})
  98. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").toggle(100);
  99. });
  100. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").children().click(function(){
  101. jQuery(cobj).text(jQuery(this).text());
  102. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").toggle(100);
  103. });
  104. }
  105. }
  106. }
  107. }
  108. }
  109. );
  110. jQuery('.el-button-cancle').click(function(){
  111. setTimeout(function(){
  112. jQuery("#notifyEdit").remove();
  113. if(jQuery(".mask").length>0){
  114. jQuery(".mask").attr("style",'left: 0px; top: 0px; width: 100%; overflow: hidden; position: absolute; z-index: 500000; background-color: rgb(255, 255, 255)');
  115. jQuery(".mask").attr("class","");
  116. }
  117. },200);
  118. });
  119. jQuery('.el-button-primary').click(function(){
  120. var sflag = true;
  121. jQuery(".inline-input[notempty='true']").each(function(index,element){
  122. if(jQuery(element).val()=="" && jQuery(element).text()==""){
  123. sflag = false;
  124. var nameStr = jQuery(element).parent().prev().text()+'不能为空';
  125. if(jQuery(element).nextAll(".empError").length>0)jQuery(element).nextAll(".empError").remove();
  126. jQuery(element).parent().append('<div class="empError" style="color:#f56c6c;padding: 0;line-height: 1;">'+nameStr+'</div>');
  127. }else{
  128. if(jQuery(element).nextAll(".empError").length>0)jQuery(element).nextAll(".empError").remove();
  129. }
  130. });
  131. if(sflag){
  132. var filter = {};
  133. filter = {
  134. name:jQuery('div[lable="name"]').next().children().eq(0).val(),
  135. source:jQuery('div[lable="source"]').next().children().eq(0).val(),
  136. telephone:jQuery('div[lable="telephone"]').next().children().eq(0).val(),
  137. cellphone:jQuery('div[lable="cellphone"]').next().children().eq(0).val(),
  138. industry:jQuery('div[lable="industry"]').next().children().eq(0).text(),
  139. level:jQuery('div[lable="level"]').next().children().eq(0).text(),
  140. address:jQuery('div[lable="address"]').next().children().eq(0).val(),
  141. nexttime:jQuery('div[lable="nexttime"]').next().children().eq(0).val(),
  142. remark:jQuery('div[lable="remark"]').next().children().eq(0).val()
  143. };
  144. _self.actions.saveClue( filter, function (json) {
  145. if(json.type=="success"){
  146. Showbo.Msg.alert('保存成功!');
  147. }
  148. setTimeout(function(){
  149. jQuery("#notifyEdit").remove();
  150. if(jQuery(".mask").length>0){
  151. jQuery(".mask").attr("style",'left: 0px; top: 0px; width: 100%; overflow: hidden; position: absolute; z-index: 500000; background-color: rgb(255, 255, 255)');
  152. jQuery(".mask").attr("class","");
  153. }
  154. },200);
  155. }.bind(_self));
  156. }
  157. });
  158. jQuery(".inline-input[notempty='true']").blur( function () {
  159. if(jQuery(this).attr("stype")!="datetime"){
  160. if(jQuery(this).val()=="" && jQuery(this).text()==""){
  161. var nameStr = jQuery(this).parent().prev().text()+'不能为空';
  162. if(jQuery(this).nextAll(".empError").length>0)jQuery(this).nextAll(".empError").remove();
  163. jQuery(this).parent().append('<div class="empError" style="color:#f56c6c;padding: 0;line-height: 1;">'+nameStr+'</div>');
  164. }else{
  165. if(jQuery(this).nextAll(".empError").length>0)jQuery(this).nextAll(".empError").remove();
  166. }
  167. }
  168. });
  169. },
  170. loadTimeContainer: function(stime){
  171. jQuery("#"+stime).ymdateplugin({
  172. showTimePanel: true
  173. });
  174. },
  175. getItemTemplate: function( lp ){
  176. _self = this;
  177. return {
  178. name: {
  179. text: lp.name,
  180. type: "text",
  181. //attr : {placeholder:lp.name},
  182. notEmpty:true,
  183. value:this.customerData && this.customerData.customername?this.customerData.customername:""
  184. },
  185. source:{
  186. type: "text",
  187. notEmpty:true,
  188. text: lp.source
  189. },
  190. telephone: {
  191. type: "text",
  192. notEmpty:true,
  193. text: lp.telephone
  194. },
  195. cellphone: {
  196. notEmpty:true,
  197. text: lp.cellphone
  198. },
  199. industry:{
  200. type: "select",
  201. text: lp.industry,
  202. notEmpty:true,
  203. value:this.app.lp.clue.industry.value
  204. },
  205. level:{
  206. type: "select",
  207. text: lp.level,
  208. notEmpty:true,
  209. value:this.app.lp.clue.level.value
  210. },
  211. address: {
  212. text: lp.address,
  213. name:"address",
  214. notEmpty:true,
  215. type: "text"
  216. },
  217. nexttime: {
  218. text: lp.nexttime,
  219. name:"nexttime",
  220. notEmpty:true,
  221. attr : {id:"nexttime"},
  222. type: "datetime"
  223. },
  224. remark: {
  225. text: lp.remark,
  226. name:"remark",
  227. type: "textarea"
  228. }
  229. }
  230. },
  231. _ok: function (data, callback) {
  232. var saveDataStr = "";
  233. for ( i in this.data){
  234. saveDataStr = saveDataStr+"'"+i+"':'"+this.data[i]+"',";
  235. }
  236. debugger;
  237. saveDataStr = "'{"+saveDataStr.replace(/'/g, '"')+"}'";
  238. debugger;
  239. //var saveData = JSON.parse(saveDataStr);
  240. var saveData = eval('(' + saveDataStr.substring(1,saveDataStr.length - 1) + ')');
  241. debugger;
  242. //alert(JSON.stringify(saveData))
  243. this.app.createShade();
  244. this.actions.saveClue(saveData,function(json){
  245. this.app.destroyShade();
  246. this.app.notice(this.lp.saveSuccess,"success");
  247. this.close();
  248. this.fireEvent("reloadView",json);
  249. }.bind(this),function(xhr,text,error){
  250. this.app.showErrorMessage(xhr,text,error);
  251. this.app.destroyShade();
  252. }.bind(this));
  253. }
  254. });