Brak opisu

addOrEditKind.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * 添加或修改配送物品种类
  3. * */
  4. $(function() {
  5. //项目名称
  6. autosize($('textarea'));
  7. helper.getDropList.getProlistDrop($('#pro_title'))
  8. .then(function(){
  9. init();
  10. });
  11. });
  12. function init() {
  13. var isEdit = helper.request.queryString("isEdit");
  14. var mid = helper.request.queryString("mid");
  15. var txt = helper.request.queryString("txt");
  16. txt = decodeURIComponent(txt);
  17. var pid = helper.request.queryString("pid");
  18. var pTxt = helper.request.queryString("pTxt");
  19. pTxt = decodeURIComponent(pTxt);
  20. if (isEdit) {
  21. //修改
  22. if (pid == null || pid == "undefined") {
  23. $('#menus').val("顶级分类");
  24. $('#menus').attr('data-id', null);
  25. } else {
  26. $('#menus').val(pTxt);
  27. $('#menus').attr('data-id', pid);
  28. }
  29. getMenusInfo();
  30. $('#save_btns').on('click', saveAccount);
  31. } else {
  32. //添加
  33. if (mid == "undefined") {
  34. $('#menus').val("顶级分类");
  35. $('#menus').attr('data-id', null);
  36. } else {
  37. $('#menus').val(txt);
  38. $('#menus').attr('data-id', mid);
  39. }
  40. //配送物品种类下拉数据
  41. getMenuLists();
  42. $('#save_btns').on('click', saveAccount);
  43. }
  44. $('#menus').on('focus click', function() {
  45. $('#menusTreeView').removeClass('hidden').addClass('show');
  46. });
  47. $('#menus').on('keyup', function() {
  48. if ($(this).val() == '') {
  49. $('menusTreeView').treeview('uncheckAll', {
  50. silent: true
  51. });
  52. $(this).attr('data-id', null);
  53. }
  54. });
  55. $('#menus + .caret').on('click', function() {
  56. $('#menusTreeView').removeClass('hidden').addClass('show');
  57. });
  58. $('#menusTreeView').mouseleave(function() {
  59. $(this).removeClass('show').addClass('hidden');
  60. });
  61. }
  62. //获取配送物品种类信息
  63. function getMenusInfo() {
  64. var mid = helper.request.queryString("mid");
  65. $.getJSON(huayi.config.callcenter_url + "distributionapi/api/DistriGoodsType/getdetailes", {
  66. id: mid,
  67. }, function(data) {
  68. if (data.state == "success") {
  69. var res = data.data;
  70. $('#pro_title').selectpicker('val', res.projectid).trigger('change');
  71. $('#kindname').val(res.kindname);
  72. $('#sortnum').val(res.sortnum);
  73. $('#remark').val(res.remark);
  74. //配送物品种类下拉数据
  75. getMenuLists(res.projectid);
  76. }
  77. });
  78. }
  79. //保存配送物品种类信息
  80. function saveAccount() {
  81. var wURL;
  82. var mid = helper.request.queryString("mid");
  83. var isEdit = helper.request.queryString("isEdit");
  84. if (isEdit) {
  85. wURL = "distributionapi/api/DistriGoodsType/update";
  86. } else {
  87. mid = null;
  88. wURL = "distributionapi/api/DistriGoodsType/add";
  89. }
  90. if (!$.trim($('#pro_title').val())) {
  91. layer.confirm('项目名称不允许为空!', {
  92. icon: 2,
  93. btn: ['确定'] //按钮
  94. });
  95. return;
  96. }
  97. if (!$.trim($('#kindname').val())) {
  98. layer.confirm('配送物品种类名称不允许为空!', {
  99. icon: 2,
  100. btn: ['确定'] //按钮
  101. });
  102. return;
  103. }
  104. if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
  105. layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
  106. icon: 2,
  107. btn: ['确定'] //按钮
  108. });
  109. return;
  110. }
  111. $.post(huayi.config.callcenter_url + wURL, {
  112. id: mid, // 是 string id
  113. parentid: $('#menus').attr('data-id'), // 当前选择节点ID父级ID,无父级ID为null string 父级id
  114. projectid: $('#pro_title').val(), // string 项目名称id
  115. kindname: $('#kindname').val(), // string 配送物品种类名称
  116. sortnum: $('#sortnum').val(), // string 排序
  117. remark: helper.filter.delHtmlTag($('#remark').val()), // string 备注
  118. }, function(data) {
  119. var data = JSON.parse(data);
  120. if (data.state == "success") {
  121. var index = parent.layer.getFrameIndex(window.name);
  122. parent.layer.close(index);
  123. parent.$("#gridList").resetSelection();
  124. parent.$("#gridList").trigger("reloadGrid");
  125. parent.layer.msg("保存成功");
  126. }
  127. });
  128. }
  129. //配送物品种类下拉
  130. function getMenuLists(pro_id) {
  131. $.getJSON(huayi.config.callcenter_url + 'distributionapi/api/DistriGoodsType/getlistdrop', {
  132. projectid: pro_id,// 否 string 项目id
  133. }, function(result) {
  134. if (result.state.toLowerCase() == "success") {
  135. var defaultDatas = result.data;
  136. defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/kindname/g, "text"));
  137. defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/\[\]/g, null));
  138. var $sTree = $('#menusTreeView').treeview({
  139. color: "#428bca",
  140. expandIcon: 'glyphicon glyphicon-chevron-right',
  141. collapseIcon: 'glyphicon glyphicon-chevron-down',
  142. nodeIcon: 'fa fa-folder-o',
  143. //selectedIcon: "glyphicon glyphicon-stop",
  144. //icon: "glyphicon glyphicon-stop",
  145. //emptyIcon: 'glyphicon',
  146. //showCheckbox: true,
  147. selectable: true,
  148. state: {
  149. selected: true
  150. },
  151. data: defaultDatas,
  152. onNodeSelected: function(event, node) {
  153. $sTree.treeview('clearSearch');
  154. $('#menus').val(node.text);
  155. $('#menus').attr('data-id', node.id);
  156. $('#menusTreeView').removeClass('show').addClass('hidden');
  157. },
  158. onNodeUnselected: function(event, node) {
  159. $('#menus').val('顶级分类');
  160. $('#menus').attr('data-id', null);
  161. }
  162. });
  163. $('#menusTreeView').treeview('collapseAll', {
  164. silent: true
  165. });
  166. var findSNodes = function() {
  167. return $sTree.treeview('search', [$('#menus').val(), {
  168. ignoreCase: false,
  169. exactMatch: false
  170. }]);
  171. };
  172. $('#menus').on('keyup', function(e) {
  173. var selectableNodes = findSNodes();
  174. });
  175. }
  176. })
  177. }