checkout.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. var dateArray = [];
  5. Page({
  6. data: {
  7. checkedGoodsList: [],
  8. addressVo: {},
  9. checkedCoupon: [],
  10. couponList: [],
  11. goodsTotalPrice: 0.00, //商品总价
  12. freightPrice: 0.00, //快递费
  13. couponPrice: 0.00, //优惠券的价格
  14. orderTotalPrice: 0.00, //订单总价
  15. actualPrice: 0.00, //实际需要支付的总价
  16. userCouponId: 0,
  17. fullCutCouponId: 0,
  18. fullCutCouponDec: 0, //满减优惠券
  19. postscript: "",
  20. checkStore: false,
  21. storeVo: {},
  22. delivery_date: '',
  23. delivery_remark: '尽快送达',
  24. multiArray: [],
  25. multiIndex: [0, 0],
  26. timeArray:util.getNowTimeArray()
  27. },
  28. bindMultiPickerColumnChange: function (e) {
  29. let that = this;
  30. console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
  31. var data = {
  32. multiArray: this.data.multiArray,
  33. multiIndex: this.data.multiIndex
  34. };
  35. data.multiIndex[e.detail.column] = e.detail.value
  36. if (e.detail.column == 0){
  37. data.multiIndex[1] = 0
  38. }
  39. let timeArray = that.data.timeArray;
  40. if (data.multiIndex[0] == 1){
  41. timeArray = util.timeArray.slice(0);
  42. }else{
  43. timeArray = util.getNowTimeArray();
  44. }
  45. data.timeArray = timeArray;
  46. data.multiArray[1] = timeArray;
  47. this.setData(data)
  48. },
  49. bindMultiPickerChange: function (e) {
  50. let that = this;
  51. console.log('picker发送选择改变,携带值为', e.detail.value)
  52. this.setData({
  53. multiIndex: e.detail.value,
  54. delivery_date: dateArray[e.detail.value[0]],
  55. delivery_remark: e.detail.value[0] == 0 ? that.data.timeArray[e.detail.value[1]] : that.data.timeArray[e.detail.value[1]]
  56. })
  57. console.log('delivery_date', this.data.delivery_date, ',delivery_remark', this.data.delivery_remark)
  58. },
  59. initPicker(){
  60. let that = this;
  61. let date = new Date();
  62. let hours = date.getHours();
  63. let minutes = date.getMinutes();
  64. let index = 0;
  65. var today = util.getNowTime();
  66. var tomorrow = util.getDateStr(new Date(),1);
  67. dateArray = [today, tomorrow];
  68. this.setData({
  69. 'multiArray[0]': dateArray,
  70. 'multiArray[1]': that.data.timeArray,
  71. })
  72. },
  73. getCheckoutInfo: function () {
  74. let that = this;
  75. util.request(api.CartCheckout, { userCouponId: that.data.userCouponId }).then(function (res) {
  76. if (res.errno === 0) {
  77. console.log(res.data);
  78. that.setData({
  79. checkedGoodsList: res.data.checkedGoodsList,
  80. actualPrice: res.data.actualPrice,
  81. // addressVo: res.data.addressVo,
  82. checkedCoupon: res.data.checkedCoupon,
  83. couponList: res.data.couponList,
  84. fullCutCouponId: res.data.fullCutCouponId,
  85. couponPrice: res.data.couponPrice,
  86. freightPrice: res.data.freightPrice,
  87. goodsTotalPrice: res.data.goodsTotalPrice,
  88. orderTotalPrice: res.data.orderTotalPrice,
  89. fullCutCouponDec: res.data.fullCutCouponDec
  90. });
  91. if (that.data.addressVo != null && null == that.data.addressVo.id){
  92. that.setData({
  93. addressVo: res.data.addressVo
  94. });
  95. }
  96. // 选择优惠券
  97. if (that.data.userCouponId && that.data.couponList.length > 0) {
  98. for (var i = 0; i < that.data.couponList.length; i++) {
  99. if (that.data.userCouponId == that.data.couponList[i].id) {
  100. that.setData({
  101. checkedCoupon: that.data.couponList[i],
  102. couponPrice: that.data.couponList[i].type_money
  103. });
  104. break;
  105. }
  106. }
  107. }
  108. }
  109. wx.hideLoading();
  110. that.checkStore();
  111. });
  112. },
  113. selectAddress() {
  114. this.setData({
  115. checkStore: false
  116. });
  117. wx.navigateTo({
  118. url: '/pages/shopping/address/address',
  119. })
  120. },
  121. addAddress() {
  122. wx.navigateTo({
  123. url: '/pages/shopping/addressAdd/addressAdd',
  124. })
  125. },
  126. selectCoupon() {
  127. let that = this;
  128. wx.navigateTo({
  129. url: '/pages/shopping/coupon/coupon',
  130. })
  131. },
  132. bindPostscriptBlur(e) {
  133. let postscript = e.detail.value;
  134. this.setData({
  135. postscript: postscript
  136. });
  137. },
  138. submitOrder: function (e) {
  139. console.log(e.detail.formId);
  140. if (!this.data.addressVo) {
  141. util.showErrorToast('请选择收货地址');
  142. return false;
  143. }
  144. // if (!this.data.checkStore || !this.data.checkStore) {
  145. // util.showErrorToast('超过门店配送范围');
  146. // return false;
  147. // }
  148. let that = this;
  149. util.request(api.OrderSubmit, {
  150. checkedAddress: that.data.addressVo,
  151. userCouponId: that.data.userCouponId,
  152. fullCutCouponId: that.data.fullCutCouponId,
  153. postscript: that.data.postscript,
  154. delivery_date: that.data.delivery_date,
  155. delivery_remark: that.data.delivery_remark
  156. }, 'POST').then(function (res) {
  157. if (res.errno === 0) {
  158. let actualPrice = that.data.actualPrice;
  159. let orderIds = [];
  160. for (let i = 0; i < res.data.orderInfo.length; i++){
  161. orderIds[i] = res.data.orderInfo[i].id;
  162. }
  163. console.log(actualPrice);
  164. console.log(orderIds);
  165. wx.redirectTo({
  166. url: '/pages/pay/pay?orderIds=' + orderIds + '&actualPrice=' + actualPrice
  167. })
  168. } else {
  169. wx.showModal({
  170. title: '提示信息',
  171. content: res.errmsg,
  172. showCancel: false
  173. });
  174. // util.showErrorToast(res.errmsg);
  175. }
  176. });
  177. },
  178. // 校验门店
  179. checkStore: function () {
  180. let that = this;
  181. util.request(api.CheckStore, {
  182. checkedAddress: that.data.addressVo,
  183. storeId: wx.getStorageSync('storeId')
  184. }, 'POST').then(function (res) {
  185. // if (res.errno === 0) {
  186. // that.setData({
  187. // storeVo: res.data,
  188. // checkStore: true
  189. // });
  190. // } else if (res.errno === 1) {
  191. // console.log(res.errmsg);
  192. // util.showErrorToast(res.errmsg);
  193. // that.setData({
  194. // checkStore: false
  195. // });
  196. // }
  197. that.setData({
  198. storeVo: res.data,
  199. checkStore: true
  200. });
  201. });
  202. },
  203. onLoad: function (options) {
  204. // 页面初始化 options为页面跳转所带来的参数
  205. },
  206. onReady: function () {
  207. // 页面渲染完成
  208. },
  209. onShow: function () {
  210. // 页面显示
  211. wx.showLoading({
  212. title: '加载中...',
  213. })
  214. this.getCheckoutInfo();
  215. this.initPicker()
  216. },
  217. onHide: function () {
  218. // 页面隐藏
  219. },
  220. onUnload: function () {
  221. // 页面关闭
  222. }
  223. })