No Description

planAddAddress.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * 添加或修改地址
  3. * */
  4. $(function() {
  5. autosize($('textarea'));
  6. init();
  7. });
  8. function init() {
  9. // initDept();
  10. var proId = helper.request.queryString("proId");
  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(proId){
  36. $('#pro_title').selectpicker('val', proId);
  37. helper.getDropList.getBuildlistDrop($('#building'), proId)
  38. }
  39. $('#save_btns').on('click', btn_save);
  40. });
  41. }
  42. //初始化科室下拉
  43. function initDept() {
  44. $('#department').on('focus click', function() {
  45. $('#deptTreeView').removeClass('hidden').addClass('show');
  46. });
  47. $('#department').on('keyup', function() {
  48. if ($(this).val() == '') {
  49. $('deptTreeView').treeview('uncheckAll', {
  50. silent: true
  51. });
  52. $(this).attr('data-id', '');
  53. }
  54. });
  55. $('#department + .caret').on('click', function() {
  56. $('#deptTreeView').removeClass('hidden').addClass('show');
  57. });
  58. $('#deptTreeView').mouseleave(function() {
  59. $(this).removeClass('show').addClass('hidden');
  60. });
  61. }
  62. //保存地址信息
  63. function btn_save() {
  64. var loadIndex;
  65. if (!$.trim($('#pro_title').val())) {
  66. layer.confirm('项目名称不允许为空!', {
  67. icon: 2,
  68. btn: ['确定'] //按钮
  69. });
  70. return;
  71. }
  72. if (!$.trim($('#building').val())) {
  73. layer.confirm('楼宇名称不允许为空!', {
  74. icon: 2,
  75. btn: ['确定'] //按钮
  76. });
  77. return;
  78. }
  79. if (!$.trim($('#floor').val())) {
  80. layer.confirm('楼层名称不允许为空!', {
  81. icon: 2,
  82. btn: ['确定'] //按钮
  83. });
  84. return;
  85. }
  86. if (!$.trim($('#fullname').val())) {
  87. layer.confirm('姓名不允许为空!', {
  88. icon: 2,
  89. btn: ['确定'] //按钮
  90. });
  91. return;
  92. }
  93. if (!regexs.phone.test($.trim($('#mobile').val()))) {
  94. layer.confirm('请输入正确的电话号码!', {
  95. icon: 2,
  96. btn: ['确定']
  97. });
  98. return;
  99. }
  100. // if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
  101. // layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
  102. // icon: 2,
  103. // btn: ['确定'] //按钮
  104. // });
  105. // return;
  106. // }
  107. var cobj = [{
  108. "building_name": $('#building option:selected').text(),
  109. "floor_name": $('#floor option:selected').text().split(' ')[0],
  110. "department_name": $('#floor option:selected').text().split(" ")[1],
  111. "fullname": $('#fullname').val(),
  112. "mobile": $('#mobile').val(),
  113. }];
  114. $.ajax({
  115. type: 'post',
  116. url: huayi.config.callcenter_url + 'distributionapi/api/DistriAddress/add',
  117. dataType: 'json',
  118. async: true,
  119. beforeSend: function() { //触发ajax请求开始时执行
  120. $('#save_btns').attr("disabled", true);
  121. $('#save_btns').text('保存中...');
  122. loadIndex = layer.load();
  123. },
  124. data: {
  125. addresstype: 0, // 否 string 地址类型:0发货/1收货
  126. projectid: $('#pro_title').val(), // 是 string 项目名称id
  127. buildingid: $('#building').val(), // 是 string 楼宇名称id
  128. floorid: $('#floor').val(), // 是 string 层数id
  129. // departmentid: $('#department').attr('data-id'), // 否 string 科室id
  130. fullname: $('#fullname').val(), // 否 string 姓名
  131. mobile: $('#mobile').val(), // 否 string 电话
  132. isdefault: $('#isdefault').find('input[name="isdefault_flag"]:checked').val(), // 否 bool 是否默认
  133. remark: helper.filter.delHtmlTag($('#remark').val()), // 否 string 备注
  134. // sortnum: $('#sortnum').val(), // 否 string 排序
  135. },
  136. success: function(data) {
  137. layer.close(loadIndex);
  138. if (data.state === "success") {
  139. var index = parent.layer.getFrameIndex(window.name);
  140. parent.layer.close(index);
  141. console.log(JSON.stringify(cobj))
  142. parent.$('#deliverylist').append('<option value=' + JSON.stringify(cobj) + '>' + $('#building option:selected').text() + ' ' + $('#floor option:selected').text().split(' ')[0] + ' ' + $('#floor option:selected').text().split(' ')[1] + '</option>');
  143. parent.$('#deliverylist').selectpicker('refresh');
  144. parent.$('#deliverylist').selectpicker('val', JSON.stringify(cobj));
  145. parent.layer.msg("保存成功");
  146. } else {
  147. $('#save_btns').attr("disabled", false);
  148. $('#save_btns').text('保存');
  149. }
  150. },
  151. error: function(textStatus) {
  152. layer.close(loadIndex);
  153. layer.confirm('网络繁忙,请稍后再试...', {
  154. icon: 7,
  155. closeBtn: 0,
  156. btn: ['确定'] //按钮
  157. });
  158. $('#save_btns').attr("disabled", false);
  159. $('#save_btns').text('保存');
  160. },
  161. complete: function(XMLHttpRequest, textStatus) {
  162. layer.close(loadIndex);
  163. if (textStatus == 'timeout') {
  164. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  165. xmlhttp.abort();
  166. layer.confirm('网络超时,请稍后再试...', {
  167. icon: 7,
  168. closeBtn: 0,
  169. btn: ['确定'] //按钮
  170. });
  171. }
  172. $('#save_btns').attr("disabled", false);
  173. $('#save_btns').text('保存');
  174. },
  175. });
  176. }