groupList.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view>
  3. <!--product/list/list.wxml-->
  4. <view class="ssbox bgfff">
  5. <view class="search dflex" @tap="search">
  6. <image src="/static/pages/images/ssico.png"></image>
  7. <view>搜索你想要的商品</view>
  8. </view>
  9. </view>
  10. <view class="filter dflex bgfff">
  11. <view v-for="(item, index) in tabList" :key="index" @tap="swtichTab" :data-index="index" :class="'li ' + (tabIndex == index ? 'active' : '')">{{item.name}}
  12. <block v-if="item.isSort">
  13. <image src="/static/pages/images/up.png" class="updown" v-if="item.isAsc == 2"></image>
  14. <image src="/static/pages/images/down.png" class="updown" v-else-if="item.isAsc == 1"></image>
  15. <image src="/static/pages/images/jiage.png" class="updown" v-else></image>
  16. </block>
  17. </view>
  18. </view>
  19. <view class="shequ bgfff mt20">
  20. <view v-for="(item, index) in pageList" :key="index" class="li">
  21. <view class="dflex">
  22. <image :src="item.pic" mode="aspectFit" class="proimg" :data-index="index" @tap="toGroupRemind"></image>
  23. <view class="flex">
  24. <view class="proname" :data-index="index" @tap="toGroupRemind">{{item.productName}}</view>
  25. <view class="endtime" :data-index="index" @tap="toGroupRemind">{{item.start ? '距结束' : '距开始'}} {{item.times?item.times:''}}</view>
  26. <view class="operate dflex">
  27. <view class="price proprice">¥<text>{{item.money}}</text><text class="del" v-if="item.marketPrice!=0&&item.marketPrice>item.money">¥{{item.marketPrice}}</text></view>
  28. <view class="add-cart">
  29. <image src="/static/pages/images/jia.png" :data-index="index" @tap="toGroupRemind" v-if="item.start"></image>
  30. <block v-else>
  31. <view class="remind mbglinear" @tap="cancelActivityRemind" :data-index="index" v-if="item.isRemind">取消提醒</view>
  32. <view class="remind mbglinear" @tap="addActivityRemind" :data-index="index" v-else>开团提醒</view>
  33. </block>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="datas dflex" v-if="item.start" :data-index="index" @tap="toGroupRemind">
  39. <view class="yigou dflex">
  40. <image v-for="(item, index2) in item.dtoList" :key="index2" :src="item.avatar" mode="aspectFit"></image>
  41. <image src="/static/pages/images/more1.png" mode="aspectFit" class="more1" v-if="item.dtoList && item.dtoList.length > 0"></image>
  42. <text>已售{{item.payQuantity}}/剩余{{item.quantity - item.payQuantity}}</text>
  43. </view>
  44. <view class="xiaoliang">累计销量 {{item.sellStock}}</view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="nomore dflex" v-if="!ishow">亲,没有更多了</view>
  49. <view class="nodata nosp" v-if="ishow">
  50. <image :src="picUrlss+'empty_sp.png'"></image>
  51. <text>暂无商品</text>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. const app = getApp();
  57. const req = require("../../utils/request.js");
  58. const utils = require("../../utils/util.js");
  59. const requsetmessage = require("../../utils/requestmessage.js");
  60. export default {
  61. data() {
  62. return {
  63. picUrlss: req.public.picUrls,
  64. form: {
  65. page: 1,
  66. limit: 10,
  67. type: 1
  68. },
  69. searchTitle: '',
  70. pageList: [],
  71. tabIndex: 0,
  72. tabList: [{
  73. name: '默认'
  74. }, {
  75. name: '销量'
  76. }, {
  77. name: '价格',
  78. isSort: true
  79. }],
  80. isLoad: true,
  81. ishow: false
  82. };
  83. },
  84. components: {},
  85. props: {},
  86. onLoad: function (options) {
  87. // console.log(options);
  88. this.query = options; // this.loadCoupon();
  89. },
  90. onShow() {
  91. this.isLoad = true, this.form.page = 1;
  92. this.setData({
  93. pageList: []
  94. });
  95. this.loadCoupon();
  96. },
  97. onReachBottom() {
  98. this.form.page++;
  99. this.loadCoupon();
  100. },
  101. onUnload() {
  102. this.clearAllTimer();
  103. },
  104. onHide() {
  105. this.clearAllTimer();
  106. },
  107. methods: {
  108. search() {
  109. // app.openPage('pages/search/search?merchantId=' + this.data.merchant.id)
  110. if (req.getStorage('MERCHANT').id) {
  111. app.globalData.openPage('pages/search/search?searchTitle=' + this.searchTitle + '&merchantId=' + req.getStorage('MERCHANT').id);
  112. } else if (this.query.merchantId) {
  113. app.globalData.openPage('pages/search/search?searchTitle=' + this.searchTitle + '&merchantId=' + this.query.merchantId);
  114. }
  115. },
  116. swtichTab(event) {
  117. this.clearAllTimer();
  118. const index = event.currentTarget.dataset.index;
  119. const tab = this.tabList[index];
  120. let data = {
  121. pageList: [],
  122. tabIndex: index,
  123. form: {
  124. page: 1,
  125. type: 1,
  126. limit: 10
  127. },
  128. isLoad: true
  129. };
  130. if (index === 1) {
  131. data.form['stockSort'] = 1;
  132. } else if (index === 2) {
  133. data.form['moneySort'] = tab.isAsc ? tab.isAsc === 1 ? 2 : 1 : 2;
  134. data['tabList[' + index + '].isAsc'] = tab.isAsc ? tab.isAsc === 1 ? 2 : 1 : 2;
  135. }
  136. if (index !== 2) data['tabList[2].isAsc'] = null;
  137. this.setData(data);
  138. this.clearAllTimer();
  139. this.loadCoupon();
  140. },
  141. loadCoupon() {
  142. let isShowLoading = false;
  143. if (this.form.page == 1 && !isShowLoading) {
  144. req.loadIng('加载中');
  145. isShowLoading = true;
  146. }
  147. if (!this.isLoad) return false;
  148. this.isLoad = false;
  149. // console.log(this.isLoad);
  150. let that = this;
  151. let from = this.form;
  152. if (this.query.merchantId) {
  153. from.merchantId = this.query.merchantId;
  154. // console.log("456");
  155. } else if (req.getStorage('MERCHANT')) {
  156. from.merchantId = req.getStorage('MERCHANT').id;
  157. // console.log("123");
  158. }
  159. req.getRequest('/api/activity/list', from, data => {
  160. if (data && data.length == 10) this.isLoad = true;
  161. data = data.map(it => {
  162. it.isRemind = it.remindId;
  163. return it;
  164. });
  165. if (that.form.page > 1) data = that.pageList.concat(data);
  166. that.setData({
  167. pageList: data
  168. });
  169. if (this.pageList.length <= 0) {
  170. that.setData({
  171. ishow: true
  172. });
  173. } else {
  174. that.setData({
  175. ishow: false
  176. });
  177. }
  178. if (isShowLoading) {
  179. uni.hideLoading();
  180. isShowLoading = false;
  181. }
  182. // console.log(this.pageList);
  183. this.clearAllTimer();
  184. that.initGroupTimer();
  185. });
  186. },
  187. initGroupTimer() {
  188. //社区拼图定时器
  189. let _ts = this;
  190. if (this.pageList && this.pageList.length > 0) {
  191. let pageList = this.pageList;
  192. const initPage = (parseInt(this.form.page) - 1) * 10;
  193. for (let i = initPage, len = pageList.length; i < len; i++) {
  194. let group = pageList[i];
  195. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  196. let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
  197. let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
  198. if (!group.start) endTime = startTime;
  199. let times = parseInt((endTime - nowTime) / 1000);
  200. let timer = setInterval(() => {
  201. times--;
  202. let data = {};
  203. if (times === 0) {
  204. //重新加载列表
  205. data['pageList[' + i + '].end'] = true;
  206. clearInterval(timer);
  207. } else {
  208. let n = utils.formatDayTimes(times);
  209. data['pageList[' + i + '].times'] = n;
  210. }
  211. _ts.setData(data);
  212. }, 1000);
  213. let fs = [];
  214. fs['pageList[' + i + '].timer'] = timer;
  215. _ts.setData(fs);
  216. }
  217. }
  218. },
  219. toGroupRemind(event) {
  220. const index = event.currentTarget.dataset.index;
  221. const activity = this.pageList[index];
  222. let merchantId;
  223. if (this.query.merchantId) {
  224. merchantId = this.query.merchantId;
  225. } else if (req.getStorage('MERCHANT')) {
  226. merchantId = req.getStorage('MERCHANT').id;
  227. }
  228. let url ='product/groupDetail/groupDetail?acid=' + activity.id + "&id=" + activity.productId
  229. if(!merchantId){
  230. }else{
  231. url+="&merchantId=" + merchantId
  232. }
  233. app.globalData.openPage(url);
  234. },
  235. clearAllTimer() {
  236. this.pageList.forEach(it => {
  237. clearInterval(it.timer);
  238. clearInterval(it.times);
  239. });
  240. },
  241. addActivityRemind(event) {
  242. const index = event.currentTarget.dataset.index;
  243. const page = this.pageList[index]; // 订阅调用
  244. req.postRequest('/api/activity/remind', {
  245. activityId: page.id
  246. }, res => {
  247. requsetmessage.remind().then(res => res);
  248. req.msg('订阅提醒成功');
  249. let data = {};
  250. data['pageList[' + index + '].isRemind'] = true;
  251. this.setData(data);
  252. });
  253. },
  254. cancelActivityRemind(event) {
  255. const index = event.currentTarget.dataset.index;
  256. const page = this.pageList[index];
  257. if(req.header.appId=='ZQ1VK5oc17I387E'){
  258. }else{
  259. req.postRequest('/api/activity/cancel/remind', {
  260. id: page.id
  261. }, res => {
  262. req.msg('取消提醒成功');
  263. let data = {};
  264. data['pageList[' + index + '].isRemind'] = false;
  265. this.setData(data);
  266. });
  267. }
  268. }
  269. }
  270. };
  271. </script>
  272. <style>
  273. @import "./groupList.css";
  274. </style>