submitOrder.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // pages/groupmeallist/submitOrder/submitOrder.js
  2. import storeGoods from '../../../api/storeGoods'
  3. const cache = require('../../../utils/cache.js');
  4. import base from '../../../utils/base'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. orderGoodList: [{}, {}, {}, {}],
  11. store: {},
  12. phone: '',
  13. storeWay: '',
  14. addressvaule:'',
  15. addressId:'',
  16. showAllSku: false,
  17. isShowPannel: false,
  18. forSelectList: [],
  19. discoutTitle: '',
  20. couponSn: '',
  21. orderMode: '',
  22. discountPriceY: ''
  23. },
  24. //全部显示和收起
  25. handleFlodExtend() {
  26. this.setData({
  27. showAllSku: !this.data.showAllSku
  28. })
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. let addressvaule = options.addressvalue
  35. let addressId = options.addressId
  36. if(addressvaule !=null && addressId!=null ){
  37. this.setData({
  38. addressvaule:addressvaule,
  39. addressId:addressId
  40. })
  41. }
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow: function () {
  52. let store = cache.getCurrStore();
  53. let storeWay = cache.getStoreWay()
  54. console.log(store)
  55. console.log(storeWay)
  56. if (store != null) {
  57. this.setData({
  58. store: store,
  59. storeWay: storeWay
  60. })
  61. }
  62. this.loadCartData();
  63. this.getUseConfirmOrderCoupon()
  64. },
  65. // 自动获取手机号
  66. getPhone() {
  67. let phone = cache.getMobile()
  68. this.setData({
  69. phone: phone
  70. })
  71. },
  72. // 选择收货地址
  73. chooseAdress() {
  74. wx.redirectTo({
  75. url: '../address/address?isreturn=' + 'true',
  76. })
  77. },
  78. getUseConfirmOrderCoupon() {
  79. storeGoods.orderCouponForSelect({
  80. storeId: cache.getStoreId(),
  81. mobile: cache.getMobile(),
  82. // tableId: 1
  83. }).then(res => {
  84. if (res.code == 200) {
  85. this.setData({
  86. forSelectList: res.data
  87. })
  88. }
  89. }).catch(_ => {
  90. // // this.setData({
  91. // // isShowPannel: true
  92. // // })
  93. // this.tapSex()
  94. console.log(_)
  95. })
  96. },
  97. /**
  98. * 加载购物车数据
  99. */
  100. loadCartData() {
  101. storeGoods.getCartData(cache.getStoreId(), cache.getMobile(), null, null).then(res => {
  102. if (res.code == 200) {
  103. this.cartDataMapToView(res.data)
  104. }
  105. }).catch(_ => {
  106. console.log(_)
  107. })
  108. },
  109. cartDataMapToView(data) {
  110. var isShowCartPannel = true;
  111. if (base.isEmpty(data.skuList) || data.skuList.length == 0) {
  112. isShowCartPannel = false
  113. data.totalPriceY = "0.00"
  114. data.totalNum = 0
  115. }
  116. // let skuList = data.skuList || []
  117. // skuList.forEach(sku => {
  118. // if (!base.isEmpty(sku.specList)) {
  119. // let specValueList = []
  120. // sku.specList.forEach(spec => {
  121. // specValueList.push(spec.specValue)
  122. // })
  123. // sku.specDes = specValueList.join("、")
  124. // } else {
  125. // sku.specDes = ""
  126. // }
  127. // sku.allFee = base.fenToYuan(sku.num * sku.price)
  128. // sku.allOriFee = base.fenToYuan(sku.num * sku.oriPrice)
  129. // })
  130. this.setData({
  131. isValid: data.skuList.length > 0,
  132. skuList: data.skuList,
  133. areaName: data.areaName,
  134. tableCode: data.tableCode,
  135. totalNum: data.totalNum,
  136. totalOriPriceY: data.totalOriPriceY,
  137. totalPriceY: data.totalPriceY - data.discountPriceY,
  138. totalPrice: data.totalPrice,
  139. totalOriPrice: data.totalOriPrice,
  140. discountPriceY: data.discountPriceY
  141. })
  142. },
  143. // 详情和收起
  144. changeCollapseOrDetail: function (e) {
  145. let idx = e.currentTarget.dataset.idx;
  146. var that = this;
  147. that.data.skuList[idx].show = !that.data.skuList[idx].show
  148. that.setData({
  149. skuList: that.data.skuList
  150. });
  151. console.log("购物车详情");
  152. console.log(that.data.skuList);
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. }
  179. })