sendOwnAddress.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. allowDelete: true, //默认可以删除
  25. allowEdit: true, //默认可以编辑
  26. arr: {},
  27. flag: 0,
  28. hidden: 'hidden',
  29. order_number:''
  30. },
  31. onLoad: function (options) {
  32. wx.showNavigationBarLoading();
  33. var that = this;
  34. var order_number = options.order_number;
  35. console.log("order_number::" + order_number);
  36. var un_id = getApp().globalData.un_id;
  37. var host = getApp().globalData.servsers;
  38. that.setData({
  39. order_number: order_number
  40. })
  41. if (un_id != undefined && un_id != '' && un_id != null){
  42. wx.login({
  43. success: function (res) {
  44. var code = res.code;
  45. wx.request({
  46. url: host + "/adressapi/adressview",
  47. data: {
  48. user_id: un_id
  49. },
  50. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  51. header: {
  52. 'Accept': 'application/json'
  53. },
  54. success: function (res) {
  55. that.setData({
  56. addressList: res.data.rows
  57. });
  58. if (res == null || res.data == null) {
  59. console.error('网络请求失败');
  60. return;
  61. }
  62. wx.hideNavigationBarLoading(
  63. that.setData({
  64. hidden: ''
  65. })
  66. )
  67. }
  68. });
  69. }
  70. })
  71. }
  72. },
  73. onShow: function (e) {
  74. var that = this;
  75. //that.onLoad();
  76. var listLength = addressList.length;
  77. var defaultData = [];
  78. var count = 0;
  79. for (var i = 1; i < listLength; i++) {//判断是否有默认地址
  80. defaultData[i] = addressList[i].addressDefault;
  81. if (defaultData[i] == 1) {
  82. this.setData({
  83. 'selectnum': i
  84. })
  85. count++;
  86. }
  87. }
  88. if (listLength == 1) {
  89. this.setData({
  90. 'selectnum': 0
  91. })
  92. } else {
  93. if (count == 0) {
  94. this.setData({
  95. 'selectnum': 0
  96. })
  97. }
  98. }
  99. },
  100. editAddress: function (e) {//编辑地址
  101. var that = this;
  102. var order_number = that.data.order_number;
  103. var id = e.currentTarget.dataset.id;
  104. var dataId = that.data.addressList[id].id;
  105. var name = that.data.addressList[id].consignee;
  106. var phone = that.data.addressList[id].phone;
  107. var adress = that.data.addressList[id].adress;
  108. var province = that.data.addressList[id].province;
  109. var city = that.data.addressList[id].city;
  110. var county = that.data.addressList[id].area;
  111. var cityData = that.data.cityData;
  112. var provinceId = 0;
  113. var cityId = 0;
  114. var countyId = 0;
  115. var flag = that.data.addressList[id].adress_flag;
  116. tcity.init(that);
  117. var cityData = that.data.cityData;
  118. var len1 = that.data.cityData.length;
  119. for (var i = 0; i < len1; i++) {
  120. if (cityData[i].name == province) {
  121. provinceId = i;
  122. }
  123. }
  124. var len2 = cityData[provinceId].sub.length;
  125. for (var i = 0; i < len2; i++) {
  126. if (cityData[provinceId].sub[i].name == city) {
  127. cityId = i;
  128. }
  129. }
  130. var len3 = cityData[provinceId].sub[cityId].sub.length;
  131. for (var i = 0; i < len3; i++) {
  132. if (cityData[provinceId].sub[cityId].sub[i].name == county) {
  133. countyId = i;
  134. }
  135. }
  136. var arr = {
  137. id: dataId,
  138. name: name,
  139. phone: phone,
  140. adress: adress,
  141. province: province,
  142. city: city,
  143. county: county,
  144. flag: flag,
  145. provinceId: provinceId,
  146. cityId: cityId,
  147. countyId: countyId
  148. };
  149. this.setData({
  150. arr: arr
  151. })
  152. wx.navigateTo({
  153. url: '/pages/editAddressSendOwn/editAddressSendOwn?arr=' + JSON.stringify(that.data.arr) + '&order_number=' + order_number,
  154. success: function (res) { },
  155. fail: function (res) { },
  156. complete: function (res) { },
  157. })
  158. },
  159. deleteAddress: function (e) {//删除地址
  160. var that = this;
  161. var host = getApp().globalData.servsers;
  162. var id = e.currentTarget.dataset.deleteid;
  163. var index = e.currentTarget.dataset.index;
  164. var addressList = that.data.addressList;
  165. wx.request({
  166. url: host + 'adressapi/delete',
  167. data: {
  168. id: id
  169. },
  170. method: 'GET',
  171. success: function (res) {
  172. addressList.splice(index, 1);
  173. that.setData({
  174. addressList: addressList
  175. });
  176. if (res == null || res.data == null) {
  177. console.error('网络请求失败');
  178. return;
  179. }
  180. }
  181. })
  182. }
  183. })