4f871a80e96fb01e97aa3e9dc4a18675c580f4f2.svn-base 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. var userId = top.com.sinosoft.lz.system.user.LoginInfo.getUser_id();
  2. $(function(){
  3. $("#back").hover(function(){
  4. $(this).attr("src","/nwyj/images/temp/back_hover.png");
  5. },function(){
  6. $(this).attr("src","/nwyj/images/temp/back.png");
  7. });
  8. $("#back").on("click",function(){
  9. window.parent.document.getElementById("frmright").setAttribute("src", "/nwyj/page/system/sms/msg_manage.html");
  10. });
  11. var columns = getColunms("lxr");
  12. initGrid(columns);
  13. /*var row = g.getRow(0);
  14. g.deleteRow(row);*/
  15. $("#downloadUserModel").on("click",function(){
  16. var intVal = $("input:radio[name=type]").filter("[checked]").val();
  17. var url = "";
  18. if(intVal=="lxr"){
  19. url = "/nwyj/excels/lianxiren.xls";
  20. }else{
  21. url = "/nwyj/excels/lxz.xls";
  22. }
  23. window.open(url);
  24. });
  25. $("#save").on("click",function(){
  26. g.endEdit();
  27. var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]");
  28. var text = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i;
  29. var peopleData = g.getData();
  30. var intVal = $("input:radio[name=type]").filter("[checked]").val();
  31. var len = peopleData.length;
  32. if(len==0){
  33. top.Dialog.alert("请导入数据再保存");
  34. return;
  35. }
  36. var dataUrl = "";
  37. var dataParams = {userId:userId};
  38. if("lxr"==intVal){
  39. dataUrl = $.pathname() + '/ws/getContactPeoples/ContactpeopleService/getTel';
  40. var cyTel = getThing(dataUrl,dataParams).rows;
  41. for(var i=0;i<len;i++){
  42. var row = i+1;
  43. var tel = peopleData[i]["CONTACT_TEL"];
  44. var name = peopleData[i]["CONTACT_USER_NAME"];
  45. var dept = peopleData[i]["CONTACT_DEPT"];
  46. var corp = peopleData[i]["CONTACT_COMP"];
  47. if(!checkTel(tel, cyTel)){
  48. top.Dialog.alert("第"+(i+1)+"行的联系人已存在");
  49. return;
  50. }
  51. if(tel==""){
  52. top.Dialog.alert("第"+row+"行的电话为空");
  53. return;
  54. }
  55. if(name==""){
  56. top.Dialog.alert("第"+row+"行的联系人名字为空");
  57. return;
  58. }
  59. if(!text.test(tel)){
  60. top.Dialog.alert("第"+row+"行的手机号码有误,请重新输入");
  61. return;
  62. }
  63. if(pattern.test(name)){
  64. top.Dialog.alert("第"+row+"行的联系人姓名含有特殊字符,请重新输入");
  65. return;
  66. }
  67. if(pattern.test(dept)){
  68. top.Dialog.alert("第"+row+"行的部门名称含有特殊字符,请重新输入");
  69. return;
  70. }
  71. if(pattern.test(corp)){
  72. top.Dialog.alert("第"+row+"行的公司名称含有特殊字符,请重新输入");
  73. return;
  74. }
  75. }
  76. }else{
  77. dataUrl = $.pathname() + "/ws/addContent/AddSmsContentService/getUsedGroup";
  78. var groupData = getThing(dataUrl,dataParams);
  79. for(var i=0;i<len;i++){
  80. var row = i+1;
  81. var groupName = peopleData[i]["GROUP_NAME"];
  82. var groupPeople = peopleData[i]["GROUP_PEOPLE"];
  83. var groupPeopleTel = peopleData[i]["GROUP_PEOPLE_TEL"];
  84. console.log(groupPeopleTel);
  85. var groupComp = peopleData[i]["GROUP_PEOPLE_COMP"];
  86. if(groupName==""){
  87. top.Dialog.alert("第"+row+"行的联系组名称为空");
  88. return;
  89. }
  90. if(groupPeople==""){
  91. top.Dialog.alert("第"+row+"行的人员名字为空");
  92. return;
  93. }
  94. if(groupPeopleTel==""){
  95. top.Dialog.alert("第"+row+"行的人员电话为空");
  96. return;
  97. }
  98. if(pattern.test(groupName)){
  99. top.Dialog.alert("第"+row+"行的联系组名称包含特殊字符,请重新输入");
  100. return;
  101. }
  102. if(pattern.test(groupPeople)){
  103. top.Dialog.alert("第"+row+"行的人员名字包含特殊字符,请重新输入");
  104. return;
  105. }
  106. if(pattern.test(groupComp)){
  107. top.Dialog.alert("第"+row+"行的公司名称包含特殊字符,请重新输入");
  108. return;
  109. }
  110. if(!text.test(groupPeopleTel)){
  111. top.Dialog.alert("第"+row+"行的手机号码有误,请重新输入");
  112. return;
  113. }
  114. if(!checkGroupTel(groupName,groupPeopleTel,groupData)){
  115. top.Dialog.alert("联系人"+groupPeople+"已存在"+groupName+"组中");
  116. return;
  117. }
  118. }
  119. }
  120. var saveUrl = $.pathname() + "/ws/addContent/AddSmsContentService/saveContent";
  121. peopleData = JSON.stringify(peopleData);
  122. var params = {userId:userId,json:peopleData,type:intVal};
  123. var flag = getThing(saveUrl,params,'text');
  124. if(flag=="true"){
  125. top.Dialog.alert("批量导入新增成功");
  126. window.parent.document.getElementById("frmright").setAttribute("src", "/nwyj/page/system/sms/msg_manage.html");
  127. }else{
  128. top.Dialog.alert("批量导入新增失败");
  129. }
  130. });
  131. $("#resetTable").on("click",function(){
  132. var data = g.getData();
  133. var len = data.length;
  134. if(len>0){
  135. top.Dialog.confirm("确定要重置?导入的信息会全部清除,请慎重选择|重置", function() {
  136. for(var i=0;i<len;i++){
  137. var row = g.getRow(0);
  138. g.deleteRow(row);
  139. }
  140. });
  141. }
  142. });
  143. $("#importCon").on("click",function(){
  144. var val= $("#import_report").val();
  145. if(val==""||val==null){
  146. top.Dialog.alert("请导入excel文件");
  147. return;
  148. }
  149. var end = val.substring(val.indexOf(".")+1);
  150. if(end=="xls"||end=="xlsx"){
  151. var intVal = $("input:radio[name=type]").filter("[checked]").val();
  152. addfn(intVal);
  153. }else{
  154. top.Dialog.alert("请导入正确的excel文件");
  155. return;
  156. }
  157. });
  158. });
  159. function addfn(intVal) {
  160. var $form = $("#editForm");
  161. fileToSave($form,intVal);
  162. };
  163. function change(val){
  164. var columns = getColunms(val);
  165. g.setOptions({"columns":columns,"data":""});
  166. g.loadData();
  167. }
  168. function fileToSave($form,intVal){
  169. //showProgressBar("正在提交中...");
  170. //表单异步提交处理
  171. $form.ajaxSubmit({
  172. url:$.pathname() + "/ws/addContent/AddSmsContentService/daoRuContent?type="+intVal,
  173. type : 'post',
  174. success: function(responseText, statusText, xhr, $form){
  175. responseText = eval('('+responseText+')');
  176. var result = responseText["rows"];
  177. if(result.length==0){
  178. top.Dialog.alert("请填写数据再导入");
  179. return;
  180. }else if(result[0]["result"]===false){
  181. top.Dialog.alert("导入的模板跟选择的类型不一致,请检查");
  182. return;
  183. }else{
  184. var data = JSON.stringify(responseText);
  185. g.setOptions({
  186. "data" :JSON.parse(decodeURI(data))
  187. });
  188. }
  189. },
  190. error : function(e) {
  191. top.Dialog.alert("导入文件格式不对,请重新导入");
  192. }
  193. });
  194. }
  195. function initGrid(columns) {
  196. g = $("#dataGrid").quiGrid({
  197. columns : columns,
  198. data:"",
  199. rownumbers : true,
  200. width : "98%",
  201. height : '500',
  202. pageSize : 10,
  203. enabledSort:false,
  204. percentWidthMode : true,
  205. enabledEdit: true,
  206. /* clickToEdit: false,*/
  207. // 顶部图标按钮栏
  208. toolbar :false
  209. });
  210. }
  211. function getColunms(val){
  212. var columns = "";
  213. if(val=="lxz"){
  214. columns = [
  215. {
  216. display : '常用联系组',
  217. name : 'GROUP_NAME',
  218. align : 'center',
  219. width : '20%',
  220. editor: { type: 'text',maxlength:'15'}
  221. }, {
  222. display : '组人员名字',
  223. name : 'GROUP_PEOPLE',
  224. align : 'center',
  225. width : '20%',
  226. editor: { type: 'text',maxlength:'15'}
  227. }, {
  228. display : '组人员电话',
  229. name : 'GROUP_PEOPLE_TEL',
  230. align : 'center',
  231. width : '20%',
  232. editor: { type: 'text',maxlength:'11'}
  233. }, {
  234. display : '组人员公司',
  235. name : 'GROUP_PEOPLE_COMP',
  236. align : 'center',
  237. width : '20%',
  238. editor: { type: 'text',maxlength:'15'}
  239. } ];
  240. }else{
  241. columns = [
  242. {
  243. display : '常用联系人名字',
  244. name : 'CONTACT_USER_NAME',
  245. align : 'center',
  246. width : '20%',
  247. editor: { type: 'text',maxlength:'15'}
  248. },{
  249. display : '联系人电话',
  250. name : 'CONTACT_TEL',
  251. align : 'center',
  252. width : '20%',
  253. editor: { type: 'text',maxlength:'11'}
  254. },
  255. {
  256. display : '联系人部门',
  257. name : 'CONTACT_DEPT',
  258. align : 'center',
  259. width : '20%',
  260. editor: { type: 'text',maxlength:'15'}
  261. }, {
  262. display : '联系人公司',
  263. name : 'CONTACT_COMP',
  264. align : 'center',
  265. width : '20%',
  266. editor: { type: 'text',maxlength:'15'}
  267. }];
  268. }
  269. var display = {
  270. display: '操作', isSort: false, width: "20%", render: function (rowdata, rowindex, value,column)
  271. {
  272. var h = "";
  273. if (!rowdata._editing)
  274. {
  275. h += "<a onclick='onDelete("+rowindex+")' id='del'><span class='icon_delete'>删除</span></a> ";
  276. }
  277. return h;
  278. }
  279. };
  280. columns.push(display);
  281. return columns;
  282. }
  283. function onDelete(rowid){
  284. top.Dialog.confirm("确定要删除该联系人?|删除", function() {
  285. var row = g.getRow(rowid);
  286. g.deleteRow(row);
  287. });
  288. }
  289. function checkTel(str,arr){
  290. if(arr.length==0){
  291. return true;
  292. }
  293. for(var i=0;i<arr.length;i++){
  294. if(str==arr[i].CONTACT_TEL){
  295. return false;
  296. }
  297. }
  298. return true;
  299. }
  300. function checkGroupTel(name,tel,arr){
  301. if(arr.length==0){
  302. return true;
  303. }
  304. name = $.trim(name);
  305. var groupTel = arr[0][name];
  306. if(groupTel==undefined){
  307. return true;
  308. }
  309. var groupTelArr = groupTel.split(",");
  310. for(var i=0;i<groupTelArr.length;i++){
  311. if(groupTelArr[i]==tel){
  312. console.log(11);
  313. return false;
  314. }
  315. }
  316. return true;
  317. }