index.vue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. <template>
  2. <!-- 首页 -->
  3. <view v-if="pageShow" class="page"
  4. :class="bgTabVal==2?'fullsize noRepeat':bgTabVal==1?'repeat ysize':'noRepeat ysize'"
  5. :style="'background-color:'+bgColor+';background-image: url('+bgPic+');min-height:'+windowHeight+'px;'">
  6. <view v-if="!errorNetwork" :style="colorStyle">
  7. <skeletons v-if="showSkeleton"></skeletons>
  8. <view class="index">
  9. <!-- #ifdef H5 -->
  10. <view v-for="(item, index) in styleConfig" :key="index">
  11. <component :is="item.name" :index="index" :dataConfig="item" @changeBarg="changeBarg"
  12. @detail="goDetail" :isSortType="isSortType" @bindSortId="bindSortId" @changeLogin="changeLogin"
  13. @bindHeight="bindHeight" :isFixed="isFixed" :productVideoStatus='product_video_status'
  14. :isScrolled="isScrolled">
  15. </component>
  16. </view>
  17. <!-- #endif -->
  18. <!-- #ifdef MP || APP-PLUS -->
  19. <!-- 自定义样式 -->
  20. <block v-for="(item, index) in styleConfig" :key="index">
  21. <homeComb v-if="item.name == 'homeComb'" :dataConfig="item" @bindSortId="bindSortId"
  22. :isScrolled="isScrolled"></homeComb>
  23. <shortVideo v-if="item.name == 'shortVideo'" :dataConfig="item" :isSortType="isSortType">
  24. </shortVideo>
  25. <userInfor v-if="item.name == 'userInfor'" :dataConfig="item" :isSortType="isSortType"
  26. @changeLogin="changeLogin">
  27. </userInfor>
  28. <newVip v-if="item.name == 'newVip'" :dataConfig="item" :isSortType="isSortType">
  29. </newVip>
  30. <activeParty v-if="item.name == 'activeParty'" :dataConfig="item" :isSortType="isSortType">
  31. </activeParty>
  32. <!-- 文章列表 -->
  33. <articleList v-if="item.name == 'articleList'" :dataConfig="item" :isSortType="isSortType">
  34. </articleList>
  35. <bargain v-if="item.name == 'bargain'" :dataConfig="item" @changeBarg="changeBarg"
  36. :isSortType="isSortType"></bargain>
  37. <blankPage v-if="item.name == 'blankPage'" :dataConfig="item" :isSortType="isSortType"></blankPage>
  38. <combination v-if="item.name == 'combination'" :dataConfig="item" :isSortType="isSortType">
  39. </combination>
  40. <!-- 优惠券 -->
  41. <coupon v-if="item.name == 'coupon'" :dataConfig="item" :isSortType="isSortType"
  42. @changeLogin="changeLogin"></coupon>
  43. <!-- 客户服务 -->
  44. <customerService v-if="item.name == 'customerService'" :dataConfig="item" :isSortType="isSortType">
  45. </customerService>
  46. <!-- 商品列表 -->
  47. <goodList v-if="item.name == 'goodList'" :dataConfig="item" @detail="goDetail"
  48. :isSortType="isSortType"></goodList>
  49. <guide v-if="item.name == 'guide'" :dataConfig="item" :isSortType="isSortType"></guide>
  50. <!-- 顶部搜索框 -->
  51. <headerSerch v-if="item.name == 'headerSerch'" :dataConfig="item"></headerSerch>
  52. <!-- 直播模块 -->
  53. <liveBroadcast v-if="item.name == 'liveBroadcast'" :dataConfig="item" :isSortType="isSortType">
  54. </liveBroadcast>
  55. <menus v-if="item.name == 'menus'" :dataConfig="item" :isSortType="isSortType"></menus>
  56. <!-- 实时消息 -->
  57. <news v-if="item.name == 'news'" :dataConfig="item" :isSortType="isSortType"></news>
  58. <!-- 图片库 -->
  59. <pictureCube v-if="item.name == 'pictureCube'" :dataConfig="item" :isSortType="isSortType">
  60. </pictureCube>
  61. <!-- 促销列表 -->
  62. <promotionList v-if="item.name == 'promotionList'" :dataConfig="item" @detail="goDetail"
  63. :isSortType="isSortType" :productVideoStatus='product_video_status'>
  64. </promotionList>
  65. <richText v-if="item.name == 'richText'" :dataConfig="item" :isSortType="isSortType"></richText>
  66. <seckill v-if="item.name == 'seckill'" :dataConfig="item" :isSortType="isSortType"></seckill>
  67. <!-- 轮播图-->
  68. <swiperBg v-if="item.name == 'swiperBg'" :dataConfig="item" :isSortType="isSortType"></swiperBg>
  69. <swipers v-if="item.name == 'swipers'" :dataConfig="item" :isSortType="isSortType"></swipers>
  70. <!-- 顶部选项卡 -->
  71. <tabNav v-if="item.name == 'tabNav'" :dataConfig="item" @bindHeight="bindHeighta"
  72. @bindSortId="bindSortId" :isFixed="isFixed"></tabNav>
  73. <!-- 标题 -->
  74. <titles v-if="item.name == 'titles'" :dataConfig="item" :isSortType="isSortType"></titles>
  75. </block>
  76. <!-- #endif -->
  77. <!-- 分类商品模块 -->
  78. <!-- #ifdef APP-PLUS -->
  79. <view class="sort-product" v-if="isSortType == 1" style="margin-top: 0;">
  80. <scroll-view scroll-x="true" class="sort-scroll">
  81. <view class="sort-box" v-if="sortList.children && sortList.children.length">
  82. <view class="sort-item" v-for="(item, index) in sortList.children" :key="index"
  83. @click="changeSort(item, index)" :class="{ on: curSort == index }">
  84. <image :src="item.pic" mode="" v-if="item.pic"></image>
  85. <image src="/static/images/sort-img.png" mode="" v-else></image>
  86. <view class="txt">{{ item.cate_name }}</view>
  87. </view>
  88. </view>
  89. </scroll-view>
  90. <!-- 首页商品列表 -->
  91. <view class="product-list" v-if="goodList.length">
  92. <view class="product-item" v-for="(item, index) in goodList" @click="goGoodsDetail(item)">
  93. <image :src="item.image" mode="aspectFill"></image>
  94. <span class="pictrue_log_big pictrue_log_class"
  95. v-if="item.activity && item.activity.type === '1'">秒杀</span>
  96. <span class="pictrue_log_big pictrue_log_class"
  97. v-if="item.activity && item.activity.type === '2'">砍价</span>
  98. <span class="pictrue_log_big pictrue_log_class"
  99. v-if="item.activity && item.activity.type === '3'">拼团</span>
  100. <view class="info">
  101. <view class="title line1">{{ item.store_name }}</view>
  102. <view class="price-box">
  103. <text>¥</text>
  104. {{ item.price }}
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. <Loading :loaded="loaded" :loading="loading"></Loading>
  110. <view v-if="goodList.length == 0 && loaded" class="sort-scroll">
  111. <view class="empty-box">
  112. <image :src="imgHost + '/statics/images/no-thing.png'"></image>
  113. <view class="tips">暂无商品,去看点别的吧</view>
  114. </view>
  115. <recommend :hostProduct="hostProduct"></recommend>
  116. </view>
  117. </view>
  118. <!-- #endif -->
  119. <!-- #ifndef APP-PLUS -->
  120. <!-- 商品排序 -->
  121. <view class="sort-product" v-if="isSortType == 1" :style="{ marginTop: sortMpTop + 'px' }">
  122. <scroll-view scroll-x="true" class="sort-scroll">
  123. <view class="sort-box" v-if="sortList.children && sortList.children.length">
  124. <view class="sort-item" v-for="(item, index) in sortList.children" :key="index"
  125. @click="changeSort(item, index)" :class="{ on: curSort == index }">
  126. <image :src="item.pic" mode="" v-if="item.pic"></image>
  127. <image src="/static/images/sort-img.png" mode="" v-else></image>
  128. <view class="txt">{{ item.cate_name }}</view>
  129. </view>
  130. </view>
  131. </scroll-view>
  132. <!-- 首页底部商品列表 -->
  133. <view class="product-list" v-if="goodList.length">
  134. <view class="product-item" v-for="(item, index) in goodList" @click="goGoodsDetail(item)">
  135. <view class="pictrue">
  136. <image :src="item.image" mode="aspectFill"></image>
  137. <span class="pictrue_log_big pictrue_log_class"
  138. v-if="item.activity && item.activity.type === '1'">秒杀</span>
  139. <span class="pictrue_log_big pictrue_log_class"
  140. v-if="item.activity && item.activity.type === '2'">砍价</span>
  141. <span class="pictrue_log_big pictrue_log_class"
  142. v-if="item.activity && item.activity.type === '3'">拼团</span>
  143. <view class="activityFrame" v-if="item.activity_frame.image"
  144. :style="'background-image: url('+item.activity_frame.image+');'"></view>
  145. </view>
  146. <view class="info">
  147. <view class="title line1">{{ item.store_name }}</view>
  148. <view class="price-box">
  149. <text>¥</text>
  150. {{ item.price }}
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. <Loading :loaded="loaded" :loading="loading"></Loading>
  156. <view class="" v-if="goodList.length == 0 && loaded" class="sort-scroll">
  157. <view class="empty-box">
  158. <image :src="imgHost + '/statics/images/no-thing.png'"></image>
  159. <view class="tips">暂无商品,去看点别的吧</view>
  160. </view>
  161. <recommend :hostProduct="hostProduct"></recommend>
  162. </view>
  163. </view>
  164. <!-- #endif -->
  165. <couponWindow :window="isCouponShow" @onColse="couponClose" :couponImage="couponObj.image"
  166. :couponList="couponObj.list"></couponWindow>
  167. <view class="uni-p-b-98" v-if="footerStatus"></view>
  168. <view v-if="site_config" class="site-config" @click="goICP">{{ site_config }}</view>
  169. <pageFooter></pageFooter>
  170. <!-- #ifdef MP -->
  171. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  172. <!-- #endif -->
  173. </view>
  174. </view>
  175. <view v-else>
  176. <view class="error-network">
  177. <image :src="imgHost + '/statics/images/error-network.png'"></image>
  178. <view class="title">网络连接断开</view>
  179. <view class="con">
  180. <view class="label">请检查情况:</view>
  181. <view class="item">· 在设置中是否已开启网络权限</view>
  182. <view class="item">· 当前是否处于弱网环境</view>
  183. <view class="item">· 版本是否过低,升级试试吧</view>
  184. </view>
  185. <view class="btn" @click="reconnect">重新连接</view>
  186. </view>
  187. </view>
  188. </view>
  189. </template>
  190. <script>
  191. const app = getApp();
  192. import colors from "@/mixins/color";
  193. import couponWindow from '@/components/couponWindow/index';
  194. import permision from "@/js_sdk/wa-permission/permission.js";
  195. import skeletons from './components/skeletons';
  196. import {
  197. getCouponV2,
  198. getCouponNewUser,
  199. copyRight
  200. } from '@/api/api.js';
  201. import {
  202. getShare
  203. } from '@/api/public.js';
  204. // #ifdef H5
  205. import mConfig from './components/index.js';
  206. import {
  207. silenceAuth
  208. } from '@/api/public.js';
  209. // #endif
  210. // #ifdef MP || APP-PLUS
  211. import userInfor from './components/userInfor';
  212. import homeComb from './components/homeComb';
  213. import newVip from './components/newVip';
  214. import shortVideo from './components/shortVideo';
  215. import activeParty from './components/activeParty';
  216. import headerSerch from './components/headerSerch';
  217. import swipers from './components/swipers';
  218. import coupon from './components/coupon';
  219. import articleList from './components/articleList';
  220. import bargain from './components/bargain';
  221. import blankPage from './components/blankPage';
  222. import combination from './components/combination';
  223. import customerService from './components/customerService';
  224. import goodList from './components/goodList';
  225. import guide from './components/guide';
  226. import liveBroadcast from './components/liveBroadcast';
  227. import menus from './components/menus';
  228. import news from './components/news';
  229. import pictureCube from './components/pictureCube';
  230. import promotionList from './components/promotionList';
  231. import richText from './components/richText';
  232. import seckill from './components/seckill';
  233. import swiperBg from './components/swiperBg';
  234. import tabNav from './components/tabNav';
  235. import titles from './components/titles';
  236. import {
  237. getTemlIds
  238. } from '@/api/api.js';
  239. import {
  240. SUBSCRIBE_MESSAGE,
  241. TIPS_KEY
  242. } from '@/config/cache';
  243. // #endif
  244. import {
  245. mapGetters,
  246. mapMutations
  247. } from 'vuex';
  248. import {
  249. getDiy,
  250. getIndexData,
  251. getDiyVersion,
  252. } from '@/api/api.js';
  253. import {
  254. getCategoryList,
  255. getProductslist,
  256. getProductHot,
  257. diyProduct
  258. } from '@/api/store.js';
  259. import {
  260. goShopDetail
  261. } from '@/libs/order.js';
  262. import {
  263. toLogin
  264. } from '@/libs/login.js';
  265. import {
  266. HTTP_REQUEST_URL
  267. } from '@/config/app';
  268. import pageFooter from '@/components/pageFooter/index.vue';
  269. import Loading from '@/components/Loading/index.vue';
  270. import recommend from '@/components/recommend';
  271. export default {
  272. computed: mapGetters(['isLogin', 'uid', 'cartNum']),
  273. mixins: [colors],
  274. components: {
  275. skeletons,
  276. recommend,
  277. Loading,
  278. pageFooter,
  279. couponWindow,
  280. // #ifdef H5
  281. ...mConfig,
  282. // #endif
  283. // #ifdef MP || APP-PLUS
  284. homeComb,
  285. newVip,
  286. userInfor,
  287. shortVideo,
  288. activeParty,
  289. headerSerch,
  290. swipers,
  291. coupon,
  292. articleList,
  293. bargain,
  294. blankPage,
  295. combination,
  296. customerService,
  297. goodList,
  298. guide,
  299. liveBroadcast,
  300. menus,
  301. pictureCube,
  302. news,
  303. promotionList,
  304. richText,
  305. seckill,
  306. swiperBg,
  307. tabNav,
  308. titles
  309. // #endif
  310. },
  311. data() {
  312. return {
  313. showSkeleton: true, //骨架屏显示隐藏
  314. styleConfig: [],
  315. loading: false,
  316. loadend: false,
  317. loadTitle: '下拉加载更多', //提示语
  318. page: 1,
  319. limit: this.$config.LIMIT,
  320. numConfig: 0,
  321. code: '',
  322. isCouponShow: false,
  323. couponObj: {},
  324. couponObjs: {
  325. show: false
  326. },
  327. shareInfo: {},
  328. footConfig: {},
  329. isSortType: 0,
  330. sortList: '',
  331. sortAll: [],
  332. goodPage: 1,
  333. goodList: [],
  334. sid: 0,
  335. curSort: 0,
  336. sortMpTop: 0,
  337. loaded: false,
  338. loading: false,
  339. hostProduct: [],
  340. hotScroll: false,
  341. hotPage: 1,
  342. hotLimit: 10,
  343. domOffsetTop: 50,
  344. // #ifdef APP-PLUS || MP
  345. isFixed: true,
  346. // #endif
  347. // #ifdef H5
  348. isFixed: false,
  349. // #endif
  350. site_config: '',
  351. errorNetwork: false, // 是否断网
  352. footerStatus: false,
  353. isHeaderSerch: false,
  354. bgColor: '',
  355. bgPic: '',
  356. bgTabVal: '',
  357. pageShow: true,
  358. windowHeight: 0,
  359. imgHost: HTTP_REQUEST_URL,
  360. isShowAuth: false,
  361. isScrolled: false,
  362. product_video_status: false,
  363. confirm_video_status: false
  364. };
  365. },
  366. onLoad(options) {
  367. let that = this
  368. that.getOptions(options);
  369. this.$nextTick(function() {
  370. uni.getSystemInfo({
  371. success: function(res) {
  372. that.windowHeight = res.windowHeight;
  373. }
  374. });
  375. })
  376. const {
  377. state,
  378. scope
  379. } = options;
  380. this.diyData();
  381. this.getIndexData();
  382. // #ifdef H5
  383. this.setOpenShare();
  384. // #endif
  385. // #ifdef MP
  386. this.getTemlIds();
  387. // #endif
  388. getShare().then(res => {
  389. this.shareInfo = res.data;
  390. });
  391. this.getCopyRight();
  392. this.$eventHub.$on('confirm_video_status', () => {
  393. if (this.confirm_video_status) {
  394. return;
  395. }
  396. this.confirm_video_status = true;
  397. let flag = true;
  398. // #ifdef H5
  399. flag = window.self == window.top;
  400. // #endif
  401. if (!flag) {
  402. return;
  403. }
  404. uni.showModal({
  405. content: '当前使用移动网络,是否继续播放视频?',
  406. success: (res) => {
  407. if (res.confirm) {
  408. // 监听
  409. this.SET_AUTOPLAY(true);
  410. this.$eventHub.$emit('product_video_observe');
  411. }
  412. }
  413. });
  414. });
  415. },
  416. onUnload() {
  417. // 清除监听
  418. uni.$off('activeFn');
  419. },
  420. watch: {
  421. isLogin: {
  422. deep: true, //深度监听设置为 true
  423. handler: function(newV, oldV) {
  424. // 优惠券弹窗
  425. var newDates = new Date().toLocaleDateString();
  426. if (newV) {
  427. try {
  428. var oldDate = uni.getStorageSync('oldDate') || '';
  429. } catch {}
  430. if (oldDate != newDates) {
  431. this.getCoupon();
  432. }
  433. }
  434. }
  435. }
  436. },
  437. onShow() {
  438. if (this.cartNum > 0) {
  439. uni.setTabBarBadge({
  440. index: 3,
  441. text: this.cartNum > 99 ? '99+' : this.cartNum + ''
  442. })
  443. } else {
  444. uni.hideTabBarRedDot({
  445. index: 3
  446. })
  447. }
  448. uni.removeStorageSync('form_type_cart');
  449. // 优惠券弹窗
  450. if (this.isLogin) {
  451. this.getCoupon();
  452. }
  453. this.getdiyProduct()
  454. },
  455. onReady() {},
  456. methods: {
  457. ...mapMutations(['SET_AUTOPLAY']),
  458. // 授权关闭
  459. authColse: function(e) {
  460. this.isShowAuth = e
  461. },
  462. // div商品详情
  463. getdiyProduct() {
  464. diyProduct().then(res => {
  465. uni.setStorageSync('diyProduct', JSON.stringify(res.data.product_detail))
  466. uni.setStorageSync('product_video_status', JSON.stringify(res.data.product_video_status))
  467. this.$eventHub.$emit('product_video_status', res.data.product_video_status);
  468. this.product_video_status = res.data.product_video_status;
  469. })
  470. },
  471. getCopyRight() {
  472. copyRight().then(res => {
  473. let data = res.data;
  474. uni.setStorageSync('wechatStatus', data.wechat_status)
  475. // #ifndef APP-PLUS
  476. this.site_config = data.record_No;
  477. // #endif
  478. if (!data.copyrightContext && !data.copyrightImage) {
  479. data.copyrightImage = '/static/images/support.png'
  480. }
  481. uni.setStorageSync('copyNameInfo', data.copyrightContext);
  482. uni.setStorageSync('copyImageInfo', data.copyrightImage);
  483. // #ifdef MP
  484. uni.setStorageSync('MPSiteData', JSON.stringify({
  485. site_logo: data.site_logo,
  486. site_name: data.site_name
  487. }));
  488. // #endif
  489. }).catch(err => {
  490. return this.$util.Tips({
  491. title: err.msg
  492. });
  493. });
  494. },
  495. getOptions(options) {
  496. let that = this;
  497. // #ifdef MP
  498. if (options.scene) {
  499. let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
  500. //记录推广人uid
  501. if (value.spid) app.globalData.spid = value.spid;
  502. }
  503. // #endif
  504. if (options.spid) app.globalData.spid = options.spid;
  505. },
  506. // 重新链接
  507. reconnect() {
  508. // uni.showLoading({
  509. // title: '加载中'
  510. // })
  511. this.diyData();
  512. this.getIndexData();
  513. getShare().then(res => {
  514. this.shareInfo = res.data;
  515. });
  516. },
  517. goICP() {
  518. // #ifdef H5
  519. window.open('http://beian.miit.gov.cn/');
  520. // #endif
  521. // #ifdef MP
  522. uni.navigateTo({
  523. url: `/pages/annex/web_view/index?url=https://beian.miit.gov.cn/`
  524. });
  525. // #endif
  526. },
  527. bindHeighta(data) {
  528. // #ifdef APP-PLUS
  529. this.sortMpTop = data.top + data.height;
  530. // #endif
  531. },
  532. bindHeight(data) {
  533. uni.hideLoading();
  534. this.domOffsetTop = data.top;
  535. },
  536. // 去商品详情
  537. goGoodsDetail(item) {
  538. goShopDetail(item, this.uid).then(res => {
  539. uni.navigateTo({
  540. url: `/pages/goods_details/index?id=${item.id}`
  541. });
  542. });
  543. },
  544. /**
  545. * 获取我的推荐
  546. */
  547. get_host_product: function() {
  548. let that = this;
  549. if (that.hotScroll) return;
  550. getProductHot(that.hotPage, that.hotLimit).then(res => {
  551. that.hotPage++;
  552. that.hotScroll = res.data.length < that.hotLimit;
  553. that.hostProduct = that.hostProduct.concat(res.data);
  554. // that.$set(that, 'hostProduct', res.data)
  555. });
  556. },
  557. // 分类点击
  558. changeSort(item, index) {
  559. if (this.curSort == index) return;
  560. this.curSort = index;
  561. this.sid = item.id;
  562. this.goodList = [];
  563. this.goodPage = 1;
  564. this.loaded = false;
  565. this.getGoodsList();
  566. },
  567. // 获取分类id
  568. bindSortId(data) {
  569. this.isSortType = data == -99 ? 0 : 1;
  570. this.getProductList(data);
  571. if (this.hostProduct.length == 0) {
  572. this.get_host_product();
  573. }
  574. },
  575. getProductList(data) {
  576. let tempObj = '';
  577. this.curSort = 0;
  578. this.loaded = false;
  579. if (this.sortAll.length > 0) {
  580. this.sortAll.forEach((el, index) => {
  581. if (el.id == data) {
  582. this.$set(this, 'sortList', el);
  583. this.sid = el.children.length ? el.children[0].id : '';
  584. }
  585. });
  586. this.goodList = [];
  587. this.goodPage = 1;
  588. this.$nextTick(() => {
  589. if (this.sortList != '') this.getGoodsList();
  590. });
  591. } else {
  592. getCategoryList().then(res => {
  593. this.sortAll = res.data;
  594. res.data.forEach((el, index) => {
  595. if (el.id == data) {
  596. this.sortList = el;
  597. this.sid = el.children.length ? el.children[0].id : '';
  598. }
  599. });
  600. this.goodList = [];
  601. this.goodPage = 1;
  602. this.$nextTick(() => {
  603. if (this.sortList != '') this.getGoodsList();
  604. });
  605. });
  606. }
  607. },
  608. // 商品列表
  609. getGoodsList() {
  610. if (this.loading || this.loaded) return;
  611. this.loading = true;
  612. getProductslist({
  613. sid: this.sid,
  614. keyword: '',
  615. priceOrder: '',
  616. salesOrder: '',
  617. news: 0,
  618. page: this.goodPage,
  619. limit: 10,
  620. cid: this.sortList.id
  621. }).then(res => {
  622. this.loading = false;
  623. this.loaded = res.data.length < 10;
  624. this.goodPage++;
  625. this.goodList = this.goodList.concat(res.data);
  626. });
  627. },
  628. // 新用户优惠券
  629. getNewCoupon() {
  630. const oldUser = uni.getStorageSync('oldUser') || 0;
  631. if (!oldUser) {
  632. getCouponNewUser().then(res => {
  633. const {
  634. data
  635. } = res;
  636. if (data.show) {
  637. if (data.list.length) {
  638. this.isCouponShow = true;
  639. this.couponObj = data;
  640. uni.setStorageSync('oldUser', 1);
  641. }
  642. } else {
  643. uni.setStorageSync('oldUser', 1);
  644. }
  645. });
  646. }
  647. },
  648. // 优惠券弹窗
  649. getCoupon() {
  650. const tagDate = uni.getStorageSync('tagDate') || '',
  651. nowDate = new Date().toLocaleDateString();
  652. if (tagDate === nowDate) {
  653. this.getNewCoupon();
  654. } else {
  655. getCouponV2().then(res => {
  656. const {
  657. data
  658. } = res;
  659. if (data.list.length) {
  660. this.isCouponShow = true;
  661. this.couponObj = data;
  662. uni.setStorageSync('tagDate', new Date().toLocaleDateString());
  663. } else {
  664. this.getNewCoupon();
  665. }
  666. });
  667. }
  668. },
  669. // 优惠券弹窗关闭
  670. couponClose() {
  671. this.isCouponShow = false;
  672. if (!uni.getStorageSync('oldUser')) {
  673. this.getNewCoupon();
  674. }
  675. },
  676. onLoadFun() {
  677. this.isShowAuth = false
  678. },
  679. // #ifdef H5
  680. // 获取url后面的参数
  681. getQueryString(name) {
  682. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  683. var reg_rewrite = new RegExp('(^|/)' + name + '/([^/]*)(/|$)', 'i');
  684. var r = window.location.search.substr(1).match(reg);
  685. var q = window.location.pathname.substr(1).match(reg_rewrite);
  686. if (r != null) {
  687. return unescape(r[2]);
  688. } else if (q != null) {
  689. return unescape(q[2]);
  690. } else {
  691. return null;
  692. }
  693. },
  694. // #endif
  695. // #ifdef MP
  696. getTemlIds() {
  697. let messageTmplIds = wx.getStorageSync(SUBSCRIBE_MESSAGE);
  698. if (!messageTmplIds) {
  699. getTemlIds().then(res => {
  700. if (res.data) wx.setStorageSync(SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  701. });
  702. }
  703. },
  704. // #endif
  705. // 对象转数组
  706. objToArr(data) {
  707. let obj = Object.keys(data);
  708. let m = obj.map(key => data[key]);
  709. return m;
  710. },
  711. setDiyData(data) {
  712. console.log(data)
  713. this.errorNetwork = false
  714. if (data.is_bg_color) {
  715. this.bgColor = data.color_picker
  716. }
  717. if (data.is_bg_pic) {
  718. this.bgPic = data.bg_pic
  719. this.bgTabVal = data.bg_tab_val
  720. }
  721. this.pageShow = data.is_show
  722. uni.setNavigationBarTitle({
  723. title: data.title
  724. });
  725. let temp = [];
  726. let lastArr = this.objToArr(data.value);
  727. lastArr.forEach((item, index, arr) => {
  728. if (item.name == 'headerSerch') {
  729. this.isHeaderSerch = true
  730. }
  731. if (item.name == 'pageFoot') {
  732. arr.splice(index, 1);
  733. }
  734. if (item.name == 'tabNav') {
  735. // #ifndef APP-PLUS
  736. // uni.showLoading({
  737. // title: '加载中',
  738. // mask: true,
  739. // });
  740. // #endif
  741. // setTimeout(function() {
  742. // uni.hideLoading();
  743. // }, 8000);
  744. }
  745. temp = arr;
  746. });
  747. function sortNumber(a, b) {
  748. return a.timestamp - b.timestamp;
  749. }
  750. temp.sort(sortNumber)
  751. this.styleConfig = temp;
  752. this.showSkeleton = false
  753. },
  754. getDiyData() {
  755. getDiy(0).then(res => {
  756. uni.setStorageSync('diyData', JSON.stringify(res.data));
  757. this.setDiyData(res.data);
  758. }).catch(error => {
  759. // #ifdef APP-PLUS
  760. if (error.status) {
  761. uni.hideLoading()
  762. if (this.errorNetwork) {
  763. uni.showToast({
  764. title: '请开启网络连接',
  765. icon: 'none',
  766. duration: 2000
  767. })
  768. }
  769. this.errorNetwork = true
  770. this.showSkeleton = false;
  771. }
  772. // #endif
  773. });
  774. },
  775. diyData() {
  776. let diyData = uni.getStorageSync('diyData');
  777. if (diyData) {
  778. getDiyVersion(0).then(res => {
  779. let diyVersion = uni.getStorageSync('diyVersion');
  780. if ((res.data.version + '0') === diyVersion) {
  781. this.setDiyData(JSON.parse(diyData));
  782. } else {
  783. uni.setStorageSync('diyVersion', (res.data.version + '0'));
  784. this.getDiyData();
  785. }
  786. });
  787. } else {
  788. this.getDiyData();
  789. }
  790. // getDiy(0).then(res => {
  791. // this.errorNetwork = false
  792. // let data = res.data;
  793. // if (data.is_bg_color) {
  794. // this.bgColor = data.color_picker
  795. // }
  796. // if (data.is_bg_pic) {
  797. // this.bgPic = data.bg_pic
  798. // this.bgTabVal = data.bg_tab_val
  799. // }
  800. // this.pageShow = data.is_show
  801. // uni.setNavigationBarTitle({
  802. // title: res.data.title
  803. // });
  804. // let temp = [];
  805. // let lastArr = that.objToArr(res.data.value);
  806. // lastArr.forEach((item, index, arr) => {
  807. // if (item.name == 'headerSerch') {
  808. // this.isHeaderSerch = true
  809. // }
  810. // if (item.name == 'pageFoot') {
  811. // arr.splice(index, 1);
  812. // }
  813. // if (item.name == 'tabNav') {
  814. // // #ifndef APP-PLUS
  815. // // uni.showLoading({
  816. // // title: '加载中',
  817. // // mask: true,
  818. // // });
  819. // // #endif
  820. // // setTimeout(function() {
  821. // // uni.hideLoading();
  822. // // }, 8000);
  823. // }
  824. // temp = arr;
  825. // });
  826. // function sortNumber(a, b) {
  827. // return a.timestamp - b.timestamp;
  828. // }
  829. // temp.sort(sortNumber)
  830. // that.styleConfig = temp;
  831. // this.showSkeleton = false
  832. // }).catch(error => {
  833. // // #ifdef APP-PLUS
  834. // if (error.status) {
  835. // uni.hideLoading()
  836. // if (that.errorNetwork) {
  837. // uni.showToast({
  838. // title: '连接失败',
  839. // icon: 'none',
  840. // duration: 2000
  841. // })
  842. // }
  843. // this.errorNetwork = true
  844. // this.showSkeleton = false;
  845. // }
  846. // // #endif
  847. // });
  848. },
  849. getIndexData() {},
  850. changeLogin() {
  851. this.getIsLogin();
  852. },
  853. getIsLogin() {
  854. // #ifndef MP
  855. toLogin()
  856. // #endif
  857. // #ifdef MP
  858. this.isShowAuth = true;
  859. // #endif
  860. },
  861. changeBarg(item) {
  862. if (!this.isLogin) {
  863. this.getIsLogin();
  864. } else {
  865. uni.navigateTo({
  866. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&spid=${this.$store.state.app.uid}`
  867. });
  868. }
  869. },
  870. goDetail(item) {
  871. goShopDetail(item, this.$store.state.app.uid).then(res => {
  872. uni.navigateTo({
  873. url: `/pages/goods_details/index?id=${item.id}`
  874. });
  875. });
  876. },
  877. // #ifdef H5
  878. // 微信分享;
  879. setOpenShare: function() {
  880. let that = this;
  881. let uid = this.uid ? this.uid : 0;
  882. if (that.$wechat.isWeixin()) {
  883. getShare().then(res => {
  884. let data = res.data;
  885. let configAppMessage = {
  886. desc: data.synopsis,
  887. title: data.title,
  888. link: location.href + '?spid=' + uid,
  889. imgUrl: data.img
  890. };
  891. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData',
  892. 'onMenuShareAppMessage', 'onMenuShareTimeline'
  893. ],
  894. configAppMessage);
  895. });
  896. }
  897. }
  898. // #endif
  899. },
  900. onReachBottom: function() {
  901. if (this.isSortType == 0) {} else {
  902. this.getGoodsList();
  903. }
  904. },
  905. onPageScroll(e) {
  906. // #ifdef H5
  907. if (this.isHeaderSerch) {
  908. if (e.scrollTop > this.domOffsetTop) {
  909. this.isFixed = true;
  910. }
  911. if (e.scrollTop < this.domOffsetTop) {
  912. this.$nextTick(() => {
  913. this.isFixed = false;
  914. });
  915. }
  916. } else {
  917. this.isFixed = false
  918. }
  919. // #endif
  920. if (e.scrollTop > 10) {
  921. this.isScrolled = true;
  922. } else {
  923. this.isScrolled = false;
  924. }
  925. },
  926. //#ifdef MP
  927. onShareAppMessage() {
  928. let uid = this.uid ? this.uid : 0;
  929. return {
  930. title: this.shareInfo.title,
  931. path: '/pages/index/index?spid=' + uid,
  932. imageUrl: this.shareInfo.img,
  933. desc: this.shareInfo.synopsis
  934. };
  935. },
  936. //分享到朋友圈
  937. onShareTimeline: function() {
  938. return {
  939. title: this.shareInfo.title,
  940. path: '/pages/index/index',
  941. imageUrl: this.shareInfo.img,
  942. desc: this.shareInfo.synopsis
  943. };
  944. }
  945. //#endif
  946. };
  947. </script>
  948. <style lang="scss">
  949. // page {
  950. // padding-bottom: 50px;
  951. // }
  952. .pictrue_log_class {
  953. background-color: var(--view-theme);
  954. }
  955. .page {
  956. padding-bottom: 98rpx;
  957. padding-bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  958. padding-bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  959. }
  960. .ysize {
  961. background-size: 100%;
  962. }
  963. .fullsize {
  964. background-size: 100% 100%;
  965. }
  966. .repeat {
  967. background-repeat: repeat;
  968. }
  969. .noRepeat {
  970. background-repeat: no-repeat;
  971. }
  972. .privacy-wrapper {
  973. z-index: 999;
  974. position: fixed;
  975. left: 0;
  976. top: 0;
  977. width: 100%;
  978. height: 100%;
  979. background: #7F7F7F;
  980. .privacy-box {
  981. position: absolute;
  982. left: 50%;
  983. top: 50%;
  984. transform: translate(-50%, -50%);
  985. width: 560rpx;
  986. padding: 50rpx 45rpx 0;
  987. background: #fff;
  988. border-radius: 20rpx;
  989. .title {
  990. text-align: center;
  991. font-size: 32rpx;
  992. text-align: center;
  993. color: #333;
  994. font-weight: 700;
  995. }
  996. .content {
  997. margin-top: 20rpx;
  998. line-height: 1.5;
  999. font-size: 26rpx;
  1000. color: #666;
  1001. navigator {
  1002. display: inline-block;
  1003. color: #E93323;
  1004. }
  1005. }
  1006. .btn-box {
  1007. margin-top: 40rpx;
  1008. text-align: center;
  1009. font-size: 30rpx;
  1010. .btn-item {
  1011. height: 82rpx;
  1012. line-height: 82rpx;
  1013. background: linear-gradient(90deg, #F67A38 0%, #F11B09 100%);
  1014. color: #fff;
  1015. border-radius: 41rpx;
  1016. }
  1017. .btn {
  1018. padding: 30rpx 0;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. .error-network {
  1024. position: fixed;
  1025. left: 0;
  1026. top: 0;
  1027. display: flex;
  1028. flex-direction: column;
  1029. align-items: center;
  1030. width: 100%;
  1031. height: 100%;
  1032. padding-top: 40rpx;
  1033. background: #fff;
  1034. image {
  1035. width: 414rpx;
  1036. height: 336rpx;
  1037. }
  1038. .title {
  1039. position: relative;
  1040. top: -40rpx;
  1041. font-size: 32rpx;
  1042. color: #666;
  1043. }
  1044. .con {
  1045. font-size: 24rpx;
  1046. color: #999;
  1047. .label {
  1048. margin-bottom: 20rpx;
  1049. }
  1050. .item {
  1051. margin-bottom: 20rpx;
  1052. }
  1053. }
  1054. .btn {
  1055. display: flex;
  1056. align-items: center;
  1057. justify-content: center;
  1058. width: 508rpx;
  1059. height: 86rpx;
  1060. margin-top: 100rpx;
  1061. border: 1px solid #D74432;
  1062. color: #E93323;
  1063. font-size: 30rpx;
  1064. border-radius: 120rpx;
  1065. }
  1066. }
  1067. .sort-scroll {
  1068. background-color: #fff;
  1069. }
  1070. .sort-product {
  1071. margin-top: 20rpx;
  1072. .sort-box {
  1073. display: flex;
  1074. width: 100%;
  1075. border-radius: 16rpx;
  1076. padding: 30rpx 0;
  1077. .sort-item {
  1078. width: 20%;
  1079. display: flex;
  1080. flex-direction: column;
  1081. align-items: center;
  1082. justify-content: center;
  1083. flex-shrink: 0;
  1084. image {
  1085. width: 90rpx;
  1086. height: 90rpx;
  1087. border-radius: 50%;
  1088. }
  1089. .txt {
  1090. color: #272727;
  1091. font-size: 24rpx;
  1092. margin-top: 10rpx;
  1093. overflow: hidden;
  1094. white-space: nowrap;
  1095. text-overflow: ellipsis;
  1096. width: 140rpx;
  1097. text-align: center;
  1098. }
  1099. .pictrues {
  1100. width: 90rpx;
  1101. height: 90rpx;
  1102. background: #f8f8f8;
  1103. border-radius: 50%;
  1104. margin: 0 auto;
  1105. }
  1106. .icon-gengduo1 {
  1107. color: #333;
  1108. }
  1109. &.on {
  1110. .txt {
  1111. color: #fc4141;
  1112. }
  1113. image {
  1114. border: 1px solid #fc4141;
  1115. }
  1116. }
  1117. }
  1118. }
  1119. .product-list {
  1120. display: flex;
  1121. flex-wrap: wrap;
  1122. justify-content: space-between;
  1123. margin-top: 30rpx;
  1124. padding: 0 20rpx;
  1125. .product-item {
  1126. position: relative;
  1127. width: 344rpx;
  1128. background: #fff;
  1129. border-radius: 10rpx;
  1130. margin-bottom: 20rpx;
  1131. overflow: hidden;
  1132. .pictrue {
  1133. position: relative;
  1134. }
  1135. image {
  1136. width: 100%;
  1137. height: 344rpx;
  1138. border-radius: 10rpx 10rpx 0 0;
  1139. }
  1140. .info {
  1141. padding: 14rpx 16rpx;
  1142. .title {
  1143. font-size: 28rpx;
  1144. }
  1145. .price-box {
  1146. font-size: 34rpx;
  1147. font-weight: 700;
  1148. margin-top: 8px;
  1149. color: #fc4141;
  1150. text {
  1151. font-size: 26rpx;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. }
  1158. .empty-box {
  1159. text-align: center;
  1160. padding-top: 50rpx;
  1161. .tips {
  1162. color: #aaa;
  1163. font-size: 26rpx;
  1164. }
  1165. image {
  1166. width: 414rpx;
  1167. height: 304rpx;
  1168. }
  1169. }
  1170. .site-config {
  1171. margin: 40rpx 0;
  1172. font-size: 24rpx;
  1173. text-align: center;
  1174. color: #666;
  1175. &.fixed {
  1176. position: fixed;
  1177. bottom: 69px;
  1178. left: 0;
  1179. width: 100%;
  1180. }
  1181. }
  1182. </style>