1
0

campMinus.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. var app = getApp();
  2. var util = require('../../../utils/util.js');
  3. var api = require('../../../config/api.js');
  4. Page({
  5. data: {
  6. campMinus: {},
  7. page: 1,
  8. size: 4,
  9. referrer: 0,
  10. storeId: '',
  11. campMinusId: '',
  12. merchSn: '',
  13. openCampAttr: false,
  14. storeName: '',
  15. isShare: '',
  16. categoryFilter: false,
  17. filterCategory: [],
  18. goodsList: [],
  19. categoryId: 0,
  20. currentSortType: 'desc',
  21. currentSortOrder: 'a.create_time',
  22. goodsCount: 0,
  23. },
  24. onLoad: function(options) {
  25. let that = this;
  26. // options.scene = '6&8&满4件减1&1';
  27. if (options.scene) {
  28. var scene = decodeURIComponent(options.scene);
  29. console.log("scene is ", scene);
  30. var scanArray = scene.split('&');
  31. var id = scanArray[0];
  32. var storeId = scanArray[1];
  33. var campName = scanArray[2];
  34. var isShare = scanArray[3];
  35. // console.log(campName);
  36. // console.log(storeId);
  37. this.setData({
  38. campMinusId: id,
  39. storeId: storeId,
  40. campName: campName,
  41. isShare: isShare
  42. });
  43. if(campName){
  44. wx.setNavigationBarTitle({
  45. title: campName
  46. })
  47. }
  48. } else {
  49. if (options.campName) {
  50. wx.setNavigationBarTitle({
  51. title: options.campName
  52. })
  53. }
  54. if (options.campMinusId) {
  55. that.setData({
  56. campMinusId: options.campMinusId
  57. });
  58. }
  59. if (options.storeId) {
  60. that.setData({
  61. storeId: options.storeId
  62. });
  63. }
  64. if (options.isShare) {
  65. that.setData({
  66. isShare: options.isShare
  67. });
  68. }
  69. }
  70. },
  71. onReady: function() {
  72. let that = this;
  73. that.getCampminusDetail();
  74. that.getGoodsList();
  75. },
  76. getCampminusDetail() {
  77. var that = this;
  78. util.request(api.CampminusDetail, {
  79. campMinusId: that.data.campMinusId,
  80. storeId: that.data.storeId
  81. })
  82. .then(function (res) {
  83. if (res.errno === 0) {
  84. if (res.data) {
  85. that.setData({
  86. campMinus: res.data,
  87. storeName: res.data.storeName
  88. });
  89. util.countdown(that, that.data.campMinus, 'campMinus', null);
  90. // console.log(that.data.campMinus.dateformat.day)
  91. // console.log(that.data.campMinus.dateformat.hr)
  92. // console.log(that.data.campMinus.dateformat.min)
  93. // console.log(that.data.campMinus.dateformat)
  94. // console.log(that.data.campMinus.dateformat.sec)
  95. }
  96. }
  97. });
  98. },
  99. getGoodsList() {
  100. wx.showLoading({
  101. title: '加载中...',
  102. });
  103. var that = this;
  104. util.request(api.StoreCampMinusGoodsList, { campMinusId: that.data.campMinusId, page: that.data.page, size: that.data.size, order: that.data.currentSortOrder, sort: that.data.currentSortType, categoryId: that.data.categoryId, storeId: that.data.storeId })
  105. .then(function (res) {
  106. if (res.errno === 0) {
  107. console.log(res.data.goodsList);
  108. let goodsList = that.data.goodsList.concat(res.data.goodsList);
  109. that.setData({
  110. goodsList: goodsList,
  111. goodsCount: res.data.goodsCount,
  112. filterCategory: res.data.filterCategory
  113. });
  114. wx.hideLoading();
  115. if (that.data.categoryId > 0) {
  116. let filterCategory = that.data.filterCategory;
  117. filterCategory.forEach(function (val, index, arr) {
  118. if (val.id == that.data.categoryId) {
  119. val.checked = true;
  120. filterCategory[index] = val;
  121. that.setData({ filterCategory: filterCategory });
  122. } else {
  123. val.checked = false;
  124. }
  125. }, that);
  126. }
  127. }
  128. });
  129. },
  130. openSortFilter: function (event) {
  131. let currentId = event.currentTarget.id;
  132. switch (currentId) {
  133. case 'categoryFilter':
  134. this.setData({
  135. 'categoryFilter': !this.data.categoryFilter,
  136. 'currentSortType': 'category',
  137. 'currentSortOrder': 'asc'
  138. });
  139. break;
  140. case 'priceSort':
  141. let tmpSortOrder = 'asc';
  142. if (this.data.currentSortOrder == 'asc') {
  143. tmpSortOrder = 'desc';
  144. }
  145. this.setData({
  146. 'currentSortType': 'price',
  147. 'currentSortOrder': tmpSortOrder,
  148. 'categoryFilter': false,
  149. goodsList: [],
  150. page: 1
  151. });
  152. this.getGoodsList();
  153. break;
  154. default:
  155. //综合排序
  156. this.setData({
  157. 'currentSortType': 'default',
  158. 'currentSortOrder': 'desc',
  159. 'categoryFilter': false,
  160. goodsList: [],
  161. page: 1
  162. });
  163. this.getGoodsList();
  164. }
  165. },
  166. selectCategory: function (event) {
  167. let that = this;
  168. let currentIndex = event.target.dataset.categoryIndex;
  169. this.setData({
  170. categoryFilter: false,
  171. categoryId: this.data.filterCategory[currentIndex].id,
  172. goodsList: []
  173. });
  174. that.getGoodsList();
  175. },
  176. /**
  177. * 去逛逛
  178. */
  179. toIndexPage: function() {
  180. wx.switchTab({
  181. url: "/pages/index/index"
  182. });
  183. },
  184. selectCampMinus(e) {
  185. let goodsBizType = e.currentTarget.dataset.goodsType;
  186. let that = this;
  187. // wx.navigateTo({
  188. // url: '/pages/shopping/coupon/coupon',
  189. // })
  190. that.setData({
  191. openCampAttr: !that.data.openCampAttr
  192. })
  193. if (that.data.openCampAttr) {
  194. // that.getTicketDiscountList(goodsBizType);
  195. }
  196. },
  197. hideSwitchCampPop: function() {
  198. this.setData({
  199. openCampAttr: false
  200. })
  201. },
  202. onReachBottom() {
  203. var that = this;
  204. if (!that.data.goodsList) {
  205. wx.showLoading({
  206. title: '加载中...',
  207. })
  208. }
  209. that.setData({
  210. page: that.data.page + 1,
  211. });
  212. that.getGoodsList();
  213. }
  214. })