Нет описания

addOrEditGoods.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. * 添加或修改配送物品
  3. * */
  4. $(function() {
  5. autosize($('textarea'));
  6. init();
  7. });
  8. function init() {
  9. var edit_id = helper.request.queryString("edit_id");
  10. //初始化物品种类
  11. initKind();
  12. $('#isremind').find('input[name="isremind_flag"]').on('change', changeRemind)
  13. //项目名称 物品种类
  14. $.when(helper.getDropList.getProlistDrop($('#pro_title')),
  15. helper.getDropList.getDeptTreeLists($('#kindid'), $('#kindidTreeView'), {}, 'distributionapi/api/DistriGoodsType/getlistdrop'))
  16. .then(function() {
  17. $('#pro_title').on('change', function(){
  18. $('#building').selectpicker('destroy');
  19. $('#floor').selectpicker('destroy');
  20. $('#floor').empty();
  21. $('#floor').append("<option value=''>请选择楼层</option>");
  22. $('#kindid').val('');
  23. $('#kindid').attr('data-id', '');
  24. $('#kindidTreeView').empty();
  25. helper.getDropList.getBuildlistDrop($('#building'), $(this).val());
  26. });
  27. $('#building').on('change', function() {
  28. $('#floor').selectpicker('destroy');
  29. $('#kindidTreeView').empty();
  30. helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
  31. helper.getDropList.getDeptTreeLists($('#kindid'), $('#kindidTreeView'), {
  32. projectid: $('#pro_title').val(),// 否 string 项目id
  33. }, 'distributionapi/api/DistriGoodsType/getlistdrop');
  34. });
  35. if (edit_id) {
  36. getDetail();
  37. }
  38. $('#save_btns').on('click', btn_save);
  39. });
  40. }
  41. //初始化物品种类
  42. function initKind() {
  43. $('#kindid').on('focus click', function() {
  44. $('#kindidTreeView').removeClass('hidden').addClass('show');
  45. });
  46. $('#kindid').on('keyup', function() {
  47. if ($(this).val() == '') {
  48. $('kindidTreeView').treeview('uncheckAll', {
  49. silent: true
  50. });
  51. $(this).attr('data-id', '');
  52. }
  53. });
  54. $('#kindid + .caret').on('click', function() {
  55. $('#kindidTreeView').removeClass('hidden').addClass('show');
  56. });
  57. $('#kindidTreeView').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/DistriGoods/getsingle", {
  65. id: edit_id,
  66. }, function(data) {
  67. if (data.state === "success") {
  68. var res = data.data;
  69. $('#pro_title').selectpicker('val', res.projectid).trigger('change'); // 是 string 项目名称id
  70. helper.getDropList.getBuildlistDrop($('#building'), res.projectid)
  71. .then(function(){
  72. $('#building').selectpicker('val', res.buildingid);
  73. });
  74. helper.getDropList.getFloorlistDrop($('#floor'), res.buildingid)
  75. .then(function(){
  76. $('#floor').selectpicker('val', res.floorid);
  77. });
  78. $('#kindidTreeView').empty();
  79. helper.getDropList.getDeptTreeLists($('#kindid'), $('#kindidTreeView'), {
  80. projectid: res.projectid,// 否 string 项目id
  81. }, 'distributionapi/api/DistriGoodsType/getlistdrop')
  82. .then(function(){
  83. $('#kindid').val(res.kindidname).trigger('keyup');// 是 string 物品种类(字典)
  84. $('#kindid').attr('data-id', res.kindid);
  85. });
  86. $('#typeId').find('input[name="typeId_flag"][value="' + res.typeid + '"]').prop("checked",
  87. "checked"); // 是 int 紧急程度 - 1一般 2紧急
  88. $('#goodsname').val(res.goodsname); // 否 string 物品名称
  89. $('#isremind').find('input[name="isremind_flag"][value="' + res.isremind + '"]').prop("checked",
  90. "checked");// 否 bool 是否提醒
  91. $('#remark').val(res.remark); // 否 string 提醒备注
  92. $('#sortnum').val(res.sortnum); // 否 string 排序
  93. }
  94. });
  95. }
  96. //保存配送物品信息
  97. function btn_save() {
  98. var wURL, loadIndex;
  99. var edit_id = helper.request.queryString("edit_id");
  100. if (edit_id) {
  101. wURL = "distributionapi/api/DistriGoods/update";
  102. } else {
  103. wURL = "distributionapi/api/DistriGoods/add";
  104. }
  105. if (!$.trim($('#pro_title').val())) {
  106. layer.confirm('请选择项目名称!', {
  107. icon: 2,
  108. btn: ['确定'] //按钮
  109. });
  110. return;
  111. }
  112. if (!$.trim($('#building').val())) {
  113. layer.confirm('楼宇名称不允许为空!', {
  114. icon: 2,
  115. btn: ['确定'] //按钮
  116. });
  117. return;
  118. }
  119. if (!$.trim($('#floor').val())) {
  120. layer.confirm('楼层名称不允许为空!', {
  121. icon: 2,
  122. btn: ['确定'] //按钮
  123. });
  124. return;
  125. }
  126. if (!$.trim($('#kindid').attr('data-id'))) {
  127. layer.confirm('请选择物品种类!', {
  128. icon: 2,
  129. btn: ['确定'] //按钮
  130. });
  131. return;
  132. }
  133. if (!$.trim($('#goodsname').val())) {
  134. layer.confirm('您还没有输入物品名称!', {
  135. icon: 2,
  136. btn: ['确定'] //按钮
  137. });
  138. return;
  139. }
  140. if ($.trim($('#sortnum').val())) {
  141. if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
  142. layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
  143. icon: 2,
  144. btn: ['确定'] //按钮
  145. });
  146. return;
  147. }
  148. }
  149. if($('#isremind').find('input[name="isremind_flag"]:checked').val() === 'true') {
  150. if (!$.trim($('#remark').val())) {
  151. layer.confirm('您还没有输入提醒备注!', {
  152. icon: 2,
  153. btn: ['确定'] //按钮
  154. });
  155. return;
  156. }
  157. }else {
  158. $('#remark').val('');
  159. }
  160. $.ajax({
  161. type: 'post',
  162. url: huayi.config.callcenter_url + wURL,
  163. dataType: 'json',
  164. async: true,
  165. beforeSend: function() { //触发ajax请求开始时执行
  166. $('#save_btns').attr("disabled", true);
  167. $('#save_btns').text('保存中...');
  168. loadIndex = layer.load();
  169. },
  170. data: {
  171. id: edit_id, // 否 string id
  172. projectid: $('#pro_title').val(), // 是 string 项目名称id
  173. buildingid: $('#building').val(), // 是 string 楼宇名称id
  174. floorid: $('#floor').val(), // 是 string 层数id
  175. kindid: $('#kindid').attr('data-id'), // 是 string 物品种类(字典)
  176. typeid: $('#typeId').find('input[name="typeId_flag"]:checked').val(), // 是 int 紧急程度 - 1一般 2紧急
  177. goodsname: $('#goodsname').val(), // 否 string 物品名称
  178. isremind: $('#isremind').find('input[name="isremind_flag"]:checked').val(), // 否 bool 是否提醒
  179. remark: helper.filter.delHtmlTag($('#remark').val()), // 否 string 提醒备注
  180. sortnum: $('#sortnum').val(), // 否 string 排序
  181. },
  182. success: function(data) {
  183. layer.close(loadIndex);
  184. if (data.state === "success") {
  185. var index = parent.layer.getFrameIndex(window.name);
  186. parent.layer.close(index);
  187. parent.$('#table_all').bootstrapTable('refresh');
  188. parent.layer.msg("保存成功");
  189. } else {
  190. $('#save_btns').attr("disabled", false);
  191. $('#save_btns').text('保存');
  192. }
  193. },
  194. error: function(textStatus) {
  195. layer.close(loadIndex);
  196. layer.confirm('网络繁忙,请稍后再试...', {
  197. icon: 7,
  198. closeBtn: 0,
  199. btn: ['确定'] //按钮
  200. });
  201. $('#save_btns').attr("disabled", false);
  202. $('#save_btns').text('保存');
  203. },
  204. complete: function(XMLHttpRequest, textStatus) {
  205. layer.close(loadIndex);
  206. if (textStatus == 'timeout') {
  207. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  208. xmlhttp.abort();
  209. layer.confirm('网络超时,请稍后再试...', {
  210. icon: 7,
  211. closeBtn: 0,
  212. btn: ['确定'] //按钮
  213. });
  214. }
  215. $('#save_btns').attr("disabled", false);
  216. $('#save_btns').text('保存');
  217. },
  218. });
  219. }
  220. //是否提醒切换
  221. function changeRemind(){
  222. if($(this).val() === 'true'){
  223. $('#remaindRemark').show();
  224. }else{
  225. $('#remaindRemark').hide();
  226. }
  227. }