Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shop_add_addr.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // 获取联动地址
  2. function GetRegionData(t,type){
  3. var parent_id = $(t).val();
  4. if(!parent_id > 0){
  5. return false ;
  6. }
  7. var url = $('#GetRegionDataS').val();
  8. $.ajax({
  9. url: url,
  10. data: {parent_id:parent_id,_ajax:1},
  11. type:'post',
  12. dataType:'json',
  13. success:function(res){
  14. if ('province' == type) {
  15. res = '<option value="0">请选择城市</option>'+ res;
  16. $('#city').empty().html(res);
  17. $('#district').empty().html('<option value="0">请选择县/区/镇</option>');
  18. } else if ('city' == type) {
  19. res = '<option value="0">请选择县/区/镇</option>'+ res;
  20. $('#district').empty().html(res);
  21. }
  22. },
  23. error : function(e) {
  24. layer.closeAll();
  25. layer.alert(e.responseText, {icon: 5});
  26. }
  27. });
  28. }
  29. // 添加收货地址
  30. function AddAddress(){
  31. var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  32. var types = $('#types').val();
  33. var url = $('#ShopAddAddress').val();
  34. if (url.indexOf('?') > -1) {
  35. url += '&';
  36. } else {
  37. url += '?';
  38. }
  39. url += '_ajax=1';
  40. var _parent = parent;
  41. $.ajax({
  42. url: url,
  43. data: $('#theForm').serialize(),
  44. type:'post',
  45. dataType:'json',
  46. success:function(res){
  47. if(res.code == 1){
  48. if (res.data.url) {
  49. parent.layer.close(parentObj);
  50. parent.layer.msg(res.msg, {time: 1000}, function(){
  51. _parent.returnUrl(res.data.url);
  52. });
  53. } else {
  54. parent.layer.close(parentObj);
  55. AddHtml(res.data,types);
  56. parent.layer.msg(res.msg, {time: 1000});
  57. }
  58. }else{
  59. layer.closeAll();
  60. layer.msg(res.msg, {icon: 5});
  61. }
  62. },
  63. error : function(e) {
  64. layer.closeAll();
  65. layer.alert(e.responseText, {icon: 5});
  66. }
  67. });
  68. };
  69. // 地址管理页追加地址html
  70. function AddHtml(data,types)
  71. {
  72. var divhtml = $('#divhtml').html();
  73. var strings = '';
  74. // 替换ID值
  75. strings = divhtml.replace('#ul_li_id#', data.addr_id + "_ul_li");
  76. strings = strings.replace('#consigneeid#', data.addr_id + "_consignee");
  77. strings = strings.replace('#mobileid#', data.addr_id + "_mobile");
  78. strings = strings.replace('#infoid#', data.addr_id + "_info");
  79. strings = strings.replace('#addressid#', data.addr_id + "_address");
  80. // 替换地址内容信息
  81. strings = strings.replace('#consignee#', data.consignee);
  82. strings = strings.replace('#mobile#', data.mobile);
  83. strings = strings.replace('#info#', data.country+" "+data.province+" "+data.city+" "+data.district);
  84. strings = strings.replace('#address#', data.address);
  85. // 替换JS方法
  86. strings = strings.replace('#selected#', "SelectEd('addr_id','" + data.addr_id + "');");
  87. strings = strings.replace('#setdefault#', "SetDefault(this, '" + data.addr_id + "');\" data-is_default=\"0\" id=\"" + data.addr_id + "_color\" data-setbtn=\"1\" data-attr_id=\"" + data.addr_id + "\"");
  88. strings = strings.replace('#shopeditaddr#', "ShopEditAddress('" + data.addr_id + "');");
  89. strings = strings.replace('#shopdeladdr#', "ShopDelAddress('" + data.addr_id + "');");
  90. // 隐藏域,下单页第一次添加收货地址则出现一次,存在则替换数据
  91. strings = strings.replace('#name#', "addr_id");
  92. strings = strings.replace('#id#', "addr_id");
  93. strings = strings.replace('#value#', data.addr_id);
  94. // 追加到页面
  95. parent.$('#UlHtml').append(strings);
  96. if ('order' == types) {
  97. // 下单页新增地址后,调用选择方法,选择新增的地址
  98. parent.SelectEd('addr_id',data.addr_id);
  99. }
  100. }