list.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. mixins: [require('../../mixin/cartMixin.js')],
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. list: [],
  10. specialList: [],
  11. navBackUrl: '/lionfish_comshop/moduleA/special/list'
  12. },
  13. page: 1,
  14. noMore: false,
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. app.setShareConfig();
  20. if (options.share_id != 'undefined' && options.share_id > 0) wx.setStorageSync('share_id', options.share_id);
  21. this.getData();
  22. },
  23. /**
  24. * 授权成功回调
  25. */
  26. authSuccess: function () {
  27. let that = this;
  28. this.page = 1;
  29. this.setData({
  30. needAuth: false,
  31. noMore: false,
  32. list: [],
  33. specialList: []
  34. }, () => {
  35. that.getData();
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. let that = this;
  43. util.check_login_new().then((res) => {
  44. if (res) {
  45. this.setData({ needAuth: false });
  46. } else {
  47. this.setData({ needAuth: true });
  48. }
  49. })
  50. },
  51. getData: function () {
  52. wx.showLoading();
  53. var token = wx.getStorageSync('token');
  54. var that = this;
  55. var cur_community = wx.getStorageSync('community');
  56. app.util.request({
  57. 'url': 'entry/wxapp/index',
  58. 'data': {
  59. controller: 'marketing.get_special_page_list',
  60. token: token,
  61. head_id: cur_community.communityId,
  62. page: this.page
  63. },
  64. dataType: 'json',
  65. success: function (res) {
  66. wx.stopPullDownRefresh();
  67. wx.hideLoading();
  68. if (res.data.code == 0) {
  69. let specialList = res.data.data;
  70. let oldList = that.data.specialList;
  71. specialList = oldList.concat(specialList);
  72. that.page++;
  73. that.setData({ specialList })
  74. } else if(res.data.code == 1) {
  75. that.noMore = true;
  76. } else if (res.data.code == 2) {
  77. that.setData({ needAuth: true })
  78. }
  79. }
  80. })
  81. },
  82. goSpecial: function (e) {
  83. let id = e.currentTarget.dataset.id;
  84. id && wx.navigateTo({
  85. url: `/lionfish_comshop/moduleA/special/index?id=${id}`,
  86. })
  87. },
  88. openSku: function (e) {
  89. if (!this.authModal()) return;
  90. let shopidx = e.currentTarget.dataset.idx;
  91. let specialList = this.data.specialList;
  92. let rushList = specialList[shopidx].list || [];
  93. this.setData({ list: rushList })
  94. var that = this;
  95. let idx = e.currentTarget.dataset.gidx;
  96. let spuItem = rushList[idx];
  97. var goods_id = spuItem.actId;
  98. var options = spuItem.skuList;
  99. that.setData({
  100. addCar_goodsid: goods_id
  101. })
  102. let list = options.list || [];
  103. let arr = [];
  104. if (list.length > 0) {
  105. for (let i = 0; i < list.length; i++) {
  106. let sku = list[i]['option_value'][0];
  107. let temp = {
  108. name: sku['name'],
  109. id: sku['option_value_id'],
  110. index: i,
  111. idx: 0
  112. };
  113. arr.push(temp);
  114. }
  115. //把单价剔除出来begin
  116. var id = '';
  117. for (let i = 0; i < arr.length; i++) {
  118. if (i == arr.length - 1) {
  119. id = id + arr[i]['id'];
  120. } else {
  121. id = id + arr[i]['id'] + "_";
  122. }
  123. }
  124. var cur_sku_arr = options.sku_mu_list[id];
  125. that.setData({
  126. sku: arr,
  127. sku_val: 1,
  128. cur_sku_arr: cur_sku_arr,
  129. skuList: spuItem.skuList,
  130. visible: true,
  131. showSku: true
  132. });
  133. } else {
  134. let goodsInfo = spuItem;
  135. that.setData({
  136. sku: [],
  137. sku_val: 1,
  138. skuList: [],
  139. cur_sku_arr: goodsInfo
  140. })
  141. let formIds = {
  142. detail: {
  143. formId: ""
  144. }
  145. };
  146. formIds.detail.formId = "the formId is a mock one";
  147. that.gocarfrom(formIds);
  148. }
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. this.noMore = false;
  155. this.page = 1;
  156. let that = this;
  157. that.setData({ list: [], specialList: [] },()=>{
  158. that.getData();
  159. })
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. this.noMore || this.getData();
  166. },
  167. /**
  168. * 用户点击右上角分享
  169. */
  170. onShareAppMessage: function () {
  171. var share_title = '活动专题列表';
  172. var share_id = wx.getStorageSync('member_id');
  173. var share_path = `lionfish_comshop/moduleA/special/list?share_id=${share_id}`;
  174. return {
  175. title: share_title,
  176. path: share_path,
  177. success: function (res) {
  178. // 转发成功
  179. },
  180. fail: function (res) {
  181. // 转发失败
  182. }
  183. }
  184. },
  185. onShareTimeline: function () {
  186. var share_title = '活动专题列表';
  187. var share_id = wx.getStorageSync('member_id');
  188. var query= `share_id=${share_id}`;
  189. return {
  190. title: share_title,
  191. query,
  192. success: function (res) {
  193. // 转发成功
  194. },
  195. fail: function (res) {
  196. // 转发失败
  197. }
  198. }
  199. }
  200. })