scoreCartMixin.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. var a = require("../utils/public");
  2. var app = getApp();
  3. var status = require('../utils/index.js');
  4. var util = require('../utils/util.js');
  5. module.exports = {
  6. data: {
  7. visible: false,
  8. stopClick: false,
  9. updateCart: 0
  10. },
  11. vipModal: function(t) {
  12. this.setData(t.detail)
  13. },
  14. authModal: function (t = false) {
  15. t.detail && this.setData({ needAuth: true });
  16. if (this.data.needAuth) {
  17. this.setData({ showAuthModal: !this.data.showAuthModal });
  18. return false;
  19. }
  20. return true;
  21. },
  22. openSku: function (t) {
  23. if (!this.authModal()) return;
  24. var that = this,
  25. e = t.detail;
  26. var goods_id = e.actId;
  27. var options = e.skuList;
  28. that.setData({
  29. addCar_goodsid: goods_id
  30. })
  31. let list = options.list || [];
  32. let arr = [];
  33. if (list.length > 0) {
  34. for (let i = 0; i < list.length; i++) {
  35. let sku = list[i]['option_value'][0];
  36. let temp = {
  37. name: sku['name'],
  38. id: sku['option_value_id'],
  39. index: i,
  40. idx: 0
  41. };
  42. arr.push(temp);
  43. }
  44. //把单价剔除出来begin
  45. var id = '';
  46. for (let i = 0; i < arr.length; i++) {
  47. if (i == arr.length - 1) {
  48. id = id + arr[i]['id'];
  49. } else {
  50. id = id + arr[i]['id'] + "_";
  51. }
  52. }
  53. var cur_sku_arr = options.sku_mu_list[id];
  54. that.setData({
  55. sku: arr,
  56. sku_val: 1,
  57. cur_sku_arr: cur_sku_arr,
  58. skuList: e.skuList,
  59. visible: true,
  60. showSku: true
  61. });
  62. } else {
  63. let goodsInfo = e.skuList;
  64. that.setData({
  65. sku: [],
  66. sku_val: 1,
  67. skuList: [],
  68. cur_sku_arr: goodsInfo
  69. })
  70. let formIds = {
  71. detail: {
  72. formId: ""
  73. }
  74. };
  75. formIds.detail.formId = "the formId is a mock one";
  76. that.gocarfrom(formIds);
  77. }
  78. },
  79. /**
  80. * 确认加入购物车
  81. */
  82. gocarfrom: function (e) {
  83. var that = this;
  84. var is_just_addcar = 1;
  85. wx.showLoading();
  86. a.collectFormIds(e.detail.formId);
  87. that.goOrder();
  88. },
  89. goOrder: function () {
  90. let that = this;
  91. let tdata = that.data;
  92. if (tdata.can_car) {
  93. tdata.can_car = false;
  94. }
  95. var token = wx.getStorageSync('token');
  96. var community = wx.getStorageSync('community');
  97. var community_id = community.communityId;
  98. var goods_id = tdata.addCar_goodsid;
  99. var quantity = tdata.sku_val;
  100. var cur_sku_arr = tdata.cur_sku_arr;
  101. var sku_str = '';
  102. var is_just_addcar = 1;
  103. if (cur_sku_arr && cur_sku_arr.option_item_ids) {
  104. sku_str = cur_sku_arr.option_item_ids;
  105. }
  106. let data = {
  107. goods_id,
  108. community_id,
  109. quantity,
  110. sku_str,
  111. buy_type: 'integral',
  112. pin_id: 0,
  113. is_just_addcar
  114. }
  115. util.addCart(data).then(res=>{
  116. if(res.showVipModal==1) {
  117. let { pop_vipmember_buyimage } = res.data;
  118. that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
  119. } else {
  120. if (res.data.code == 3 || res.data.code == 7) {
  121. wx.showToast({
  122. title: res.data.msg,
  123. icon: 'none',
  124. duration: 2000
  125. })
  126. } else if (res.data.code == 4) {
  127. wx.showToast({
  128. title: '您未登录',
  129. duration: 2000,
  130. success: () => {
  131. that.setData({
  132. needAuth: true
  133. })
  134. }
  135. })
  136. } else if (res.data.code == 6) {
  137. var msg = res.data.msg;
  138. wx.showToast({
  139. title: msg,
  140. icon: 'none',
  141. duration: 2000
  142. })
  143. } else {
  144. if (is_just_addcar == 1) {
  145. that.closeSku();
  146. var pages_all = getCurrentPages();
  147. if (pages_all.length > 3) {
  148. wx.redirectTo({
  149. url: `/lionfish_comshop/pages/order/placeOrder?type=integral`,
  150. })
  151. } else {
  152. wx.navigateTo({
  153. url: `/lionfish_comshop/pages/order/placeOrder?type=integral`,
  154. })
  155. }
  156. }
  157. }
  158. }
  159. })
  160. },
  161. /**
  162. * 关闭购物车选项卡
  163. */
  164. closeSku: function () {
  165. this.setData({
  166. visible: false,
  167. stopClick: false
  168. });
  169. }
  170. }