user_info.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /**
  2. * 用户详情对话框(可用于添加和修改对话框)
  3. */
  4. var UserInfoDlg = {
  5. userInfoData: {},
  6. validateFields: {
  7. account: {
  8. validators: {
  9. notEmpty: {
  10. message: '账户不能为空'
  11. }
  12. }
  13. },
  14. name: {
  15. validators: {
  16. notEmpty: {
  17. message: '姓名不能为空'
  18. }
  19. }
  20. },
  21. phone: {
  22. validators: {
  23. notEmpty: {
  24. message: '电话号码不能为空'
  25. },
  26. regexp: {
  27. regexp: /^1\d{10}$/,
  28. message: '手机号码格式错误'
  29. }
  30. }
  31. },
  32. type: {
  33. validators: {
  34. notEmpty: {
  35. message: '账号类型不能为空'
  36. }
  37. }
  38. },
  39. companyId: {
  40. validators: {
  41. notEmpty: {
  42. message: '单位不能为空'
  43. }
  44. }
  45. },
  46. password: {
  47. validators: {
  48. notEmpty: {
  49. message: '密码不能为空'
  50. },
  51. identical: {
  52. field: 're_password',
  53. message: '两次密码不一致'
  54. },
  55. }
  56. },
  57. re_password: {
  58. validators: {
  59. notEmpty: {
  60. message: '密码不能为空'
  61. },
  62. identical: {
  63. field: 'password',
  64. message: '两次密码不一致'
  65. },
  66. }
  67. }
  68. }
  69. };
  70. /**
  71. * 清除数据
  72. */
  73. UserInfoDlg.clearData = function () {
  74. this.userInfoData = {};
  75. };
  76. /**
  77. * 设置对话框中的数据
  78. *
  79. * @param key 数据的名称
  80. * @param val 数据的具体值
  81. */
  82. UserInfoDlg.set = function (key, value) {
  83. if (typeof value == "undefined") {
  84. if (typeof $("#" + key).val() == "undefined") {
  85. var str = "";
  86. var ids = "";
  87. $("input[name='" + key + "']:checkbox").each(function () {
  88. if (true == $(this).is(':checked')) {
  89. str += $(this).val() + ",";
  90. }
  91. });
  92. if (str) {
  93. if (str.substr(str.length - 1) == ',') {
  94. ids = str.substr(0, str.length - 1);
  95. }
  96. } else {
  97. $("input[name='" + key + "']:radio").each(function () {
  98. if (true == $(this).is(':checked')) {
  99. ids = $(this).val()
  100. }
  101. });
  102. }
  103. this.userInfoData[key] = ids;
  104. } else {
  105. this.userInfoData[key] = $("#" + key).val();
  106. }
  107. }
  108. return this;
  109. };
  110. /**
  111. * 设置对话框中的数据
  112. *
  113. * @param key 数据的名称
  114. * @param val 数据的具体值
  115. */
  116. UserInfoDlg.get = function (key) {
  117. return $("#" + key).val();
  118. };
  119. /**
  120. * 关闭此对话框
  121. */
  122. UserInfoDlg.close = function () {
  123. parent.layer.close(window.parent.MgrUser.layerIndex);
  124. };
  125. // /**
  126. // * 点击部门input框时
  127. // *
  128. // * @param e
  129. // * @param treeId
  130. // * @param treeNode
  131. // * @returns
  132. // */
  133. // UserInfoDlg.onClickDept = function (e, treeId, treeNode) {
  134. // $("#citySel").attr("value", instance.getSelectedVal());
  135. // $("#deptid").attr("value", treeNode.id);
  136. // };
  137. //
  138. // /**
  139. // * 显示部门选择的树
  140. // *
  141. // * @returns
  142. // */
  143. // UserInfoDlg.showDeptSelectTree = function () {
  144. // var cityObj = $("#citySel");
  145. // var cityOffset = $("#citySel").offset();
  146. // $("#menuContent").css({
  147. // left: cityOffset.left + "px",
  148. // top: cityOffset.top + cityObj.outerHeight() + "px"
  149. // }).slideDown("fast");
  150. //
  151. // $("body").bind("mousedown", onBodyDown);
  152. // };
  153. //
  154. // /**
  155. // * 显示用户详情部门选择的树
  156. // *
  157. // * @returns
  158. // */
  159. // UserInfoDlg.showInfoDeptSelectTree = function () {
  160. // var cityObj = $("#citySel");
  161. // var cityPosition = $("#citySel").position();
  162. // $("#menuContent").css({
  163. // left: cityPosition.left + "px",
  164. // top: cityPosition.top + cityObj.outerHeight() + "px"
  165. // }).slideDown("fast");
  166. //
  167. // $("body").bind("mousedown", onBodyDown);
  168. // };
  169. //
  170. // /**
  171. // * 隐藏部门选择的树
  172. // */
  173. // UserInfoDlg.hideDeptSelectTree = function () {
  174. // $("#menuContent").fadeOut("fast");
  175. // $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
  176. // };
  177. /**
  178. * 收集数据
  179. */
  180. UserInfoDlg.collectData = function () {
  181. this.set('id')
  182. .set('account')
  183. .set('sex')
  184. .set('type')
  185. .set('password')
  186. .set('avatar')
  187. .set('email')
  188. .set('name')
  189. .set('birthday')
  190. .set('re_password')
  191. .set('deptid')
  192. .set('phone')
  193. .set('companyId')
  194. .set("groupCode");
  195. };
  196. /**
  197. * 验证两个密码是否一致
  198. */
  199. UserInfoDlg.validatePwd = function () {
  200. var password = this.get("password");
  201. var re_password = this.get("re_password");
  202. if (password == re_password) {
  203. return true;
  204. } else {
  205. return false;
  206. }
  207. };
  208. /**
  209. * 验证数据是否为空
  210. */
  211. UserInfoDlg.validate = function () {
  212. $('#userInfoForm').data("bootstrapValidator").resetForm();
  213. $('#userInfoForm').bootstrapValidator('validate');
  214. return $("#userInfoForm").data('bootstrapValidator').isValid();
  215. };
  216. /**
  217. * 提交添加用户
  218. */
  219. UserInfoDlg.addSubmit = function () {
  220. this.clearData();
  221. this.collectData();
  222. if (!this.validate()) {
  223. return;
  224. }
  225. if (!this.validatePwd()) {
  226. Feng.error("两次密码输入不一致");
  227. return;
  228. }
  229. //提交信息
  230. var ajax = new $ax("/admin/user/add", function (data) {
  231. Feng.success(data.msg);
  232. window.parent.MgrUser.table.refresh();
  233. UserInfoDlg.close();
  234. }, function (data) {
  235. Feng.error(data.responseJSON.msg);
  236. });
  237. ajax.set(this.userInfoData);
  238. ajax.start();
  239. };
  240. /**
  241. * 提交修改
  242. */
  243. UserInfoDlg.editSubmit = function () {
  244. this.clearData();
  245. this.collectData();
  246. if (!this.validate()) {
  247. return;
  248. }
  249. //提交信息
  250. var ajax = new $ax("/admin/user/edit", function (data) {
  251. Feng.success(data.msg);
  252. if (window.parent.MgrUser != undefined) {
  253. window.parent.MgrUser.table.refresh();
  254. UserInfoDlg.close();
  255. }
  256. }, function (data) {
  257. Feng.error(data.responseJSON.msg);
  258. });
  259. ajax.set(this.userInfoData);
  260. ajax.start();
  261. };
  262. /**
  263. * 提交修改
  264. */
  265. UserInfoDlg.editInfo = function () {
  266. this.clearData();
  267. this.collectData();
  268. if (!this.validate()) {
  269. return;
  270. }
  271. //提交信息
  272. var ajax = new $ax("/admin/user/info", function (data) {
  273. Feng.success(data.msg);
  274. if (window.parent.MgrUser != undefined) {
  275. window.parent.MgrUser.table.refresh();
  276. UserInfoDlg.close();
  277. }
  278. }, function (data) {
  279. Feng.error(data.responseJSON.msg);
  280. });
  281. ajax.set(this.userInfoData);
  282. ajax.start();
  283. };
  284. UserInfoDlg.companyChange = function () {
  285. var companyId = $("#companyId").val()
  286. if (Feng.isNotEmptyStr(companyId)) {
  287. var ajax = new $ax("/admin/company/detail/id/" + companyId, function (data) {
  288. if (data.code == CONFIG.COM_VISITGROUP) {
  289. $("#groupCode").parent().parent().css("display", "block");
  290. } else {
  291. $("#groupCode").val("")
  292. $("#groupCode").parent().parent().css("display", "none");
  293. }
  294. }, function (data) {
  295. Feng.error("查询失败!" + data.responseJSON.message + "!");
  296. });
  297. ajax.start();
  298. } else {
  299. $("#groupCode").val("")
  300. $("#groupCode").parent().parent().css("display", "none");
  301. }
  302. }
  303. /**
  304. * 修改密码
  305. */
  306. UserInfoDlg.chPwd = function () {
  307. var ajax = new $ax("/admin/user/change_pwd", function (data) {
  308. Feng.success(data.msg);
  309. }, function (data) {
  310. Feng.error(data.responseJSON.msg);
  311. });
  312. ajax.set("old_password");
  313. ajax.set("password");
  314. ajax.set("re_password");
  315. ajax.start();
  316. };
  317. function onBodyDown(event) {
  318. if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(
  319. event.target).parents("#menuContent").length > 0)) {
  320. UserInfoDlg.hideDeptSelectTree();
  321. }
  322. }
  323. $(function () {
  324. Feng.initValidatorTip("userInfoForm", UserInfoDlg.validateFields);
  325. Feng.addAjaxSelect({
  326. "id": "companyId",
  327. "displayCode": "id",
  328. "displayName": "name",
  329. "type": "GET",
  330. "url": "/admin/company/selectAll"
  331. });
  332. var arr = [{"name": "groupCode", "code": "un_visit_group"}];
  333. Feng.findChildDictBatch(JSON.stringify(arr));
  334. //批量加载时间控件
  335. laydate.render({elem: "#birthday", type: "date", trigger: 'click', format: 'yyyy-MM-dd', value: new Date($("#birthday").val())});
  336. $("select").each(function () {
  337. $(this).val($(this).attr("value")).trigger("change");
  338. });
  339. // var ztree = new $ZTree("treeDemo", "/dept/tree");
  340. // ztree.bindOnClick(UserInfoDlg.onClickDept);
  341. // ztree.init();
  342. // instance = ztree;
  343. // 初始化头像上传
  344. var avatarUp = new $WebUpload("avatar");
  345. avatarUp.setUploadBarId("progressBar");
  346. avatarUp.init();
  347. });