説明なし

addOrEditDeliveryOrder.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /**
  2. * 添加或修改配送工单
  3. * */
  4. var indexNum = 0;
  5. var previous = ''; //项目名称切换前的值
  6. $(function() {
  7. autosize($('textarea'));
  8. init();
  9. });
  10. function init() {
  11. var edit_id = helper.request.queryString("edit_id");
  12. helper.getDropList.getProlistDrop($('#pro_title'))
  13. .then(function() {
  14. $('#pro_title').on('change', function() {
  15. $('#building').selectpicker('destroy');
  16. $('#floor').selectpicker('destroy');
  17. $('#floor').empty();
  18. $('#floor').append("<option value=''>请选择楼层</option>");
  19. helper.getDropList.getBuildlistDrop($('#building'), $(this).val());
  20. });
  21. $('#building').on('change', function() {
  22. $('#floor').selectpicker('destroy');
  23. helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
  24. });
  25. // getAddressSelect($('#deliverylist'), $('#pro_title').val(), 0);//发货
  26. // getAddressSelect($('#receiverlist'), $('#pro_title').val(), 1);//1收货
  27. })
  28. .then(function() {
  29. if (edit_id) {
  30. $('#add_goods').empty();
  31. getDetail();
  32. }
  33. $('#save_btns').on('click', btn_save);
  34. });
  35. //绑定项目名称 切换
  36. $('#pro_title').parent().on('mouseup', proTitleClick);
  37. $('#pro_title').on('change', proTitleChange);
  38. }
  39. //获取配送物品信息
  40. function getDetail() {
  41. var edit_id = helper.request.queryString("edit_id");
  42. $.getJSON(huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/getsingle", {
  43. id: edit_id,
  44. }, function(data) {
  45. if (data.state === "success") {
  46. var res = data.data.model;
  47. $('#pro_title').selectpicker('val', res.projectid); // 是 string 项目名称id
  48. // 发货地址
  49. helper.getDropList.getBuildlistDrop($('#building'), res.projectid)
  50. .then(function(){
  51. $('#building').selectpicker('val', res.deliverylist[0].buildingid);
  52. });// 是 string 楼宇id
  53. helper.getDropList.getFloorlistDrop($('#floor'), res.deliverylist[0].buildingid)
  54. .then(function(){
  55. $('#floor').selectpicker('val', res.deliverylist[0].floorid);
  56. });// 是 string 楼层id
  57. $('#deliveryname').val(res.deliveryname); // 否 string 发货人 - 随机工单
  58. $('#deliverytel').val(res.deliverytel); // 否 string 发货人电话 - 随机工单
  59. //发货
  60. // getAddressSelect($('#deliverylist'), res.projectid, 0)
  61. // .then(function(){
  62. // res.deliverylist = res.deliverylist ? JSON.stringify(res.deliverylist) : '';
  63. // $('#deliverylist').selectpicker('val', res.deliverylist); // 发货(地址,科室,联系)
  64. // });
  65. $('#emergencyid').find('input[name="emergencyid_flag"][value="' + res.emergencyid + '"]').prop("checked",
  66. "checked"); // 是 int 紧急程度 - 1一般 2紧急
  67. // $('#remark').val(res.detail); // 是 string 工单内容
  68. //配送物品
  69. if (res.goodslist && res.goodslist.length > 0) {
  70. for (var i = 0, len = res.goodslist.length; i < len; i++) {
  71. var cobj = {
  72. "goodsid": res.goodslist[i].goodsid,
  73. "goodsname": res.goodslist[i].goodsname,
  74. "isremind": res.goodslist[i].isremind,
  75. "typeid": res.goodslist[i].typeid,
  76. "remark": res.goodslist[i].remark === null ? '' : res.goodslist[i].remark,
  77. }
  78. //紧急程度 - 1一般 2紧急
  79. var typeName = res.goodslist[i].typeid === 1 ? '一般' : '紧急';
  80. var tplstr = '<div class="goodsLists_item col-md-12 row" data-ide="identifier_' + i + '">' +
  81. '<div class="form-group col-md-9 col-sm-9">' +
  82. '<input type="text" id="goodsSelect_' + i + '" value="' + res.goodslist[i].goodsname + ' (' + typeName +
  83. ')" data-goods=' + JSON.stringify(cobj) + ' class="form-control" disabled readonly style="width: 100%" />' +
  84. '</div>' +
  85. '<div class="form-group col-md-3 col-sm-3">' +
  86. '<div class="input-group delibery_num">' +
  87. '<span class="input-group-addon" id="btn_reduce_' + i + '">-</span>' +
  88. '<input id="goodsNum_' + i + '" type="text" value="' + res.goodslist[i].num +
  89. '" class="form-control" placeholder="请输入配送物品数量" aria-describedby="配送物品数量">' +
  90. '<span class="input-group-addon" id="btn_plus_' + i + '">+</span>' +
  91. '</div>' +
  92. '</div>' +
  93. '<button class="form-control btn btn-default btn_delete" style="width:60px;margin-left:15px" onclick="btn_delete($(this))">删除</button>' +
  94. '</div>';
  95. $('#goodsLists').prepend(tplstr);
  96. // 绑定 + - 事件
  97. $('#btn_reduce_' + i).on('click', { _index: i }, btn_reduce);
  98. $('#btn_plus_' + i).on('click', { _index: i }, btn_plus);
  99. $('#goodsNum_' + i).on('input keyup propertychange', inputValid);
  100. }
  101. indexNum = res.goodslist.length;
  102. }
  103. //收件(地址,科室,联系)
  104. // getAddressSelect($('#receiverlist'), res.projectid, 1)
  105. // .then(function(){
  106. // res.receiverlist = res.receiverlist ? JSON.stringify(res.receiverlist) : '';
  107. // $('#receiverlist').selectpicker('val', res.receiverlist);
  108. // });
  109. // 收货
  110. $('#receiverLists').show();
  111. helper.getDropList.getBuildlistDrop($('#rec_building'), res.projectid)
  112. .then(function(){
  113. $('#rec_building').selectpicker('val', res.receiverlist[0].buildingid);
  114. });// 是 string 楼宇id
  115. helper.getDropList.getFloorlistDrop($('#rec_floor'), res.receiverlist[0].buildingid)
  116. .then(function(){
  117. $('#rec_floor').selectpicker('val', res.receiverlist[0].floorid);
  118. });// 是 string 楼层id
  119. $('#pro_title').on('change', function() {
  120. $('#rec_building').selectpicker('destroy');
  121. $('#rec_floor').selectpicker('destroy');
  122. $('#rec_floor').empty();
  123. $('#rec_floor').append("<option value=''>请选择楼层</option>");
  124. helper.getDropList.getBuildlistDrop($('#rec_building'), $(this).val());
  125. });
  126. $('#rec_building').on('change', function() {
  127. $('#rec_floor').selectpicker('destroy');
  128. helper.getDropList.getFloorlistDrop($('#rec_floor'), $(this).val());
  129. });
  130. }
  131. });
  132. }
  133. //保存配送物品信息
  134. function btn_save() {
  135. var wURL, loadIndex;
  136. var deliveryDatas; // 添加编辑 发货 地址
  137. var goodslist_chaidan; // 添加 物品
  138. var receiverDatas; //编辑 收货 地址
  139. var goodslist; // 编辑 物品
  140. var edit_id = helper.request.queryString("edit_id");
  141. if (edit_id) {
  142. wURL = "distributionapi/api/DistriWorkOrder/update";
  143. } else {
  144. wURL = "distributionapi/api/DistriWorkOrder/add";
  145. }
  146. if (!$.trim($('#pro_title').val())) {
  147. layer.confirm('请选择项目名称!', {
  148. icon: 2,
  149. btn: ['确定'] //按钮
  150. });
  151. return;
  152. }
  153. if (!$.trim($('#building').val())) {
  154. layer.confirm('发货地址中,楼宇名称不允许为空!', {
  155. icon: 2,
  156. btn: ['确定'] //按钮
  157. });
  158. return;
  159. }
  160. if (!$.trim($('#floor').val())) {
  161. layer.confirm('发货地址中,楼层名称不允许为空!', {
  162. icon: 2,
  163. btn: ['确定'] //按钮
  164. });
  165. return;
  166. }
  167. if (!$.trim($('#deliveryname').val())) {
  168. layer.confirm('发货人姓名不允许为空!', {
  169. icon: 2,
  170. btn: ['确定'] //按钮
  171. });
  172. return;
  173. }
  174. if(!regexs.phone.test($.trim($('#deliverytel').val()))) {
  175. layer.confirm('请输入正确格式的发货人电话!', {
  176. icon: 2,
  177. btn: ['确定'] //按钮
  178. });
  179. return;
  180. }
  181. // if (!$.trim($('#remark').val())) {
  182. // layer.confirm('请输入工单内容!', {
  183. // icon: 2,
  184. // btn: ['确定'] //按钮
  185. // });
  186. // return;
  187. // }
  188. deliveryDatas = getDeliverDatas($('#building'),$('#floor')); //发货地址
  189. if(edit_id){
  190. goodslist = getFields(); // 编辑 物品
  191. if (!$.trim($('#rec_building').val())) {
  192. layer.confirm('收货地址中,楼宇名称不允许为空!', {
  193. icon: 2,
  194. btn: ['确定'] //按钮
  195. });
  196. return;
  197. }
  198. if (!$.trim($('#rec_floor').val())) {
  199. layer.confirm('收货地址中,楼层名称不允许为空!', {
  200. icon: 2,
  201. btn: ['确定'] //按钮
  202. });
  203. return;
  204. }
  205. receiverDatas = getDeliverDatas($('#rec_building'),$('#rec_floor')); //编辑 收货 地址
  206. }else{
  207. valideFields(); // 验证配送物品
  208. goodslist_chaidan = getFields(); // 添加 物品
  209. }
  210. $.ajax({
  211. type: 'post',
  212. url: huayi.config.callcenter_url + wURL,
  213. dataType: 'json',
  214. async: true,
  215. beforeSend: function() { //触发ajax请求开始时执行
  216. $('#save_btns').attr("disabled", true);
  217. $('#save_btns').text('保存中...');
  218. loadIndex = layer.load();
  219. },
  220. data: {
  221. id: edit_id, // 否 string id
  222. projectid: $('#pro_title').val(), // 是 string 项目名称id
  223. emergencyid: $('#emergencyid').find('input[name="emergencyid_flag"]:checked').val(), // 是 int 紧急程度 - 1一般 2紧急
  224. deliverylist: deliveryDatas,// 否 List<DistributionDddressModel> 发货(地址,科室,联系)
  225. // deliverylist: $('#deliverylist').val() && JSON.parse($('#deliverylist').val()),// 否 List<DistributionDddressModel> 发货(地址,科室,联系)
  226. // detail: helper.filter.delHtmlTag($('#remark').val()),// 是 string 工单内容
  227. deliveryname: $('#deliveryname').val(),// 否 string 发货人 - 随机工单
  228. deliverytel: $('#deliverytel').val(),// 否 string 发货人电话 - 随机工单
  229. goodslist_chaidan: goodslist_chaidan,// 添加传 是 List<DistributionGoodsLists> 添加的时候传 配送物品 - 随机工单不用
  230. goodslist: goodslist, // 编辑传 是 List<DistributionGoodsList> 配送物品 编辑的时候传
  231. receiverlist: receiverDatas,// 编辑传 否 List<DistributionDddressModel> 收件(地址,科室,联系)
  232. },
  233. success: function(data) {
  234. layer.close(loadIndex);
  235. if (data.state === "success") {
  236. var index = parent.layer.getFrameIndex(window.name);
  237. parent.layer.close(index);
  238. parent.$('#table_all').bootstrapTable('refresh');
  239. parent.layer.msg("保存成功");
  240. } else {
  241. $('#save_btns').attr("disabled", false);
  242. $('#save_btns').text('保存');
  243. }
  244. },
  245. error: function(textStatus) {
  246. layer.close(loadIndex);
  247. layer.confirm('网络繁忙,请稍后再试...', {
  248. icon: 7,
  249. closeBtn: 0,
  250. btn: ['确定'] //按钮
  251. });
  252. $('#save_btns').attr("disabled", false);
  253. $('#save_btns').text('保存');
  254. },
  255. complete: function(XMLHttpRequest, textStatus) {
  256. layer.close(loadIndex);
  257. if (textStatus == 'timeout') {
  258. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  259. xmlhttp.abort();
  260. layer.confirm('网络超时,请稍后再试...', {
  261. icon: 7,
  262. closeBtn: 0,
  263. btn: ['确定'] //按钮
  264. });
  265. }
  266. $('#save_btns').attr("disabled", false);
  267. $('#save_btns').text('保存');
  268. },
  269. });
  270. }
  271. //项目名称切换前
  272. function proTitleClick() {
  273. previous = $(this).find('#pro_title').val();
  274. }
  275. //项目名称切换
  276. function proTitleChange() {
  277. var self = this;
  278. if ($('#goodsLists').find('.goodsLists_item').length > 0) {
  279. layer.confirm('切换项目名称将清除当前配送物品内容,您确定要切换项目名称吗?', {
  280. icon: 7,
  281. closeBtn: 0,
  282. btn: ['确定', '取消'], //按钮
  283. }, function(index) {
  284. $('#goodsLists').html('');
  285. // getAddressSelect($('#deliverylist'), $(self).val(), 0); //发货
  286. // getAddressSelect($('#receiverlist'), $(self).val(), 1); //1收货
  287. layer.close(index);
  288. }, function() {
  289. $(self).selectpicker('val', previous);
  290. });
  291. } else {
  292. // getAddressSelect($('#deliverylist'), $(self).val(), 0); //发货
  293. // getAddressSelect($('#receiverlist'), $(self).val(), 1); //1收货
  294. }
  295. }
  296. //添加配送物品
  297. function btn_add() {
  298. if (!$.trim($('#pro_title').val())) {
  299. layer.confirm('请选择项目名称!', {
  300. icon: 2,
  301. btn: ['确定'] //按钮
  302. });
  303. return;
  304. }
  305. var tplstr = '';
  306. tplstr = '<div class="goodsLists_item col-md-12 row" data-ide="identifier_' + indexNum + '">' +
  307. '<div class="form-group col-md-3 col-sm-3">' +
  308. '<select id="goodsSelect_' + indexNum + '" class="form-control selectpicker" data-live-search="true">' +
  309. '<option value="">请选择物品</option>' +
  310. '</select>' +
  311. '</div>' +
  312. '<div class="form-group col-md-3 col-sm-3">' +
  313. '<select id="buildingSelect_' + indexNum + '" class="form-control selectpicker" data-live-search="true">' +
  314. '<option value="">请选择楼宇名称</option>' +
  315. '</select>' +
  316. '</div>' +
  317. '<div class="form-group col-md-3 col-sm-3">' +
  318. '<select id="floorSelect_' + indexNum + '" class="form-control selectpicker" data-live-search="true">' +
  319. '<option value="">请选择楼层名称</option>' +
  320. '</select>' +
  321. '</div>' +
  322. '<div class="form-group col-md-3 col-sm-3">' +
  323. '<div class="input-group delibery_num">' +
  324. '<span class="input-group-addon" id="btn_reduce_' + indexNum + '">-</span>' +
  325. '<input id="goodsNum_' + indexNum +
  326. '" type="text" value="1" class="form-control" placeholder="请输入配送物品数量" aria-describedby="配送物品数量">' +
  327. '<span class="input-group-addon" id="btn_plus_' + indexNum + '">+</span>' +
  328. '</div>' +
  329. '</div>' +
  330. '<button class="form-control btn btn-default btn_delete" style="width:60px;margin-left:15px" onclick="btn_delete($(this))">删除</button>' +
  331. '</div>';
  332. $('#goodsLists').prepend(tplstr);
  333. // 获取配送物品下拉
  334. $.when(
  335. getGoodsSelect($('#goodsSelect_' + indexNum), $('#pro_title').val()),
  336. helper.getDropList.getBuildlistDrop($('#buildingSelect_' + indexNum), $('#pro_title').val()),
  337. helper.getDropList.getFloorlistDrop($('#floorSelect_' + indexNum), $('#buildingSelect_' + indexNum).val())
  338. )
  339. .then(function() {
  340. var curData = null;
  341. $('#goodsSelect_' + indexNum).on('change', function() {
  342. var curentIndex = $(this).attr('id').split('_')[1];
  343. if ($(this).val()) {
  344. curData = JSON.parse($(this).val());
  345. $('#buildingSelect_' + curentIndex).selectpicker('val', curData.buildingid).trigger('change');
  346. } else {
  347. $('#buildingSelect_' + curentIndex).selectpicker('destroy');
  348. $('#floorSelect_' + curentIndex).selectpicker('destroy');
  349. $('#floorSelect_' + curentIndex).empty();
  350. $('#floorSelect_' + curentIndex).append("<option value=''>请选择楼层</option>");
  351. }
  352. });
  353. $('#buildingSelect_' + indexNum).on('change', function() {
  354. var curentIndex = $(this).attr('id').split('_')[1];
  355. $('#floorSelect_' + curentIndex).selectpicker('destroy');
  356. $('#floorSelect_' + curentIndex).empty();
  357. $('#floorSelect_' + curentIndex).append("<option value=''>请选择楼层</option>");
  358. if($(this).val()){
  359. helper.getDropList.getFloorlistDrop($('#floorSelect_' + curentIndex), $(this).val())
  360. .then(function(){
  361. if(curData){
  362. $('#floorSelect_' + curentIndex).selectpicker('val', curData.floorid);
  363. }
  364. });
  365. }
  366. });
  367. // 绑定 + - 事件
  368. $('#btn_reduce_' + indexNum).on('click', {
  369. _index: indexNum
  370. }, btn_reduce);
  371. $('#btn_plus_' + indexNum).on('click', {
  372. _index: indexNum
  373. }, btn_plus);
  374. $('#goodsNum_' + indexNum).on('input keyup propertychange', inputValid);
  375. $('#goodsSelect_' + indexNum).on('change', changeEmergency);
  376. indexNum++;
  377. });
  378. }
  379. // 获取发货 收货地址的值
  380. // el1 $('#building')
  381. // el2 $('#floor')
  382. function getDeliverDatas(el1, el2){
  383. var deliverSelect = [];
  384. var buiding_id = el1.val();
  385. var floor_id = el2.val();
  386. var floor_names = el2.find('option[value="'+ floor_id +'"]').text(); // "1楼 护士部"
  387. deliverSelect.push({
  388. buildingid: buiding_id, //"5b6bfd5faa3e390cef675be8"
  389. building_name: el1.find('option[value="'+ buiding_id +'"]').text(), //"住院部"
  390. floor_name: floor_names && floor_names.split(' ')[0], //"1楼"
  391. floorid: floor_id, //"5b6bfdb8aa3e390cef675bed"
  392. department_name: floor_names && floor_names.split(' ')[1], //"护士部"
  393. });
  394. return deliverSelect;
  395. }
  396. //获取配送物品的值
  397. function getFields() {
  398. var goodslists = [];
  399. var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
  400. $.each(goodsLists_items, function(i, v) {
  401. var goodsNum = {
  402. "num": $(v).find('input[id*="goodsNum_"]').val()
  403. }
  404. var goodsSelect;
  405. if ($(v).find('input[id*="goodsSelect_"]').length) {
  406. goodsSelect = JSON.parse($(v).find('input[id*="goodsSelect_"]').attr('data-goods'));
  407. } else {
  408. goodsSelect = JSON.parse($(v).find('select[id*="goodsSelect_"]').val());
  409. var buiding_id = $(v).find('select[id*="buildingSelect_"]').val();
  410. var floor_id = $(v).find('select[id*="floorSelect_"]').val();
  411. var floor_names = $(v).find('option[value="'+ floor_id +'"]').text(); // "1楼 护士部"
  412. goodsSelect.building_name = $(v).find('option[value="'+ buiding_id +'"]').text(); //"住院部"
  413. goodsSelect.buildingid = buiding_id; //"5b6bfd5faa3e390cef675be8"
  414. goodsSelect.department_name = floor_names && floor_names.split(' ')[1]; //"护士部"
  415. goodsSelect.floor_name = floor_names && floor_names.split(' ')[0]; //"1楼"
  416. goodsSelect.floorid = floor_id; //"5b6bfdb8aa3e390cef675bed"
  417. }
  418. if ($.trim(goodsNum.num)) {
  419. var cobj = $.extend(goodsSelect, goodsNum);
  420. goodslists.push(cobj);
  421. }
  422. });
  423. //去重
  424. // goodslists = helper.methods.uniqueObjArray(goodslists, 'goodsid');
  425. return goodslists;
  426. }
  427. // 验证配送物品 的值是否填写
  428. function valideFields() {
  429. var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
  430. if(goodsLists_items.length){
  431. for (var i = 0; i < goodsLists_items.length; i++) {
  432. var goodsSelect = $(goodsLists_items[i]).find('[id*="goodsSelect_"]').val();
  433. if(!goodsSelect){
  434. layer.confirm('请选择配送物品!', {
  435. icon: 7,
  436. closeBtn: 0,
  437. btn: ['确定'] //按钮
  438. });
  439. return;
  440. }
  441. var buiding_id = $(goodsLists_items[i]).find('[id*="buildingSelect_"]').val();
  442. if(!buiding_id){
  443. layer.confirm('配送物品中楼宇还没有选择!', {
  444. icon: 7,
  445. closeBtn: 0,
  446. btn: ['确定'] //按钮
  447. });
  448. return false;
  449. }
  450. var floor_id = $(goodsLists_items[i]).find('[id*="floorSelect_"]').val();
  451. if(!floor_id){
  452. layer.confirm('配送物品中楼层还没有选择!', {
  453. icon: 7,
  454. closeBtn: 0,
  455. btn: ['确定'] //按钮
  456. });
  457. return false;
  458. }
  459. }
  460. }else{
  461. layer.confirm('请添加配送物品!', {
  462. icon: 2,
  463. btn: ['确定'] //按钮
  464. });
  465. return;
  466. }
  467. }
  468. //获取配送物品 - 下拉
  469. function getGoodsSelect(el, proid) {
  470. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  471. $.ajax({
  472. type: "get",
  473. url: huayi.config.callcenter_url + "distributionapi/api/DistriGoods/getlist",
  474. dataType: 'json',
  475. data: {
  476. // keyword: , //否 string 模糊查询
  477. projectid: proid, //否 string 项目id
  478. },
  479. success: function(data) {
  480. if (data.state.toLowerCase() === 'success') {
  481. el.empty();
  482. var res = data.data;
  483. if (res) {
  484. $('<option value="">请选择物品</option>').appendTo(el);
  485. for (var i = 0; i < res.length; i++) {
  486. var cobj = {
  487. "goodsid": res[i].id,
  488. "goodsname": res[i].goodsname,
  489. "isremind": res[i].isremind,
  490. "typeid": res[i].typeid,
  491. "remark": res[i].remark,
  492. "buildingid": res[i].buildingid, // "楼宇id"
  493. "building_name": res[i].buildingname, // "楼宇"
  494. "floor_name": res[i].floorname, // "层数"
  495. "floorid": res[i].floorid, // "层数id"
  496. "department_name": res[i].departmentname, // “科室(例如:内科|消化科[一级|二级|三级]) 用"|"隔开”
  497. }
  498. //紧急程度 - 1一般 2紧急
  499. var typeName = res[i].typeid === 1 ? '一般' : '紧急';
  500. $('<option value=' + JSON.stringify(cobj) + '>' + res[i].goodsname + ' (' + typeName + ')</option>').appendTo(
  501. el);
  502. }
  503. el.selectpicker('refresh');
  504. }
  505. dtd.resolve(); // 改变Deferred对象的执行状态
  506. }
  507. }
  508. });
  509. return dtd.promise(); // 返回promise对象
  510. }
  511. //修改紧急程度
  512. function changeEmergency() {
  513. var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
  514. for (var i = 0; i < goodsLists_items.length; i++) {
  515. var curentVal = $(goodsLists_items[i]).find('option:selected').val() && JSON.parse($(goodsLists_items[i]).find(
  516. 'option:selected').val());
  517. //紧急
  518. if (curentVal && curentVal.typeid === 2) {
  519. $('#emergencyid').find('input[type="radio"][value="2"]').prop('checked', true);
  520. break;
  521. } else {
  522. $('#emergencyid').find('input[type="radio"][value="1"]').prop('checked', true);
  523. }
  524. }
  525. }
  526. //验证是不是数字, 不是数字直接变成1
  527. function inputValid() {
  528. var validValue = Number($(this).val());
  529. if (isNaN(validValue)) {
  530. $(this).val(0);
  531. }
  532. }
  533. //减少
  534. function btn_reduce(event) {
  535. var index = event.data._index;
  536. var num = Number($('#goodsNum_' + index).val());
  537. num--;
  538. if (num <= 1) {
  539. num = 1;
  540. }
  541. $('#goodsNum_' + index).val(num);
  542. }
  543. //增加
  544. function btn_plus(event) {
  545. var index = event.data._index;
  546. var num = Number($('#goodsNum_' + index).val());
  547. num++;
  548. $('#goodsNum_' + index).val(num);
  549. }
  550. //删除配送物品
  551. function btn_delete(el) {
  552. var goodsLists_items = $('#goodsLists').find('.goodsLists_item');
  553. if(goodsLists_items.length === 1){
  554. layer.confirm('配送物品不能为空!', {
  555. icon: 2,
  556. btn: ['确定'] //按钮
  557. });
  558. return;
  559. }
  560. el.parent().remove();
  561. }
  562. /**
  563. * 获取收发地址 - 下拉
  564. * @el 元素
  565. * @proid 项目id
  566. * @addt 地址类型 init 0发货/1收货
  567. */
  568. function getAddressSelect(el, proid, addt) {
  569. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  570. $.ajax({
  571. type: "get",
  572. url: huayi.config.callcenter_url + "distributionapi/api/DistriAddress/getlist",
  573. dataType: 'json',
  574. data: {
  575. // keyword: , //否 string 模糊查询
  576. projectid: proid, //否 string 项目id
  577. addresstype: addt, // 否 int 地址类型:0发货/1收货
  578. },
  579. success: function(data) {
  580. el.empty();
  581. if (data.state.toLowerCase() === 'success') {
  582. var res = data.data;
  583. var txt = '请选择收货地址';
  584. if (addt === 0) {
  585. txt = '请选择发货地址';
  586. }
  587. $('<option value="">' + txt + '</option>').appendTo(el);
  588. for (var i = 0; i < res.length; i++) {
  589. var cobj = [{
  590. "building_name": res[i].buildingname,
  591. "floor_name": res[i].floorname,
  592. "department_name": res[i].departmentname,
  593. "fullname": res[i].fullname,
  594. "mobile": res[i].mobile,
  595. }];
  596. var addressTxt = res[i].buildingname + ' ' + res[i].floorname + ' ' + res[i].departmentname;
  597. $('<option value=' + JSON.stringify(cobj) + '>' + addressTxt + '</option>').appendTo(el);
  598. }
  599. el.selectpicker('refresh');
  600. }
  601. dtd.resolve(); // 改变Deferred对象的执行状态
  602. }
  603. });
  604. return dtd.promise(); // 返回promise对象
  605. }