shop.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. <template>
  2. <view>
  3. <!--mine/shop/shop.wxml-->
  4. <view class="top">
  5. <view class="topc dflex">
  6. <image :src="merchant.logo" mode="aspectFill" class="userimg"></image>
  7. <view class="userinfo flex">
  8. <view class="username">{{merchant.title}}</view>
  9. <view class="username">电话:{{merchant.phone?merchant.phone:''}}</view>
  10. </view>
  11. <button open-type="share" class="share dflex">
  12. <image src="/static/pages/images/bshare.png"></image>分享
  13. </button>
  14. </view>
  15. </view>
  16. <view class="box1">
  17. <view class="search dflex">
  18. <view class="dflex flex" @tap="search">
  19. <image src="/static/pages/images/ssico.png"></image>
  20. <view class="flex">搜索你想要的商品</view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="con">
  25. <!-- 秒杀 -->
  26. <view class="box" v-if="seckill.length>0">
  27. <view class="mstit dflex">
  28. <image src="/static/pages/images/msico.png" class="msico"></image>
  29. <image src="/static/pages/images/xsms.png" class="xsms"></image>
  30. <view class="countdown dflex">
  31. <text>{{timer[0]}}</text>:<text>{{timer[1]}}</text>:<text>{{timer[2]}}</text>
  32. </view>
  33. </view>
  34. <view class="times dflex">
  35. <view v-for="(item, index) in TabList" :key="index"
  36. :class="'li ' + (item.active ? 'active' : '') + ' left'" :data-index="index" @tap="switchTab">
  37. <text :class="item.active ? 'weight' : ''">{{item.label}}</text>
  38. <view :class="'state ' + (item.active? 'bg' :'')">{{item.state}}</view>
  39. </view>
  40. <!-- <view class="li active"><text>08:00</text>已开抢</view>
  41. <view class="li"><text>10:00</text>已开抢</view>
  42. <view class="li"><text>12:00</text>抢购中</view>
  43. <view class="li"><text>14:00</text>即将开抢</view>
  44. <view class="li"><text>16:00</text>待开抢</view> -->
  45. </view>
  46. <navigator v-for="(item, index) in seckill" :key="index" url hover-class="none"
  47. class="msinfos bgfff r10">
  48. <image :src="item.pic" mode="aspectFill" @tap="toSeckillList" :data-id="item.id"
  49. :data-productId="item.productId"></image>
  50. <view class="msinfo">
  51. <view class="msname" @tap="toSeckillList" :data-id="item.id" :data-productId="item.productId">
  52. {{item.productName}}
  53. </view>
  54. <view class="qgsta dflex">
  55. <view class="price proprice" @tap="toSeckillList" :data-id="item.id"
  56. :data-productId="item.productId">¥<text>{{item.money}}</text><text
  57. class="del">¥{{item.marketPrice}}</text></view>
  58. <view class="qiang mbgcolor" v-if="item.start" @tap="toSeckillList" :data-id="item.id"
  59. :data-productId="item.productId">立即抢购</view>
  60. <!-- <view class="remind mbglinear" bindtap="cancelActivityRemind" data-index="{{index}}" data-id="{{item.id}}" wx:if="{{item.isRemind}}" data-type="1">取消预约</view> -->
  61. <block v-else>
  62. <view class="qiang mbggreen" @tap="cancelActivityRemind" :data-index="index"
  63. :data-id="item.id" v-if="item.isRemind" data-type="3">取消提醒</view>
  64. <view class="qiang mbggreen" @tap="addActivityRemind" :data-index="index"
  65. :data-id="item.id" data-type="3" v-else>预约提醒</view>
  66. </block>
  67. </view>
  68. </view>
  69. </navigator>
  70. </view>
  71. <!-- 社区团购 -->
  72. <view class="mt20 bgfff r10" v-if="group.length > 0">
  73. <navigator hover-class="none" url="/product/groupList/groupList" class="title pdlr20 dflex">社区团购<image
  74. src="/static/pages/images/more.png" class="more"></image>
  75. </navigator>
  76. <view class="shequ">
  77. <view v-for="(item, index) in group" :key="index" class="li">
  78. <view class="dflex">
  79. <image :src="item.pic" mode="aspectFill" class="proimg" :data-index="index"
  80. @tap="toGroupRemind">
  81. </image>
  82. <view class="flex">
  83. <view class="proname" :data-index="index" @tap="toGroupRemind">{{item.title}}</view>
  84. <view class="endtime" :data-index="index" @tap="toGroupRemind">
  85. {{item.start ? '距结束' : '距开始'}}
  86. {{item.times}}
  87. </view>
  88. <view class="operate dflex">
  89. <view class="price proprice" :data-index="index" @tap="toGroupRemind">
  90. ¥<text>{{item.money}}</text><text class="del">¥{{item.marketPrice}}</text>
  91. </view>
  92. <view class="add-cart">
  93. <image src="/static/pages/images/jia.png" :data-index="index"
  94. @tap="toGroupRemind" v-if="item.start"></image>
  95. <block v-else>
  96. <view class="remind mbggreen" @tap="cancelActivityRemind"
  97. :data-index="index" :data-id="item.id" v-if="item.isRemind"
  98. data-type="1">取消提醒</view>
  99. <view class="remind mbggreen" @tap="addActivityRemind" :data-index="index"
  100. :data-id="item.id" data-type="1" v-else>开团提醒</view>
  101. </block>
  102. </view>
  103. </view>
  104. </view>
  105. </view>
  106. <view class="datas dflex" v-if="item.start" :data-index="index" @tap="toGroupRemind">
  107. <view class="yigou dflex">
  108. <image v-for="(item, index2) in item.dtoList" :key="index2" :src="item.avatar"
  109. mode="aspectFill"></image>
  110. <image src="/static/pages/images/more1.png" mode="aspectFill" class="more1"
  111. v-if="item.dtoList && item.dtoList.length > 0"></image>
  112. <text>已售{{item.payQuantity}}/剩余{{item.quantity - item.payQuantity}}</text>
  113. </view>
  114. <view class="xiaoliang">累计销量 {{item.sellStock}}</view>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. <!-- 拼团 -->
  120. <view class="mt20 bgfff pdlr20 r10" v-if="joingroup.length>0">
  121. <view class="title dflex" @tap="goUrl" data-url="activity/group/index/index?type=4">拼团<image
  122. src="/static/pages/images/more.png" class="more"></image>
  123. </view>
  124. <goodsList :pageList="joingroup" :merchant="web">
  125. </goodsList>
  126. <!-- <view class="pintuan">
  127. <view v-for="(item, index) in joingroup" :key="index" class="li dflex">
  128. <view class="pinimgs" @tap="goUrl"
  129. :data-url="'activity/group/detail/detail?acid=' + item.id + '&id=' + item.productId">
  130. <image :src="item.pic" mode="aspectFill" class="pinimg"></image>
  131. <view class="tuan">
  132. <image src="/static/pages/images/tagbg.png"></image>
  133. <text>3人团</text>
  134. </view>
  135. </view>
  136. <view class="pininfo flex">
  137. <view class="proname" @tap="goUrl"
  138. :data-url="'activity/group/detail/detail?acid=' + item.id + '&id=' + item.productId">
  139. {{item.productName}}
  140. </view>
  141. <view :class="'endtime ' + (item.start? '' : 'wei')">{{item.start ? '距结束': '距开始'}}
  142. {{item.times}}
  143. </view>
  144. <view class="del" @tap="goUrl"
  145. :data-url="'activity/group/detail/detail?acid=' + item.id + '&id=' + item.productId">
  146. ¥{{item.marketPrice}}</view>
  147. <view class="operate dflex">
  148. <view class="price" @tap="goUrl"
  149. :data-url="'activity/group/detail/detail?acid=' + item.id + '&id=' + item.productId">
  150. 拼团价¥<text>{{item.money}}</text></view>
  151. <view class="add-cart">
  152. <view class="remind mbglinear dflex" v-if="item.start" @tap="goUrl"
  153. :data-url="'activity/group/detail/detail?acid=' + item.id + '&id=' + item.productId">
  154. 立即开团</view>
  155. <block v-else>
  156. <view class="remind mbggreen dflex" v-if="item.isRemind"
  157. @tap="cancelActivityRemind" :data-index="index" data-type="2"
  158. :data-id="item.id">取消预约</view>
  159. <view class="remind mbggreen dflex" @tap="addActivityRemind" :data-index="index"
  160. data-type="2" :data-id="item.id" v-else>
  161. <icon class="iconfont icon-yugao"></icon>预约提醒
  162. </view>
  163. </block>
  164. </view>
  165. </view>
  166. </view>
  167. </view>
  168. </view> -->
  169. </view>
  170. <!-- 店长推荐 -->
  171. <view class="tuijian dflex" v-if="activityGroup.products.length>0">
  172. <image src="/static/pages/images/tjico.png"></image>
  173. <text>店长推荐</text>
  174. <image src="/static/pages/images/tjico.png"></image>
  175. </view>
  176. <!-- <view class="tjlist">
  177. <navigator v-for="(item, index) in activityGroup" :key="index" url hover-class="none"
  178. class="msinfos bgfff r10" @tap="toDetail" :data-id="item.id">
  179. <image :src="item.pic" mode="aspectFill"></image>
  180. <view class="msinfo">
  181. <view class="msname">{{item.title}}</view>
  182. <view class="qgsta dflex">
  183. <view class="price proprice">¥<text>{{item.actualPrice}}</text><text
  184. class="del">¥{{item.marketPrice}}</text>
  185. </view>
  186. <view class="qiang mbgcolor">立即抢购</view>
  187. </view>
  188. </view>
  189. </navigator>
  190. </view> -->
  191. <goodsList :pageList="activityGroup" :merchant="web">
  192. </goodsList>
  193. </view>
  194. <view class="nodata_cart"
  195. v-if="activityGroup.products.length<1&&joingroup.products.length<1&&group.products.length<1&&seckill.products.length<1&&bargain.products.length<1">
  196. <image :src="picUrlss+'empty_xd.png'"></image>
  197. <view>小店橱窗,空空如也~</view>
  198. <text>挑选宝贝 > 查看详情 > 添加到小店</text>
  199. <navigator url="/pages/index/index" open-type="switchTab" hover-class="none">去逛逛</navigator>
  200. </view>
  201. <!-- <view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 115) + 'rpx'"></view> -->
  202. <!-- <foot channel="shop" :isUpdate="isUpdate"></foot> -->
  203. </view>
  204. </template>
  205. <script>
  206. // mine/shop/shop.js
  207. const app = getApp();
  208. const req = require("../../utils/request.js");
  209. const api = require("../../utils/api.js");
  210. const utils = require("../../utils/util.js");
  211. const mes = require("../../utils/requestmessage.js");
  212. // import foot from "../../components/nav-bar/index";
  213. import goodsList from "../../components/goodsList/goodsList";
  214. export default {
  215. data() {
  216. return {
  217. picUrlss: req.public.picUrls,
  218. bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
  219. isUpdate: false,
  220. // 是否更新消息
  221. activityGroup: {},
  222. //店长推荐
  223. group: {},
  224. //社区团购
  225. seckill: [],
  226. //秒杀
  227. joingroup: {},
  228. //拼团
  229. bargain: [],
  230. //砍价
  231. TabList: [{
  232. label: '今天',
  233. active: true,
  234. state: "抢购中",
  235. dayType: 1,
  236. time: ''
  237. }, {
  238. label: '明天',
  239. state: "预热中",
  240. active: false,
  241. time: '',
  242. dayType: 2
  243. }, {
  244. label: '后天',
  245. state: "预热中",
  246. dayType: 3,
  247. time: ''
  248. }, {
  249. label: '',
  250. state: "预热中",
  251. dayType: 4,
  252. active: false,
  253. time: ''
  254. }, {
  255. label: '',
  256. state: "预热中",
  257. dayType: 5,
  258. active: false,
  259. time: ''
  260. }],
  261. timer: "",
  262. userInfo: "",
  263. merchant: {},
  264. homeTemplate: {},
  265. web: ''
  266. };
  267. },
  268. components: {
  269. // foot
  270. goodsList
  271. },
  272. props: {},
  273. onLoad: function(options) {
  274. console.log(options);
  275. this.query = options;
  276. if (options.scene) {
  277. this.scene = options.scene;
  278. }
  279. if (options.isShare) {
  280. req.setStorage('pidCode', options.userId);
  281. }
  282. this.web = '&merchantId=' + options.merchantId + '&shopId=' + options.shopId
  283. uni.setNavigationBarColor({
  284. frontColor: '#ffffff',
  285. backgroundColor: req.public.titleTopBgColor
  286. });
  287. this.init();
  288. this.getTime();
  289. this.getShop();
  290. this.getHomeTemplateConfig()
  291. },
  292. onShow() {
  293. let _ts = this;
  294. _ts.setData({
  295. isUpdate: !_ts.isUpdate
  296. });
  297. },
  298. onShareAppMessage: function() {
  299. return {
  300. title: req.excludeSpecial(req.getStorage('userInfo').nickName) + '为你推荐' + this.merchant.title,
  301. // imageUrl: this.data.seckill[0].pic
  302. // path: '/product/detail/detail?id=' + this.query.id + '&isShare=' + true + '&userId=' + req.getStorage('userInfo').id
  303. path: '/pages/shop/shop?userId=' + req.getStorage('userInfo').id + '&isShare=' + true + '&shopId=' +
  304. this.query.shopId + '&merchantId=' + this.query.merchantId
  305. };
  306. },
  307. methods: {
  308. //获取小店配置
  309. getHomeTemplateConfig() {
  310. let _ts = this;
  311. req.getRequest('/api/config', {}, data => {
  312. if (data.shop_config) {
  313. this.setData({
  314. homeTemplate: JSON.parse(data.shop_config)
  315. });
  316. }
  317. console.log(this.homeTemplate)
  318. });
  319. },
  320. /**
  321. *
  322. * 设置tab导航
  323. */
  324. switchTab(event) {
  325. let index = event.currentTarget.dataset.index;
  326. let def = this.TabList.findIndex(it => it.active);
  327. let d = {};
  328. console.log(index, def);
  329. d[`TabList[${def}].active`] = false;
  330. d[`TabList[${index}].active`] = true;
  331. console.log(d);
  332. this.isLoad = true; // this.data.form.page = 1;
  333. d['pageList'] = []; // this.data.form.dayType = this.data.TabList[index].dayType;
  334. this.setData(d);
  335. this.seckillFun();
  336. this.clearAllTimer(); // this.getDate()
  337. },
  338. /**
  339. * 获取当前时间往后退四天
  340. */
  341. laterDay(num) {
  342. var t = new Date();
  343. var iToDay = t.getDate();
  344. var iToMon = t.getMonth();
  345. var iToYear = t.getFullYear();
  346. var arr = [];
  347. for (var i = 1; i < num + 1; i++) {
  348. var newDate = new Date(iToYear, iToMon, iToDay + i);
  349. arr.push(newDate.getFullYear() + '-' + (newDate.getMonth() + 1).toString().padStart(2, '0') + "-" +
  350. newDate.getDate().toString().padStart(2, '0'));
  351. } // console.log(arr)
  352. return arr;
  353. },
  354. /**
  355. * 给tab添加动态时间
  356. */
  357. getTime() {
  358. const data = this.TabList;
  359. var t = new Date();
  360. var iToDay = t.getDate().toString().padStart(2, '0');
  361. var iToMon = (t.getMonth() + 1).toString().padStart(2, '0');
  362. var iToYear = t.getFullYear();
  363. const rq = (iToYear + '-' + iToMon + '-' + iToDay).toString();
  364. const rq1 = this.laterDay(4)[0];
  365. const rq2 = this.laterDay(4)[1];
  366. const rq3 = this.laterDay(4)[2];
  367. const rq4 = this.laterDay(4)[3]; // console.log("rq" + "---", rq1, rq2, rq3, rq4)
  368. data[0].time = rq;
  369. data[1].time = rq1;
  370. data[2].time = rq2;
  371. data[3].label = this.getda(rq3);
  372. data[3].time = rq3;
  373. data[4].label = this.getda(rq4);
  374. data[4].time = rq4;
  375. this.setData({
  376. TabList: data
  377. }); // console.log(this.data.TabList)
  378. },
  379. /**
  380. * 时间转换
  381. */
  382. getda(str) {
  383. var strArr = str.split('-');
  384. var day = strArr[2];
  385. var month = strArr[1];
  386. var year = strArr[0];
  387. let date = (month + '月' + day + '日').toString();
  388. return date;
  389. },
  390. search() {
  391. app.globalData.openPage('pages/search/search');
  392. },
  393. async init() {
  394. await this.loadGroup();
  395. await this.groupFun();
  396. await this.seckillFun();
  397. await this.joingroupFun();
  398. await this.bargainFun();
  399. },
  400. // 获取店长推荐
  401. loadGroup() {
  402. let _ts = this; // type
  403. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  404. req.getRequest('/api/shopProduct/list', {
  405. page: 1,
  406. limit: 3,
  407. type: 1,
  408. // userId: this.query.userId
  409. shopId: this.query.shopId,
  410. merchantId: this.query.merchantId
  411. }, data => {
  412. data = data.map(it => {
  413. it.isRemind = it.remindId;
  414. return it;
  415. });
  416. console.log(data[0]);
  417. let arrObjFilter
  418. arrObjFilter = {
  419. // backgroundColor:this.homeTemplate.backgroundColor,
  420. displayStyle: this.homeTemplate.displayStyle,
  421. lineNumber: this.homeTemplate.lineNumber,
  422. products: data
  423. };
  424. _ts.setData({
  425. activityGroup: arrObjFilter
  426. });
  427. console.log(this.activityGroup)
  428. // _ts.initGroupTimer();
  429. });
  430. },
  431. // 获取社区团购产品
  432. groupFun() {
  433. let _ts = this; // type
  434. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  435. req.getRequest('/api/shopProduct/list', {
  436. page: 1,
  437. limit: 3,
  438. // userId: this.query.userId
  439. type: 2,
  440. merchantId: this.query.merchantId,
  441. sid: this.query.shopId
  442. }, data => {
  443. data = data.list.map(it => {
  444. it.isRemind = it.remindId;
  445. return it;
  446. });
  447. console.log(data);
  448. let arrObjFilter
  449. arrObjFilter = {
  450. // backgroundColor:this.homeTemplate.backgroundColor,
  451. displayStyle: this.homeTemplate.displayStyle,
  452. lineNumber: this.homeTemplate.lineNumber,
  453. products: data.filter(ele => ele.end == false)
  454. };
  455. _ts.setData({
  456. group: arrObjFilter
  457. }); // console.log(this.data.activityGroup)
  458. _ts.initGroupTimer(2);
  459. });
  460. },
  461. // 获取秒杀产品
  462. seckillFun() {
  463. let _ts = this; // type
  464. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  465. req.getRequest('/api/shopProduct/list', {
  466. page: 1,
  467. limit: 3,
  468. type: 3,
  469. // userId: this.query.userId
  470. shopId: this.query.shopId,
  471. merchantId: this.query.merchantId
  472. }, data => {
  473. data = data.list.map(it => {
  474. it.isRemind = it.remindId;
  475. return it;
  476. });
  477. console.log(data);
  478. let arrObjFilter
  479. arrObjFilter = {
  480. // backgroundColor:this.homeTemplate.backgroundColor,
  481. displayStyle: this.homeTemplate.displayStyle,
  482. lineNumber: this.homeTemplate.lineNumber,
  483. products: data.filter(ele => ele.end == false)
  484. };
  485. _ts.setData({
  486. seckill: arrObjFilter
  487. }); // console.log(this.data.activityGroup)
  488. var now = new Date();
  489. var next = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
  490. this.NextTime(next, function(hour, minute, second) {
  491. hour = _ts.lpad(hour, 2);
  492. minute = _ts.lpad(minute, 2);
  493. second = _ts.lpad(second, 2);
  494. let res = [hour, minute, second];
  495. _ts.setData({
  496. timer: res
  497. });
  498. });
  499. _ts.initGroupTimer(3);
  500. });
  501. },
  502. // 获取拼团产品
  503. joingroupFun() {
  504. let _ts = this; // type
  505. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  506. req.getRequest('/api/shopProduct/list', {
  507. page: 1,
  508. limit: 3,
  509. type: 4,
  510. // userId: this.query.userId
  511. shopId: this.query.shopId,
  512. merchantId: this.query.merchantId
  513. }, data => {
  514. data = data.list.map(it => {
  515. it.isRemind = it.remindId;
  516. return it;
  517. });
  518. let arrObjFilter
  519. arrObjFilter = {
  520. // backgroundColor:this.homeTemplate.backgroundColor,
  521. displayStyle: this.homeTemplate.displayStyle,
  522. lineNumber: this.homeTemplate.lineNumber,
  523. products:data.filter(ele => ele.end == false)
  524. };
  525. _ts.setData({
  526. joingroup: arrObjFilter
  527. }); // console.log(this.data.activityGroup)
  528. _ts.initGroupTimer(4);
  529. });
  530. },
  531. // 获取砍价产品
  532. bargainFun() {
  533. let _ts = this; // type
  534. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  535. req.getRequest('/api/shopProduct/list', {
  536. page: 1,
  537. limit: 3,
  538. type: 7,
  539. // userId: this.query.userId
  540. shopId: this.query.shopId,
  541. merchantId: this.query.merchantId
  542. }, data => {
  543. data = data.list.map(it => {
  544. it.isRemind = it.remindId;
  545. return it;
  546. });
  547. let arrObjFilter
  548. arrObjFilter = {
  549. // backgroundColor:this.homeTemplate.backgroundColor,
  550. displayStyle: this.homeTemplate.displayStyle,
  551. lineNumber: this.homeTemplate.lineNumber,
  552. products:data.filter(ele => ele.end == false)
  553. };
  554. _ts.setData({
  555. bargain: arrObjFilter
  556. }); // console.log(this.data.activityGroup)
  557. _ts.initGroupTimer(7);
  558. });
  559. },
  560. // 获取新客产品
  561. //2为社区团购,4为拼团,7为砍价
  562. initGroupTimer(type) {
  563. //社区拼图定时器
  564. let _ts = this;
  565. let list = [];
  566. if (type == 2) list = this.group.products;
  567. else if (type == 4) list = this.joingroup.products;
  568. else if (type == 7) list = this.bargain.products; // console.log(this.data.joingroupList)
  569. if (list && list.length > 0) {
  570. // let activityGroup = this.data.activityGroup;
  571. for (let i = 0, len = list.length; i < len; i++) {
  572. let group = list[i];
  573. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  574. let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
  575. let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
  576. if (!group.start) endTime = startTime;
  577. let times = parseInt((endTime - nowTime) / 1000);
  578. console.log(times);
  579. let timer = setInterval(() => {
  580. times--;
  581. let data = {};
  582. if (times === 0) {
  583. //重新加载列表
  584. if (type == 2) data['group[' + i + '].end'] = true;
  585. else if (type == 4) data['joingroup[' + i + '].end'] = true;
  586. else if (type == 7) data['bargain[' + i + '].end'] = true;
  587. clearInterval(timer);
  588. } else {
  589. let n = utils.formatDayTimes(times);
  590. if (type == 2) data['group[' + i + '].times'] = n;
  591. else if (type == 4) data['joingroup[' + i + '].times'] = n;
  592. else if (type == 7) data['bargain[' + i + '].times'] = n.split(/:|天/g);
  593. }
  594. _ts.setData(data);
  595. }, 1000);
  596. if (type == 2) this.group[i]['timer'] = timer;
  597. else if (type == 4) this.joingroup[i]['timer'] = timer;
  598. else if (type == 7) this.bargain[i]['timer'] = timer; // let fs = [];
  599. // fs['activityGroup[' + i + '].timer'] = timer;
  600. // _ts.setData(fs);
  601. }
  602. }
  603. },
  604. // 一天倒计时
  605. NextTime(next, cb) {
  606. var t;
  607. (function ft() {
  608. var dif = (next.getTime() - new Date().getTime()) / 1000;
  609. if (dif > 0) {
  610. t = setTimeout(ft, 1000);
  611. if (cb) cb(Math.floor(dif % 86400 / 3600), Math.floor(dif % 3600 / 60), Math.floor(dif % 60));
  612. } else {
  613. clearTimeout(t);
  614. }
  615. })();
  616. return function() {
  617. clearTimeout(t);
  618. };
  619. },
  620. lpad(num, n) {
  621. var len = num.toString().length;
  622. while (len < n) {
  623. num = "0" + num;
  624. len++;
  625. }
  626. return num;
  627. },
  628. toGroupRemind(event) {
  629. const index = event.currentTarget.dataset.index;
  630. const activity = this.activityGroup[index];
  631. app.globalData.openPage('product/groupDetail/groupDetail?acid=' + activity.id + "&id=" + activity
  632. .productId);
  633. console.log('acid', activity.id);
  634. console.log('productId', activity.productId);
  635. },
  636. addActivityRemind(event) {
  637. const index = event.currentTarget.dataset.index;
  638. const id = event.currentTarget.dataset.id;
  639. const type = event.currentTarget.dataset.type;
  640. mes.remind().then(res => res);
  641. req.postRequest('/api/activity/remind', {
  642. activityId: id
  643. }, res => {
  644. req.msg('订阅提醒成功');
  645. let data = {};
  646. if (type == 1) data['activityGroup[' + index + '].isRemind'] = true;
  647. else if (type == 2) data['joingroup[' + index + '].isRemind'] = true;
  648. else if (type == 3) data['seckill[' + index + '].isRemind'] = true;
  649. else if (type == 4) data['bargain[' + index + '].isRemind'] = true;
  650. this.setData(data);
  651. });
  652. },
  653. cancelActivityRemind(event) {
  654. const index = event.currentTarget.dataset.index;
  655. const id = event.currentTarget.dataset.id;
  656. const type = event.currentTarget.dataset.type;
  657. req.postRequest('/api/activity/cancel/remind', {
  658. id: id
  659. }, res => {
  660. req.msg('取消提醒成功');
  661. let data = {};
  662. if (type == 1) data['activityGroup[' + index + '].isRemind'] = false;
  663. else if (type == 2) data['joingroup[' + index + '].isRemind'] = false;
  664. else if (type == 3) data['seckill[' + index + '].isRemind'] = false;
  665. else if (type == 4) data['bargain[' + index + '].isRemind'] = false;
  666. this.setData(data);
  667. });
  668. },
  669. clearAllTimer() {
  670. this.activityGroup.forEach(it => clearInterval(it.timer));
  671. },
  672. // 获取小店详情
  673. getShop() {
  674. let that = this;
  675. req.getRequest('/api/merchant/detail', {
  676. id: this.query.shopId
  677. }, data => {
  678. console.log(data);
  679. this.setData({
  680. merchant: data
  681. });
  682. console.log(this.merchant);
  683. });
  684. },
  685. toDetail(e) {
  686. let id = e.currentTarget.dataset.id;
  687. app.globalData.openPage("product/detail/detail?id=" + id + '&&hideShop=' + false + '&shopId=' + this.query
  688. .shopId + '&merchantId=' + this.query.merchantId);
  689. },
  690. goUrl(event) {
  691. //跳转链接
  692. let url = event.currentTarget.dataset.url;
  693. app.globalData.openPage(url + '&&hideShop=' + false + '&shopId=' + this.query.shopId + '&merchantId=' +
  694. this.query.merchantId);
  695. },
  696. toSeckillList(event) {
  697. const id = event.currentTarget.dataset.id;
  698. const productId = event.currentTarget.dataset.productid;
  699. console.log(event.currentTarget.dataset);
  700. app.globalData.openPage('activity/seckillDetails/seckillDetails?acid=' + id + "&id=" + productId +
  701. '&&hideShop=' + false + '&shopId=' + this.query.shopId + '&merchantId=' + this.query.merchantId);
  702. }
  703. }
  704. };
  705. </script>
  706. <style>
  707. @import "./shop.css";
  708. </style>