index.vue 31 KB

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