index2.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // index.js 我的地址
  2. var tcity = require("../../utils/citys.js");
  3. // addressDefault :设为默认地址 1为默认
  4. var addressList = [
  5. ];
  6. Page({
  7. data: {
  8. addressList: addressList,
  9. isSelect: false,
  10. nickName: '',
  11. userInfoAvatar: '',
  12. sex: '',
  13. province: '',
  14. city: '',
  15. provinces: [],
  16. province: "",
  17. citys: [],
  18. city: "",
  19. countys: [],
  20. county: '',
  21. value: [0, 0, 0],
  22. values: [0, 0, 0],
  23. condition: false
  24. },
  25. onLoad: function () {
  26. console.log("onLoad");
  27. var that = this;
  28. tcity.init(that);
  29. var cityData = that.data.cityData;
  30. const provinces = [];
  31. const citys = [];
  32. const countys = [];
  33. for (let i = 0; i < cityData.length; i++) {
  34. provinces.push(cityData[i].name);
  35. }
  36. console.log('省份完成');
  37. for (let i = 0; i < cityData[0].sub.length; i++) {
  38. citys.push(cityData[0].sub[i].name)
  39. }
  40. console.log('city完成');
  41. for (let i = 0; i < cityData[0].sub[0].sub.length; i++) {
  42. countys.push(cityData[0].sub[0].sub[i].name)
  43. }
  44. that.setData({
  45. 'provinces': provinces,
  46. 'citys': citys,
  47. 'countys': countys,
  48. 'province': cityData[0].name,
  49. 'city': cityData[0].sub[0].name,
  50. 'county': cityData[0].sub[0].sub[0].name
  51. })
  52. console.log('初始化完成');
  53. var un_id = getApp().globalData.un_id;
  54. var host = getApp().globalData.servsers;
  55. console.log('获取用户openid成功' + openid)
  56. //人气推荐
  57. wx.request({
  58. url: host+"adressapi/adressview",
  59. data: {
  60. user_id: un_id
  61. },
  62. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  63. header: {
  64. 'Accept': 'application/json'
  65. },
  66. success: function (res) {
  67. that.setData({
  68. addressList: res.data.rows
  69. });
  70. if (res == null || res.data == null) {
  71. console.error('网络请求失败');
  72. return;
  73. }
  74. }
  75. });
  76. },
  77. onShow:function(e){
  78. var listLength = addressList.length;
  79. var defaultData = [];
  80. var count = 0;
  81. for (var i = 1; i < listLength; i++) {//判断是否有默认地址
  82. defaultData[i] = addressList[i].addressDefault;
  83. if (defaultData[i] == 1) {
  84. this.setData({
  85. 'selectnum': i
  86. })
  87. count++;
  88. }
  89. }
  90. if (listLength == 1){
  91. this.setData({
  92. 'selectnum': 0
  93. })
  94. }else{
  95. if (count == 0){
  96. this.setData({
  97. 'selectnum': 0
  98. })
  99. }
  100. }
  101. },
  102. selectAddress: function (options){//勾选地址
  103. var that = this
  104. var id = options.currentTarget.dataset.id;
  105. var pages = getCurrentPages();
  106. var currPage = pages[pages.length - 1]; //当前页面
  107. var prevPage = pages[pages.length - 2]; //上一个页面
  108. console.log(pages);
  109. console.log(currPage);
  110. console.log(prevPage);
  111. prevPage.setData({
  112. address: '32131'
  113.   })
  114. wx.navigateBack();
  115. //设置当前样式
  116. that.setData({
  117. 'selectnum': id
  118. })
  119. },
  120. deleteAddress:function(e){//删除地址
  121. var id = event.currentTarget.dataset.deleteid;
  122. wx.request({
  123. url: 'https://shop.yunapply.com/home/shipping/delAddress?id=' + id,
  124. data: {},
  125. method: 'GET',
  126. success: function (res) {
  127. if (res.data.status == 0) {
  128. wx.showToast({
  129. title: res.data.info,
  130. icon: 'loading',
  131. duration: 1500
  132. })
  133. } else {
  134. wx.showToast({
  135. title: res.data.info,
  136. icon: 'success',
  137. duration: 1000
  138. })
  139. //删除之后应该有一个刷新页面的效果,等和其他页面刷新跳转一起做
  140. }
  141. },
  142. fail: function () {
  143. wx.showToast({
  144. title: '服务器网络错误!',
  145. icon: 'loading',
  146. duration: 1500
  147. })
  148. }
  149. })
  150. }
  151. })