addAddressSendOwn.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. order_number_new : '',//拆分单号
  26. goodsList:[],
  27. hiddenLoading:false,//隐藏加载层
  28. saveInforClick : false,//防止连点
  29. },
  30. onLoad: function (options) {
  31. var that = this;
  32. var order_number = options.order_number;
  33. var order_number_new = options.order_number_new;
  34. var goodsList = options.goodsList;
  35. goodsList = goodsList.replace(/zss/g, "&");
  36. goodsList = JSON.parse(goodsList);
  37. var total = 0;
  38. for (var i = 0; i < goodsList.list_order_aff_data.length; i++) {
  39. var boxPrice = goodsList.list_order_aff_data[i].box_price;
  40. var goodsPrice = goodsList.list_order_aff_data[i].com_price;
  41. if (boxPrice == '' && boxPrice == null) {
  42. boxPrice = 0;
  43. }
  44. total += (parseFloat(goodsPrice) + parseFloat(boxPrice)) * parseInt(goodsList.list_order_aff_data[i].break_num);
  45. }
  46. for (var i = 0; i < goodsList.list_order_aff_data.length; i++) {
  47. goodsList.list_order_aff_data[i].order_Price = total;
  48. }
  49. that.setData({//从领取礼物页带过来的礼物得订单号
  50. order_number: options.order_number,
  51. order_number_new: options.order_number_new,
  52. goodsList: goodsList
  53. })
  54. console.log(goodsList);
  55. tcity.init(that);
  56. var cityData = that.data.cityData;
  57. const provinces = [];
  58. const citys = [];
  59. const countys = [];
  60. for (let i = 0; i < cityData.length; i++) {
  61. provinces.push(cityData[i].name);
  62. }
  63. console.log('省份完成');
  64. for (let i = 0; i < cityData[0].sub.length; i++) {
  65. citys.push(cityData[0].sub[i].name)
  66. }
  67. console.log('city完成');
  68. for (let i = 0; i < cityData[0].sub[0].sub.length; i++) {
  69. countys.push(cityData[0].sub[0].sub[i].name)
  70. }
  71. that.setData({
  72. 'provinces': provinces,
  73. 'citys': citys,
  74. 'countys': countys,
  75. 'province': cityData[0].name,
  76. 'city': cityData[0].sub[0].name,
  77. 'county': cityData[0].sub[0].sub[0].name,
  78. order_number: order_number
  79. })
  80. console.log('初始化完成');
  81. },
  82. onShow:function(){
  83. var that = this;
  84. that.setData({
  85. saveInforClick: false
  86. })
  87. },
  88. bindChange: function (e) {
  89. var val = e.detail.value
  90. var t = this.data.values;
  91. var cityData = this.data.cityData;
  92. if (val[0] != t[0]) {
  93. const citys = [];
  94. const countys = [];
  95. for (let i = 0; i < cityData[val[0]].sub.length; i++) {
  96. citys.push(cityData[val[0]].sub[i].name)
  97. }
  98. for (let i = 0; i < cityData[val[0]].sub[0].sub.length; i++) {
  99. countys.push(cityData[val[0]].sub[0].sub[i].name)
  100. }
  101. this.setData({
  102. province: this.data.provinces[val[0]],
  103. city: cityData[val[0]].sub[0].name,
  104. citys: citys,
  105. county: cityData[val[0]].sub[0].sub[0].name,
  106. countys: countys,
  107. values: val,
  108. value: [val[0], 0, 0]
  109. })
  110. return;
  111. }
  112. if (val[1] != t[1]) {
  113. const countys = [];
  114. for (let i = 0; i < cityData[val[0]].sub[val[1]].sub.length; i++) {
  115. countys.push(cityData[val[0]].sub[val[1]].sub[i].name)
  116. }
  117. this.setData({
  118. city: this.data.citys[val[1]],
  119. county: cityData[val[0]].sub[val[1]].sub[0].name,
  120. countys: countys,
  121. values: val,
  122. value: [val[0], val[1], 0]
  123. })
  124. return;
  125. }
  126. if (val[2] != t[2]) {
  127. this.setData({
  128. county: this.data.countys[val[2]],
  129. values: val
  130. })
  131. return;
  132. }
  133. },
  134. open: function () {
  135. var that = this;
  136. this.setData({
  137. condition: !this.data.condition
  138. })
  139. if (that.data.condition == false){
  140. var province = that.data.province;
  141. var city = that.data.city;
  142. var county = that.data.county;
  143. var cityData = that.data.cityData;
  144. var provinceId = 0;
  145. var cityId = 0;
  146. var countyId = 0;
  147. var len1 = cityData.length;
  148. for (var i = 0; i < len1; i++) {
  149. if (cityData[i].name == province) {
  150. provinceId = i;
  151. }
  152. }
  153. var len2 = cityData[provinceId].sub.length;
  154. for (var i = 0; i < len2; i++) {
  155. if (cityData[provinceId].sub[i].name == city) {
  156. cityId = i;
  157. }
  158. }
  159. var len3 = cityData[provinceId].sub[cityId].sub.length;
  160. for (var i = 0; i < len3; i++) {
  161. if (cityData[provinceId].sub[cityId].sub[i].name == county) {
  162. countyId = i;
  163. }
  164. }
  165. that.setData({
  166. value: [provinceId, cityId, countyId]
  167. })
  168. }
  169. },
  170. userNameInput: function (e) {
  171. this.setData({
  172. userName: e.detail.value
  173. })
  174. },
  175. userAddressInput: function (e) {
  176. this.setData({
  177. userAddress: e.detail.value
  178. })
  179. },
  180. userTelephoneInput: function (e) {
  181. this.setData({
  182. userTelephone: e.detail.value
  183. })
  184. },
  185. switchChange: function (e) {
  186. if (e.detail.value == false){
  187. this.setData({
  188. isDefault: 0
  189. })
  190. }else{
  191. this.setData({
  192. isDefault: 1
  193. })
  194. }
  195. },
  196. //插入订单
  197. insertOrder: function (i, order_number, order_number_new, un_id) {
  198. var that = this;
  199. var host = getApp().globalData.servsers;
  200. var stateNum = that.data.stateNum;//记录带有定制的商品数量
  201. var pages = getCurrentPages();
  202. var currPage = pages[pages.length - 1]; //当前页面
  203. var prevPage = pages[pages.length - 2]; //上一个页面
  204. console.log("i:" + i);
  205. if (i == 0) {
  206. that.setData({
  207. hiddenLoading:true,
  208. hiddenmodal: false,
  209. modalCont: '礼物领取成功,等待迎接您的礼物上门吧'
  210. })
  211. setTimeout(function () {
  212. that.setData({
  213. hiddenmodal: true
  214. })
  215. prevPage.setData({
  216. order_type: '1',
  217. goosdListnew: {}
  218. })
  219. prevPage.onShow();
  220. wx.navigateBack({
  221. delta: 1
  222. })
  223. }, 1500)
  224. } else {
  225. i -= 1;
  226. var break_num = that.data.goodsList.list_order_aff_data[i].break_num;
  227. var giftbox_name = that.data.goodsList.list_order_aff_data[i].com_dz;
  228. var process_name = that.data.goodsList.list_order_aff_data[i].com_lh;
  229. var process_id = 20;
  230. var giftbox_id = 20;
  231. if (process_name == '无需定制' || process_name == '') {
  232. process_id = -1;
  233. }
  234. if (giftbox_name == '无需定制' || giftbox_name == '') {
  235. giftbox_id = -1;
  236. }
  237. if (break_num > 0) {
  238. wx.request({
  239. url: host + "orderaffapi/insertOrderAff_n",
  240. data: {
  241. order_number_o: order_number,//原始单号
  242. order_number: "N" + order_number_new,
  243. cost: that.data.goodsList.list_order_aff_data[i].com_price,
  244. com_id: that.data.goodsList.list_order_aff_data[i].com_id,
  245. logo: that.data.goodsList.list_order_aff_data[i].logo,
  246. name: that.data.goodsList.list_order_aff_data[i].com_name,
  247. num: that.data.goodsList.list_order_aff_data[i].break_num,
  248. process: process_id,
  249. giftbox_name: that.data.goodsList.list_order_aff_data[i].com_dz,
  250. giftbox_id: giftbox_id,
  251. box_price: that.data.goodsList.list_order_aff_data[i].box_price,
  252. process_name: that.data.goodsList.list_order_aff_data[i].com_lh,
  253. process_id: process_id,
  254. logo: that.data.goodsList.list_order_aff_data[i].logo,
  255. style1_name: that.data.goodsList.list_order_aff_data[i].com_style1,
  256. style2_name: that.data.goodsList.list_order_aff_data[i].com_style2,
  257. style3_name: that.data.goodsList.list_order_aff_data[i].com_style3,
  258. style4_name: that.data.goodsList.list_order_aff_data[i].com_style4,
  259. style5_name: that.data.goodsList.list_order_aff_data[i].com_style5,
  260. affId: that.data.goodsList.list_order_aff_data[i].id,
  261. },
  262. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  263. header: {
  264. 'Accept': 'application/json'
  265. },
  266. success: function (res) {
  267. //for (var j = 0; j < that.data.goodsList.length; j++) {
  268. if ((that.data.goodsList.list_order_aff_data[i].process_name != '') && (that.data.goodsList.list_order_aff_data[i].process != -1)) {
  269. that.setData({
  270. stateNum: stateNum + 1
  271. })
  272. }
  273. //}
  274. that.insertOrder(i, order_number, order_number_new, un_id);
  275. if (res == null || res.data == null) {
  276. console.error('网络请求失败');
  277. return;
  278. }
  279. }
  280. })
  281. } else {
  282. that.insertOrder(i, order_number, order_number_new, un_id);
  283. }
  284. }
  285. },
  286. saveInfor: function (e) {//领取礼物
  287. var that = this;
  288. var host = getApp().globalData.servsers;
  289. var un_id = getApp().globalData.un_id;
  290. var consignee = this.data.userName;
  291. if (consignee == undefined || consignee == '') {
  292. that.setData({
  293. hiddenmodal: false,
  294. modalCont: '请填写收货人姓名'
  295. })
  296. setTimeout(function () {
  297. that.setData({
  298. hiddenmodal: true
  299. })
  300. }, 1000)
  301. return false;
  302. }
  303. var userAddress = this.data.userAddress;
  304. if (userAddress == undefined || userAddress == '') {
  305. that.setData({
  306. hiddenmodal: false,
  307. modalCont: '请填写详细地址'
  308. })
  309. setTimeout(function () {
  310. that.setData({
  311. hiddenmodal: true
  312. })
  313. }, 1000)
  314. return false;
  315. }
  316. var userTelephone = this.data.userTelephone;
  317. if (userTelephone == undefined || userTelephone == '') {
  318. that.setData({
  319. hiddenmodal: false,
  320. modalCont: '请填写电话号码'
  321. })
  322. setTimeout(function () {
  323. that.setData({
  324. hiddenmodal: true
  325. })
  326. }, 1000)
  327. return false;
  328. }
  329. var pages = getCurrentPages();
  330. var currPage = pages[pages.length - 1]; //当前页面
  331. var prevPage = pages[pages.length - 2]; //上一个页面
  332. var num = pages.length;
  333. var timestamp = Date.parse(new Date());
  334. timestamp = timestamp / 1000;
  335. var formIdTime = timestamp;//formId 生成时间
  336. var formId = e.detail;//formId
  337. console.log(formId);
  338. //针对消息模版:存储模板消息使用的form_id【操作人产生的form_id,仅可用于给当前操作人发送消息】
  339. wx.request({
  340. url: host + "userapi/insertadduserwxsend",
  341. data: {
  342. user_id: un_id,
  343. form_id_fh: formId.formId,
  344. order_number: "N" + that.data.order_number_new
  345. },
  346. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  347. header: {
  348. 'Accept': 'application/json'
  349. },
  350. success: function (res) {
  351. if (res == null || res.data == null) {
  352. console.error('网络请求失败');
  353. return;
  354. }
  355. }
  356. })
  357. if(un_id != undefined && un_id != '' && un_id != null){
  358. that.setData({
  359. saveInforClick: true
  360. })
  361. wx.request({
  362. url: host + "orderapi/insertorder_n",
  363. data: {
  364. order_userid: un_id,
  365. order_sta: '3',//待发货
  366. order_number_o: that.data.order_number,//原始单号
  367. order_number: "N" + that.data.order_number_new,//新单号
  368. order_type: 1,//订单最终状态标志位 - 送自己
  369. order_Price: that.data.goodsList.list_order_aff_data[0].order_Price,
  370. order_Consignee: '',
  371. order_phone: '',
  372. order_address: '',
  373. order_commodityid: that.data.goodsList.list_order_aff_data[0].id,
  374. order_Specifications: '',
  375. order_gixbox: '',
  376. invoice_send_flag: 3,
  377. invoice_flag: 3, //发票标志位,如果为3,则为无需发票
  378. },
  379. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  380. header: {
  381. 'Accept': 'application/json'
  382. },
  383. success: function (res) {
  384. that.setData({
  385. hiddenLoading:true
  386. })
  387. //更改送出的礼物的订单收货地址
  388. wx.request({
  389. url: host + "orderapi/updateOrderInfo",
  390. data: {
  391. //user_id: un_id,
  392. order_number: "N" + that.data.order_number_new,
  393. order_type: 1,//订单最终状态标志位
  394. order_Consignee: that.data.userName,
  395. order_address: that.data.province + that.data.city + that.data.county + that.data.userAddress,
  396. order_phone: that.data.userTelephone
  397. },
  398. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  399. header: {
  400. 'Accept': 'application/json'
  401. },
  402. success: function (res) {
  403. if (res == null || res.data == null) {
  404. console.error('网络请求失败');
  405. return;
  406. }
  407. }
  408. })
  409. //插入订单
  410. var len = that.data.goodsList.list_order_aff_data.length;
  411. that.insertOrder(len, that.data.order_number, that.data.order_number_new, un_id);
  412. if (res == null || res.data == null) {
  413. console.error('网络请求失败');
  414. return;
  415. }
  416. }
  417. });
  418. }
  419. //更改送出的礼物的订单收货地址
  420. // wx.request({
  421. // url: host + "orderapi/updateOrderInfo",
  422. // data: {
  423. // //user_id: un_id,
  424. // order_number: that.data.order_number,
  425. // order_type : 1,//订单最终状态标志位
  426. // order_Consignee: that.data.userName,
  427. // order_address: that.data.province + that.data.city + that.data.county + that.data.userAddress,
  428. // order_phone: that.data.userTelephone
  429. // },
  430. // method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  431. // header: {
  432. // 'Accept': 'application/json'
  433. // },
  434. // success: function (res) {
  435. // that.setData({
  436. // hiddenmodal: false,
  437. // modalCont: '礼物领取成功,等待迎接您的礼物上门吧'
  438. // })
  439. // setTimeout(function () {
  440. // that.setData({
  441. // hiddenmodal: true
  442. // })
  443. // prevPage.setData({
  444. // order_type: '1',
  445. // });
  446. // wx.navigateBack({
  447. // delta:2
  448. // })
  449. // }, 1500)
  450. // if (res == null || res.data == null) {
  451. // console.error('网络请求失败');
  452. // return;
  453. // }
  454. // }
  455. // })
  456. }
  457. })
  458. var that;
  459. var Util = require('../../utils/util.js');