Нет описания

addOrEditAddress.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. * 添加或修改地址
  3. * */
  4. $(function() {
  5. autosize($('textarea'));
  6. init();
  7. });
  8. function init() {
  9. var edit_id = helper.request.queryString("edit_id");
  10. // initDept();
  11. //项目名称 科室下拉数据
  12. helper.getDropList.getProlistDrop($('#pro_title'))
  13. .then(function() {
  14. $('#pro_title').on('change', function() {
  15. $('#building').selectpicker('destroy');
  16. $('#floor').selectpicker('destroy');
  17. $('#deptTreeView').empty();
  18. helper.getDropList.getBuildlistDrop($('#building'), $(this).val())
  19. });
  20. $('#building').on('change', function() {
  21. $('#floor').selectpicker('destroy');
  22. $('#deptTreeView').empty();
  23. helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
  24. });
  25. // $('#floor').on('change', function() {
  26. // $('#deptTreeView').empty();
  27. // helper.getDropList.getDeptTreeLists($('#department'), $('#deptTreeView'), {
  28. // projectid: $('#pro_title').val(), // 否 string 项目id
  29. // building: $('#building').val(), // 否 string 楼栋id
  30. // floorid: $(this).val(), // 否 string 楼层id
  31. // }, 'configurationapi/api/Department/getlistdrop');
  32. // });
  33. })
  34. .then(function() {
  35. if (edit_id) {
  36. getDetail();
  37. }
  38. $('#save_btns').on('click', btn_save);
  39. });
  40. }
  41. //初始化科室下拉
  42. function initDept() {
  43. $('#department').on('focus click', function() {
  44. $('#deptTreeView').removeClass('hidden').addClass('show');
  45. });
  46. $('#department').on('keyup', function() {
  47. if ($(this).val() == '') {
  48. $('deptTreeView').treeview('uncheckAll', {
  49. silent: true
  50. });
  51. $(this).attr('data-id', '');
  52. }
  53. });
  54. $('#department + .caret').on('click', function() {
  55. $('#deptTreeView').removeClass('hidden').addClass('show');
  56. });
  57. $('#deptTreeView').mouseleave(function() {
  58. $(this).removeClass('show').addClass('hidden');
  59. });
  60. }
  61. //获取地址信息
  62. function getDetail() {
  63. var edit_id = helper.request.queryString("edit_id");
  64. $.getJSON(huayi.config.callcenter_url + "distributionapi/api/DistriAddress/getsingle", {
  65. id: edit_id,
  66. }, function(data) {
  67. if (data.state == "success") {
  68. var res = data.data;
  69. $('#addressType').find('input[name="addressType_flag"][value="' + res.addresstype + '"]').prop("checked",
  70. "checked");
  71. $('#pro_title').selectpicker('val', res.projectid);
  72. helper.getDropList.getBuildlistDrop($('#building'), res.projectid)
  73. .then(function(){
  74. $('#building').selectpicker('val', res.buildingid);
  75. });
  76. helper.getDropList.getFloorlistDrop($('#floor'), res.buildingid)
  77. .then(function(){
  78. $('#floor').selectpicker('val', res.floorid);
  79. });
  80. // helper.getDropList.getDeptTreeLists($('#department'), $('#deptTreeView'), {
  81. // projectid: res.projectid, // 否 string 项目id
  82. // building: res.buildingid, // 否 string 楼栋id
  83. // floorid: res.floorid, // 否 string 楼层id
  84. // }, 'configurationapi/api/Department/getlistdrop')
  85. // .then(function(){
  86. // $('#department').val(res.departmentname);
  87. // $('#department').attr('data-id', res.departmentid);
  88. // });
  89. $('#fullname').val(res.fullname);
  90. $('#mobile').val(res.mobile);
  91. $('#remark').val(res.remark);
  92. // $('#sortnum').val(res.sortnum);
  93. $('#isdefault').find('input[name="isdefault_flag"][value="' + res.isdefault + '"]').prop("checked", "checked");
  94. }
  95. });
  96. }
  97. //保存地址信息
  98. function btn_save() {
  99. var wURL, loadIndex;
  100. var edit_id = helper.request.queryString("edit_id");
  101. if (edit_id) {
  102. wURL = "distributionapi/api/DistriAddress/update";
  103. } else {
  104. wURL = "distributionapi/api/DistriAddress/add";
  105. }
  106. if (!$.trim($('#pro_title').val())) {
  107. layer.confirm('项目名称不允许为空!', {
  108. icon: 2,
  109. btn: ['确定'] //按钮
  110. });
  111. return;
  112. }
  113. if (!$.trim($('#building').val())) {
  114. layer.confirm('楼宇名称不允许为空!', {
  115. icon: 2,
  116. btn: ['确定'] //按钮
  117. });
  118. return;
  119. }
  120. if (!$.trim($('#floor').val())) {
  121. layer.confirm('楼层名称不允许为空!', {
  122. icon: 2,
  123. btn: ['确定'] //按钮
  124. });
  125. return;
  126. }
  127. if (!$.trim($('#fullname').val())) {
  128. layer.confirm('姓名不允许为空!', {
  129. icon: 2,
  130. btn: ['确定'] //按钮
  131. });
  132. return;
  133. }
  134. if (!regexs.phone.test($.trim($('#mobile').val()))) {
  135. layer.confirm('请输入正确的电话号码!', {
  136. icon: 2,
  137. btn: ['确定']
  138. });
  139. return;
  140. }
  141. // if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
  142. // layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
  143. // icon: 2,
  144. // btn: ['确定'] //按钮
  145. // });
  146. // return;
  147. // }
  148. $.ajax({
  149. type: 'post',
  150. url: huayi.config.callcenter_url + wURL,
  151. dataType: 'json',
  152. async: true,
  153. beforeSend: function() { //触发ajax请求开始时执行
  154. $('#save_btns').attr("disabled", true);
  155. $('#save_btns').text('保存中...');
  156. loadIndex = layer.load();
  157. },
  158. data: {
  159. id: edit_id, // 否 string id
  160. addresstype: $('#addressType').find('input[name="addressType_flag"]:checked').val(), // 否 string 地址类型:0发货/1收货
  161. projectid: $('#pro_title').val(), // 是 string 项目名称id
  162. buildingid: $('#building').val(), // 是 string 楼宇名称id
  163. floorid: $('#floor').val(), // 是 string 层数id
  164. // departmentid: $('#department').attr('data-id'), // 否 string 科室id
  165. fullname: $('#fullname').val(), // 否 string 姓名
  166. mobile: $('#mobile').val(), // 否 string 电话
  167. isdefault: $('#isdefault').find('input[name="isdefault_flag"]:checked').val(), // 否 bool 是否默认
  168. remark: helper.filter.delHtmlTag($('#remark').val()), // 否 string 备注
  169. // sortnum: $('#sortnum').val(), // 否 string 排序
  170. },
  171. success: function(data) {
  172. layer.close(loadIndex);
  173. if (data.state === "success") {
  174. var index = parent.layer.getFrameIndex(window.name);
  175. parent.layer.close(index);
  176. parent.$('#table_all').bootstrapTable('refresh');
  177. parent.layer.msg("保存成功");
  178. } else {
  179. $('#save_btns').attr("disabled", false);
  180. $('#save_btns').text('保存');
  181. }
  182. },
  183. error: function(textStatus) {
  184. layer.close(loadIndex);
  185. layer.confirm('网络繁忙,请稍后再试...', {
  186. icon: 7,
  187. closeBtn: 0,
  188. btn: ['确定'] //按钮
  189. });
  190. $('#save_btns').attr("disabled", false);
  191. $('#save_btns').text('保存');
  192. },
  193. complete: function(XMLHttpRequest, textStatus) {
  194. layer.close(loadIndex);
  195. if (textStatus == 'timeout') {
  196. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  197. xmlhttp.abort();
  198. layer.confirm('网络超时,请稍后再试...', {
  199. icon: 7,
  200. closeBtn: 0,
  201. btn: ['确定'] //按钮
  202. });
  203. }
  204. $('#save_btns').attr("disabled", false);
  205. $('#save_btns').text('保存');
  206. },
  207. });
  208. }