goods.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. var WxParse = require("../../wxParse/wxParse.js"),
  2. shoppingCart = require("../../components/shopping_cart/shopping_cart.js"),
  3. specificationsModel = require("../../components/specifications_model/specifications_model.js"),
  4. gSpecificationsModel = require("../../components/goods/specifications_model.js"),
  5. goodsBanner = require("../../components/goods/goods_banner.js"),
  6. goodsInfo = require("../../components/goods/goods_info.js"),
  7. goodsBuy = require("../../components/goods/goods_buy.js"),
  8. goodsRecommend = require("../../components/goods/goods_recommend.js"),
  9. p = 1,
  10. is_loading_comment = !1,
  11. is_more_comment = !0,
  12. share_count = 0;
  13. Page({
  14. data: {
  15. pageType: "STORE",
  16. id: null,
  17. topic_id: null,
  18. goods: {},
  19. show_attr_picker: !1,
  20. form: {
  21. number: 1
  22. },
  23. tab_detail: "active",
  24. tab_comment: "",
  25. comment_list: [],
  26. comment_count: {
  27. score_all: 0,
  28. score_3: 0,
  29. score_2: 0,
  30. score_1: 0
  31. },
  32. autoplay: !1,
  33. hide: "hide",
  34. show: !1,
  35. x: getApp().core.getSystemInfoSync().windowWidth,
  36. y: getApp().core.getSystemInfoSync().windowHeight - 20,
  37. page: 1,
  38. drop: !1,
  39. goodsModel: !1,
  40. goods_num: 0,
  41. temporaryGood: {
  42. price: 0,
  43. num: 0,
  44. use_attr: 1
  45. },
  46. goodNumCount: 0
  47. },
  48. onLoad: function (t) {
  49. console.log('传过来的数据',t)
  50. getApp().page.onLoad(this, t);
  51. var o = this;
  52. share_count = 0,
  53. is_more_comment = !(is_loading_comment = !(p = 1));
  54. var e = t.quick;
  55. if (e) {
  56. var a = getApp().core.getStorageSync(getApp().const.ITEM);
  57. if (a) var i = a.total,
  58. s = a.carGoods;
  59. else i = {
  60. total_price: 0,
  61. total_num: 0
  62. }, s = [];
  63. o.setData({
  64. quick: e,
  65. quick_list: a.quick_list,
  66. total: i,
  67. carGoods: s,
  68. quick_hot_goods_lists: a.quick_hot_goods_lists
  69. })
  70. }
  71. if ("undefined" == typeof my) {
  72. var n = decodeURIComponent(t.scene);
  73. if (void 0 !== n) {
  74. var d = getApp().helper.scene_decode(n);
  75. d.uid && d.gid && (t.id = d.gid)
  76. }
  77. } else if (null !== getApp().query) {
  78. var c = getApp().query;
  79. getApp().query = null, t.id = c.gid
  80. }
  81. o.setData({
  82. id: t.id,
  83. topic_id: t.topic_id
  84. }),
  85. o.getGoods(),
  86. o.getCommentList()
  87. },
  88. onReady: function () {
  89. getApp().page.onReady(this)
  90. },
  91. onShow: function () {
  92. getApp().page.onShow(this),
  93. shoppingCart.init(this),
  94. specificationsModel.init(this, shoppingCart),
  95. gSpecificationsModel.init(this),
  96. goodsBanner.init(this),
  97. goodsInfo.init(this),
  98. goodsBuy.init(this),
  99. goodsRecommend.init(this);
  100. var t = getApp().core.getStorageSync(getApp().const.ITEM);
  101. if (t) var o = t.total,
  102. e = t.carGoods,
  103. a = this.data.goods_num;
  104. else o = {
  105. total_price: 0,
  106. total_num: 0
  107. }, e = [], a = 0;
  108. this.setData({
  109. total: o,
  110. carGoods: e,
  111. goods_num: a
  112. })
  113. },
  114. onHide: function () {
  115. getApp().page.onHide(this), shoppingCart.saveItemData(this)
  116. },
  117. onUnload: function () {
  118. getApp().page.onUnload(this), shoppingCart.saveItemData(this)
  119. },
  120. onPullDownRefresh: function () {
  121. getApp().page.onPullDownRefresh(this)
  122. },
  123. onReachBottom: function () {
  124. getApp().page.onReachBottom(this);
  125. var t = this;
  126. "active" == t.data.tab_detail && t.data.drop ? (t.data.drop = !1, t.goods_recommend({
  127. goods_id: t.data.goods.id,
  128. loadmore: !0
  129. })) : "active" == t.data.tab_comment && t.getCommentList(!0)
  130. },
  131. onShareAppMessage: function () {
  132. getApp().page.onShareAppMessage(this);
  133. var o = this,
  134. t = getApp().getUser();
  135. return {
  136. path: "/pages/goods/goods?id=" + this.data.id + "&user_id=" + t.id,
  137. success: function (t) {
  138. 1 == ++share_count && o.shareSendCoupon(o)
  139. },
  140. title: o.data.goods.name,
  141. imageUrl: o.data.goods.pic_list[0]
  142. }
  143. },
  144. closeCouponBox: function (t) {
  145. this.setData({
  146. get_coupon_list: ""
  147. })
  148. },
  149. to_dial: function (t) {
  150. var o = this.data.store.contact_tel;
  151. getApp().core.makePhoneCall({
  152. phoneNumber: o
  153. })
  154. },
  155. getGoods: function () {
  156. var n = this;
  157. if (n.data.quick) {
  158. var t = n.data.carGoods;
  159. if (t) {
  160. for (var o = t.length, e = 0, a = 0; a < o; a++) t[a].goods_id == n.data.id && (e += parseInt(t[a].num));
  161. n.setData({
  162. goods_num: e
  163. })
  164. }
  165. }
  166. let data = {}
  167. if(n.data.topic_id == undefined || n.data.topic_id == null || n.data.topic_id == ''){
  168. data = {
  169. id: n.data.id
  170. }
  171. }else{
  172. data = {
  173. id: n.data.id,
  174. topic_id: n.data.topic_id
  175. }
  176. }
  177. getApp().request({
  178. url: getApp().api.default.goods,
  179. data: data,
  180. success: function (t) {
  181. if (0 == t.code) {
  182. var o = t.data.detail;
  183. WxParse.wxParse("detail", "html", o, n);
  184. var e = t.data;
  185. e.attr_pic = t.data.attr_pic, e.cover_pic = t.data.pic_list[0].pic_url;
  186. var a = e.pic_list,
  187. i = [];
  188. for (var s in a) i.push(a[s].pic_url);
  189. e.pic_list = i, n.setData({
  190. goods: e,
  191. attr_group_list: t.data.attr_group_list,
  192. btn: !0
  193. }), n.goods_recommend({
  194. goods_id: t.data.id,
  195. reload: !0
  196. }), n.selectDefaultAttr()
  197. }
  198. 1 == t.code && getApp().core.showModal({
  199. title: "提示",
  200. content: t.msg,
  201. showCancel: !1,
  202. success: function (t) {
  203. t.confirm && getApp().core.switchTab({
  204. url: "/pages/index/index"
  205. })
  206. }
  207. })
  208. }
  209. })
  210. },
  211. getCommentList: function (o) {
  212. var e = this;
  213. o && "active" != e.data.tab_comment || is_loading_comment || is_more_comment && (is_loading_comment = !0, getApp().request({
  214. url: getApp().api.default.comment_list,
  215. data: {
  216. goods_id: e.data.id,
  217. page: p
  218. },
  219. success: function (t) {
  220. 0 == t.code && (is_loading_comment = !1, p++, e.setData({
  221. comment_count: t.data.comment_count,
  222. comment_list: o ? e.data.comment_list.concat(t.data.list) : t.data.list
  223. }), 0 == t.data.list.length && (is_more_comment = !1))
  224. }
  225. }))
  226. },
  227. tabSwitch: function (t) {
  228. "detail" == t.currentTarget.dataset.tab ? this.setData({
  229. tab_detail: "active",
  230. tab_comment: ""
  231. }) : this.setData({
  232. tab_detail: "",
  233. tab_comment: "active"
  234. })
  235. },
  236. commentPicView: function (t) {
  237. var o = t.currentTarget.dataset.index,
  238. e = t.currentTarget.dataset.picIndex;
  239. getApp().core.previewImage({
  240. current: this.data.comment_list[o].pic_list[e],
  241. urls: this.data.comment_list[o].pic_list
  242. })
  243. }
  244. });