shop.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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/service/index" open-type="reLaunch" 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. <!-- #ifdef H5 -->
  204. <wx-share ref="wxshare" />
  205. <!-- #endif -->
  206. </view>
  207. </template>
  208. <script>
  209. // mine/shop/shop.js
  210. const app = getApp();
  211. const req = require("../../utils/request.js");
  212. const api = require("../../utils/api.js");
  213. const utils = require("../../utils/util.js");
  214. const mes = require("../../utils/requestmessage.js");
  215. // import foot from "../../components/nav-bar/index";
  216. import goodsList from "../../components/goodsList/goodsList";
  217. export default {
  218. data() {
  219. return {
  220. picUrlss: req.public.picUrls,
  221. bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
  222. isUpdate: false,
  223. // 是否更新消息
  224. activityGroup: {},
  225. //店长推荐
  226. group: {},
  227. //社区团购
  228. seckill: [],
  229. //秒杀
  230. joingroup: {},
  231. //拼团
  232. bargain: [],
  233. //砍价
  234. TabList: [{
  235. label: '今天',
  236. active: true,
  237. state: "抢购中",
  238. dayType: 1,
  239. time: ''
  240. }, {
  241. label: '明天',
  242. state: "预热中",
  243. active: false,
  244. time: '',
  245. dayType: 2
  246. }, {
  247. label: '后天',
  248. state: "预热中",
  249. dayType: 3,
  250. time: ''
  251. }, {
  252. label: '',
  253. state: "预热中",
  254. dayType: 4,
  255. active: false,
  256. time: ''
  257. }, {
  258. label: '',
  259. state: "预热中",
  260. dayType: 5,
  261. active: false,
  262. time: ''
  263. }],
  264. timer: "",
  265. userInfo: "",
  266. merchant: {},
  267. homeTemplate: {},
  268. web: ''
  269. };
  270. },
  271. components: {
  272. // foot
  273. goodsList
  274. },
  275. props: {},
  276. onLoad: function(options) {
  277. console.log(options);
  278. if(options.appId) req.setStorage('appId',options.appId);
  279. this.query = options;
  280. if (options.scene) {
  281. this.scene = options.scene;
  282. }
  283. if (options.isShare) {
  284. req.setStorage('pidCode', options.userId);
  285. }
  286. this.web = '&merchantId=' + options.merchantId + '&shopId=' + options.shopId
  287. uni.setNavigationBarColor({
  288. frontColor: '#ffffff',
  289. backgroundColor: req.public.titleTopBgColor
  290. });
  291. this.init();
  292. this.getTime();
  293. this.getShop();
  294. this.getHomeTemplateConfig()
  295. },
  296. onShow() {
  297. let _ts = this;
  298. _ts.setData({
  299. isUpdate: !_ts.isUpdate
  300. });
  301. },
  302. onShareAppMessage: function() {
  303. return this.onShareMessage();
  304. },
  305. onReady() {
  306. // #ifdef H5
  307. var that = this;
  308. //初始化分享内容
  309. setTimeout(function() {
  310. var shareContent = that.onShareMessage();
  311. if (shareContent) {
  312. shareContent.path = window.location.origin + shareContent.path;
  313. }
  314. console.log('分享内容》》》》》', shareContent);
  315. that.$refs.wxshare.init(shareContent);
  316. }, 4 * 1000);
  317. // #endif
  318. },
  319. methods: {
  320. onShareMessage(){
  321. let path = '';
  322. let isSolution = '';
  323. // #ifndef H5
  324. isSolution = req.env[req.env.NODE_ENV].isSolution;
  325. // #endif
  326. // #ifdef H5
  327. isSolution = false;
  328. // #endif
  329. let userInfo = req.getStorage('userInfo');
  330. if(isSolution){
  331. path = '/share/home/index?appId='+req.getStorage('appId')+'&userId='+userInfo.id;
  332. }else{
  333. path = '/pages/shop/shop?userId=' + userInfo.id + '&isShare=' + true + '&shopId=' +
  334. this.query.shopId + '&merchantId=' + this.query.merchantId + '&appId=' + req.getStorage('appId');
  335. }
  336. return {
  337. title: req.excludeSpecial(req.getStorage('userInfo').nickName) + '为你推荐' + this.merchant.title,
  338. // imageUrl: this.data.seckill[0].pic
  339. // path: '/product/detail/detail?id=' + this.query.id + '&isShare=' + true + '&userId=' + req.getStorage('userInfo').id
  340. path: path
  341. };
  342. },
  343. //获取小店配置
  344. getHomeTemplateConfig() {
  345. let _ts = this;
  346. req.getRequest('/api/config', {}, data => {
  347. if (data.shop_config) {
  348. this.setData({
  349. homeTemplate: JSON.parse(data.shop_config)
  350. });
  351. }
  352. console.log(this.homeTemplate)
  353. });
  354. },
  355. /**
  356. *
  357. * 设置tab导航
  358. */
  359. switchTab(event) {
  360. let index = event.currentTarget.dataset.index;
  361. let def = this.TabList.findIndex(it => it.active);
  362. let d = {};
  363. console.log(index, def);
  364. d[`TabList[${def}].active`] = false;
  365. d[`TabList[${index}].active`] = true;
  366. console.log(d);
  367. this.isLoad = true; // this.data.form.page = 1;
  368. d['pageList'] = []; // this.data.form.dayType = this.data.TabList[index].dayType;
  369. this.setData(d);
  370. this.seckillFun();
  371. this.clearAllTimer(); // this.getDate()
  372. },
  373. /**
  374. * 获取当前时间往后退四天
  375. */
  376. laterDay(num) {
  377. var t = new Date();
  378. var iToDay = t.getDate();
  379. var iToMon = t.getMonth();
  380. var iToYear = t.getFullYear();
  381. var arr = [];
  382. for (var i = 1; i < num + 1; i++) {
  383. var newDate = new Date(iToYear, iToMon, iToDay + i);
  384. arr.push(newDate.getFullYear() + '-' + (newDate.getMonth() + 1).toString().padStart(2, '0') + "-" +
  385. newDate.getDate().toString().padStart(2, '0'));
  386. } // console.log(arr)
  387. return arr;
  388. },
  389. /**
  390. * 给tab添加动态时间
  391. */
  392. getTime() {
  393. const data = this.TabList;
  394. var t = new Date();
  395. var iToDay = t.getDate().toString().padStart(2, '0');
  396. var iToMon = (t.getMonth() + 1).toString().padStart(2, '0');
  397. var iToYear = t.getFullYear();
  398. const rq = (iToYear + '-' + iToMon + '-' + iToDay).toString();
  399. const rq1 = this.laterDay(4)[0];
  400. const rq2 = this.laterDay(4)[1];
  401. const rq3 = this.laterDay(4)[2];
  402. const rq4 = this.laterDay(4)[3]; // console.log("rq" + "---", rq1, rq2, rq3, rq4)
  403. data[0].time = rq;
  404. data[1].time = rq1;
  405. data[2].time = rq2;
  406. data[3].label = this.getda(rq3);
  407. data[3].time = rq3;
  408. data[4].label = this.getda(rq4);
  409. data[4].time = rq4;
  410. this.setData({
  411. TabList: data
  412. }); // console.log(this.data.TabList)
  413. },
  414. /**
  415. * 时间转换
  416. */
  417. getda(str) {
  418. var strArr = str.split('-');
  419. var day = strArr[2];
  420. var month = strArr[1];
  421. var year = strArr[0];
  422. let date = (month + '月' + day + '日').toString();
  423. return date;
  424. },
  425. search() {
  426. app.globalData.openPage('pages/search/search');
  427. },
  428. async init() {
  429. await this.loadGroup();
  430. await this.groupFun();
  431. await this.seckillFun();
  432. await this.joingroupFun();
  433. await this.bargainFun();
  434. },
  435. // 获取店长推荐
  436. loadGroup() {
  437. let _ts = this; // type
  438. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  439. req.getRequest('/api/shopProduct/list', {
  440. page: 1,
  441. limit: 3,
  442. type: 1,
  443. // userId: this.query.userId
  444. shopId: this.query.shopId,
  445. merchantId: this.query.merchantId
  446. }, data => {
  447. data = data.map(it => {
  448. it.isRemind = it.remindId;
  449. return it;
  450. });
  451. console.log(data[0]);
  452. let arrObjFilter
  453. arrObjFilter = {
  454. // backgroundColor:this.homeTemplate.backgroundColor,
  455. displayStyle: this.homeTemplate.displayStyle,
  456. lineNumber: this.homeTemplate.lineNumber,
  457. products: data
  458. };
  459. _ts.setData({
  460. activityGroup: arrObjFilter
  461. });
  462. console.log(this.activityGroup)
  463. // _ts.initGroupTimer();
  464. });
  465. },
  466. // 获取社区团购产品
  467. groupFun() {
  468. let _ts = this; // type
  469. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  470. req.getRequest('/api/shopProduct/list', {
  471. page: 1,
  472. limit: 3,
  473. // userId: this.query.userId
  474. type: 2,
  475. merchantId: this.query.merchantId,
  476. sid: this.query.shopId
  477. }, data => {
  478. data = data.list.map(it => {
  479. it.isRemind = it.remindId;
  480. return it;
  481. });
  482. console.log(data);
  483. let arrObjFilter
  484. arrObjFilter = {
  485. // backgroundColor:this.homeTemplate.backgroundColor,
  486. displayStyle: this.homeTemplate.displayStyle,
  487. lineNumber: this.homeTemplate.lineNumber,
  488. products: data.filter(ele => ele.end == false)
  489. };
  490. _ts.setData({
  491. group: arrObjFilter
  492. }); // console.log(this.data.activityGroup)
  493. _ts.initGroupTimer(2);
  494. });
  495. },
  496. // 获取秒杀产品
  497. seckillFun() {
  498. let _ts = this; // type
  499. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  500. req.getRequest('/api/shopProduct/list', {
  501. page: 1,
  502. limit: 3,
  503. type: 3,
  504. // userId: this.query.userId
  505. shopId: this.query.shopId,
  506. merchantId: this.query.merchantId
  507. }, data => {
  508. data = data.list.map(it => {
  509. it.isRemind = it.remindId;
  510. return it;
  511. });
  512. console.log(data);
  513. let arrObjFilter
  514. arrObjFilter = {
  515. // backgroundColor:this.homeTemplate.backgroundColor,
  516. displayStyle: this.homeTemplate.displayStyle,
  517. lineNumber: this.homeTemplate.lineNumber,
  518. products: data.filter(ele => ele.end == false)
  519. };
  520. _ts.setData({
  521. seckill: arrObjFilter
  522. }); // console.log(this.data.activityGroup)
  523. var now = new Date();
  524. var next = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
  525. this.NextTime(next, function(hour, minute, second) {
  526. hour = _ts.lpad(hour, 2);
  527. minute = _ts.lpad(minute, 2);
  528. second = _ts.lpad(second, 2);
  529. let res = [hour, minute, second];
  530. _ts.setData({
  531. timer: res
  532. });
  533. });
  534. _ts.initGroupTimer(3);
  535. });
  536. },
  537. // 获取拼团产品
  538. joingroupFun() {
  539. let _ts = this; // type
  540. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  541. req.getRequest('/api/shopProduct/list', {
  542. page: 1,
  543. limit: 3,
  544. type: 4,
  545. // userId: this.query.userId
  546. shopId: this.query.shopId,
  547. merchantId: this.query.merchantId
  548. }, data => {
  549. data = data.list.map(it => {
  550. it.isRemind = it.remindId;
  551. return it;
  552. });
  553. let arrObjFilter
  554. arrObjFilter = {
  555. // backgroundColor:this.homeTemplate.backgroundColor,
  556. displayStyle: this.homeTemplate.displayStyle,
  557. lineNumber: this.homeTemplate.lineNumber,
  558. products:data.filter(ele => ele.end == false)
  559. };
  560. _ts.setData({
  561. joingroup: arrObjFilter
  562. }); // console.log(this.data.activityGroup)
  563. _ts.initGroupTimer(4);
  564. });
  565. },
  566. // 获取砍价产品
  567. bargainFun() {
  568. let _ts = this; // type
  569. // 类型:1 普通商品 2 社区团购订单 3 秒杀订单 4 拼团订单 5 及时达订单 6 新客特价 7 优惠砍价
  570. req.getRequest('/api/shopProduct/list', {
  571. page: 1,
  572. limit: 3,
  573. type: 7,
  574. // userId: this.query.userId
  575. shopId: this.query.shopId,
  576. merchantId: this.query.merchantId
  577. }, data => {
  578. data = data.list.map(it => {
  579. it.isRemind = it.remindId;
  580. return it;
  581. });
  582. let arrObjFilter
  583. arrObjFilter = {
  584. // backgroundColor:this.homeTemplate.backgroundColor,
  585. displayStyle: this.homeTemplate.displayStyle,
  586. lineNumber: this.homeTemplate.lineNumber,
  587. products:data.filter(ele => ele.end == false)
  588. };
  589. _ts.setData({
  590. bargain: arrObjFilter
  591. }); // console.log(this.data.activityGroup)
  592. _ts.initGroupTimer(7);
  593. });
  594. },
  595. // 获取新客产品
  596. //2为社区团购,4为拼团,7为砍价
  597. initGroupTimer(type) {
  598. //社区拼图定时器
  599. let _ts = this;
  600. let list = [];
  601. if (type == 2) list = this.group.products;
  602. else if (type == 4) list = this.joingroup.products;
  603. else if (type == 7) list = this.bargain.products; // console.log(this.data.joingroupList)
  604. if (list && list.length > 0) {
  605. // let activityGroup = this.data.activityGroup;
  606. for (let i = 0, len = list.length; i < len; i++) {
  607. let group = list[i];
  608. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  609. let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
  610. let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
  611. if (!group.start) endTime = startTime;
  612. let times = parseInt((endTime - nowTime) / 1000);
  613. console.log(times);
  614. let timer = setInterval(() => {
  615. times--;
  616. let data = {};
  617. if (times === 0) {
  618. //重新加载列表
  619. if (type == 2) data['group[' + i + '].end'] = true;
  620. else if (type == 4) data['joingroup[' + i + '].end'] = true;
  621. else if (type == 7) data['bargain[' + i + '].end'] = true;
  622. clearInterval(timer);
  623. } else {
  624. let n = utils.formatDayTimes(times);
  625. if (type == 2) data['group[' + i + '].times'] = n;
  626. else if (type == 4) data['joingroup[' + i + '].times'] = n;
  627. else if (type == 7) data['bargain[' + i + '].times'] = n.split(/:|天/g);
  628. }
  629. _ts.setData(data);
  630. }, 1000);
  631. if (type == 2) this.group[i]['timer'] = timer;
  632. else if (type == 4) this.joingroup[i]['timer'] = timer;
  633. else if (type == 7) this.bargain[i]['timer'] = timer; // let fs = [];
  634. // fs['activityGroup[' + i + '].timer'] = timer;
  635. // _ts.setData(fs);
  636. }
  637. }
  638. },
  639. // 一天倒计时
  640. NextTime(next, cb) {
  641. var t;
  642. (function ft() {
  643. var dif = (next.getTime() - new Date().getTime()) / 1000;
  644. if (dif > 0) {
  645. t = setTimeout(ft, 1000);
  646. if (cb) cb(Math.floor(dif % 86400 / 3600), Math.floor(dif % 3600 / 60), Math.floor(dif % 60));
  647. } else {
  648. clearTimeout(t);
  649. }
  650. })();
  651. return function() {
  652. clearTimeout(t);
  653. };
  654. },
  655. lpad(num, n) {
  656. var len = num.toString().length;
  657. while (len < n) {
  658. num = "0" + num;
  659. len++;
  660. }
  661. return num;
  662. },
  663. toGroupRemind(event) {
  664. const index = event.currentTarget.dataset.index;
  665. const activity = this.activityGroup[index];
  666. app.globalData.openPage('product/groupDetail/groupDetail?acid=' + activity.id + "&id=" + activity
  667. .productId);
  668. console.log('acid', activity.id);
  669. console.log('productId', activity.productId);
  670. },
  671. addActivityRemind(event) {
  672. const index = event.currentTarget.dataset.index;
  673. const id = event.currentTarget.dataset.id;
  674. const type = event.currentTarget.dataset.type;
  675. mes.remind().then(res => res);
  676. req.postRequest('/api/activity/remind', {
  677. activityId: id
  678. }, res => {
  679. req.msg('订阅提醒成功');
  680. let data = {};
  681. if (type == 1) data['activityGroup[' + index + '].isRemind'] = true;
  682. else if (type == 2) data['joingroup[' + index + '].isRemind'] = true;
  683. else if (type == 3) data['seckill[' + index + '].isRemind'] = true;
  684. else if (type == 4) data['bargain[' + index + '].isRemind'] = true;
  685. this.setData(data);
  686. });
  687. },
  688. cancelActivityRemind(event) {
  689. const index = event.currentTarget.dataset.index;
  690. const id = event.currentTarget.dataset.id;
  691. const type = event.currentTarget.dataset.type;
  692. req.postRequest('/api/activity/cancel/remind', {
  693. id: id
  694. }, res => {
  695. req.msg('取消提醒成功');
  696. let data = {};
  697. if (type == 1) data['activityGroup[' + index + '].isRemind'] = false;
  698. else if (type == 2) data['joingroup[' + index + '].isRemind'] = false;
  699. else if (type == 3) data['seckill[' + index + '].isRemind'] = false;
  700. else if (type == 4) data['bargain[' + index + '].isRemind'] = false;
  701. this.setData(data);
  702. });
  703. },
  704. clearAllTimer() {
  705. this.activityGroup.forEach(it => clearInterval(it.timer));
  706. },
  707. // 获取小店详情
  708. getShop() {
  709. let that = this;
  710. req.getRequest('/api/merchant/detail', {
  711. id: this.query.shopId
  712. }, data => {
  713. console.log(data);
  714. this.setData({
  715. merchant: data
  716. });
  717. console.log(this.merchant);
  718. });
  719. },
  720. toDetail(e) {
  721. let id = e.currentTarget.dataset.id;
  722. app.globalData.openPage("product/detail/detail?id=" + id + '&&hideShop=' + false + '&shopId=' + this.query
  723. .shopId + '&merchantId=' + this.query.merchantId);
  724. },
  725. goUrl(event) {
  726. //跳转链接
  727. let url = event.currentTarget.dataset.url;
  728. app.globalData.openPage(url + '&&hideShop=' + false + '&shopId=' + this.query.shopId + '&merchantId=' +
  729. this.query.merchantId);
  730. },
  731. toSeckillList(event) {
  732. const id = event.currentTarget.dataset.id;
  733. const productId = event.currentTarget.dataset.productid;
  734. console.log(event.currentTarget.dataset);
  735. app.globalData.openPage('activity/seckillDetails/seckillDetails?acid=' + id + "&id=" + productId +
  736. '&&hideShop=' + false + '&shopId=' + this.query.shopId + '&merchantId=' + this.query.merchantId);
  737. }
  738. }
  739. };
  740. </script>
  741. <style>
  742. @import "./shop.css";
  743. </style>