No Description

details.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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 j = 0; j < length; j++) {
  122. for (var n = j + 1; n < oValueList.length + 1;) {
  123. if (oValueList[j] == oValueList[n]) {
  124. oValueList.remove(n);
  125. repeat = false;
  126. } else {
  127. n++;
  128. }
  129. }
  130. }
  131. for (var j = 0; j < oValueList.length;) {
  132. for (var i = 0; i < oJudge.length; i++) {
  133. if (oValueList[j] == oJudge[i]) {
  134. oValueList.remove(j);
  135. repeat = false;
  136. b = true;
  137. }
  138. }
  139. if (b) {
  140. b = false
  141. } else j++;
  142. }
  143. if (repeat == false) {
  144. util.alert('提示', '添加内容不能重复');
  145. }
  146. for (var m = 0; m < oValueList.length; m++) {
  147. ca.items.push({code: oValueList[m], caption: oValueList[m]});
  148. oJudge.push(oValueList[m]);
  149. }
  150. }
  151. };
  152. var part2 = function (one, list) {
  153. oValue = one;
  154. oJudge = list || [];
  155. var repeat,
  156. b;
  157. if (!oValue) {
  158. util.alert('提示', '请先填写内容');
  159. return;
  160. }
  161. if (oValue.length > 30) {
  162. util.alert('提示', '添加内容不能超过30个字');
  163. return;
  164. } else {
  165. var oValueList = oValue.split(","),
  166. length = oValueList.length;
  167. for (var j = 0; j < length; j++) {
  168. for (var n = j + 1; n < oValueList.length + 1;) {
  169. if (oValueList[j] == oValueList[n]) {
  170. oValueList.remove(n);
  171. repeat = false;
  172. } else {
  173. n++;
  174. }
  175. }
  176. }
  177. for (var j = 0; j < oValueList.length;) {
  178. for (var i = 0; i < oJudge.length; i++) {
  179. if (oValueList[j] == oJudge[i]) {
  180. oValueList.remove(j);
  181. repeat = false;
  182. b = true;
  183. }
  184. }
  185. if (b) {
  186. b = false
  187. } else j++;
  188. }
  189. if (repeat == false) {
  190. util.alert('提示', '添加内容不能重复');
  191. }
  192. for (var m = 0; m < oValueList.length; m++) {
  193. ca.items.push({code: oValueList[m], caption: oValueList[m]});
  194. oJudge.push(oValueList[m]);
  195. }
  196. }
  197. };
  198. var split = function (data) {
  199. var index = data.split(",");
  200. var arr = [];
  201. for (var m = 0; m < index.length; m++) {
  202. ca.items.push({code: index[m], caption: index[m]});
  203. arr.push(index[m]);
  204. }
  205. return arr;
  206. };
  207. var split2 = function (data) {
  208. var arr = [];
  209. for (var m = 0; m < data.length; m++) {
  210. ca.items.push({code: data[m], caption: data[m]});
  211. arr.push(data[m]);
  212. }
  213. return arr;
  214. };
  215. if (data.data.industry) {
  216. form.val({industryList: split(data.data.industry)});
  217. }
  218. if (data.data.subject) {
  219. form.val({subjectList: split(data.data.subject)});
  220. }
  221. if (data.data.researchArea) {
  222. form.val({researchAreaList: split2(data.data.researchArea)});
  223. }
  224. Array.prototype.remove = function (obj) {
  225. for (var i = 0; i < this.length; i++) {
  226. var temp = this[i];
  227. if (!isNaN(obj)) {
  228. temp = i;
  229. }
  230. if (temp == obj) {
  231. for (var j = i; j < this.length; j++) {
  232. this[j] = this[j + 1];
  233. }
  234. this.length = this.length - 1;
  235. }
  236. }
  237. };
  238. function oString(data) {
  239. var arry = new Array();
  240. if (data) {
  241. for (var i = 0; i < data.length; i++) {
  242. arry.push(data[i]);
  243. }
  244. }
  245. return arry.join(",");
  246. }
  247. root.find(".opt-industry").on("click", function () {
  248. part(form.val().newIndustry, form.val().industryList);
  249. form.val({newIndustry: "", industryList: oJudge});
  250. });
  251. root.find(".opt-subject").on("click", function () {
  252. part(form.val().newSubject, form.val().subjectList);
  253. form.val({newSubject: "", subjectList: oJudge});
  254. });
  255. root.find(".opt-ra").on("click", function () {
  256. part2(form.val().newResearchArea, form.val().researchAreaList);
  257. form.val({newResearchArea: "", researchAreaList: oJudge});
  258. });
  259. root.find(".modal-ctrl .icon-times").on("click", function () {
  260. spa.closeModal();
  261. });
  262. root.find(".opt-project-new").on("click", function () {
  263. spa.showModal("sys_userinfo_project_new", {
  264. data: data.data.projects, hand: function () {
  265. dp.val(data.data.projects);
  266. }
  267. });
  268. });
  269. root.on("click", ".opt-project-edit", function () {
  270. var pNo = $(this).parent().attr("pNo");
  271. spa.showModal("sys_userinfo_project_edit", {
  272. data: data.data.projects[pNo], hand: function () {
  273. dp.val(data.data.projects);
  274. }
  275. })
  276. });
  277. root.on("click", ".opt-project-del", function () {
  278. var pNo = $(this).parent().attr("pNo");
  279. if (pNo) {
  280. util.boxMsg({
  281. title: "确认删除",
  282. content: "确认删除该项目经历?",
  283. btns: [{
  284. caption: "删除",
  285. hand: function () {
  286. data.data.projects.remove(pNo);
  287. data.data.projects = data.data.projects || [];
  288. for (var i = 0; i < data.data.projects.length; ++i) {
  289. data.data.projects[i].no = i;
  290. }
  291. dp.val(data.data.projects);
  292. console.log(data.data.projects);
  293. }
  294. },
  295. {caption: "取消"}
  296. ]
  297. });
  298. } else {
  299. util.alert("该项目经历不存在");
  300. }
  301. });
  302. root.find(".opt-honor-new").on("click", function () {
  303. spa.showModal("sys_userinfo_honor_new", {
  304. data: data.data.honors, hand: function () {
  305. dh.val(data.data.honors);
  306. }
  307. })
  308. });
  309. root.on("click", ".opt-honor-edit", function () {
  310. var hNo = $(this).parent().attr("hNo");
  311. spa.showModal("sys_userinfo_honor_edit", {
  312. data: data.data.honors[hNo], hand: function () {
  313. dh.val(data.data.honors);
  314. }
  315. })
  316. });
  317. root.on("click", ".opt-honor-del", function () {
  318. var hNo = $(this).parent().attr("hNo");
  319. if (hNo) {
  320. util.boxMsg({
  321. title: "确认删除",
  322. content: "确认删除该荣誉奖项?",
  323. btns: [{
  324. caption: "删除",
  325. hand: function () {
  326. data.data.honors.remove(hNo);
  327. data.data.honors = data.data.honors || [];
  328. for (var i = 0; i < data.data.honors.length; ++i) {
  329. data.data.honors[i].no = i;
  330. }
  331. dh.val(data.data.honors);
  332. console.log(data.data.honors);
  333. }
  334. },
  335. {caption: "取消"}
  336. ]
  337. });
  338. } else {
  339. util.alert("该荣誉奖项不存在");
  340. }
  341. });
  342. root.find(".opt-job-new").on("click", function () {
  343. spa.showModal("sys_userinfo_job_new", {
  344. data: data.data.jobs, hand: function () {
  345. dj.val(data.data.jobs);
  346. }
  347. });
  348. });
  349. root.on("click", ".opt-job-edit", function () {
  350. var jNo = $(this).parent().attr("jNo");
  351. spa.showModal("sys_userinfo_job_edit", {
  352. data: data.data.jobs[jNo], hand: function () {
  353. dj.val(data.data.jobs);
  354. }
  355. })
  356. });
  357. root.on("click", ".opt-job-del", function () {
  358. var jNo = $(this).parent().attr("jNo");
  359. if (jNo) {
  360. util.boxMsg({
  361. title: "确认删除",
  362. content: "确认删除该工作经历?",
  363. btns: [{
  364. caption: "删除",
  365. hand: function () {
  366. data.data.jobs.remove(jNo);
  367. data.data.jobs = data.data.jobs || [];
  368. for (var i = 0; i < data.data.jobs.length; ++i) {
  369. data.data.jobs[i].no = i;
  370. }
  371. dj.val(data.data.jobs);
  372. console.log(data.data.jobs);
  373. }
  374. },
  375. {caption: "取消"}
  376. ]
  377. });
  378. } else {
  379. util.alert("该工作经历不存在");
  380. }
  381. });
  382. root.find(".opt-edu-new").on("click", function () {
  383. spa.showModal("sys_userinfo_edu_new", {
  384. data: data.data.edus, hand: function () {
  385. de.val(data.data.edus);
  386. }
  387. });
  388. });
  389. root.on("click", ".opt-edu-edit", function () {
  390. var eNo = $(this).parent().attr("eNo");
  391. spa.showModal("sys_userinfo_edu_edit", {
  392. data: data.data.edus[eNo], hand: function () {
  393. de.val(data.data.edus);
  394. }
  395. })
  396. });
  397. root.on("click", ".opt-edu-del", function () {
  398. var eNo = $(this).parent().attr("eNo");
  399. if (eNo) {
  400. util.boxMsg({
  401. title: "确认删除",
  402. content: "确认删除该工作经历?",
  403. btns: [{
  404. caption: "删除",
  405. hand: function () {
  406. data.data.edus.remove(eNo);
  407. data.data.edus = data.data.edus || [];
  408. for (var i = 0; i < data.data.edus.length; ++i) {
  409. data.data.edus[i].no = i;
  410. }
  411. de.val(data.data.edus);
  412. console.log(data.data.edus);
  413. }
  414. },
  415. {caption: "取消"}
  416. ]
  417. });
  418. } else {
  419. util.alert("该工作经历不存在");
  420. }
  421. });
  422. $.fn.citySelect();
  423. $(document).on("click", "#City li a", function () {
  424. var aVal = $(this).text();
  425. $(this).parent().parent().parent().find('.mr_show').text(aVal);
  426. $(this).parent().parent().parent().find('input[name=cho_City]').val(aVal);
  427. if ($("#ocity").text() == "请选择城市") {
  428. $("#ocity").removeClass("mr_select");
  429. } else {
  430. $("#ocity").addClass("mr_select");
  431. }
  432. if ($("#oprovince").text() != "请选择省份") {
  433. form.val({province: $("#oprovince").text()});
  434. }
  435. if ($("#ocity").text() != "请选择城市") {
  436. form.val({address: $("#ocity").text()});
  437. }
  438. });
  439. if (data.data.province) {
  440. $("#oprovince").text(data.data.province);
  441. }
  442. if (data.data.address) {
  443. $("#ocity").text(data.data.address);
  444. }
  445. saveBtn.on("click", function () {
  446. save();
  447. });
  448. data.data.projects = data.data.projects || [];
  449. for (var i = 0; i < data.data.projects.length; ++i) {
  450. data.data.projects[i].no = i;
  451. }
  452. dp.val(data.data.projects);
  453. data.data.honors = data.data.honors || [];
  454. for (var i = 0; i < data.data.honors.length; ++i) {
  455. data.data.honors[i].no = i;
  456. }
  457. dh.val(data.data.honors);
  458. data.data.jobs = data.data.jobs || [];
  459. for (var i = 0; i < data.data.jobs.length; ++i) {
  460. data.data.jobs[i].no = i;
  461. }
  462. dj.val(data.data.jobs);
  463. data.data.edus = data.data.edus || [];
  464. for (var i = 0; i < data.data.edus.length; ++i) {
  465. data.data.edus[i].no = i;
  466. }
  467. de.val(data.data.edus);
  468. if (!form.val().pMobile) {
  469. form.val({pMobile: data.data.mobile})
  470. }
  471. if (!form.val().pEmail) {
  472. form.val({pEmail: data.data.email})
  473. }
  474. form.val(data.data);
  475. }
  476. }
  477. });
  478. });