accounts.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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;
  77. //生成订单
  78. goodsList.forEach(res=>{
  79. res['userId'] = app.globalData.user_id, //'oovpNwjlsY6xx8ceCebFa1dOLd9E',
  80. res['adress'] = '虹漕路88号',
  81. res['area'] = '闵行区',
  82. res['city'] = '上海市',
  83. res['province'] = '上海市',
  84. res['consignee'] = '阿哥子',
  85. res['phone'] = '18888888888'
  86. });
  87. // let params = {
  88. // userId: 'oovpNwjlsY6xx8ceCebFa1dOLd9E', //app.globalData.user_id,
  89. // adress: '',// string 街道
  90. // area: '闵行区',// string 区
  91. // city: '上海市',// string 市
  92. // province: '上海市',// string 省
  93. // consignee: '王勇',// string 收件人
  94. // phone: '15055166539',// string 收件人电话
  95. // shopCarList: [...that.data.goodsList]
  96. // }
  97. wx.request({
  98. url: host + '/createNewOrderCustomer',
  99. method:'post',
  100. // header: {
  101. // 'content-type': 'application/x-www-form-urlencoded'
  102. // },
  103. data: {
  104. shopCarList:goodsList
  105. },
  106. success(res){
  107. console.log(res)
  108. }
  109. })
  110. },
  111. addressBtn(){
  112. wx.navigateTo({
  113. url: '/customized/pages/address/address',
  114. })
  115. }
  116. })