暫無描述

contacts_modify.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. var userId = helper.request.queryString("id"); //用户id
  2. $(document).ready(function () {
  3. //保存
  4. $('.customerSubmit').click(function() {
  5. saveCustomer();
  6. });
  7. //获取部门
  8. getDepartment();
  9. //获取省份
  10. getProvince($("#source"));
  11. //获取详情
  12. getDetails();
  13. })
  14. //下拉框
  15. $('.inps').focus(function() {
  16. $(this).siblings('.add-tree').css('display', 'block');
  17. })
  18. $('.drop-down').click(function() {
  19. var dropDown = $(this).siblings('.add-tree');
  20. if(dropDown.css('display') == 'block') {
  21. dropDown.css('display', 'none')
  22. } else {
  23. dropDown.css('display', 'block')
  24. }
  25. })
  26. $('.add-tree').mouseleave(function() {
  27. $(this).css('display', 'none')
  28. })
  29. //获取所属部门
  30. var setting = {
  31. data: {
  32. key: {
  33. name: "text"
  34. },
  35. simpleData: {
  36. enable: true,
  37. idKey: "id",
  38. rootPId: 0
  39. }
  40. },
  41. callback: {
  42. onClick: ztreeDep
  43. }
  44. };
  45. var departmentId; //部门id
  46. var departmentName; //部门name
  47. function ztreeDep(event, treeId, treeNode) {
  48. departmentId = treeNode.id;
  49. departmentName = treeNode.text;
  50. $('.inps2').val(departmentName);
  51. };
  52. //获取部门
  53. function getDepartment() {
  54. $.get(huayi.config.callcenter_url + "Department/GetDeptList", {
  55. "token": $.cookie("token"),
  56. "pid": "",
  57. }, function(result) {
  58. result = $.parseJSON(result);
  59. $.fn.zTree.init($("#departmentTree"), setting, result.data); //实例化树形图
  60. });
  61. }
  62. /*
  63. * 省
  64. * 市
  65. * 区/县
  66. */
  67. //省
  68. function getProvince(obj) {
  69. obj.empty();
  70. obj.append('<option selected="selected" value="">请选择</option>');
  71. $.getJSON(huayi.config.callcenter_url + "RegionCategory/GetCountyList", {
  72. "token": $.cookie("token"),
  73. pid: 0,
  74. }, function (data) {
  75. if (data.state.toLowerCase() == "success") {
  76. var content = data.data;
  77. $(content).each(function (i, n) {
  78. $("<option value='" + n.F_RegionId + "'>" + n.F_RegionName + "</option>").appendTo(obj);
  79. })
  80. }
  81. })
  82. }
  83. //市
  84. function getCity(obj) {
  85. obj.empty();
  86. obj.append('<option selected="selected" value="">请选择</option>');
  87. $.getJSON(huayi.config.callcenter_url + "RegionCategory/GetCountyList", {
  88. "token": $.cookie("token"),
  89. pid:$('#source').val(),
  90. }, function (data) {
  91. if (data.state.toLowerCase() == "success") {
  92. var content = data.data;
  93. $(content).each(function (i, n) {
  94. $("<option value='" + n.F_RegionId + "'>" + n.F_RegionName + "</option>").appendTo(obj);
  95. })
  96. }
  97. })
  98. }
  99. //区/县
  100. function getCounty(obj) {
  101. obj.empty();
  102. obj.append('<option selected="selected" value="">请选择</option>');
  103. $.getJSON(huayi.config.callcenter_url + "RegionCategory/GetCountyList", {
  104. "token": $.cookie("token"),
  105. pid:$('#type').val(),
  106. }, function (data) {
  107. if (data.state.toLowerCase() == "success") {
  108. var content = data.data;
  109. $(content).each(function (i, n) {
  110. $("<option value='" + n.F_RegionId + "'>" + n.F_RegionName + "</option>").appendTo(obj);
  111. })
  112. }
  113. })
  114. }
  115. //通过省获取市
  116. $('#source').on('change',function(){
  117. getCity($("#type"));
  118. });
  119. //通过市获取区/县
  120. $('#type').on('change',function(){
  121. getCounty($("#keyid"));
  122. });
  123. // 地址(省+市+区/县)
  124. function detailedAddress() {
  125. if($('#source').val() === ""){
  126. var province = '';
  127. } else {
  128. var province = $('#source').find("option:selected").text()
  129. }
  130. if($('#type').val() === ""){
  131. var city = '';
  132. } else {
  133. var city = $('#type').find("option:selected").text()
  134. }
  135. if($('#keyid').val() === ""){
  136. var county = '';
  137. } else {
  138. var county = $('#keyid').find("option:selected").text()
  139. }
  140. var address = province + '-' + city + '-' + county;
  141. return address;
  142. }
  143. //获取详情
  144. function getDetails() {
  145. $.ajax({
  146. type: "get",
  147. url: huayi.config.callcenter_url + "AddressBook/GetInfo",
  148. dataType: "json",
  149. async: true,
  150. data: {
  151. token: $.cookie("token"),
  152. infoid: userId,
  153. },
  154. success: function(data){
  155. if (data.state.toLowerCase() == "success") {
  156. var data = data.data;
  157. displayDetails(data);
  158. }
  159. }
  160. })
  161. }
  162. //回显
  163. function displayDetails(data) {
  164. $("#addUserName").val(data.F_Name); //用户姓名
  165. $("#addSex").val(data.F_Sex); //性别
  166. provinceCity(data)//地址
  167. $("#addTelephone").val(data.F_Telephone); //内线电话
  168. $("#addMobile").val(data.F_Mobile); //手机
  169. $("#addElseMobile").val(data.F_ElseMobile); //其他号码
  170. $(".inps2").val(data.F_Department)//部门
  171. $('.inps2').attr('data_id', data.F_DepartmentId);
  172. $("#addPosition").val(data.F_Position); //职位
  173. $("#addNote").val(data.F_Note); //备注
  174. //原部门id
  175. departmentId = $('.inps2').attr('data_id');
  176. }
  177. //省市县回显
  178. function provinceCity(data){
  179. var provinceCityArr = data.F_Address.split("-");
  180. $("#source option:selected").text(provinceCityArr[0]);
  181. $("#source option:selected").val(provinceCityArr[0]);
  182. $("#type option:selected").text(provinceCityArr[1]);
  183. $("#type option:selected").val(provinceCityArr[1]);
  184. $("#keyid option:selected").text(provinceCityArr[2]);
  185. $("#keyid option:selected").val(provinceCityArr[2]);
  186. }
  187. //保存
  188. function saveCustomer() {
  189. $.ajax({
  190. type: "post",
  191. url: huayi.config.callcenter_url + "AddressBook/Add",
  192. dataType: 'json',
  193. async: true,
  194. beforeSend: function() { //触发ajax请求开始时执行
  195. $('.customerSubmit').attr("disabled", true);
  196. $('.customerSubmit').text('确定中...');
  197. },
  198. data: {
  199. id: userId,//用户id
  200. token: $.cookie("token"),
  201. F_Name: $("#addUserName").val(), //用户姓名
  202. F_Sex: $("#addSex").val(), //性别
  203. F_Address: detailedAddress(), //地址
  204. F_Telephone: $("#addTelephone").val(), //内线电话
  205. F_Mobile: $("#addMobile").val(), //手机
  206. F_ElseMobile: $("#addElseMobile").val(), //其他号码
  207. // F_Departmentid: $("#addDepartmentid").val(), //部门ID
  208. F_Departmentid: departmentId, //部门ID
  209. F_Position: $("#addPosition").val(), //职位
  210. F_Note: $("#addNote").val(), //备注
  211. },
  212. success: function(data) {
  213. if (data.state.toLowerCase() == 'success') {
  214. $('.customerSubmit').attr("disabled", false);
  215. $('.customerSubmit').text('确定');
  216. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  217. parent.layer.close(index); //再执行关闭
  218. parent.layer.msg("保存成功!");
  219. parent.initTable();
  220. } else {
  221. $('.customerSubmit').attr("disabled", false);
  222. $('.customerSubmit').text('确定');
  223. }
  224. }
  225. });
  226. }