accounts.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. let app = getApp();
  2. let host = app.globalData.servsers; // 请求的url
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. goodsList:[],
  9. host: app.globalData.servsers,
  10. amount:'',
  11. address:{},// 地址为空
  12. },
  13. onLoad(){
  14. let that =this;
  15. wx.request({
  16. url: host + '/adressapi/getdefaustAdress',
  17. method:'get',
  18. data:{
  19. user_id: app.globalData.user_id
  20. },
  21. header: {
  22. 'content-type': 'application/x-www-form-urlencoded'
  23. },
  24. success(res){
  25. console.log(res,"获取默认地址")
  26. that.setData({
  27. address: res.data
  28. })
  29. }
  30. })
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. let goodsList=[],that=this;
  37. let address = wx.getStorageSync('accountAddress');
  38. console.log(address,"addressaddress")
  39. if (address){
  40. that.setData({
  41. address: address
  42. })
  43. }
  44. goodsList = [...wx.getStorageSync('goodsList')];
  45. that.setData({
  46. goodsList: goodsList,
  47. amount: wx.getStorageSync('amount')
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload: function () {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh: function () {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom: function () {
  69. },
  70. /**
  71. * 用户点击右上角分享
  72. */
  73. onShareAppMessage: function () {
  74. },
  75. submitOrder(){
  76. let that = this, goodsList = that.data.goodsList, address = that.data.address;
  77. //生成订单
  78. goodsList.forEach(res=>{
  79. res['userId'] = app.globalData.user_id; //'oovpNwjlsY6xx8ceCebFa1dOLd9E',
  80. res['adress'] = address.adress;
  81. res['area'] = address.area;
  82. res['city'] = address.city;
  83. res['province'] = address.province;
  84. res['consignee'] = address.consignee;
  85. res['phone'] = address.phone;
  86. delete res.imgArray
  87. });
  88. wx.request({
  89. url: host + '/createNewOrderCustomer',
  90. method:'post',
  91. data: {
  92. shopCarList:JSON.stringify(goodsList)
  93. },
  94. success(res){
  95. console.log(res)
  96. }
  97. })
  98. },
  99. addressBtn(){
  100. wx.navigateTo({
  101. url: '/customized/pages/address/address',
  102. })
  103. }
  104. })