| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /**
- * 添加或修改配送物品种类
- * */
- $(function() {
- //项目名称
- autosize($('textarea'));
- helper.getDropList.getProlistDrop($('#pro_title'))
- .then(function(){
- init();
- });
- });
- function init() {
- var isEdit = helper.request.queryString("isEdit");
- var mid = helper.request.queryString("mid");
- var txt = helper.request.queryString("txt");
- txt = decodeURIComponent(txt);
- var pid = helper.request.queryString("pid");
- var pTxt = helper.request.queryString("pTxt");
- pTxt = decodeURIComponent(pTxt);
- if (isEdit) {
- //修改
- if (pid == null || pid == "undefined") {
- $('#menus').val("顶级分类");
- $('#menus').attr('data-id', null);
- } else {
- $('#menus').val(pTxt);
- $('#menus').attr('data-id', pid);
- }
- getMenusInfo();
- $('#save_btns').on('click', saveAccount);
- } else {
- //添加
- if (mid == "undefined") {
- $('#menus').val("顶级分类");
- $('#menus').attr('data-id', null);
- } else {
- $('#menus').val(txt);
- $('#menus').attr('data-id', mid);
- }
- //配送物品种类下拉数据
- getMenuLists();
- $('#save_btns').on('click', saveAccount);
- }
- $('#menus').on('focus click', function() {
- $('#menusTreeView').removeClass('hidden').addClass('show');
- });
- $('#menus').on('keyup', function() {
- if ($(this).val() == '') {
- $('menusTreeView').treeview('uncheckAll', {
- silent: true
- });
- $(this).attr('data-id', null);
- }
- });
- $('#menus + .caret').on('click', function() {
- $('#menusTreeView').removeClass('hidden').addClass('show');
- });
- $('#menusTreeView').mouseleave(function() {
- $(this).removeClass('show').addClass('hidden');
- });
- }
- //获取配送物品种类信息
- function getMenusInfo() {
- var mid = helper.request.queryString("mid");
- $.getJSON(huayi.config.callcenter_url + "distributionapi/api/DistriGoodsType/getdetailes", {
- id: mid,
- }, function(data) {
- if (data.state == "success") {
- var res = data.data;
- $('#pro_title').selectpicker('val', res.projectid).trigger('change');
- $('#kindname').val(res.kindname);
- $('#sortnum').val(res.sortnum);
- $('#remark').val(res.remark);
- //配送物品种类下拉数据
- getMenuLists(res.projectid);
- }
- });
- }
- //保存配送物品种类信息
- function saveAccount() {
- var wURL;
- var mid = helper.request.queryString("mid");
- var isEdit = helper.request.queryString("isEdit");
- if (isEdit) {
- wURL = "distributionapi/api/DistriGoodsType/update";
- } else {
- mid = null;
- wURL = "distributionapi/api/DistriGoodsType/add";
- }
-
- if (!$.trim($('#pro_title').val())) {
- layer.confirm('项目名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
-
- if (!$.trim($('#kindname').val())) {
- layer.confirm('配送物品种类名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
- layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- $.post(huayi.config.callcenter_url + wURL, {
- id: mid, // 是 string id
- parentid: $('#menus').attr('data-id'), // 当前选择节点ID父级ID,无父级ID为null string 父级id
- projectid: $('#pro_title').val(), // string 项目名称id
- kindname: $('#kindname').val(), // string 配送物品种类名称
- sortnum: $('#sortnum').val(), // string 排序
- remark: helper.filter.delHtmlTag($('#remark').val()), // string 备注
- }, function(data) {
- var data = JSON.parse(data);
- if (data.state == "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$("#gridList").resetSelection();
- parent.$("#gridList").trigger("reloadGrid");
- parent.layer.msg("保存成功");
- }
- });
- }
- //配送物品种类下拉
- function getMenuLists(pro_id) {
- $.getJSON(huayi.config.callcenter_url + 'distributionapi/api/DistriGoodsType/getlistdrop', {
- projectid: pro_id,// 否 string 项目id
- }, function(result) {
- if (result.state.toLowerCase() == "success") {
- var defaultDatas = result.data;
- defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/kindname/g, "text"));
- defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/\[\]/g, null));
- var $sTree = $('#menusTreeView').treeview({
- color: "#428bca",
- expandIcon: 'glyphicon glyphicon-chevron-right',
- collapseIcon: 'glyphicon glyphicon-chevron-down',
- nodeIcon: 'fa fa-folder-o',
- //selectedIcon: "glyphicon glyphicon-stop",
- //icon: "glyphicon glyphicon-stop",
- //emptyIcon: 'glyphicon',
- //showCheckbox: true,
- selectable: true,
- state: {
- selected: true
- },
- data: defaultDatas,
- onNodeSelected: function(event, node) {
- $sTree.treeview('clearSearch');
- $('#menus').val(node.text);
- $('#menus').attr('data-id', node.id);
- $('#menusTreeView').removeClass('show').addClass('hidden');
- },
- onNodeUnselected: function(event, node) {
- $('#menus').val('顶级分类');
- $('#menus').attr('data-id', null);
- }
- });
- $('#menusTreeView').treeview('collapseAll', {
- silent: true
- });
- var findSNodes = function() {
- return $sTree.treeview('search', [$('#menus').val(), {
- ignoreCase: false,
- exactMatch: false
- }]);
- };
- $('#menus').on('keyup', function(e) {
- var selectableNodes = findSNodes();
- });
- }
- })
- }
|