CustomerEdit.js 13 KB

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