| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /**
- * 添加或修改地址
- * */
- $(function() {
- autosize($('textarea'));
- init();
- });
- function init() {
- // initDept();
- var proId = helper.request.queryString("proId");
- //项目名称 科室下拉数据
- helper.getDropList.getProlistDrop($('#pro_title'))
- .then(function() {
- $('#pro_title').on('change', function() {
- $('#building').selectpicker('destroy');
- $('#floor').selectpicker('destroy');
- $('#deptTreeView').empty();
- helper.getDropList.getBuildlistDrop($('#building'), $(this).val())
- });
- $('#building').on('change', function() {
- $('#floor').selectpicker('destroy');
- $('#deptTreeView').empty();
- helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
- });
- // $('#floor').on('change', function() {
- // $('#deptTreeView').empty();
- // helper.getDropList.getDeptTreeLists($('#department'), $('#deptTreeView'), {
- // projectid: $('#pro_title').val(), // 否 string 项目id
- // building: $('#building').val(), // 否 string 楼栋id
- // floorid: $(this).val(), // 否 string 楼层id
- // }, 'configurationapi/api/Department/getlistdrop');
- // });
- })
- .then(function() {
- if(proId){
- $('#pro_title').selectpicker('val', proId);
- helper.getDropList.getBuildlistDrop($('#building'), proId)
- }
- $('#save_btns').on('click', btn_save);
- });
- }
- //初始化科室下拉
- function initDept() {
- $('#department').on('focus click', function() {
- $('#deptTreeView').removeClass('hidden').addClass('show');
- });
- $('#department').on('keyup', function() {
- if ($(this).val() == '') {
- $('deptTreeView').treeview('uncheckAll', {
- silent: true
- });
- $(this).attr('data-id', '');
- }
- });
- $('#department + .caret').on('click', function() {
- $('#deptTreeView').removeClass('hidden').addClass('show');
- });
- $('#deptTreeView').mouseleave(function() {
- $(this).removeClass('show').addClass('hidden');
- });
- }
- //保存地址信息
- function btn_save() {
- var loadIndex;
- 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($('#fullname').val())) {
- layer.confirm('姓名不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!regexs.phone.test($.trim($('#mobile').val()))) {
- layer.confirm('请输入正确的电话号码!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- // if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
- // layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- var cobj = [{
- "building_name": $('#building option:selected').text(),
- "floor_name": $('#floor option:selected').text().split(' ')[0],
- "department_name": $('#floor option:selected').text().split(" ")[1],
- "fullname": $('#fullname').val(),
- "mobile": $('#mobile').val(),
- }];
- $.ajax({
- type: 'post',
- url: huayi.config.callcenter_url + 'distributionapi/api/DistriAddress/add',
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('#save_btns').attr("disabled", true);
- $('#save_btns').text('保存中...');
- loadIndex = layer.load();
- },
- data: {
- addresstype: 0, // 否 string 地址类型:0发货/1收货
- projectid: $('#pro_title').val(), // 是 string 项目名称id
- buildingid: $('#building').val(), // 是 string 楼宇名称id
- floorid: $('#floor').val(), // 是 string 层数id
- // departmentid: $('#department').attr('data-id'), // 否 string 科室id
- fullname: $('#fullname').val(), // 否 string 姓名
- mobile: $('#mobile').val(), // 否 string 电话
- isdefault: $('#isdefault').find('input[name="isdefault_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);
- console.log(JSON.stringify(cobj))
- 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>');
- parent.$('#deliverylist').selectpicker('refresh');
- parent.$('#deliverylist').selectpicker('val', JSON.stringify(cobj));
- 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('保存');
- },
- });
- }
|