/** * [ONEMAP.M.feedback] * @return {[object]} */ define([ 'html!templates/feedback', 'css!styles/feedback' ], function (tplLayout) { function init() { setLayout(); bindEvent(); subscribe(); }; function setLayout() { $(tplLayout).appendTo($("body")); } function bindEvent() { $('.feedbackPanel .close').off('click').on('click', function () { $('.feedbackPanel').remove(); }) $('.feedbackPanel .submit').off('click').on('click', function () { var ajaxData = { gcms_title: $('.feedbackPanel .fk_title').val(), name: $('.feedbackPanel .name').val(), company: $('.feedbackPanel .companyName').val(), phonenum: $('.feedbackPanel .tel').val(), email: $('.feedbackPanel .e-mail').val(), question: $('.feedbackPanel .question').val(), reply: "", } var ajaxUrl = onemapUrlConfigNetwork.gcmsServiceUrl + '/content/fankui'; if (ajaxData.company.replace(/ /g, '') === "") { ONEMAP.C.publisher.publish({ type: "warning", message: "公司不能为空!" }, 'noteBar::add'); return false; } if (ajaxData.name.replace(/ /g, '') === "") { ONEMAP.C.publisher.publish({ type: "warning", message: "名称不能为空!" }, 'noteBar::add'); return false; } if (ajaxData.phonenum.replace(/ /g, '') === "") { ONEMAP.C.publisher.publish({ type: "warning", message: "联系电话不能为空!" }, 'noteBar::add'); return false; } else { //验证手机号 var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/; if (!reg.test(ajaxData.phonenum)) { ONEMAP.C.publisher.publish({ type: 'warning', message: '请输入正确的手机号' }, 'noteBar::add'); return false; } } if (ajaxData.question.replace(/ /g, '') === "") { ONEMAP.C.publisher.publish({ type: "warning", message: "需求问题不能为空!" }, 'noteBar::add'); return false; } $.ajax({ url: ajaxUrl, type: 'POST', dataType: 'json', data: ajaxData }) .done(function (data) { console.log(data); if (data.code == 4) { ONEMAP.C.publisher.publish({ type: "warning", message: "无权限添加内容" }, 'noteBar::add'); } if (data.code == 3) { // GCMSAPP.C.logout('addArticle'); } if (data.code == 0) { ONEMAP.C.publisher.publish({ type: "success", message: "反馈成功" }, 'noteBar::add'); $('.feedbackPanel').remove() } }) .fail(function () { ONEMAP.C.publisher.publish({ type: "error", message: "无权限添加内容" }, 'noteBar::add'); }); }) }; /** * 注册订阅 * @type {Function} * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type'); * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange'); */ function subscribe() { } return ONEMAP.M.feedback = { init: init, }; })