addAddressFriend.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. checked : false,
  22. hiddenmodal : 'hidden',
  23. modalCont : '',
  24. order_number : '',
  25. addGiftListClick : false
  26. },
  27. onLoad: function (options) {
  28. var that = this;
  29. that.setData({//从领取礼物页带过来的礼物得订单号
  30. order_number: options.order_number
  31. })
  32. console.log("1:"+options.order_number);
  33. tcity.init(that);
  34. var cityData = that.data.cityData;
  35. const provinces = [];
  36. const citys = [];
  37. const countys = [];
  38. for (let i = 0; i < cityData.length; i++) {
  39. provinces.push(cityData[i].name);
  40. }
  41. console.log('省份完成');
  42. for (let i = 0; i < cityData[0].sub.length; i++) {
  43. citys.push(cityData[0].sub[i].name)
  44. }
  45. console.log('city完成');
  46. for (let i = 0; i < cityData[0].sub[0].sub.length; i++) {
  47. countys.push(cityData[0].sub[0].sub[i].name)
  48. }
  49. that.setData({
  50. 'provinces': provinces,
  51. 'citys': citys,
  52. 'countys': countys,
  53. 'province': cityData[0].name,
  54. 'city': cityData[0].sub[0].name,
  55. 'county': cityData[0].sub[0].sub[0].name
  56. })
  57. console.log('初始化完成');
  58. },
  59. bindChange: function (e) {
  60. var val = e.detail.value
  61. var t = this.data.values;
  62. var cityData = this.data.cityData;
  63. if (val[0] != t[0]) {
  64. const citys = [];
  65. const countys = [];
  66. for (let i = 0; i < cityData[val[0]].sub.length; i++) {
  67. citys.push(cityData[val[0]].sub[i].name)
  68. }
  69. for (let i = 0; i < cityData[val[0]].sub[0].sub.length; i++) {
  70. countys.push(cityData[val[0]].sub[0].sub[i].name)
  71. }
  72. this.setData({
  73. province: this.data.provinces[val[0]],
  74. city: cityData[val[0]].sub[0].name,
  75. citys: citys,
  76. county: cityData[val[0]].sub[0].sub[0].name,
  77. countys: countys,
  78. values: val,
  79. value: [val[0], 0, 0]
  80. })
  81. return;
  82. }
  83. if (val[1] != t[1]) {
  84. const countys = [];
  85. for (let i = 0; i < cityData[val[0]].sub[val[1]].sub.length; i++) {
  86. countys.push(cityData[val[0]].sub[val[1]].sub[i].name)
  87. }
  88. this.setData({
  89. city: this.data.citys[val[1]],
  90. county: cityData[val[0]].sub[val[1]].sub[0].name,
  91. countys: countys,
  92. values: val,
  93. value: [val[0], val[1], 0]
  94. })
  95. return;
  96. }
  97. if (val[2] != t[2]) {
  98. this.setData({
  99. county: this.data.countys[val[2]],
  100. values: val
  101. })
  102. return;
  103. }
  104. },
  105. open: function () {
  106. var that = this;
  107. this.setData({
  108. condition: !this.data.condition
  109. })
  110. if (that.data.condition == false){
  111. var province = that.data.province;
  112. var city = that.data.city;
  113. var county = that.data.county;
  114. var cityData = that.data.cityData;
  115. var provinceId = 0;
  116. var cityId = 0;
  117. var countyId = 0;
  118. var len1 = 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. that.setData({
  137. value: [provinceId, cityId, countyId]
  138. })
  139. }
  140. },
  141. userNameInput: function (e) {
  142. this.setData({
  143. userName: e.detail.value
  144. })
  145. },
  146. userAddressInput: function (e) {
  147. this.setData({
  148. userAddress: e.detail.value
  149. })
  150. },
  151. userTelephoneInput: function (e) {
  152. this.setData({
  153. userTelephone: e.detail.value
  154. })
  155. },
  156. switchChange: function (e) {
  157. if (e.detail.value == false){
  158. this.setData({
  159. isDefault: 0
  160. })
  161. }else{
  162. this.setData({
  163. isDefault: 1
  164. })
  165. }
  166. },
  167. saveInfor: function (e) {//领取礼物
  168. var host = getApp().globalData.servsers;
  169. var un_id = getApp().globalData.un_id;
  170. var that = this;
  171. var consignee = this.data.userName;
  172. if (consignee == undefined || consignee == '') {
  173. that.setData({
  174. hiddenmodal: false,
  175. modalCont: '请填写收货人姓名'
  176. })
  177. setTimeout(function () {
  178. that.setData({
  179. hiddenmodal: true
  180. })
  181. }, 1000)
  182. return false;
  183. }
  184. var userAddress = this.data.userAddress;
  185. if (userAddress == undefined || userAddress == '') {
  186. that.setData({
  187. hiddenmodal: false,
  188. modalCont: '请填写详细地址'
  189. })
  190. setTimeout(function () {
  191. that.setData({
  192. hiddenmodal: true
  193. })
  194. }, 1000)
  195. return false;
  196. }
  197. var userTelephone = this.data.userTelephone;
  198. if (userTelephone == undefined || userTelephone == '') {
  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. wx.showLoading({
  211. title: '礼物领取中,请稍候',
  212. icon: 'loading',
  213. mask: true,
  214. success: function () {
  215. }
  216. })
  217. var pages = getCurrentPages();
  218. var currPage = pages[pages.length - 1]; //当前页面
  219. var prevPage = pages[pages.length - 2]; //上一个页面
  220. var num = pages.length;
  221. var timestamp = Date.parse(new Date());
  222. var formIdTime = timestamp / 1000;//formId 生成时间
  223. var formId = e.detail;//formId
  224. console.log(formId);
  225. //针对消息模版:存储模板消息[用于已发货提醒]使用的form_id【操作人产生的form_id,仅可用于给当前操作人发送消息】
  226. wx.request({
  227. url: host + "userapi/insertadduserwxsend",
  228. data: {
  229. user_id: un_id,
  230. form_id_fh: formId.formId,
  231. order_number: that.data.order_number
  232. },
  233. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  234. header: {
  235. 'Accept': 'application/json'
  236. },
  237. success: function (res) {
  238. console.log(res);
  239. if (res == null || res.data == null) {
  240. console.error('网络请求失败');
  241. return;
  242. }
  243. }
  244. })
  245. that.setData({
  246. addGiftListClick : true
  247. })
  248. //更改送出的礼物的订单收货地址
  249. wx.request({
  250. url: host + "orderapi/updateOrderInfo",
  251. data: {
  252. //user_id: un_id,
  253. order_number: that.data.order_number,
  254. order_type : 2,//订单最终状态标志位
  255. order_Consignee: that.data.userName,
  256. order_address: that.data.province + that.data.city + that.data.county + that.data.userAddress,
  257. order_phone: that.data.userTelephone
  258. },
  259. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  260. header: {
  261. 'Accept': 'application/json'
  262. },
  263. success: function (res) {
  264. wx.hideLoading();
  265. that.setData({
  266. hiddenmodal: false,
  267. modalCont: '礼物领取成功,等待迎接您的礼物上门吧'
  268. })
  269. setTimeout(function () {
  270. that.setData({
  271. hiddenmodal: true
  272. })
  273. prevPage.setData({
  274. isSelect: 1,
  275. goosdListnew: {},
  276. goosdListnew2: {}
  277. })
  278. prevPage.onShow();
  279. wx.navigateBack({
  280. delta: 1
  281. })
  282. }, 1500)
  283. if (res == null || res.data == null) {
  284. console.error('网络请求失败');
  285. return;
  286. }
  287. }
  288. })
  289. }
  290. })
  291. var that;
  292. var Util = require('../../utils/util.js');