index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Copyright (C) 2018-2019
  3. * All rights reserved, Designed By www.joolun.com
  4. * 注意:
  5. * 本软件为www.joolun.com开发研制,项目使用请保留此说明
  6. */
  7. const app = getApp()
  8. Page({
  9. data: {
  10. orderConfirmData: [],
  11. salesPrice: 0,
  12. paymentPrice: 0,
  13. freightPrice: 0,
  14. userAddress: null,
  15. orderSubParm: {
  16. paymentType: '1',
  17. deliveryWay: '1'
  18. },
  19. loading: false,
  20. userInfo: null,
  21. spuIds: [],
  22. },
  23. onShow() {
  24. },
  25. onLoad: function () {
  26. this.userAddressPage()
  27. this.userInfoGet()
  28. this.orderConfirmDo()
  29. },
  30. deliveryWayChange(e){
  31. this.setData({
  32. [`orderSubParm.deliveryWay`]: e.detail.value,
  33. freightMap: null
  34. })
  35. this.orderConfirmDo()
  36. },
  37. orderConfirmDo(){
  38. // 本地获取参数信息
  39. let that = this
  40. wx.getStorage({
  41. key: 'param-orderConfirm',
  42. success: function (res) {
  43. let orderConfirmData = res.data
  44. let salesPrice = 0 //订单金额
  45. let freightPrice = 0 //运费
  46. let spuIds = null
  47. orderConfirmData.forEach((orderConfirm, index) => {
  48. if (spuIds) {
  49. spuIds = spuIds + ',' + orderConfirm.spuId
  50. } else {
  51. spuIds = orderConfirm.spuId
  52. }
  53. salesPrice = (Number(salesPrice) + orderConfirm.salesPrice * orderConfirm.quantity).toFixed(2)
  54. orderConfirm.paymentPrice = (orderConfirm.salesPrice * orderConfirm.quantity).toFixed(2)
  55. //计算运费
  56. orderConfirm.freightPrice = 0
  57. freightPrice = (Number(freightPrice) + Number(orderConfirm.freightPrice)).toFixed(2)
  58. })
  59. that.setData({
  60. orderConfirmData: orderConfirmData,
  61. salesPrice: salesPrice,
  62. freightPrice: freightPrice,
  63. paymentPrice: salesPrice,
  64. spuIds: spuIds
  65. })
  66. }
  67. })
  68. },
  69. //计算运费
  70. countFreight(orderConfirm, freightTemplat, quantity){
  71. },
  72. //获取默认收货地址
  73. userAddressPage() {
  74. app.api.userAddressPage(
  75. {
  76. searchCount: false,
  77. current: 1,
  78. size: 1,
  79. isDefault: '1'
  80. })
  81. .then(res => {
  82. let records = res.data.records
  83. if (records && records.length > 0){
  84. this.setData({
  85. userAddress: records[0]
  86. })
  87. }
  88. })
  89. },
  90. //获取商城用户信息
  91. userInfoGet() {
  92. app.api.wxUserGet()
  93. .then(res => {
  94. this.setData({
  95. userInfo: res.data
  96. })
  97. })
  98. },
  99. userMessageInput(e){
  100. this.setData({
  101. [`orderSubParm.userMessage`]: e.detail.value
  102. })
  103. },
  104. //提交订单
  105. orderSub(){
  106. let that = this
  107. let userAddress = that.data.userAddress
  108. if (that.data.orderSubParm.deliveryWay == '1' && userAddress == null){
  109. wx.showToast({
  110. title: '请选择收货地址',
  111. icon: 'none',
  112. duration: 2000
  113. })
  114. return
  115. }
  116. that.setData({
  117. loading: true
  118. })
  119. let orderSubParm = that.data.orderSubParm
  120. orderSubParm.skus = that.data.orderConfirmData
  121. app.api.orderSub(Object.assign(
  122. {},
  123. { userAddressId: that.data.orderSubParm.deliveryWay == '1' ? userAddress.id : null},
  124. orderSubParm
  125. ))
  126. .then(res => {
  127. wx.redirectTo({
  128. url: '/pages/order/order-detail/index?callPay=true&id=' + res.data.id
  129. })
  130. }).catch(() => {
  131. that.setData({
  132. loading: false
  133. })
  134. })
  135. }
  136. })