goods_buy.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. module.exports = {
  2. currentPage: null,
  3. init: function (t) {
  4. var a = this;
  5. void 0 === (a.currentPage = t).favoriteAdd && (t.favoriteAdd = function (t) {
  6. a.favoriteAdd(t)
  7. }), void 0 === t.favoriteRemove && (t.favoriteRemove = function (t) {
  8. a.favoriteRemove(t)
  9. }), void 0 === t.kfMessage && (t.kfMessage = function (t) {
  10. a.kfMessage(t)
  11. }), void 0 === t.callPhone && (t.callPhone = function (t) {
  12. a.callPhone(t)
  13. }), void 0 === t.addCart && (t.addCart = function (t) {
  14. a.addCart(t)
  15. }), void 0 === t.buyNow && (t.buyNow = function (t) {
  16. a.buyNow(t)
  17. }), void 0 === t.goHome && (t.goHome = function (t) {
  18. a.goHome(t)
  19. })
  20. },
  21. favoriteAdd: function () {
  22. var e = this.currentPage;
  23. getApp().request({
  24. url: getApp().api.user.favorite_add,
  25. method: "post",
  26. data: {
  27. goods_id: e.data.goods.id
  28. },
  29. success: function (t) {
  30. if (0 == t.code) {
  31. var a = e.data.goods;
  32. a.is_favorite = 1, e.setData({
  33. goods: a
  34. })
  35. }
  36. }
  37. })
  38. },
  39. favoriteRemove: function () {
  40. var e = this.currentPage;
  41. getApp().request({
  42. url: getApp().api.user.favorite_remove,
  43. method: "post",
  44. data: {
  45. goods_id: e.data.goods.id
  46. },
  47. success: function (t) {
  48. if (0 == t.code) {
  49. var a = e.data.goods;
  50. a.is_favorite = 0, e.setData({
  51. goods: a
  52. })
  53. }
  54. }
  55. })
  56. },
  57. kfMessage: function () {
  58. getApp().core.getStorageSync(getApp().const.STORE).show_customer_service || getApp().core.showToast({
  59. title: "未启用客服功能"
  60. })
  61. },
  62. callPhone: function (t) {
  63. getApp().core.makePhoneCall({
  64. phoneNumber: t.target.dataset.info
  65. })
  66. },
  67. addCart: function () {
  68. this.currentPage.data.btn && this.submit("ADD_CART")
  69. },
  70. buyNow: function () {
  71. this.currentPage.data.btn && this.submit("BUY_NOW")
  72. },
  73. submit: function (t) {
  74. var a = this.currentPage;
  75. if (!a.data.show_attr_picker) return a.setData({
  76. show_attr_picker: !0
  77. }), !0;
  78. if (a.data.miaosha_data && 0 < a.data.miaosha_data.rest_num && a.data.form.number > a.data.miaosha_data.rest_num) return getApp().core.showToast({
  79. title: "商品库存不足,请选择其它规格或数量",
  80. image: "/images/icon-warning.png"
  81. }), !0;
  82. if (a.data.form.number > a.data.goods.num) return getApp().core.showToast({
  83. title: "商品库存不足,请选择其它规格或数量",
  84. image: "/images/icon-warning.png"
  85. }), !0;
  86. var e = a.data.attr_group_list,
  87. o = [];
  88. for (var r in e) {
  89. var i = !1;
  90. for (var s in e[r].attr_list)
  91. if (e[r].attr_list[s].checked) {
  92. i = {
  93. attr_id: e[r].attr_list[s].attr_id,
  94. attr_name: e[r].attr_list[s].attr_name
  95. };
  96. break
  97. } if (!i) return getApp().core.showToast({
  98. title: "请选择" + e[r].attr_group_name,
  99. image: "/images/icon-warning.png"
  100. }), !0;
  101. o.push({
  102. attr_group_id: e[r].attr_group_id,
  103. attr_id: i.attr_id
  104. })
  105. }
  106. if ("ADD_CART" == t && (getApp().core.showLoading({
  107. title: "正在提交",
  108. mask: !0
  109. }), getApp().request({
  110. url: getApp().api.cart.add_cart,
  111. method: "POST",
  112. data: {
  113. goods_id: a.data.goods.id,
  114. attr: JSON.stringify(o),
  115. num: a.data.form.number
  116. },
  117. success: function (t) {
  118. getApp().core.hideLoading(), getApp().core.showToast({
  119. title: t.msg,
  120. duration: 1500
  121. }), a.setData({
  122. show_attr_picker: !1
  123. })
  124. }
  125. })), "BUY_NOW" == t) {
  126. a.setData({
  127. show_attr_picker: !1
  128. });
  129. var d = [];
  130. d.push({
  131. goods_id: a.data.id,
  132. num: a.data.form.number,
  133. attr: o
  134. });
  135. var n = a.data.goods,
  136. g = 0;
  137. null != n.mch && (g = n.mch.id);
  138. var u = [];
  139. u.push({
  140. mch_id: g,
  141. goods_list: d
  142. }), getApp().core.redirectTo({
  143. url: "/pages/new-order-submit/new-order-submit?mch_list=" + JSON.stringify(u)
  144. })
  145. }
  146. },
  147. goHome: function (t) {
  148. var a = this.currentPage.data.pageType;
  149. if ("PINTUAN" === a) var e = "/pages/pt/index/index";
  150. else if ("BOOK" === a) e = "/pages/book/index/index";
  151. else e = "/pages/index/index";
  152. getApp().core.redirectTo({
  153. url: e
  154. })
  155. }
  156. };