ContactsEdit.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. MWF.xApplication.CRM.ContactsEdit = 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.contact.contactEdit;
  22. this.path = "../x_component_CRM/$ContactEdit/";
  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. },
  29. load: function () {
  30. this.loadResource(function(){
  31. this.appArea = jQuery("body").children(":first");
  32. this.createForm();
  33. }.bind(this))
  34. },
  35. loadResource: function ( callback ) {
  36. if(callback)callback();
  37. /*var baseUrls = [
  38. "../x_component_CRM/$Template/assets/js/jquery.min.js",
  39. ];
  40. var fullcalendarUrl = "../x_component_CRM/$Template/assets/js/notifyme.js";
  41. var confirmUrl = "../x_component_CRM/$Template/assets/js/showBo.js";
  42. //var confirmUrl = "../x_component_CRM/$Main/laydate/laydate.js";
  43. COMMON.AjaxModule.loadCss("../x_component_CRM/$Template/assets/css/notifyme.css",function(){
  44. COMMON.AjaxModule.load(baseUrls, function(){
  45. jQuery.noConflict();
  46. COMMON.AjaxModule.load(fullcalendarUrl, function(){
  47. COMMON.AjaxModule.load(confirmUrl, function(){
  48. if(callback)callback();
  49. }.bind(this))
  50. }.bind(this));
  51. }.bind(this))
  52. }.bind(this));
  53. COMMON.AjaxModule.loadCss("../x_component_CRM/$Template/date/css/jquery-ui.css",function(){
  54. COMMON.AjaxModule.load(baseUrls, function(){
  55. jQuery.noConflict();
  56. COMMON.AjaxModule.load("../x_component_CRM/$Template/date/jquery-ym-datePlugin-0.1.js", function(){
  57. if(callback)callback();
  58. /!* COMMON.AjaxModule.load("../x_component_CRM/$Template/date/js/datepicker.all.js", function(){
  59. if(callback)callback();
  60. }.bind(this))*!/
  61. }.bind(this));
  62. }.bind(this))
  63. }.bind(this));*/
  64. },
  65. createForm:function(){
  66. _self = this;
  67. jQuery(_self.appArea).next().attr("style","");
  68. jQuery(_self.appArea).next().attr("class","mask");
  69. var section_header = '<div class="section-header"><div class="section-mark" style="border-left-color: rgb(70, 205, 207);"></div> '+
  70. '<div data-v-ec8f8850="" class="section-title">基本信息</div></div>';
  71. var itemTemplateObject = _self.lp;
  72. var section_conent = '<div class="section-conent">';
  73. debugger
  74. for ( i in itemTemplateObject){
  75. var stype = itemTemplateObject[i].type;
  76. var notEmpty = itemTemplateObject[i].notEmpty?itemTemplateObject[i].notEmpty:"false";
  77. var innerHtml = '<input type="text" class="inline-input" name="'+i+'" id="'+i+'" notEmpty="'+notEmpty+'" stype="'+stype+'">';
  78. if(stype=="textarea"){
  79. innerHtml = '<textarea rows="6" class="el-textarea__inner" id="'+i+'" notEmpty="'+notEmpty+'" stype="'+stype+'" style="resize: none; min-height: 30.6px;"></textarea>';
  80. }
  81. if(stype=="select" || stype=="hide"){
  82. 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>';
  83. }
  84. if(i=="customername"){
  85. innerHtml = '<input type="text" class="inline-input" readonly="true" style="background-color: #e2ebf9;cursor:pointer;" name="'+i+'" id="'+i+'" notEmpty="'+notEmpty+'" stype="'+stype+'">';
  86. }
  87. section_conent = section_conent+'<div class="conent-inline"><div class="conent-title" lable="'+i+'">'+itemTemplateObject[i].text+'</div>' +
  88. '<div class="conent-value">'+innerHtml+'</div></div>';
  89. }
  90. section_conent = section_conent + '</div>';
  91. var section_button = '<div class="section_button"><div><button class="el-button handle-button el-button-cancle"><span>取消</span></button>'+
  92. '<button class="el-button handle-button el-button-primary"><span>保存</span></button></div></div>';
  93. var htmlstr = section_header+section_conent+section_button;
  94. jQuery(".headMoreImg").notifyMe(
  95. 'left',
  96. 'default',
  97. "新建联系人",
  98. '',
  99. '',
  100. htmlstr,
  101. 'notifyEdit',
  102. 50
  103. );
  104. jQuery(".conent-value").each(function(index,element){
  105. var cobj = jQuery(element).children().eq(0)
  106. var stype = jQuery(cobj).attr("stype");
  107. if(stype=="datetime"){
  108. _self.loadTimeContainer(jQuery(cobj).attr("id"));
  109. }
  110. if(stype=="openSelect"){
  111. jQuery(element).click(function(){
  112. _sself = _self.lp;
  113. _sself.cancel = "关闭";
  114. _sself.ok = "确定";
  115. _self.selectCustomer = new MWF.xApplication.CRM.ContactsEdit.selectForm (null,{},null, {
  116. app: _self,
  117. container: jQuery("#notifyEdit")[0],
  118. lp: _sself,
  119. actions: _self.actions,
  120. css: {},
  121. }
  122. );
  123. _self.selectCustomer.create();
  124. });
  125. }
  126. if(stype=="select" || stype=="hide"){
  127. var selectObjects = _self.app.lp.contact;
  128. for ( j in selectObjects){
  129. if(j==jQuery(cobj).attr("id")){
  130. var clp = itemTemplateObject[j];
  131. var valueList = clp.value;
  132. var valueArr = valueList.split(",");
  133. if(valueArr.length>0){
  134. var selectHtml = '<ul class="el-dropdown-type" style="display: none;" tid="'+jQuery(cobj).attr("id")+'">'
  135. for(var n=0;n<valueArr.length;n++){
  136. selectHtml = selectHtml+'<li class="el-dropdown-menu__item">'+valueArr[n]+'</li>'
  137. }
  138. jQuery(".notify-content").append(selectHtml+'<div class="popper__arrow"></div></ul>');
  139. jQuery(cobj).click(function(){
  140. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").css({"left":jQuery(cobj).offset().left-50,"top":jQuery(cobj).offset().top+30,"width":282})
  141. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").toggle(100);
  142. });
  143. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").children().click(function(){
  144. debugger
  145. jQuery(cobj).text(jQuery(this).text());
  146. jQuery("[tid='"+jQuery(cobj).attr("id")+"']").toggle(100);
  147. });
  148. }
  149. }
  150. }
  151. }
  152. }
  153. );
  154. jQuery('.el-button-cancle').click(function(){
  155. setTimeout(function(){
  156. jQuery("#notifyEdit").remove();
  157. if(jQuery(".mask").length>0){
  158. jQuery(".mask").attr("style",'left: 0px; top: 0px; width: 100%; overflow: hidden; position: absolute; z-index: 500000; background-color: rgb(255, 255, 255)');
  159. jQuery(".mask").attr("class","");
  160. }
  161. },200);
  162. });
  163. jQuery('.el-button-primary').click(function(){
  164. var sflag = true;
  165. jQuery(".inline-input[notempty='true']").each(function(index,element){
  166. if(jQuery(element).val()=="" && jQuery(element).text()==""){
  167. sflag = false;
  168. var nameStr = jQuery(element).parent().prev().text()+'不能为空';
  169. if(jQuery(element).nextAll(".empError").length>0)jQuery(element).nextAll(".empError").remove();
  170. jQuery(element).parent().append('<div class="empError" style="color:#f56c6c;padding: 0;line-height: 1;">'+nameStr+'</div>');
  171. }else{
  172. if(jQuery(element).nextAll(".empError").length>0)jQuery(element).nextAll(".empError").remove();
  173. }
  174. });
  175. if(sflag){
  176. var filter = {};
  177. filter = {
  178. contactsname:jQuery('div[lable="contactsname"]').next().children().eq(0).val(),
  179. customerid:jQuery('div[lable="customername"]').next().children().eq(0).attr("cid"),
  180. telephone:jQuery('div[lable="telephone"]').next().children().eq(0).val(),
  181. cellphone:jQuery('div[lable="cellphone"]').next().children().eq(0).val(),
  182. email:jQuery('div[lable="email"]').next().children().eq(0).val(),
  183. decision:jQuery('div[lable="decision"]').next().children().eq(0).text(),
  184. post:jQuery('div[lable="post"]').next().children().eq(0).val(),
  185. sex:jQuery('div[lable="sex"]').next().children().eq(0).text(),
  186. detailaddress:jQuery('div[lable="detailaddress"]').next().children().eq(0).val(),
  187. nexttime:jQuery('div[lable="nexttime"]').next().children().eq(0).val(),
  188. remark:jQuery('div[lable="remark"]').next().children().eq(0).val()
  189. };
  190. _self.actions.saveContacts( filter, function (json) {
  191. if(json.type=="success"){
  192. Showbo.Msg.alert('保存成功!');
  193. }
  194. setTimeout(function(){
  195. jQuery("#notifyEdit").remove();
  196. if(jQuery(".mask").length>0){
  197. jQuery(".mask").attr("style",'left: 0px; top: 0px; width: 100%; overflow: hidden; position: absolute; z-index: 500000; background-color: rgb(255, 255, 255)');
  198. jQuery(".mask").attr("class","");
  199. }
  200. },200);
  201. }.bind(_self));
  202. }
  203. });
  204. jQuery(".inline-input[notempty='true']").blur( function () {
  205. if(jQuery(this).attr("stype")!="datetime" || jQuery(this).attr("stype")!="openSelect"){
  206. if(jQuery(this).val()=="" && jQuery(this).text()==""){
  207. var nameStr = jQuery(this).parent().prev().text()+'不能为空';
  208. if(jQuery(this).nextAll(".empError").length>0)jQuery(this).nextAll(".empError").remove();
  209. jQuery(this).parent().append('<div class="empError" style="color:#f56c6c;padding: 0;line-height: 1;">'+nameStr+'</div>');
  210. }else{
  211. if(jQuery(this).nextAll(".empError").length>0)jQuery(this).nextAll(".empError").remove();
  212. }
  213. }
  214. });
  215. },
  216. loadTimeContainer: function(stime){
  217. jQuery("#"+stime).ymdateplugin({
  218. showTimePanel: true
  219. });
  220. },
  221. getItemTemplate: function( lp ){
  222. _self = this;
  223. return {
  224. contactsname:{
  225. type: "text",
  226. notEmpty:true,
  227. text: lp.contactsname,
  228. value:this.customerData && this.customerData.customername?this.customerData.customername:""
  229. },
  230. customername: {
  231. text: lp.customername,
  232. notEmpty:true,
  233. type: "openSelect"
  234. },
  235. cellphone: {
  236. text:lp.cellphone,
  237. notEmpty:true,
  238. type: "text"
  239. },
  240. telephone:{
  241. type: "text",
  242. text: lp.telephone
  243. },
  244. email: {
  245. text:lp.email,
  246. type: "text"
  247. },
  248. decision: {
  249. type: "select",
  250. notEmpty:true,
  251. text: lp.decision,
  252. value:_self.app.lp.contact.decision.value
  253. },
  254. post: {
  255. text:lp.post,
  256. type: "text"
  257. },
  258. sex: {
  259. type: "select",
  260. text: lp.sex,
  261. value:_self.app.lp.contact.sex.value
  262. },
  263. detailaddress: {
  264. text:lp.detailaddress,
  265. type: "text"
  266. },
  267. nexttime: {
  268. text:lp.nexttime,
  269. notEmpty:true,
  270. attr : {id:"nexttime"},
  271. type: "datetime"
  272. },
  273. remark: {
  274. text:lp.remark,
  275. type: "textarea"
  276. }
  277. }
  278. }
  279. });
  280. MWF.xApplication.CRM.ContactsEdit.selectForm = new Class({
  281. Extends : MPopupForm,
  282. options: {
  283. "style": "default",
  284. "width": "700",
  285. "height": "400",
  286. "hasTop": true,
  287. "hasIcon": false,
  288. "hasTopIcon" : false,
  289. "hasTopContent" : false,
  290. "draggable": true,
  291. "maxAction" : true,
  292. "closeAction": true,
  293. "isFull" : false,
  294. "startTime" : null,
  295. "endTime" : null,
  296. "isWholeday" : false,
  297. "title" : "选择客户",
  298. "defaultCalendarId" : "",
  299. "callback": function(){
  300. console.log("you can do something when is ok");
  301. }.bind(this)
  302. },
  303. load: function(){
  304. //console.log(this.container);
  305. //this.lp = this.lp.chanceEdit||{};
  306. this.cssPath = "../x_component_CRM/$CustomerEdit/"+this.options.style+"/opencss.wcss";
  307. this.path = "../x_component_CRM/$CustomerEdit/";
  308. this.type ={};
  309. this._loadCss();
  310. this.loadData();
  311. },
  312. _createTableContent: function () {
  313. //this.formTableArea.set("html", this.getHtml());
  314. var templateUrl = this.path+"customerSelect.json";
  315. var filter = {};
  316. this.form = new MWF.xApplication.CRM.ContactsEdit.SelectCustomer(
  317. this.formTableArea,
  318. null,
  319. this.app,
  320. this,
  321. { templateUrl : templateUrl,filterData:filter,listPageName:"getCustomerListPage"},
  322. {
  323. lp:{}
  324. }
  325. )
  326. this.form.load();
  327. },
  328. _ok: function (data, callback) {
  329. if(!data){
  330. }else{
  331. if(typeof this.options.callback == "function"){
  332. this.options.callback();
  333. }
  334. debugger
  335. //this.container.getElement("#customername").setAttribute("value",data.customername);
  336. this.container.getElement("#customername").setProperty("value",data.customername);
  337. this.container.getElement("#customername").setProperty("cid",data.id);
  338. //jQuery("#customername").val(data.customername);
  339. debugger
  340. this.app.Customer = data;
  341. if( this.formMaskNode )this.formMaskNode.destroy();
  342. if( this.formAreaNode )this.formAreaNode.destroy();
  343. this.fireEvent("postOk");
  344. }
  345. },
  346. loadData:function(){
  347. }
  348. });
  349. MWF.xApplication.CRM.ContactsEdit.SelectCustomer = new Class({
  350. Extends: MWF.xApplication.CRM.Template.SelectForm,
  351. //一般需要重写分页方法
  352. _getCurrentPageData: function(callback, count, page, searchText){
  353. var category = this.category = this.options.category;
  354. if (!count)count = 10;
  355. if (!page)page = 1;
  356. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  357. //if(id=="(0)")this.app.createShade();
  358. var filter = this.options.filterData || {};
  359. if(searchText){
  360. filter = {
  361. key:searchText
  362. };
  363. }
  364. this.actions.getCustomerListPage(page, count, filter, function (json) {
  365. if (callback)callback(json);
  366. }.bind(this));
  367. }
  368. });