index.vue 31 KB

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