Nessuna descrizione

details.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /**
  2. * Created by TT on 2017/7/7.
  3. */
  4. ;
  5. spa_define(function () {
  6. return $.use(["spa", "util", "form", "code"], function (spa, util, fb, code) {
  7. return {
  8. modal: function (data) {
  9. var root = spa.findInModal(".sys_userinfo_details");
  10. var ca = {ready: true, items: []};
  11. var dp = code.parseCode(root.find(".dt-project"));
  12. var dh = code.parseCode(root.find(".dt-honor"));
  13. var dj = code.parseCode(root.find(".dt-job"));
  14. var de = code.parseCode(root.find(".dt-edu"));
  15. var form = fb.build(root.find(".newForm"), {
  16. industryList: ca,
  17. subjectList: ca,
  18. researchAreaList: ca
  19. });
  20. var oValue;
  21. var oJudge;
  22. var trim = function (str) { //删除左右两端的空格   
  23. return str.replace(/(^\s*)|(\s*$)/g, "");
  24. };
  25. var saveBtn = root.find(".opt-save"),
  26. save = function () {
  27. form.val({
  28. industry: oString(form.val().industryList),
  29. subject: oString(form.val().subjectList),
  30. researchArea: form.val().researchAreaList,
  31. subjectList: "", industryList: "", researchAreaList: ""
  32. });
  33. if (form.val().title) {
  34. var title = form.val().title;
  35. if (title.length > 20) {
  36. util.alert("职称不得超过20个字");
  37. return;
  38. }
  39. }
  40. if (form.val().office) {
  41. var office = form.val().office;
  42. if (office.length > 20) {
  43. util.alert("职位不得超过20个字");
  44. return;
  45. }
  46. }
  47. if (form.val().orgName) {
  48. var orgName = form.val().orgName;
  49. if (orgName.length > 50) {
  50. util.alert("所在机构不得超过50个字");
  51. return;
  52. }
  53. }
  54. if (form.val().department) {
  55. var department = form.val().department;
  56. if (department.length > 20) {
  57. util.alert("所在部门不得超过20个字");
  58. return;
  59. }
  60. }
  61. if (form.val().descp) {
  62. var descp = trim(form.val().descp);
  63. if (descp.length > 500) {
  64. util.alert("个人简介不得超过500个字");
  65. }
  66. }
  67. if (form.val().mobile) {
  68. var mobile = form.val().mobile;
  69. if (mobile) {
  70. if (mobile.length > 50) {
  71. util.alert('提示', '联系电话不得超过50个字');
  72. return;
  73. }
  74. }
  75. }
  76. if (form.val().email) {
  77. var email = form.val().email;
  78. var gunf = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  79. if (!gunf.test(email)) {
  80. util.alert("联系邮箱格式有误,请检查后重新填写");
  81. return;
  82. }
  83. }
  84. if (form.val().name) {
  85. var name = form.val().name;
  86. if (name.length > 10) {
  87. util.alert("姓名最长为10个字");
  88. return;
  89. }
  90. }
  91. if (form.val().name == null) {
  92. util.alert("请输入专家姓名");
  93. } else if (form.val().mobile || form.val().email) {
  94. form.doPut("../ajax/userinfo/update", function () {
  95. spa.closeModal();
  96. if (data.hand) {
  97. data.hand();
  98. }
  99. }, function (data) {
  100. util.alert(data.msg);
  101. });
  102. } else {
  103. util.alert("手机或邮箱至少输入一项");
  104. }
  105. };
  106. var part = function (one, list) {
  107. oValue = one;
  108. oJudge = list || [];
  109. var repeat,
  110. b;
  111. if (!oValue) {
  112. util.alert('提示', '请先填写内容');
  113. return;
  114. }
  115. if (oValue.length > 15) {
  116. util.alert('提示', '添加内容不能超过15个字');
  117. return;
  118. } else {
  119. var oValueList = oValue.split(","),
  120. length = oValueList.length;
  121. for (var m = 0;m<oValueList.length;m++) {
  122. oValueList[m] = trim(oValueList[m]);
  123. }
  124. for (var j = 0; j < length; j++) {
  125. for (var n = j + 1; n < oValueList.length + 1;) {
  126. if (oValueList[j] == oValueList[n]) {
  127. oValueList.remove(n);
  128. repeat = false;
  129. } else {
  130. n++;
  131. }
  132. }
  133. }
  134. for (var j = 0; j < oValueList.length;) {
  135. for (var i = 0; i < oJudge.length; i++) {
  136. if (oValueList[j] == oJudge[i]) {
  137. oValueList.remove(j);
  138. repeat = false;
  139. b = true;
  140. }
  141. }
  142. if (b) {
  143. b = false
  144. } else j++;
  145. }
  146. if (repeat == false) {
  147. util.alert('提示', '添加内容不能重复');
  148. }
  149. for (var m = 0; m < oValueList.length; m++) {
  150. ca.items.push({code: oValueList[m], caption: oValueList[m]});
  151. oJudge.push(oValueList[m]);
  152. }
  153. }
  154. };
  155. var part2 = function (one, list) {
  156. oValue = one;
  157. oJudge = list || [];
  158. var repeat,
  159. b;
  160. if (!oValue) {
  161. util.alert('提示', '请先填写内容');
  162. return;
  163. }
  164. if (oValue.length > 30) {
  165. util.alert('提示', '添加内容不能超过30个字');
  166. return;
  167. } else {
  168. var oValueList = oValue.split(","),
  169. length = oValueList.length;
  170. for (var m = 0;m<oValueList.length;m++) {
  171. oValueList[m] = trim(oValueList[m]);
  172. }
  173. for (var j = 0; j < length; j++) {
  174. for (var n = j + 1; n < oValueList.length + 1;) {
  175. if (oValueList[j] == oValueList[n]) {
  176. oValueList.remove(n);
  177. repeat = false;
  178. } else {
  179. n++;
  180. }
  181. }
  182. }
  183. for (var j = 0; j < oValueList.length;) {
  184. for (var i = 0; i < oJudge.length; i++) {
  185. if (oValueList[j] == oJudge[i]) {
  186. oValueList.remove(j);
  187. repeat = false;
  188. b = true;
  189. }
  190. }
  191. if (b) {
  192. b = false
  193. } else j++;
  194. }
  195. if (repeat == false) {
  196. util.alert('提示', '添加内容不能重复');
  197. }
  198. for (var m = 0; m < oValueList.length; m++) {
  199. ca.items.push({code: oValueList[m], caption: oValueList[m]});
  200. oJudge.push(oValueList[m]);
  201. }
  202. }
  203. };
  204. var split = function (data) {
  205. var index = data.split(",");
  206. var arr = [];
  207. for (var m = 0; m < index.length; m++) {
  208. ca.items.push({code: index[m], caption: index[m]});
  209. arr.push(index[m]);
  210. }
  211. return arr;
  212. };
  213. var split2 = function (data) {
  214. var arr = [];
  215. for (var m = 0; m < data.length; m++) {
  216. ca.items.push({code: data[m], caption: data[m]});
  217. arr.push(data[m]);
  218. }
  219. return arr;
  220. };
  221. if (data.data.industry) {
  222. form.val({industryList: split(data.data.industry)});
  223. }
  224. if (data.data.subject) {
  225. form.val({subjectList: split(data.data.subject)});
  226. }
  227. if (data.data.researchArea) {
  228. form.val({researchAreaList: split2(data.data.researchArea)});
  229. }
  230. Array.prototype.remove = function (obj) {
  231. for (var i = 0; i < this.length; i++) {
  232. var temp = this[i];
  233. if (!isNaN(obj)) {
  234. temp = i;
  235. }
  236. if (temp == obj) {
  237. for (var j = i; j < this.length; j++) {
  238. this[j] = this[j + 1];
  239. }
  240. this.length = this.length - 1;
  241. }
  242. }
  243. };
  244. function oString(data) {
  245. var arry = new Array();
  246. if (data) {
  247. for (var i = 0; i < data.length; i++) {
  248. arry.push(data[i]);
  249. }
  250. }
  251. return arry.join(",");
  252. }
  253. root.find(".opt-industry").on("click", function () {
  254. part(form.val().newIndustry, form.val().industryList);
  255. form.val({newIndustry: "", industryList: oJudge});
  256. });
  257. root.find(".opt-subject").on("click", function () {
  258. part(form.val().newSubject, form.val().subjectList);
  259. form.val({newSubject: "", subjectList: oJudge});
  260. });
  261. root.find(".opt-ra").on("click", function () {
  262. part2(form.val().newResearchArea, form.val().researchAreaList);
  263. form.val({newResearchArea: "", researchAreaList: oJudge});
  264. });
  265. root.find(".modal-ctrl .icon-times").on("click", function () {
  266. spa.closeModal();
  267. });
  268. root.find(".opt-project-new").on("click", function () {
  269. spa.showModal("sys_userinfo_project_new", {
  270. data: data.data.projects, hand: function () {
  271. dp.val(data.data.projects);
  272. }
  273. });
  274. });
  275. root.on("click", ".opt-project-edit", function () {
  276. var pNo = $(this).parent().attr("pNo");
  277. spa.showModal("sys_userinfo_project_edit", {
  278. data: data.data.projects[pNo], hand: function () {
  279. dp.val(data.data.projects);
  280. }
  281. })
  282. });
  283. root.on("click", ".opt-project-del", function () {
  284. var pNo = $(this).parent().attr("pNo");
  285. if (pNo) {
  286. util.boxMsg({
  287. title: "确认删除",
  288. content: "确认删除该项目经历?",
  289. btns: [{
  290. caption: "删除",
  291. hand: function () {
  292. data.data.projects.remove(pNo);
  293. data.data.projects = data.data.projects || [];
  294. for (var i = 0; i < data.data.projects.length; ++i) {
  295. data.data.projects[i].no = i;
  296. }
  297. dp.val(data.data.projects);
  298. console.log(data.data.projects);
  299. }
  300. },
  301. {caption: "取消"}
  302. ]
  303. });
  304. } else {
  305. util.alert("该项目经历不存在");
  306. }
  307. });
  308. root.find(".opt-honor-new").on("click", function () {
  309. spa.showModal("sys_userinfo_honor_new", {
  310. data: data.data.honors, hand: function () {
  311. dh.val(data.data.honors);
  312. }
  313. })
  314. });
  315. root.on("click", ".opt-honor-edit", function () {
  316. var hNo = $(this).parent().attr("hNo");
  317. spa.showModal("sys_userinfo_honor_edit", {
  318. data: data.data.honors[hNo], hand: function () {
  319. dh.val(data.data.honors);
  320. }
  321. })
  322. });
  323. root.on("click", ".opt-honor-del", function () {
  324. var hNo = $(this).parent().attr("hNo");
  325. if (hNo) {
  326. util.boxMsg({
  327. title: "确认删除",
  328. content: "确认删除该荣誉奖项?",
  329. btns: [{
  330. caption: "删除",
  331. hand: function () {
  332. data.data.honors.remove(hNo);
  333. data.data.honors = data.data.honors || [];
  334. for (var i = 0; i < data.data.honors.length; ++i) {
  335. data.data.honors[i].no = i;
  336. }
  337. dh.val(data.data.honors);
  338. console.log(data.data.honors);
  339. }
  340. },
  341. {caption: "取消"}
  342. ]
  343. });
  344. } else {
  345. util.alert("该荣誉奖项不存在");
  346. }
  347. });
  348. root.find(".opt-job-new").on("click", function () {
  349. spa.showModal("sys_userinfo_job_new", {
  350. data: data.data.jobs, hand: function () {
  351. dj.val(data.data.jobs);
  352. }
  353. });
  354. });
  355. root.on("click", ".opt-job-edit", function () {
  356. var jNo = $(this).parent().attr("jNo");
  357. spa.showModal("sys_userinfo_job_edit", {
  358. data: data.data.jobs[jNo], hand: function () {
  359. dj.val(data.data.jobs);
  360. }
  361. })
  362. });
  363. root.on("click", ".opt-job-del", function () {
  364. var jNo = $(this).parent().attr("jNo");
  365. if (jNo) {
  366. util.boxMsg({
  367. title: "确认删除",
  368. content: "确认删除该工作经历?",
  369. btns: [{
  370. caption: "删除",
  371. hand: function () {
  372. data.data.jobs.remove(jNo);
  373. data.data.jobs = data.data.jobs || [];
  374. for (var i = 0; i < data.data.jobs.length; ++i) {
  375. data.data.jobs[i].no = i;
  376. }
  377. dj.val(data.data.jobs);
  378. console.log(data.data.jobs);
  379. }
  380. },
  381. {caption: "取消"}
  382. ]
  383. });
  384. } else {
  385. util.alert("该工作经历不存在");
  386. }
  387. });
  388. root.find(".opt-edu-new").on("click", function () {
  389. spa.showModal("sys_userinfo_edu_new", {
  390. data: data.data.edus, hand: function () {
  391. de.val(data.data.edus);
  392. }
  393. });
  394. });
  395. root.on("click", ".opt-edu-edit", function () {
  396. var eNo = $(this).parent().attr("eNo");
  397. spa.showModal("sys_userinfo_edu_edit", {
  398. data: data.data.edus[eNo], hand: function () {
  399. de.val(data.data.edus);
  400. }
  401. })
  402. });
  403. root.on("click", ".opt-edu-del", function () {
  404. var eNo = $(this).parent().attr("eNo");
  405. if (eNo) {
  406. util.boxMsg({
  407. title: "确认删除",
  408. content: "确认删除该工作经历?",
  409. btns: [{
  410. caption: "删除",
  411. hand: function () {
  412. data.data.edus.remove(eNo);
  413. data.data.edus = data.data.edus || [];
  414. for (var i = 0; i < data.data.edus.length; ++i) {
  415. data.data.edus[i].no = i;
  416. }
  417. de.val(data.data.edus);
  418. console.log(data.data.edus);
  419. }
  420. },
  421. {caption: "取消"}
  422. ]
  423. });
  424. } else {
  425. util.alert("该工作经历不存在");
  426. }
  427. });
  428. $.fn.citySelect();
  429. $(document).on("click", "#City li a", function () {
  430. var aVal = $(this).text();
  431. $(this).parent().parent().parent().find('.mr_show').text(aVal);
  432. $(this).parent().parent().parent().find('input[name=cho_City]').val(aVal);
  433. if ($("#ocity").text() == "请选择城市") {
  434. $("#ocity").removeClass("mr_select");
  435. } else {
  436. $("#ocity").addClass("mr_select");
  437. }
  438. if ($("#oprovince").text() != "请选择省份") {
  439. form.val({province: $("#oprovince").text()});
  440. }
  441. if ($("#ocity").text() != "请选择城市") {
  442. form.val({address: $("#ocity").text()});
  443. }
  444. });
  445. if (data.data.province) {
  446. $("#oprovince").text(data.data.province);
  447. }
  448. if (data.data.address) {
  449. $("#ocity").text(data.data.address);
  450. }
  451. saveBtn.on("click", function () {
  452. save();
  453. });
  454. data.data.projects = data.data.projects || [];
  455. for (var i = 0; i < data.data.projects.length; ++i) {
  456. data.data.projects[i].no = i;
  457. }
  458. dp.val(data.data.projects);
  459. data.data.honors = data.data.honors || [];
  460. for (var i = 0; i < data.data.honors.length; ++i) {
  461. data.data.honors[i].no = i;
  462. }
  463. dh.val(data.data.honors);
  464. data.data.jobs = data.data.jobs || [];
  465. for (var i = 0; i < data.data.jobs.length; ++i) {
  466. data.data.jobs[i].no = i;
  467. }
  468. dj.val(data.data.jobs);
  469. data.data.edus = data.data.edus || [];
  470. for (var i = 0; i < data.data.edus.length; ++i) {
  471. data.data.edus[i].no = i;
  472. }
  473. de.val(data.data.edus);
  474. if (!form.val().pMobile) {
  475. form.val({pMobile: data.data.mobile})
  476. }
  477. if (!form.val().pEmail) {
  478. form.val({pEmail: data.data.email})
  479. }
  480. form.val(data.data);
  481. }
  482. }
  483. });
  484. });