changePrice.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. orders: '',
  8. order_goods: [],
  9. priceArr: [],
  10. orderGoodsIdArr: [],
  11. goodsTot: 0,
  12. changePrice: 0
  13. },
  14. id: 0,
  15. cansub: true,
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. let id = options.order_id || '';
  21. if(!id) {
  22. app.util.message('参数错误', '/lionfish_comshop/moduleB/supply/orderManage', 'error');
  23. return;
  24. }
  25. this.id = id;
  26. this.getData(id);
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. },
  33. getData: function(order_id) {
  34. wx.showLoading();
  35. let token = wx.getStorageSync('token');
  36. app.util.ProReq('order.order_change', {token, order_id, is_supply: 1}).then(res=>{
  37. let orders = res.orders;
  38. let order_goods = res.order_goods;
  39. let priceArr = [];
  40. let orderGoodsIdArr = [];
  41. order_goods.forEach(item=>{
  42. orderGoodsIdArr.push(item.order_goods_id);
  43. priceArr.push(0);
  44. })
  45. this.calcGoodsPrice(priceArr, orders);
  46. this.setData({
  47. orders,
  48. order_goods,
  49. priceArr,
  50. orderGoodsIdArr
  51. })
  52. }).catch(err=>{
  53. app.util.message(err.msg, 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  54. })
  55. },
  56. reduceIpt: function(e) {
  57. let type = e.currentTarget.dataset.type;
  58. let idx = e.currentTarget.dataset.idx;
  59. let { priceArr, order_goods } = this.data;
  60. let goodItem = order_goods[idx];
  61. let curPrice = priceArr[idx]*1;
  62. let max = goodItem.max_total*1;
  63. let min = -max;
  64. if(type=='add') {
  65. priceArr[idx] = (curPrice+1).toFixed(2);
  66. } else {
  67. if((curPrice-1)<min) {
  68. wx.showToast({
  69. title: "改价后的商品实付价格不能低于0.1元",
  70. icon: "none"
  71. })
  72. priceArr[idx] = (min + 0.1).toFixed(2);
  73. } else {
  74. priceArr[idx] = (curPrice-1).toFixed(2);
  75. }
  76. }
  77. this.calcGoodsPrice(priceArr);
  78. this.setData({ priceArr })
  79. },
  80. changeNumber: function (e) {
  81. let idx = e.currentTarget.dataset.idx;
  82. let val = parseFloat(e.detail.value);
  83. if(!val) val = 0;
  84. let { priceArr, order_goods } = this.data;
  85. let goodItem = order_goods[idx];
  86. let max = goodItem.max_total*1;
  87. let min = -max;
  88. console.log(val)
  89. if(val<min) {
  90. wx.showToast({
  91. title: "改价后的商品实付价格不能低于0.1元",
  92. icon: "none"
  93. })
  94. priceArr[idx] = (min + 0.1).toFixed(2);
  95. } else {
  96. priceArr[idx] = val.toFixed(2);
  97. }
  98. this.calcGoodsPrice(priceArr);
  99. this.setData({ priceArr })
  100. },
  101. calcGoodsPrice: function(priceArr, orders) {
  102. if(!orders) orders = this.data.orders;
  103. let old_price = orders.old_price*1;
  104. let buyer_total = orders.buyer_total*1;
  105. let changePrice = 0;
  106. priceArr.forEach(item=>{
  107. changePrice += item*1;
  108. })
  109. console.log(old_price)
  110. buyer_total += changePrice;
  111. changePrice += orders.changeprice*1;
  112. this.setData({
  113. goodsTot: (old_price+changePrice).toFixed(2),
  114. changePrice: changePrice.toFixed(2),
  115. buyer_total: buyer_total.toFixed(2)
  116. })
  117. },
  118. subChange: function() {
  119. if(!this.cansub) return;
  120. this.cansub = false;
  121. wx.showLoading();
  122. let token = wx.getStorageSync('token');
  123. let order_id = this.id;
  124. let { priceArr, orderGoodsIdArr } = this.data;
  125. let order_goods_id = orderGoodsIdArr.join(',');
  126. let change_price = priceArr.join(',');
  127. app.util.ProReq('order.order_changeprice', {token, order_id, is_supply: 1, order_goods_id,change_price}).then(res=>{
  128. wx.showToast({
  129. title: "改价成功",
  130. icon: "none"
  131. })
  132. setTimeout(() => {
  133. this.getData(order_id);
  134. this.cansub = true;
  135. }, 1500);
  136. }).catch(err=>{
  137. this.cansub = true;
  138. app.util.message(err.msg, '', 'error');
  139. })
  140. }
  141. })