| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- /**
- * 添加或修改配送工单
- * */
- var indexNum = 0;
- var previous = ''; //项目名称切换前的值
- $(function() {
- autosize($('textarea'));
- init();
- });
- function init() {
- var edit_id = helper.request.queryString("edit_id");
- helper.getDropList.getProlistDrop($('#pro_title'))
- .then(function() {
- $('#pro_title').on('change', function() {
- $('#building').selectpicker('destroy');
- $('#floor').selectpicker('destroy');
- $('#floor').empty();
- $('#floor').append("<option value=''>请选择楼层</option>");
- helper.getDropList.getBuildlistDrop($('#building'), $(this).val());
- });
- $('#building').on('change', function() {
- $('#floor').selectpicker('destroy');
- helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
- });
- // getAddressSelect($('#deliverylist'), $('#pro_title').val(), 0);//发货
- // getAddressSelect($('#receiverlist'), $('#pro_title').val(), 1);//1收货
- })
- .then(function() {
- if (edit_id) {
- $('#add_goods').empty();
- getDetail();
- }
- $('#save_btns').on('click', btn_save);
- });
- //绑定项目名称 切换
- $('#pro_title').parent().on('mouseup', proTitleClick);
- $('#pro_title').on('change', proTitleChange);
- }
- //获取配送物品信息
- function getDetail() {
- var edit_id = helper.request.queryString("edit_id");
- $.getJSON(huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/getsingle", {
- id: edit_id,
- }, function(data) {
- if (data.state === "success") {
- var res = data.data.model;
- $('#pro_title').selectpicker('val', res.projectid); // 是 string 项目名称id
- // 发货地址
- helper.getDropList.getBuildlistDrop($('#building'), res.projectid)
- .then(function(){
- $('#building').selectpicker('val', res.deliverylist[0].buildingid);
- });// 是 string 楼宇id
-
- helper.getDropList.getFloorlistDrop($('#floor'), res.deliverylist[0].buildingid)
- .then(function(){
- $('#floor').selectpicker('val', res.deliverylist[0].floorid);
- });// 是 string 楼层id
-
- $('#deliveryname').val(res.deliveryname); // 否 string 发货人 - 随机工单
- $('#deliverytel').val(res.deliverytel); // 否 string 发货人电话 - 随机工单
-
- //发货
- // getAddressSelect($('#deliverylist'), res.projectid, 0)
- // .then(function(){
- // res.deliverylist = res.deliverylist ? JSON.stringify(res.deliverylist) : '';
- // $('#deliverylist').selectpicker('val', res.deliverylist); // 发货(地址,科室,联系)
- // });
- $('#emergencyid').find('input[name="emergencyid_flag"][value="' + res.emergencyid + '"]').prop("checked",
- "checked"); // 是 int 紧急程度 - 1一般 2紧急
- // $('#remark').val(res.detail); // 是 string 工单内容
- //配送物品
- if (res.goodslist && res.goodslist.length > 0) {
- for (var i = 0, len = res.goodslist.length; i < len; i++) {
- var cobj = {
- "goodsid": res.goodslist[i].goodsid,
- "goodsname": res.goodslist[i].goodsname,
- "isremind": res.goodslist[i].isremind,
- "typeid": res.goodslist[i].typeid,
- "remark": res.goodslist[i].remark === null ? '' : res.goodslist[i].remark,
- }
- //紧急程度 - 1一般 2紧急
- var typeName = res.goodslist[i].typeid === 1 ? '一般' : '紧急';
- var tplstr = '<div class="goodsLists_item col-md-12 row" data-ide="identifier_' + i + '">' +
- '<div class="form-group col-md-9 col-sm-9">' +
- '<input type="text" id="goodsSelect_' + i + '" value="' + res.goodslist[i].goodsname + ' (' + typeName +
- ')" data-goods=' + JSON.stringify(cobj) + ' class="form-control" disabled readonly style="width: 100%" />' +
- '</div>' +
- '<div class="form-group col-md-3 col-sm-3">' +
- '<div class="input-group delibery_num">' +
- '<span class="input-group-addon" id="btn_reduce_' + i + '">-</span>' +
- '<input id="goodsNum_' + i + '" type="text" value="' + res.goodslist[i].num +
- '" class="form-control" placeholder="请输入配送物品数量" aria-describedby="配送物品数量">' +
- '<span class="input-group-addon" id="btn_plus_' + i + '">+</span>' +
- '</div>' +
- '</div>' +
- '<button class="form-control btn btn-default btn_delete" style="width:60px;margin-left:15px" onclick="btn_delete($(this))">删除</button>' +
- '</div>';
- $('#goodsLists').prepend(tplstr);
- // 绑定 + - 事件
- $('#btn_reduce_' + i).on('click', { _index: i }, btn_reduce);
- $('#btn_plus_' + i).on('click', { _index: i }, btn_plus);
- $('#goodsNum_' + i).on('input keyup propertychange', inputValid);
- }
- indexNum = res.goodslist.length;
- }
- //收件(地址,科室,联系)
- // getAddressSelect($('#receiverlist'), res.projectid, 1)
- // .then(function(){
- // res.receiverlist = res.receiverlist ? JSON.stringify(res.receiverlist) : '';
- // $('#receiverlist').selectpicker('val', res.receiverlist);
- // });
-
- // 收货
- $('#receiverLists').show();
- helper.getDropList.getBuildlistDrop($('#rec_building'), res.projectid)
- .then(function(){
- $('#rec_building').selectpicker('val', res.receiverlist[0].buildingid);
- });// 是 string 楼宇id
-
- helper.getDropList.getFloorlistDrop($('#rec_floor'), res.receiverlist[0].buildingid)
- .then(function(){
- $('#rec_floor').selectpicker('val', res.receiverlist[0].floorid);
- });// 是 string 楼层id
-
- $('#pro_title').on('change', function() {
- $('#rec_building').selectpicker('destroy');
- $('#rec_floor').selectpicker('destroy');
- $('#rec_floor').empty();
- $('#rec_floor').append("<option value=''>请选择楼层</option>");
- helper.getDropList.getBuildlistDrop($('#rec_building'), $(this).val());
- });
- $('#rec_building').on('change', function() {
- $('#rec_floor').selectpicker('destroy');
- helper.getDropList.getFloorlistDrop($('#rec_floor'), $(this).val());
- });
-
- }
- });
- }
- //保存配送物品信息
- function btn_save() {
- var wURL, loadIndex;
- var deliveryDatas; // 添加编辑 发货 地址
- var goodslist_chaidan; // 添加 物品
- var receiverDatas; //编辑 收货 地址
- var goodslist; // 编辑 物品
- var edit_id = helper.request.queryString("edit_id");
- if (edit_id) {
- wURL = "distributionapi/api/DistriWorkOrder/update";
- } else {
- wURL = "distributionapi/api/DistriWorkOrder/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($('#deliveryname').val())) {
- layer.confirm('发货人姓名不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(!regexs.phone.test($.trim($('#deliverytel').val()))) {
- layer.confirm('请输入正确格式的发货人电话!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- // if (!$.trim($('#remark').val())) {
- // layer.confirm('请输入工单内容!', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- deliveryDatas = getDeliverDatas($('#building'),$('#floor')); //发货地址
- if(edit_id){
- goodslist = getFields(); // 编辑 物品
- if (!$.trim($('#rec_building').val())) {
- layer.confirm('收货地址中,楼宇名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!$.trim($('#rec_floor').val())) {
- layer.confirm('收货地址中,楼层名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- receiverDatas = getDeliverDatas($('#rec_building'),$('#rec_floor')); //编辑 收货 地址
- }else{
- valideFields(); // 验证配送物品
- goodslist_chaidan = getFields(); // 添加 物品
- }
-
- $.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
- emergencyid: $('#emergencyid').find('input[name="emergencyid_flag"]:checked').val(), // 是 int 紧急程度 - 1一般 2紧急
- deliverylist: deliveryDatas,// 否 List<DistributionDddressModel> 发货(地址,科室,联系)
- // deliverylist: $('#deliverylist').val() && JSON.parse($('#deliverylist').val()),// 否 List<DistributionDddressModel> 发货(地址,科室,联系)
- // detail: helper.filter.delHtmlTag($('#remark').val()),// 是 string 工单内容
- deliveryname: $('#deliveryname').val(),// 否 string 发货人 - 随机工单
- deliverytel: $('#deliverytel').val(),// 否 string 发货人电话 - 随机工单
- goodslist_chaidan: goodslist_chaidan,// 添加传 是 List<DistributionGoodsLists> 添加的时候传 配送物品 - 随机工单不用
-
- goodslist: goodslist, // 编辑传 是 List<DistributionGoodsList> 配送物品 编辑的时候传
- receiverlist: receiverDatas,// 编辑传 否 List<DistributionDddressModel> 收件(地址,科室,联系)
-
- },
- 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 proTitleClick() {
- previous = $(this).find('#pro_title').val();
- }
- //项目名称切换
- function proTitleChange() {
- var self = this;
- if ($('#goodsLists').find('.goodsLists_item').length > 0) {
- layer.confirm('切换项目名称将清除当前配送物品内容,您确定要切换项目名称吗?', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定', '取消'], //按钮
- }, function(index) {
- $('#goodsLists').html('');
- // getAddressSelect($('#deliverylist'), $(self).val(), 0); //发货
- // getAddressSelect($('#receiverlist'), $(self).val(), 1); //1收货
- layer.close(index);
- }, function() {
- $(self).selectpicker('val', previous);
- });
- } else {
- // getAddressSelect($('#deliverylist'), $(self).val(), 0); //发货
- // getAddressSelect($('#receiverlist'), $(self).val(), 1); //1收货
- }
- }
- //添加配送物品
- function btn_add() {
- if (!$.trim($('#pro_title').val())) {
- layer.confirm('请选择项目名称!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- var tplstr = '';
- tplstr = '<div class="goodsLists_item col-md-12 row" data-ide="identifier_' + indexNum + '">' +
- '<div class="form-group col-md-3 col-sm-3">' +
- '<select id="goodsSelect_' + indexNum + '" class="form-control selectpicker" data-live-search="true">' +
- '<option value="">请选择物品</option>' +
- '</select>' +
- '</div>' +
- '<div class="form-group col-md-3 col-sm-3">' +
- '<select id="buildingSelect_' + indexNum + '" class="form-control selectpicker" data-live-search="true">' +
- '<option value="">请选择楼宇名称</option>' +
- '</select>' +
- '</div>' +
- '<div class="form-group col-md-3 col-sm-3">' +
- '<select id="floorSelect_' + indexNum + '" class="form-control selectpicker" data-live-search="true">' +
- '<option value="">请选择楼层名称</option>' +
- '</select>' +
- '</div>' +
- '<div class="form-group col-md-3 col-sm-3">' +
- '<div class="input-group delibery_num">' +
- '<span class="input-group-addon" id="btn_reduce_' + indexNum + '">-</span>' +
- '<input id="goodsNum_' + indexNum +
- '" type="text" value="1" class="form-control" placeholder="请输入配送物品数量" aria-describedby="配送物品数量">' +
- '<span class="input-group-addon" id="btn_plus_' + indexNum + '">+</span>' +
- '</div>' +
- '</div>' +
- '<button class="form-control btn btn-default btn_delete" style="width:60px;margin-left:15px" onclick="btn_delete($(this))">删除</button>' +
- '</div>';
- $('#goodsLists').prepend(tplstr);
- // 获取配送物品下拉
- $.when(
- getGoodsSelect($('#goodsSelect_' + indexNum), $('#pro_title').val()),
- helper.getDropList.getBuildlistDrop($('#buildingSelect_' + indexNum), $('#pro_title').val()),
- helper.getDropList.getFloorlistDrop($('#floorSelect_' + indexNum), $('#buildingSelect_' + indexNum).val())
- )
- .then(function() {
- var curData = null;
- $('#goodsSelect_' + indexNum).on('change', function() {
- var curentIndex = $(this).attr('id').split('_')[1];
- if ($(this).val()) {
- curData = JSON.parse($(this).val());
- $('#buildingSelect_' + curentIndex).selectpicker('val', curData.buildingid).trigger('change');
- } else {
- $('#buildingSelect_' + curentIndex).selectpicker('destroy');
- $('#floorSelect_' + curentIndex).selectpicker('destroy');
- $('#floorSelect_' + curentIndex).empty();
- $('#floorSelect_' + curentIndex).append("<option value=''>请选择楼层</option>");
- }
- });
- $('#buildingSelect_' + indexNum).on('change', function() {
- var curentIndex = $(this).attr('id').split('_')[1];
- $('#floorSelect_' + curentIndex).selectpicker('destroy');
- $('#floorSelect_' + curentIndex).empty();
- $('#floorSelect_' + curentIndex).append("<option value=''>请选择楼层</option>");
- if($(this).val()){
- helper.getDropList.getFloorlistDrop($('#floorSelect_' + curentIndex), $(this).val())
- .then(function(){
- if(curData){
- $('#floorSelect_' + curentIndex).selectpicker('val', curData.floorid);
- }
- });
- }
- });
- // 绑定 + - 事件
- $('#btn_reduce_' + indexNum).on('click', {
- _index: indexNum
- }, btn_reduce);
- $('#btn_plus_' + indexNum).on('click', {
- _index: indexNum
- }, btn_plus);
- $('#goodsNum_' + indexNum).on('input keyup propertychange', inputValid);
- $('#goodsSelect_' + indexNum).on('change', changeEmergency);
- indexNum++;
- });
- }
- // 获取发货 收货地址的值
- // el1 $('#building')
- // el2 $('#floor')
- function getDeliverDatas(el1, el2){
- var deliverSelect = [];
- var buiding_id = el1.val();
- var floor_id = el2.val();
- var floor_names = el2.find('option[value="'+ floor_id +'"]').text(); // "1楼 护士部"
- deliverSelect.push({
- buildingid: buiding_id, //"5b6bfd5faa3e390cef675be8"
- building_name: el1.find('option[value="'+ buiding_id +'"]').text(), //"住院部"
- floor_name: floor_names && floor_names.split(' ')[0], //"1楼"
- floorid: floor_id, //"5b6bfdb8aa3e390cef675bed"
- department_name: floor_names && floor_names.split(' ')[1], //"护士部"
- });
- return deliverSelect;
- }
- //获取配送物品的值
- function getFields() {
- var goodslists = [];
- var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
- $.each(goodsLists_items, function(i, v) {
- var goodsNum = {
- "num": $(v).find('input[id*="goodsNum_"]').val()
- }
- var goodsSelect;
- if ($(v).find('input[id*="goodsSelect_"]').length) {
- goodsSelect = JSON.parse($(v).find('input[id*="goodsSelect_"]').attr('data-goods'));
- } else {
- goodsSelect = JSON.parse($(v).find('select[id*="goodsSelect_"]').val());
- var buiding_id = $(v).find('select[id*="buildingSelect_"]').val();
- var floor_id = $(v).find('select[id*="floorSelect_"]').val();
- var floor_names = $(v).find('option[value="'+ floor_id +'"]').text(); // "1楼 护士部"
- goodsSelect.building_name = $(v).find('option[value="'+ buiding_id +'"]').text(); //"住院部"
- goodsSelect.buildingid = buiding_id; //"5b6bfd5faa3e390cef675be8"
- goodsSelect.department_name = floor_names && floor_names.split(' ')[1]; //"护士部"
- goodsSelect.floor_name = floor_names && floor_names.split(' ')[0]; //"1楼"
- goodsSelect.floorid = floor_id; //"5b6bfdb8aa3e390cef675bed"
- }
- if ($.trim(goodsNum.num)) {
- var cobj = $.extend(goodsSelect, goodsNum);
- goodslists.push(cobj);
- }
- });
- //去重
- // goodslists = helper.methods.uniqueObjArray(goodslists, 'goodsid');
- return goodslists;
- }
- // 验证配送物品 的值是否填写
- function valideFields() {
- var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
- if(goodsLists_items.length){
- for (var i = 0; i < goodsLists_items.length; i++) {
- var goodsSelect = $(goodsLists_items[i]).find('[id*="goodsSelect_"]').val();
- if(!goodsSelect){
- layer.confirm('请选择配送物品!', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- return;
- }
- var buiding_id = $(goodsLists_items[i]).find('[id*="buildingSelect_"]').val();
- if(!buiding_id){
- layer.confirm('配送物品中楼宇还没有选择!', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- return false;
- }
- var floor_id = $(goodsLists_items[i]).find('[id*="floorSelect_"]').val();
- if(!floor_id){
- layer.confirm('配送物品中楼层还没有选择!', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- return false;
- }
- }
-
- }else{
- layer.confirm('请添加配送物品!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- }
- //获取配送物品 - 下拉
- function getGoodsSelect(el, proid) {
- var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "distributionapi/api/DistriGoods/getlist",
- dataType: 'json',
- data: {
- // keyword: , //否 string 模糊查询
- projectid: proid, //否 string 项目id
- },
- success: function(data) {
- if (data.state.toLowerCase() === 'success') {
- el.empty();
- var res = data.data;
- if (res) {
- $('<option value="">请选择物品</option>').appendTo(el);
- for (var i = 0; i < res.length; i++) {
- var cobj = {
- "goodsid": res[i].id,
- "goodsname": res[i].goodsname,
- "isremind": res[i].isremind,
- "typeid": res[i].typeid,
- "remark": res[i].remark,
- "buildingid": res[i].buildingid, // "楼宇id"
- "building_name": res[i].buildingname, // "楼宇"
- "floor_name": res[i].floorname, // "层数"
- "floorid": res[i].floorid, // "层数id"
- "department_name": res[i].departmentname, // “科室(例如:内科|消化科[一级|二级|三级]) 用"|"隔开”
- }
- //紧急程度 - 1一般 2紧急
- var typeName = res[i].typeid === 1 ? '一般' : '紧急';
- $('<option value=' + JSON.stringify(cobj) + '>' + res[i].goodsname + ' (' + typeName + ')</option>').appendTo(
- el);
- }
- el.selectpicker('refresh');
- }
- dtd.resolve(); // 改变Deferred对象的执行状态
- }
- }
- });
- return dtd.promise(); // 返回promise对象
- }
- //修改紧急程度
- function changeEmergency() {
- var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
- for (var i = 0; i < goodsLists_items.length; i++) {
- var curentVal = $(goodsLists_items[i]).find('option:selected').val() && JSON.parse($(goodsLists_items[i]).find(
- 'option:selected').val());
- //紧急
- if (curentVal && curentVal.typeid === 2) {
- $('#emergencyid').find('input[type="radio"][value="2"]').prop('checked', true);
- break;
- } else {
- $('#emergencyid').find('input[type="radio"][value="1"]').prop('checked', true);
- }
- }
- }
- //验证是不是数字, 不是数字直接变成1
- function inputValid() {
- var validValue = Number($(this).val());
- if (isNaN(validValue)) {
- $(this).val(0);
- }
- }
- //减少
- function btn_reduce(event) {
- var index = event.data._index;
- var num = Number($('#goodsNum_' + index).val());
- num--;
- if (num <= 1) {
- num = 1;
- }
- $('#goodsNum_' + index).val(num);
- }
- //增加
- function btn_plus(event) {
- var index = event.data._index;
- var num = Number($('#goodsNum_' + index).val());
- num++;
- $('#goodsNum_' + index).val(num);
- }
- //删除配送物品
- function btn_delete(el) {
- var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
- if(goodsLists_items.length === 1){
- layer.confirm('配送物品不能为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- el.parent().remove();
- }
- /**
- * 获取收发地址 - 下拉
- * @el 元素
- * @proid 项目id
- * @addt 地址类型 init 0发货/1收货
- */
- function getAddressSelect(el, proid, addt) {
- var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "distributionapi/api/DistriAddress/getlist",
- dataType: 'json',
- data: {
- // keyword: , //否 string 模糊查询
- projectid: proid, //否 string 项目id
- addresstype: addt, // 否 int 地址类型:0发货/1收货
- },
- success: function(data) {
- el.empty();
- if (data.state.toLowerCase() === 'success') {
- var res = data.data;
- var txt = '请选择收货地址';
- if (addt === 0) {
- txt = '请选择发货地址';
- }
- $('<option value="">' + txt + '</option>').appendTo(el);
- for (var i = 0; i < res.length; i++) {
- var cobj = [{
- "building_name": res[i].buildingname,
- "floor_name": res[i].floorname,
- "department_name": res[i].departmentname,
- "fullname": res[i].fullname,
- "mobile": res[i].mobile,
- }];
- var addressTxt = res[i].buildingname + ' ' + res[i].floorname + ' ' + res[i].departmentname;
- $('<option value=' + JSON.stringify(cobj) + '>' + addressTxt + '</option>').appendTo(el);
- }
- el.selectpicker('refresh');
- }
- dtd.resolve(); // 改变Deferred对象的执行状态
- }
- });
- return dtd.promise(); // 返回promise对象
- }
|