address.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <extend name="Public:pinduoduobase" />
  2. <block name="content">
  3. <link rel="stylesheet" href="__PUBLIC__/pinduoduo/assets/css/addresses.css?v=321">
  4. <style>
  5. .add-btn .normal-add-btn{background-color: #f69;}
  6. .m-addr-main .m-addr-save{background-color: #f69;}
  7. </style>
  8. <div class="addresses-main">
  9. <ul class="addresses-list">
  10. <volist name="address" id="list">
  11. <li class="address-item-use" data-address-id="{$list.address_id}">
  12. <div class="address-item-wrap">
  13. <div class="address-item-main <?php if($backcart == 1){ ?>aim-small<?php } ?>">
  14. <div class="contact-name">
  15. {$list.name},{$list.telephone}
  16. </div>
  17. <div class="contact-address">
  18. <?php echo get_area_name($list['province_id']); ?>&nbsp;
  19. <?php echo get_area_name($list['city_id']); ?>&nbsp;
  20. <?php echo get_area_name($list['country_id']); ?>&nbsp;
  21. {$list.address}
  22. </div>
  23. </div>
  24. <?php if($backcart == 1){ ?>
  25. <div class="address-item-choose-btn"></div>
  26. <?php } ?>
  27. </div>
  28. <div class="address-item-ops-1" onclick="defaultAddr(this)" >
  29. <span class="address-item-set-default<?php if($list['is_default'] == 1){ ?> default <?php } ?>">
  30. <?php if($list['is_default'] == 1){ ?> 已设为默认<?php }else{ ?>设为默认<?php } ?>
  31. </span>
  32. </div>
  33. <div class="address-item-ops-2">
  34. <div class="address-item-edit" onclick="editAddr(this)" data-address="{$list.address}" data-telephone="{$list.telephone}" data-name="{$list.name}" data-pid="{$list.province_id}" data-cityid="{$list.city_id}" data-country-id="{$list.country_id}">
  35. <span>编辑</span>
  36. </div>
  37. <div class="address-item-delete" onclick="delAddr(this)">
  38. <span>删除</span>
  39. </div>
  40. </div>
  41. </li>
  42. </volist>
  43. </ul>
  44. <div class="add-btn">
  45. <div class="normal-add-btn btn-long">
  46. <span>手动添加</span>
  47. </div>
  48. <!--ms-if-->
  49. </div>
  50. </div>
  51. <div id="m-addr-mask" avalonctrl="edit_address" style="display:none;">
  52. <div class="m-addr-main">
  53. <div class="m-addr-title">添加新收货地址</div>
  54. <div class="m-address-receiver">
  55. <input class="m-addr-name" id="name" placeholder="名字" type="text">
  56. <input class="m-addr-mobile" id="telephone" placeholder="电话" type="tel">
  57. </div>
  58. <div class="m-addr-region">
  59. <div class="m-addr-province">
  60. <select class="m-addr-select" id="areaprovince" data-duplex-changed="onProvinceEdited">
  61. <option value="0">选择省份</option>
  62. </select>
  63. </div>
  64. <div class="m-addr-city">
  65. <select class="m-addr-select" id="areacity" data-duplex-changed="onCityEdited">
  66. <option value="0">选择城市</option>
  67. <!--repeat757947232574--><!--repeat757947232574:end-->
  68. </select>
  69. </div>
  70. <div class="m-addr-district">
  71. <select class="m-addr-select" id="areadistrict" data-duplex-changed="onDistrictEdited">
  72. <option value="0">选择地区</option>
  73. <!--repeat749156095088--><!--repeat749156095088:end-->
  74. </select>
  75. </div>
  76. </div>
  77. <div class="m-addr-address">
  78. <input placeholder="请填写详细街道地址" id="addr_address" type="text">
  79. <input type="hidden" name="sub_address_id" id="sub_address_id" />
  80. </div>
  81. <div class="m-addr-save">保存</div>
  82. <div class="m-addr-close">
  83. <div class="ms-addr-close-icon"></div>
  84. </div>
  85. <!--ms-if-->
  86. </div>
  87. </div>
  88. <include file="Widget:pin_toast" />
  89. <script>
  90. var edit_url = "{:U('User/edit_address')}";
  91. var add_url = "{:U('User/add_address')}";
  92. var ajaxarea_url='{:U("/c_getarea")}';
  93. var chang_default_url = "{:U('User/change_default_address')}";
  94. $(function(){
  95. $('.address-item-choose-btn').click(function(){
  96. var address_id = $(this).parent().parent().attr('data-address-id');
  97. var back_cart_url = "{:U('User/back_choose_cart')}";
  98. var cart_url = "{:U('cart/checkout', array('buy_type' =>$buy_type))}";
  99. $.ajax({
  100. url:back_cart_url,
  101. type:'post',
  102. data:{address_id:address_id},
  103. dataType:'json',
  104. success:function(ret){
  105. location.href = cart_url;
  106. return false;
  107. }
  108. })
  109. });
  110. $('.add-btn').click(function(){
  111. $('#sub_address_id').val('');
  112. $('.m-addr-title').html('添加收货地址');
  113. var areaId=0;
  114. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  115. $('#areaprovince').html('<option value="0">选择省份</option>');
  116. $.each(data,function(no,items){
  117. $('#areaprovince').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  118. });
  119. $('#m-addr-mask').show();
  120. });
  121. })
  122. $("#areaprovince").change(function(){
  123. var areaId = $(this).val();
  124. if(areaId == 0){
  125. $('#areacity').html('<option value="0">选择城市</option>');
  126. $('#areadistrict').html('<option value="0">选择地区</option>')
  127. } else {
  128. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  129. $('#areacity').html('<option value="0">选择城市</option>');
  130. $.each(data,function(no,items){
  131. $('#areacity').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  132. });
  133. $('#areadistrict').html('<option value="0">选择地区</option>');
  134. });
  135. }
  136. })
  137. $("#areacity").change(function(){
  138. var areaId = $(this).val();
  139. if(areaId == 0){
  140. $('#areadistrict').html('<option value="0">选择地区</option>')
  141. } else {
  142. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  143. $('#areadistrict').html('<option value="0">选择地区</option>');
  144. $.each(data,function(no,items){
  145. $('#areadistrict').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  146. });
  147. });
  148. }
  149. })
  150. $('.m-addr-save').on('click',function(){
  151. var name = $('#name').val();
  152. var m_addr_mobile = $('.m-addr-mobile').val();
  153. var areaprovince = $('#areaprovince').val();
  154. var areaprovince_html = $('#areaprovince').find("option:selected").text();
  155. var areacity = $('#areacity').val();
  156. var areacity_html = $('#areacity').find("option:selected").text();
  157. var areadistrict = $('#areadistrict').val();
  158. var areadistrict_html = $('#areadistrict').find("option:selected").text();
  159. var addr_address = $('#addr_address').val();
  160. if($.trim(name) == ''){
  161. showTip('请填写姓名');
  162. return false;
  163. }
  164. if($.trim(m_addr_mobile) == ''){
  165. showTip('请填写手机');
  166. return false;
  167. }
  168. if(!m_addr_mobile.match('^1[3|4|5|6|8|7|9][0-9]{9}$')){
  169. showTip('请输入正确的手机号码');
  170. return false;
  171. }
  172. if(areaprovince <= 0)
  173. {
  174. showTip('请选择省份');
  175. return false;
  176. }
  177. if(areacity <= 0)
  178. {
  179. showTip('请选择城市');
  180. return false;
  181. }
  182. if(areadistrict <= 0)
  183. {
  184. showTip('请选择地区');
  185. return false;
  186. }
  187. if($.trim(addr_address) == ''){
  188. showTip('请填写详细街道地址');
  189. return false;
  190. }
  191. var sub_address_id = $('#sub_address_id').val();
  192. var data_obj = {name:name,telephone:m_addr_mobile,is_default:0,province_id:areaprovince,city_id:areacity,country_id:areadistrict,address:addr_address};
  193. var edit_url = "{:U('User/edit_address')}";
  194. var add_url = "{:U('User/add_address')}";
  195. if(sub_address_id != '') {
  196. var ajaxaddress_add_url = edit_url;
  197. data_obj.address_id = sub_address_id;
  198. } else {
  199. var ajaxaddress_add_url = add_url;
  200. }
  201. $.ajax({
  202. url:ajaxaddress_add_url,
  203. type:'post',
  204. data:data_obj,
  205. dataType:'json',
  206. success:function(json){
  207. if(json.code == 1) {
  208. alert('修改成功');
  209. location.href = location.href;
  210. return false;
  211. } else {
  212. showTip(json.msg);
  213. return false;
  214. }
  215. }
  216. })
  217. })
  218. $('.m-addr-close').click(function(){
  219. $('#m-addr-mask').hide();
  220. })
  221. })
  222. function getCountryList(parent_city_id,parent_country_id)
  223. {
  224. var areaId = parent_city_id;
  225. if(areaId == 0){
  226. $('#areadistrict').html('<option value="0">选择地区</option>')
  227. } else {
  228. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  229. $('#areadistrict').html('<option value="0">选择地区</option>');
  230. $.each(data,function(no,items){
  231. if(parent_country_id >0 && parent_country_id == items.area_id){
  232. $('#areadistrict').append('<option value="'+items.area_id+'" selected>'+items.area_name+'</option>');
  233. } else {
  234. $('#areadistrict').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  235. }
  236. });
  237. if(parent_country_id > 0)
  238. $('#m-addr-mask').show();
  239. });
  240. }
  241. }
  242. function getCityList(parent_province_id,parent_city_id,parent_country_id)
  243. {
  244. var areaId = parent_province_id;
  245. if(areaId == 0){
  246. $('#areacity').html('<option value="0">选择城市</option>');
  247. $('#areadistrict').html('<option value="0">选择地区</option>')
  248. } else {
  249. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  250. $('#areacity').html('<option value="0">选择城市</option>');
  251. $.each(data,function(no,items){
  252. if(parent_city_id > 0 && items.area_id == parent_city_id)
  253. $('#areacity').append('<option value="'+items.area_id+'" selected>'+items.area_name+'</option>');
  254. else {
  255. $('#areacity').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  256. }
  257. });
  258. if(parent_city_id == 0) {
  259. $('#areadistrict').html('<option value="0">选择地区</option>');
  260. } else {
  261. getCountryList(parent_city_id,parent_country_id);
  262. }
  263. });
  264. }
  265. }
  266. function getProvinceList(parent_province_id,parent_city_id,parent_country_id)
  267. {
  268. var areaId=0;
  269. $.post(ajaxarea_url,{'areaId':areaId},function(data){
  270. $('#areaprovince').html('<option value="0">选择省份</option>');
  271. $.each(data,function(no,items){
  272. if(parent_province_id > 0 && items.area_id == parent_province_id){
  273. $('#areaprovince').append('<option value="'+items.area_id+'" selected >'+items.area_name+'</option>');
  274. } else {
  275. $('#areaprovince').append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
  276. }
  277. });
  278. if(parent_province_id == 0)
  279. $('#m-addr-mask').show()
  280. else
  281. getCityList(parent_province_id,parent_city_id,parent_country_id);
  282. });
  283. }
  284. //修改地址
  285. function editAddr(obj)
  286. {
  287. var province_id = $(obj).attr('data-pid');
  288. var city_id = $(obj).attr('data-cityid');
  289. var country_id = $(obj).attr('data-country-id');
  290. var address_id = $(obj).parent().parent().attr('data-address-id');
  291. var address = $(obj).attr('data-address');
  292. var telephone = $(obj).attr('data-telephone');
  293. var name = $(obj).attr('data-name');
  294. $('#name').val(name);
  295. $('#telephone').val(telephone);
  296. $('#addr_address').val(address);
  297. $('#sub_address_id').val(address_id);
  298. $('.m-addr-title').html('编辑收货地址');
  299. getProvinceList(province_id,city_id,country_id);
  300. }
  301. //delAddr删除地址
  302. function delAddr(obj)
  303. {
  304. var del_url = "{:U('User/delete_address_ajax')}";
  305. var address_id = $(obj).parent().parent().attr('data-address-id');
  306. if(!confirm('确认删除地址吗?')) {
  307. return false;
  308. }
  309. $.ajax({
  310. url:del_url,
  311. data:{address_id:address_id},
  312. type:'post',
  313. dataType:'json',
  314. success:function(res){
  315. if(res.code == 1){
  316. alert('删除成功');
  317. location.href = location.href;
  318. return false;
  319. } else {
  320. alert(res.msg);
  321. return false;
  322. }
  323. }
  324. })
  325. }
  326. //设置为默认地址
  327. function defaultAddr(obj)
  328. {
  329. if($(obj).children('.address-item-set-default').hasClass('default') ){
  330. return false;
  331. }
  332. var address_id = $(obj).parent().attr('data-address-id');
  333. $.ajax({
  334. url:chang_default_url,
  335. type:'post',
  336. data:{address_id:address_id},
  337. dataType:'json',
  338. success:function(res){
  339. $('.address-item-use .address-item-set-default').removeClass('default');
  340. $('.address-item-use .address-item-set-default').html('设为默认');
  341. $(obj).children('.address-item-set-default').addClass('default');
  342. $(obj).children('.address-item-set-default').html('已设为默认');
  343. }
  344. })
  345. }
  346. </script>
  347. </block>