selectAddress.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. flag: 0,
  25. hidden : 'hidden'
  26. },
  27. onLoad: function () {
  28. wx.showNavigationBarLoading()
  29. var that = this;
  30. var host = getApp().globalData.servsers;
  31. var un_id = getApp().globalData.un_id;
  32. var openid = getApp().globalData.openid;
  33. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  34. wx.navigateTo({
  35. url: '/pages/authorize/authorize?link=selectAddress',
  36. })
  37. } else {
  38. wx.request({
  39. url: host + "/adressapi/adressview",
  40. data: {
  41. user_id: un_id
  42. },
  43. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  44. header: {
  45. 'Accept': 'application/json'
  46. },
  47. success: function (res) {
  48. that.setData({
  49. addressList: res.data.rows
  50. });
  51. if (res == null || res.data == null) {
  52. console.error('网络请求失败');
  53. return;
  54. }
  55. wx.hideNavigationBarLoading(
  56. that.setData({
  57. hidden: ''
  58. })
  59. )
  60. }
  61. });
  62. }
  63. },
  64. onShow:function(e){
  65. // var listLength = addressList.length;
  66. // var defaultData = [];
  67. // var count = 0;
  68. // for (var i = 1; i < listLength; i++) {//判断是否有默认地址
  69. // defaultData[i] = addressList[i].addressDefault;
  70. // if (defaultData[i] == 1) {
  71. // this.setData({
  72. // 'selectnum': i
  73. // })
  74. // count++;
  75. // }
  76. // }
  77. // if (listLength == 1){
  78. // this.setData({
  79. // 'selectnum': 0
  80. // })
  81. // }else{
  82. // if (count == 0){
  83. // this.setData({
  84. // 'selectnum': 0
  85. // })
  86. // }
  87. // }
  88. },
  89. selectAddress: function (options){//勾选地址
  90. var that = this
  91. var id = options.currentTarget.dataset.id;
  92. var province = options.currentTarget.dataset.province;
  93. var city = options.currentTarget.dataset.city;
  94. var area = options.currentTarget.dataset.area;
  95. var consignee = options.currentTarget.dataset.consignee;
  96. var phone = options.currentTarget.dataset.phone;
  97. var adress = options.currentTarget.dataset.adress;
  98. var pages = getCurrentPages();
  99. var currPage = pages[pages.length - 1]; //当前页面
  100. var prevPage = pages[pages.length - 2]; //上一个页面
  101. //if (prevPage.route == 'pages/confirmOrder/confirmOrder'){
  102. prevPage.setData({
  103. province: province,
  104. city: city,
  105. area: area,
  106. adress: adress,
  107. consignee: consignee,
  108. phone: phone
  109. });
  110. wx.navigateBack();
  111. //}
  112. }
  113. })