| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- /**
- * 添加或修改配送物品
- * */
- $(function() {
- autosize($('textarea'));
- init();
- });
- function init() {
- var edit_id = helper.request.queryString("edit_id");
- //初始化物品种类
- initKind();
- $('#isremind').find('input[name="isremind_flag"]').on('change', changeRemind)
- //项目名称 物品种类
- $.when(helper.getDropList.getProlistDrop($('#pro_title')),
- helper.getDropList.getDeptTreeLists($('#kindid'), $('#kindidTreeView'), {}, 'distributionapi/api/DistriGoodsType/getlistdrop'))
- .then(function() {
- $('#pro_title').on('change', function(){
- $('#building').selectpicker('destroy');
- $('#floor').selectpicker('destroy');
- $('#floor').empty();
- $('#floor').append("<option value=''>请选择楼层</option>");
- $('#kindid').val('');
- $('#kindid').attr('data-id', '');
- $('#kindidTreeView').empty();
- helper.getDropList.getBuildlistDrop($('#building'), $(this).val());
- });
- $('#building').on('change', function() {
- $('#floor').selectpicker('destroy');
- $('#kindidTreeView').empty();
- helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
- helper.getDropList.getDeptTreeLists($('#kindid'), $('#kindidTreeView'), {
- projectid: $('#pro_title').val(),// 否 string 项目id
- }, 'distributionapi/api/DistriGoodsType/getlistdrop');
- });
-
- if (edit_id) {
- getDetail();
- }
- $('#save_btns').on('click', btn_save);
- });
- }
- //初始化物品种类
- function initKind() {
- $('#kindid').on('focus click', function() {
- $('#kindidTreeView').removeClass('hidden').addClass('show');
- });
- $('#kindid').on('keyup', function() {
- if ($(this).val() == '') {
- $('kindidTreeView').treeview('uncheckAll', {
- silent: true
- });
- $(this).attr('data-id', '');
- }
- });
- $('#kindid + .caret').on('click', function() {
- $('#kindidTreeView').removeClass('hidden').addClass('show');
- });
- $('#kindidTreeView').mouseleave(function() {
- $(this).removeClass('show').addClass('hidden');
- });
- }
- //获取配送物品信息
- function getDetail() {
- var edit_id = helper.request.queryString("edit_id");
- $.getJSON(huayi.config.callcenter_url + "distributionapi/api/DistriGoods/getsingle", {
- id: edit_id,
- }, function(data) {
- if (data.state === "success") {
- var res = data.data;
- $('#pro_title').selectpicker('val', res.projectid).trigger('change'); // 是 string 项目名称id
- helper.getDropList.getBuildlistDrop($('#building'), res.projectid)
- .then(function(){
- $('#building').selectpicker('val', res.buildingid);
- });
-
- helper.getDropList.getFloorlistDrop($('#floor'), res.buildingid)
- .then(function(){
- $('#floor').selectpicker('val', res.floorid);
- });
-
- $('#kindidTreeView').empty();
- helper.getDropList.getDeptTreeLists($('#kindid'), $('#kindidTreeView'), {
- projectid: res.projectid,// 否 string 项目id
- }, 'distributionapi/api/DistriGoodsType/getlistdrop')
- .then(function(){
- $('#kindid').val(res.kindidname).trigger('keyup');// 是 string 物品种类(字典)
- $('#kindid').attr('data-id', res.kindid);
- });
-
- $('#typeId').find('input[name="typeId_flag"][value="' + res.typeid + '"]').prop("checked",
- "checked"); // 是 int 紧急程度 - 1一般 2紧急
- $('#goodsname').val(res.goodsname); // 否 string 物品名称
- $('#isremind').find('input[name="isremind_flag"][value="' + res.isremind + '"]').prop("checked",
- "checked");// 否 bool 是否提醒
- $('#remark').val(res.remark); // 否 string 提醒备注
- $('#sortnum').val(res.sortnum); // 否 string 排序
- }
- });
- }
- //保存配送物品信息
- function btn_save() {
- var wURL, loadIndex;
- var edit_id = helper.request.queryString("edit_id");
- if (edit_id) {
- wURL = "distributionapi/api/DistriGoods/update";
- } else {
- wURL = "distributionapi/api/DistriGoods/add";
- }
- if (!$.trim($('#pro_title').val())) {
- layer.confirm('请选择项目名称!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!$.trim($('#building').val())) {
- layer.confirm('楼宇名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!$.trim($('#floor').val())) {
- layer.confirm('楼层名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!$.trim($('#kindid').attr('data-id'))) {
- layer.confirm('请选择物品种类!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!$.trim($('#goodsname').val())) {
- layer.confirm('您还没有输入物品名称!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if ($.trim($('#sortnum').val())) {
- if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
- layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- }
-
- if($('#isremind').find('input[name="isremind_flag"]:checked').val() === 'true') {
- if (!$.trim($('#remark').val())) {
- layer.confirm('您还没有输入提醒备注!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- }else {
- $('#remark').val('');
- }
- $.ajax({
- type: 'post',
- url: huayi.config.callcenter_url + wURL,
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('#save_btns').attr("disabled", true);
- $('#save_btns').text('保存中...');
- loadIndex = layer.load();
- },
- data: {
- id: edit_id, // 否 string id
- projectid: $('#pro_title').val(), // 是 string 项目名称id
- buildingid: $('#building').val(), // 是 string 楼宇名称id
- floorid: $('#floor').val(), // 是 string 层数id
- kindid: $('#kindid').attr('data-id'), // 是 string 物品种类(字典)
- typeid: $('#typeId').find('input[name="typeId_flag"]:checked').val(), // 是 int 紧急程度 - 1一般 2紧急
- goodsname: $('#goodsname').val(), // 否 string 物品名称
- isremind: $('#isremind').find('input[name="isremind_flag"]:checked').val(), // 否 bool 是否提醒
- remark: helper.filter.delHtmlTag($('#remark').val()), // 否 string 提醒备注
- sortnum: $('#sortnum').val(), // 否 string 排序
- },
- success: function(data) {
- layer.close(loadIndex);
- if (data.state === "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$('#table_all').bootstrapTable('refresh');
- parent.layer.msg("保存成功");
- } else {
- $('#save_btns').attr("disabled", false);
- $('#save_btns').text('保存');
- }
- },
- error: function(textStatus) {
- layer.close(loadIndex);
- layer.confirm('网络繁忙,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- $('#save_btns').attr("disabled", false);
- $('#save_btns').text('保存');
- },
- complete: function(XMLHttpRequest, textStatus) {
- layer.close(loadIndex);
- if (textStatus == 'timeout') {
- var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
- xmlhttp.abort();
- layer.confirm('网络超时,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- }
- $('#save_btns').attr("disabled", false);
- $('#save_btns').text('保存');
- },
- });
- }
- //是否提醒切换
- function changeRemind(){
- if($(this).val() === 'true'){
- $('#remaindRemark').show();
- }else{
- $('#remaindRemark').hide();
- }
- }
|