newbornZone.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view>
  3. <!--product/newbornZone/newbornZone.wxml-->
  4. <view class="banner">
  5. <image :src="picUrlss+'nbzbg.png'" class="background"></image>
  6. </view>
  7. <view class="conunt" v-if="activityGroup.length > 0">
  8. <view v-for="(item, index) in activityGroup" :key="index" class="li" :data-index="index">
  9. <image :src="item.pic + '?x-oss-process=style/w210'" mode="aspectFit" class="proimg" :data-index="index" @tap="toGroupRemind" lazy-load="true"></image>
  10. <view class="flex">
  11. <view class="proname" :data-index="index" @tap="toGroupRemind">
  12. {{item.productName}}
  13. </view>
  14. <view class="progress-box" v-if="item.payQuantity">
  15. <progress stroke-width="8" color="red" :percent="item.num" border-radius="25rpx" backgroundColor="#FFB2B8" class="progress" v-if="item.payQuantity"></progress><text>已抢{{item.payQuantity}}</text>
  16. </view>
  17. <view class="progress-box" v-if="item.makePerson">
  18. <progress stroke-width="8" color="red" :percent="item.makePerson" border-radius="25rpx" backgroundColor="#FFB2B8" class="progress" v-if="item.makePerson"></progress><text>已{{item.makePerson}}人预约</text>
  19. </view>
  20. <view class="endtime" :data-index="index" @tap="toGroupRemind"><text class="black">{{item.start ? '距结束' : '距开始'}}</text><text class="red">{{item.times}}</text></view>
  21. <view :class="'operate dflex ' + (item.payQuantity?'noyuyue':'yuyue')" v-if="item.start">
  22. <view class="price proprice" :data-index="index" @tap="toGroupRemind">¥<text class="pce">{{item.money}}</text><text class="del">¥{{item.marketPrice}}</text></view>
  23. <view class="add-cart" :data-index="index" @tap="toGroupRemind">
  24. 立即抢购
  25. </view>
  26. </view>
  27. <view :class="'operate dflex ' + (item.makePerson?'noyuyue':'yuyue')" v-else>
  28. <view class="price proprice" :data-index="index" @tap="toGroupRemind">¥<text class="pce">{{item.money}}</text><text class="del">¥{{item.marketPrice}}</text></view>
  29. <view :class="(item.isRemind?'add-cart1':'add-cart') + ' car'">
  30. <image src="/activity/static/activity/images/clock2.png" v-if="!item.isRemind"></image>
  31. <view class="order or" @tap="cancelActivityRemind" :data-index="index" :data-id="item.id" v-if="item.isRemind">取消预约</view>
  32. <view class="order" @tap="addActivityRemind" :data-index="index" :data-id="item.id" v-else>预约</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- <view class="nomore dflex">亲,没有更多了</view> -->
  38. </view>
  39. <view class="nodata nosp" v-if="ishow">
  40. <image :src="picUrlss+'empty_sp.png'"></image>
  41. <text >暂无商品</text>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. // product/newbornZone/newbornZone.js
  47. const req = require("../../utils/request.js");
  48. const utils = require("../../utils/util.js");
  49. const requsetmessage = require("../../utils/requestmessage.js");
  50. const app = getApp();
  51. export default {
  52. data() {
  53. return {
  54. picUrlss: req.public.picUrls,
  55. form: {
  56. page: 1,
  57. limit: 10,
  58. type: 4
  59. },
  60. page: 1,
  61. isLoad: true,
  62. newuser: true,
  63. activityGroup: [],
  64. query: "",
  65. ishow: false,
  66. user: false
  67. };
  68. },
  69. components: {},
  70. props: {},
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options) {
  75. this.query = options;
  76. this.setData({
  77. query: options
  78. }); // this.newuser()
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. this.isLoad = true;
  85. this.form.page = 1; // this.data.activityGroup=[]
  86. this.setData({
  87. activityGroup: []
  88. });
  89. // console.log(this.activityGroup);
  90. this.loadGroup();
  91. },
  92. onReachBottom() {
  93. this.form.page++;
  94. this.loadGroup();
  95. },
  96. onHide() {
  97. this.clearAllTimer();
  98. },
  99. methods: {
  100. /**
  101. * 获取商品列表
  102. */
  103. loadGroup() {
  104. let isShowLoading = false;
  105. if (this.form.page == 1 && !isShowLoading) {
  106. req.loadIng('加载中');
  107. isShowLoading = true;
  108. }
  109. let _ts = this;
  110. // console.log(this.isLoad);
  111. if (!this.isLoad) return false;
  112. this.isLoad = false;
  113. let from = this.form;
  114. if (this.query.merchantId) {
  115. from.merchantId = this.query.merchantId;
  116. } else if (req.getStorage('MERCHANT')) {
  117. from.merchantId = req.getStorage('MERCHANT').id;
  118. }
  119. req.getRequest('/api/activity/list', from, data => {
  120. if (data && data.length == 10) this.isLoad = true;
  121. data = data.map(it => {
  122. it.isRemind = it.remindId, it.num = it.payQuantity / it.quantity * 100;
  123. return it;
  124. });
  125. if (_ts.form.page > 1) data = _ts.activityGroup.concat(data);
  126. _ts.setData({
  127. activityGroup: data
  128. });
  129. // console.log(this.activityGroup);
  130. if (this.activityGroup.length <= 0) {
  131. _ts.setData({
  132. ishow: true
  133. });
  134. } else {
  135. _ts.setData({
  136. ishow: false
  137. });
  138. }
  139. if (isShowLoading) {
  140. uni.hideLoading();
  141. isShowLoading = false;
  142. } // this.clearAllTimer();
  143. _ts.initGroupTimer();
  144. // console.log(this.activityGroup);
  145. });
  146. },
  147. initGroupTimer() {
  148. //社区拼图定时器
  149. let _ts = this;
  150. if (this.activityGroup && this.activityGroup.length > 0) {
  151. let activityGroup = this.activityGroup;
  152. const initPage = (parseInt(this.form.page) - 1) * 10;
  153. for (let i = initPage, len = activityGroup.length; i < len; i++) {
  154. let group = activityGroup[i];
  155. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  156. let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
  157. let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
  158. if (!group.start) endTime = startTime;
  159. let times = parseInt((endTime - nowTime) / 1000);
  160. let timer = setInterval(() => {
  161. times--;
  162. let data = {};
  163. if (times === 0) {
  164. //重新加载列表
  165. data['activityGroup[' + i + '].end'] = true;
  166. clearInterval(timer);
  167. } else {
  168. let n = utils.formatDayTimes(times);
  169. data['activityGroup[' + i + '].times'] = n;
  170. }
  171. _ts.setData(data);
  172. }, 1000);
  173. let fs = [];
  174. fs['activityGroup[' + i + '].timer'] = timer;
  175. _ts.setData(fs);
  176. }
  177. }
  178. },
  179. /**
  180. *
  181. * 点击li获取商品详情
  182. */
  183. toGroupRemind(event) {
  184. const index = event.currentTarget.dataset.index;
  185. // console.log(event);
  186. const activity = this.activityGroup[index];
  187. let merchantId;
  188. if (this.query.merchantId) {
  189. merchantId = this.query.merchantId;
  190. } else if (req.getStorage('MERCHANT')) {
  191. merchantId = req.getStorage('MERCHANT').id;
  192. }
  193. let url='activity/newbornDetails/newbornDetails?acid=' + activity.id + "&id=" + activity.productId
  194. if(!merchantId){
  195. }else{
  196. url +="&merchantId=" + merchantId
  197. }
  198. app.globalData.openPage(url); // console.log('acid', activity.id)
  199. // console.log('productId', activity.productId)
  200. },
  201. /**
  202. * 活动产品预约
  203. */
  204. addActivityRemind(event) {
  205. // if (!this.data.user) return req.msg('您不是新用户')
  206. const index = event.currentTarget.dataset.index;
  207. const id = event.currentTarget.dataset.id; // 订阅调用
  208. req.postRequest('/api/activity/remind', {
  209. activityId: id
  210. }, res => {
  211. this.requsetmessage.remind();
  212. req.msg('预约成功');
  213. let data = {};
  214. data['activityGroup[' + index + '].isRemind'] = true;
  215. this.setData(data);
  216. });
  217. },
  218. cancelActivityRemind(event) {
  219. const index = event.currentTarget.dataset.index;
  220. const id = event.currentTarget.dataset.id;
  221. if(req.header.appId=='ZQ1VK5oc17I387E'){
  222. }else{
  223. req.postRequest('/api/activity/cancel/remind', {
  224. id: id
  225. }, res => {
  226. req.msg('取消预约成功');
  227. let data = {};
  228. data['activityGroup[' + index + '].isRemind'] = false;
  229. this.setData(data);
  230. });
  231. }
  232. },
  233. clearAllTimer() {
  234. this.activityGroup.forEach(it => {
  235. clearInterval(it.timer);
  236. clearInterval(it.times);
  237. });
  238. },
  239. /**
  240. * 判断是否为新用户,不是,2秒后为用户跳转至该商品的详情页面
  241. */
  242. newuserFun() {
  243. id = this.query.id;
  244. req.postRequest('/api/order/isnew', {}, res => {
  245. if (res == 'false') {
  246. this.setData({
  247. user: false
  248. });
  249. uni.showToast({
  250. title: '您不是新用户,两秒后将为您跳转至该商品页面',
  251. icon: 'none',
  252. success: function () {
  253. setTimeout(function () {
  254. uni.redirectTo({
  255. url: '/product/detail/detail?id=' + id
  256. });
  257. }, 2000);
  258. }
  259. });
  260. }
  261. // console.log(res);
  262. });
  263. }
  264. }
  265. };
  266. </script>
  267. <style>
  268. @import "./newbornZone.css";
  269. </style>