editAddressSendOwn.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //index.js
  2. //获取应用实例
  3. var tcity = require("../../utils/citys.js");
  4. var app = getApp()
  5. Page({
  6. data: {
  7. provinces: [],
  8. province: "",
  9. citys: [],
  10. city: "",
  11. countys: [],
  12. county: '',
  13. value: [0, 0, 0],
  14. values: [0, 0, 0],
  15. condition: false,
  16. userName: "",//用户名
  17. userAddressArea: "",//省市区
  18. userAddress: "", //详细地址
  19. userTelephone: "", //联系方式
  20. isDefault: 0 , //是否默认
  21. arr : [],
  22. flag : 0,
  23. checked : true,
  24. user_id : '',
  25. order_number:''
  26. },
  27. onLoad: function (options) {
  28. var that = this;
  29. var order_number = options.order_number;
  30. that.data.arr = JSON.parse(options.arr);
  31. that.setData({
  32. order_number: order_number,
  33. arr: JSON.parse(options.arr),
  34. user_id: that.data.arr.id,
  35. userName: that.data.arr.name,
  36. userTelephone: that.data.arr.phone,
  37. userAddress: that.data.arr.adress,
  38. province: that.data.arr.province,
  39. city: that.data.arr.city,
  40. county: that.data.arr.county,
  41. isDefault: that.data.arr.flag,
  42. provinceId: that.data.arr.provinceId,
  43. cityId: that.data.arr.cityId,
  44. countyId: that.data.arr.countyId
  45. })
  46. if (that.data.isDefault == 1) {
  47. that.setData({
  48. checked: true
  49. })
  50. } else {
  51. that.setData({
  52. checked: false
  53. })
  54. }
  55. tcity.init(that);
  56. var cityData = that.data.cityData;
  57. const provinces = [];
  58. const citys = [];
  59. const countys = [];
  60. var provinceId = that.data.arr.provinceId;
  61. var cityId = that.data.arr.cityId;
  62. var countyId = that.data.arr.countyId;
  63. for (let i = 0; i < cityData.length; i++) {
  64. provinces.push(cityData[i].name);
  65. }
  66. console.log('省份完成');
  67. for (let i = 0; i < cityData[provinceId].sub.length; i++) {
  68. citys.push(cityData[provinceId].sub[i].name)
  69. }
  70. console.log('city完成');
  71. for (let i = 0; i < cityData[provinceId].sub[cityId].sub.length; i++) {
  72. countys.push(cityData[provinceId].sub[cityId].sub[i].name)
  73. }
  74. that.setData({
  75. 'provinces': provinces,
  76. 'citys': citys,
  77. 'countys': countys,
  78. value: [provinceId, cityId, countyId]
  79. // 'province': options.province,
  80. // 'city': options.city,
  81. // 'county': options.county
  82. })
  83. },
  84. bindChange: function (e) {
  85. var val = e.detail.value
  86. var t = this.data.values;
  87. var cityData = this.data.cityData;
  88. if (val[0] != t[0]) {
  89. const citys = [];
  90. const countys = [];
  91. for (let i = 0; i < cityData[val[0]].sub.length; i++) {
  92. citys.push(cityData[val[0]].sub[i].name)
  93. }
  94. for (let i = 0; i < cityData[val[0]].sub[0].sub.length; i++) {
  95. countys.push(cityData[val[0]].sub[0].sub[i].name)
  96. }
  97. this.setData({
  98. province: this.data.provinces[val[0]],
  99. city: cityData[val[0]].sub[0].name,
  100. citys: citys,
  101. county: cityData[val[0]].sub[0].sub[0].name,
  102. countys: countys,
  103. values: val,
  104. value: [val[0], 0, 0]
  105. })
  106. return;
  107. }
  108. if (val[1] != t[1]) {
  109. const countys = [];
  110. for (let i = 0; i < cityData[val[0]].sub[val[1]].sub.length; i++) {
  111. countys.push(cityData[val[0]].sub[val[1]].sub[i].name)
  112. }
  113. this.setData({
  114. city: this.data.citys[val[1]],
  115. county: cityData[val[0]].sub[val[1]].sub[0].name,
  116. countys: countys,
  117. values: val,
  118. value: [val[0], val[1], 0]
  119. })
  120. return;
  121. }
  122. if (val[2] != t[2]) {
  123. this.setData({
  124. county: this.data.countys[val[2]],
  125. values: val
  126. })
  127. return;
  128. }
  129. },
  130. open: function () {
  131. var that = this;
  132. this.setData({
  133. condition: !this.data.condition
  134. })
  135. if (that.data.condition == false) {
  136. var province = that.data.province;
  137. var city = that.data.city;
  138. var county = that.data.county;
  139. var cityData = that.data.cityData;
  140. var provinceId = 0;
  141. var cityId = 0;
  142. var countyId = 0;
  143. var len1 = cityData.length;
  144. for (var i = 0; i < len1; i++) {
  145. if (cityData[i].name == province) {
  146. provinceId = i;
  147. }
  148. }
  149. var len2 = cityData[provinceId].sub.length;
  150. for (var i = 0; i < len2; i++) {
  151. if (cityData[provinceId].sub[i].name == city) {
  152. cityId = i;
  153. }
  154. }
  155. var len3 = cityData[provinceId].sub[cityId].sub.length;
  156. for (var i = 0; i < len3; i++) {
  157. if (cityData[provinceId].sub[cityId].sub[i].name == county) {
  158. countyId = i;
  159. }
  160. }
  161. that.setData({
  162. value: [provinceId, cityId, countyId]
  163. })
  164. }
  165. },
  166. userNameInput: function (e) {
  167. this.setData({
  168. userName: e.detail.value
  169. })
  170. },
  171. userAddressInput: function (e) {
  172. this.setData({
  173. userAddress: e.detail.value
  174. })
  175. },
  176. userTelephoneInput: function (e) {
  177. this.setData({
  178. userTelephone: e.detail.value
  179. })
  180. },
  181. switchChange: function (e) {
  182. if (e.detail.value == false){
  183. this.setData({
  184. isDefault: 0
  185. })
  186. }else{
  187. this.setData({
  188. isDefault: 1
  189. })
  190. }
  191. },
  192. saveInfor: function (e) {
  193. var that = this;
  194. var host = getApp().globalData.servsers;
  195. var un_id = getApp().globalData.un_id;
  196. var order_number = that.data.order_number;
  197. var consignee = this.data.userName;
  198. if (consignee == undefined || consignee == '') {
  199. that.setData({
  200. hiddenmodal: false,
  201. modalCont: '请填写收货人姓名'
  202. })
  203. setTimeout(function () {
  204. that.setData({
  205. hiddenmodal: true
  206. })
  207. }, 1000)
  208. return false;
  209. }
  210. var userAddress = this.data.userAddress;
  211. if (userAddress == undefined || userAddress == '') {
  212. that.setData({
  213. hiddenmodal: false,
  214. modalCont: '请填写详细地址'
  215. })
  216. setTimeout(function () {
  217. that.setData({
  218. hiddenmodal: true
  219. })
  220. }, 1000)
  221. return false;
  222. }
  223. var userTelephone = this.data.userTelephone;
  224. if (userTelephone == undefined || userTelephone == '') {
  225. that.setData({
  226. hiddenmodal: false,
  227. modalCont: '请填写电话号码'
  228. })
  229. setTimeout(function () {
  230. that.setData({
  231. hiddenmodal: true
  232. })
  233. }, 1000)
  234. return false;
  235. }
  236. var pages = getCurrentPages();
  237. var currPage = pages[pages.length - 1]; //当前页面
  238. var prevPage = pages[pages.length - 2]; //上一个页面
  239. var num = pages.length;
  240. //更改送出的礼物的订单收货地址
  241. wx.request({
  242. url: host + "orderapi/updateOrderInfo",
  243. data: {
  244. //user_id: un_id,
  245. order_number: that.data.order_number,
  246. order_type: 1,//订单最终状态-送自己
  247. order_Consignee: that.data.userName,
  248. order_address: that.data.province + that.data.city + that.data.county + that.data.userAddress,
  249. order_phone: that.data.userTelephone
  250. },
  251. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  252. header: {
  253. 'Accept': 'application/json'
  254. },
  255. success: function (res) {
  256. that.setData({
  257. hiddenmodal: false,
  258. modalCont: '礼物领取成功,等待迎接您的礼物上门吧'
  259. })
  260. setTimeout(function () {
  261. that.setData({
  262. hiddenmodal: true
  263. })
  264. prevPage.setData({
  265. order_type: '1',
  266. });
  267. wx.navigateBack({
  268. delta: 2
  269. })
  270. }, 1500)
  271. if (res == null || res.data == null) {
  272. console.error('网络请求失败');
  273. return;
  274. }
  275. }
  276. })
  277. }
  278. })
  279. var that;
  280. var Util = require('../../utils/util.js');