detail.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. var app = getApp();
  2. Page({
  3. data: {
  4. is_heng: 1,
  5. rushList: [],
  6. current: 0
  7. },
  8. onLoad: function (options) {
  9. app.setShareConfig();
  10. let id = options.id || '';
  11. if (!id) {
  12. wx.showModal({
  13. title: '提示',
  14. content: '参数错误',
  15. showCancel: false,
  16. success(res) {
  17. if (res.confirm) {
  18. wx.redirectTo({
  19. url: '/lionfish_comshop/pages/index/index',
  20. })
  21. }
  22. }
  23. })
  24. return;
  25. }
  26. this.getData(id);
  27. this.get_goods_details(id);
  28. let showBackBtn = false;
  29. let pages_all = getCurrentPages();
  30. if (pages_all.length > 1) {
  31. showBackBtn = true;
  32. }
  33. this.setData({ showBackBtn })
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow: function () {
  39. },
  40. goDetails: function(){
  41. let goods = this.data.goods;
  42. let id = goods.id || '';
  43. id && wx.redirectTo({
  44. url: `/lionfish_comshop/pages/goods/goodsDetail?id=${id}`,
  45. })
  46. },
  47. get_goods_details: function (id) {
  48. let that = this;
  49. if (!id) {
  50. wx.hideLoading();
  51. wx.showModal({
  52. title: '提示',
  53. content: '参数错误',
  54. showCancel: false,
  55. confirmColor: '#F75451',
  56. success(res) {
  57. if (res.confirm) {
  58. wx.redirectTo({
  59. url: '/lionfish_comshop/pages/index/index',
  60. })
  61. }
  62. }
  63. })
  64. return false;
  65. }
  66. let token = wx.getStorageSync('token');
  67. let community = wx.getStorageSync('community');
  68. let community_id = community.communityId || '';
  69. app.util.request({
  70. url: 'entry/wxapp/index',
  71. data: {
  72. controller: 'goods.get_goods_detail',
  73. token: token,
  74. id,
  75. community_id
  76. },
  77. dataType: 'json',
  78. success: function (res) {
  79. wx.hideLoading();
  80. let goods = (res.data.data && res.data.data.goods) || '';
  81. // 商品不存在
  82. if (!goods || goods.length == 0 || Object.keys(goods) == '') {
  83. wx.showModal({
  84. title: '提示',
  85. content: '该商品不存在,回首页',
  86. showCancel: false,
  87. confirmColor: '#F75451',
  88. success(res) {
  89. if (res.confirm) {
  90. wx.switchTab({
  91. url: '/lionfish_comshop/pages/index/index',
  92. })
  93. }
  94. }
  95. })
  96. }
  97. that.currentOptions = res.data.data.options;
  98. that.setData({
  99. goods: goods,
  100. options: res.data.data.options,
  101. order: {
  102. goods_id: res.data.data.goods.goods_id,
  103. pin_id: res.data.data.pin_id,
  104. },
  105. share_title: goods.share_title,
  106. goods_image: res.data.data.goods_image
  107. })
  108. }
  109. })
  110. },
  111. getData: function (goodsId) {
  112. var token = wx.getStorageSync('token');
  113. var that = this;
  114. var cur_community = wx.getStorageSync('community');
  115. app.util.request({
  116. url: 'entry/wxapp/index',
  117. data: {
  118. controller: 'index.load_gps_goodslist',
  119. token: token,
  120. pageNum: 1,
  121. head_id: cur_community.communityId,
  122. per_page: 10000,
  123. is_video: 1
  124. },
  125. dataType: 'json',
  126. success: function (res) {
  127. if (res.data.code == 0) {
  128. let rdata = res.data;
  129. let rushList = rdata.list || [];
  130. let current = rushList.findIndex(item => item.actId == goodsId);
  131. that.setData({ rushList, current });
  132. }
  133. }
  134. })
  135. },
  136. changeSubject: function(t){
  137. let rushList = this.data.rushList;
  138. if (t < 0 || rushList.length<=1) {
  139. wx.showToast({
  140. title: "没有上一个视频了~",
  141. icon: "none",
  142. duration: 2000
  143. });
  144. } else {
  145. console.log(t);
  146. if (t>rushList.length-1) {
  147. wx.showToast({
  148. title: "没有下一个视频了~",
  149. icon: "none",
  150. duration: 2000
  151. });
  152. return;
  153. }
  154. var that = this;
  155. t = t || 0, that.setData({
  156. current: t
  157. }), this.get_goods_details(rushList[t].actId);
  158. }
  159. },
  160. pre: function(){
  161. this.changeSubject(this.data.current*1 - 1)
  162. },
  163. next: function () {
  164. this.changeSubject(this.data.current*1 + 1)
  165. },
  166. _backhome: function() {
  167. wx.switchTab({
  168. url: '/lionfish_comshop/pages/index/index',
  169. })
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function () {
  175. var goods = this.data.goods;
  176. var share_title = this.data.share_title;
  177. var share_id = wx.getStorageSync('member_id');
  178. var share_path = `lionfish_comshop/moduleA/video/detail?id=${goods.id}&share_id=${share_id}`;
  179. let shareImg = goods.goods_share_image;
  180. console.log('商品分享地址:', share_path);
  181. return {
  182. title: share_title,
  183. path: share_path,
  184. imageUrl: shareImg,
  185. success: function (res) {
  186. // 转发成功
  187. },
  188. fail: function (res) {
  189. // 转发失败
  190. }
  191. }
  192. },
  193. onShareTimeline: function() {
  194. var goods = this.data.goods;
  195. var share_title = this.data.share_title;
  196. var share_id = wx.getStorageSync('member_id');
  197. let shareImg = goods.goods_share_image;
  198. var query= `id=${goods.id}&share_id=${share_id}`;
  199. return {
  200. title: share_title,
  201. imageUrl: shareImg,
  202. query,
  203. success: function() {},
  204. fail: function() {}
  205. };
  206. }
  207. })