buy.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const util = require('../../utils/util')
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. storeList:[],
  9. searchParams:{
  10. storeId:'',
  11. storeName:''
  12. },
  13. productList:[],
  14. totalPrice:0,
  15. sellProductList:[]
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.bindProductStockList()
  22. },
  23. bindStorePickerChange: function (e) {
  24. var item = this.data.storeList[e.detail.value]
  25. console.log(item)
  26. this.setData({
  27. ['searchParams.storeId']: item.id,
  28. ['searchParams.storeName']: item.storeName
  29. })
  30. this.bindProductStockList()
  31. },
  32. changeNum: function (e) {
  33. this.setData({
  34. skuStock: e.detail.value
  35. })
  36. },
  37. bindProductStockList() {
  38. //获取平台商品用来订货
  39. var that = this
  40. util.request(util.api.orderGoods, that.data.searchParams, "GET", false, true, app.globalData.token).then((res) => {
  41. if (res.code == 200) {
  42. console.log(res)
  43. res.result.forEach(item => {
  44. item.checkout = false
  45. item.skuStock = 0
  46. });
  47. that.setData({
  48. productList: res.result
  49. })
  50. }
  51. }).catch((res) => {})
  52. },
  53. skuStockChange(e){
  54. let that = this;
  55. let dataset = e.currentTarget.dataset;
  56. let value = e.detail.value;
  57. var list = that.data.productList
  58. var index = dataset.index;
  59. var itemProduct = dataset.item
  60. itemProduct.skuStock = value
  61. list.splice(index,1,itemProduct)
  62. that.setData({
  63. productList:list
  64. })
  65. var list = this.data.productList.filter((e)=>e.checkout == true && e.skuStock > 0)
  66. var totalPrice = 0
  67. list.forEach((e)=>{
  68. totalPrice += e.productPrice * e.skuStock
  69. })
  70. this.setData({
  71. totalPrice: totalPrice,
  72. sellProductList: list
  73. })
  74. },
  75. checkboxChange(e){
  76. let that = this;
  77. let dataset = e.currentTarget.dataset;
  78. let value = e.detail.value;
  79. var list = that.data.productList
  80. var index = dataset.index;
  81. var itemProduct = dataset.item
  82. itemProduct.checkout = value.length>0? true : false
  83. list.splice(index,1,itemProduct)
  84. that.setData({
  85. productList:list
  86. })
  87. var list = this.data.productList.filter((e)=>e.checkout == true && e.skuStock > 0)
  88. var totalPrice = 0
  89. list.forEach((e)=>{
  90. totalPrice += e.productPrice * e.skuStock
  91. })
  92. this.setData({
  93. totalPrice: totalPrice,
  94. sellProductList: list
  95. })
  96. },
  97. // btnPay(){
  98. // if(this.data.sellProductList.length<1){
  99. // util.toast('请选择下单商品,并且订货数量必须大于0')
  100. // return
  101. // }
  102. // console.log("1111")
  103. // console.log(this.data.sellProductList)
  104. // console.log("2222")
  105. // wx.navigateTo({
  106. // url: '/pages/orderGoods/submitBuy?strJson='+encodeURIComponent(JSON.stringify(this.data.sellProductList))+'&storeId='+this.data.searchParams.storeId,
  107. // })
  108. // }
  109. reserve(){
  110. if(this.data.sellProductList.length==0){
  111. util.toast('请选择订货商品')
  112. return;
  113. }
  114. var that = this;
  115. util.request(util.api.reserve, this.data.sellProductList, "post", false, true, app.globalData.token).then((res) => {
  116. if (res.code == 200) {
  117. util.toast('订货成功,等待平台审批')
  118. wx.navigateTo({
  119. url: '/pages/orderGoods/order',
  120. })
  121. }
  122. }).catch((res) => {})
  123. }
  124. })