accounts.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. wx.showLoading({
  77. title:'结算中...'
  78. })
  79. let that = this, goodsList = that.data.goodsList, address = that.data.address;
  80. //生成订单
  81. goodsList.forEach(res=>{
  82. res['userId'] = app.globalData.user_id; //'oovpNwjlsY6xx8ceCebFa1dOLd9E',
  83. res['adress'] = address.adress;
  84. res['area'] = address.area;
  85. res['city'] = address.city;
  86. res['province'] = address.province;
  87. res['consignee'] = address.consignee;
  88. res['phone'] = address.phone;
  89. res['openId'] = app.globalData.openid;
  90. delete res.imgArray
  91. });
  92. wx.request({
  93. url: host + '/createNewOrderCustomer',
  94. method:'post',
  95. data: {
  96. shopCarList:JSON.stringify(goodsList)
  97. },
  98. success(el){
  99. let res = el.data;
  100. console.log(res)
  101. wx.requestPayment({
  102. timeStamp: res.timeStamp,
  103. nonceStr: res.nonceStr,
  104. package: res.pkg,
  105. signType: res.signType,
  106. paySign: res.sign,
  107. success(res){
  108. console.log(res,"结算结果")
  109. },
  110. fail(err){
  111. wx.showToast({
  112. title: err.errMsg,
  113. icon:'error'
  114. })
  115. console.log(err)
  116. },
  117. complete(){
  118. wx.hideLoading()
  119. }
  120. })
  121. }
  122. })
  123. },
  124. addressBtn(){
  125. wx.navigateTo({
  126. url: '/customized/pages/address/address',
  127. })
  128. }
  129. })