index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. <template>
  2. <!-- 首页 -->
  3. <view v-if="pageShow" class="page" :class="bgTabVal == 2 ? 'fullsize noRepeat' : bgTabVal == 1 ? 'repeat ysize' : 'noRepeat ysize'" :style="[pageStyle]">
  4. <view v-if="!errorNetwork" :style="colorStyle">
  5. <!-- #ifdef MP -->
  6. <view class="fixed z-1000" :style="[appletStyle]" v-if="myApplet">
  7. <view class="myApplet w-324 h-62 text-center rd-12rpx lh-62rpx fs-24 bg--w111-fff text-w111-303133">
  8. 点击添加到我的小程序
  9. <text class="iconfont icon-ic_close2 text--w111-ccc ml-16" @click="myApplet = false"></text>
  10. </view>
  11. </view>
  12. <!-- #endif -->
  13. <!-- 轮播搜索 -->
  14. <homeComb v-if="showHomeComb" :dataConfig="homeCombData" :belongIndex="belongIndex" @bindSortId="bindSortId" :isScrolled="isScrolled" @storeTap="storeTap"></homeComb>
  15. <!-- 顶部搜索框 -->
  16. <headerSerch v-if="isHeaderSerch" :dataConfig="headerSerchCombData" :belongIndex="belongIndex" @storeTap="storeTap"></headerSerch>
  17. <tabNav v-if="showCateNav" :dataConfig="cateNavData" @bindHeight="bindHeighta" @bindSortId="bindSortId" :isFixed="isFixed && !cateNavData.stickyConfig.tabVal"></tabNav>
  18. <view class="index">
  19. <!-- 自定义样式 -->
  20. <block v-for="(item, index) in styleConfig" :key="index">
  21. <userInfor v-if="item.name == 'userInfor'" :dataConfig="item" @changeLogin="changeLogin"></userInfor>
  22. <newVip v-if="item.name == 'newVip'" :dataConfig="item"></newVip>
  23. <!-- 文章列表 -->
  24. <articleList v-if="item.name == 'articleList'" :dataConfig="item"></articleList>
  25. <bargain v-if="item.name == 'bargain'" :dataConfig="item" @changeBarg="changeBarg"></bargain>
  26. <blankPage v-if="item.name == 'blankPage'" :dataConfig="item"></blankPage>
  27. <combination v-if="item.name == 'combination'" :dataConfig="item"></combination>
  28. <!-- 优惠券 -->
  29. <coupon v-if="item.name == 'coupon'" :dataConfig="item" @changeLogin="changeLogin"></coupon>
  30. <!-- 客户服务 -->
  31. <customerService v-if="item.name == 'customerService'" :dataConfig="item"></customerService>
  32. <!-- 商品列表 -->
  33. <goodList ref="goodLists" v-if="item.name == 'goodList'" :dataConfig="item"></goodList>
  34. <guide v-if="item.name == 'guide'" :dataConfig="item"></guide>
  35. <!-- 直播模块 -->
  36. <!-- #ifdef MP-WEIXIN -->
  37. <liveBroadcast v-if="item.name == 'liveBroadcast'" :dataConfig="item"></liveBroadcast>
  38. <!-- #endif -->
  39. <menus v-if="item.name == 'menus'" :dataConfig="item"></menus>
  40. <!-- 实时消息 -->
  41. <news v-if="item.name == 'news'" :dataConfig="item"></news>
  42. <!-- 图片库 -->
  43. <pictureCube v-if="item.name == 'pictureCube'" :dataConfig="item"></pictureCube>
  44. <!-- 促销列表 -->
  45. <promotionList
  46. ref="promotionLists"
  47. v-if="item.name == 'promotionList'"
  48. :dataConfig="item"
  49. :productVideoStatus="product_video_status"
  50. :positionTop="positionTop"
  51. ></promotionList>
  52. <seckill v-if="item.name == 'seckill'" :dataConfig="item"></seckill>
  53. <!-- 轮播图-->
  54. <swiperBg v-if="item.name == 'swiperBg'" :dataConfig="item"></swiperBg>
  55. <swipers v-if="item.name == 'swipers'" :dataConfig="item"></swipers>
  56. <!-- 顶部选项卡 -->
  57. <!-- 标题 -->
  58. <titles v-if="item.name == 'titles'" :dataConfig="item"></titles>
  59. <ranking v-if="item.name == 'ranking'" :dataConfig="item"></ranking>
  60. <presale v-if="item.name == 'presale'" :dataConfig="item"></presale>
  61. <pointsMall v-if="item.name == 'pointsMall'" :dataConfig="item"></pointsMall>
  62. <!-- #ifndef APP -->
  63. <richText v-if="item.name == 'richText'" :dataConfig="item"></richText>
  64. <videos v-if="item.name == 'videos'" :dataConfig="item"></videos>
  65. <!-- #endif -->
  66. <signIn v-if="item.name == 'signIn'" :dataConfig="item"></signIn>
  67. <hotspot v-if="item.name == 'hotspot'" :dataConfig="item"></hotspot>
  68. <follow v-if="item.name == 'follow'" :dataConfig="item"></follow>
  69. </block>
  70. <!-- 分类商品模块 -->
  71. <!-- #ifndef APP-PLUS -->
  72. <view class="sort-product px-20" v-if="!styleConfig.length">
  73. <!-- #endif -->
  74. <!-- #ifdef APP-PLUS -->
  75. <!-- 商品排序 -->
  76. <view class="sort-product px-20" :style="{ marginTop: sortMpTop + 'px' }" v-if="!styleConfig.length">
  77. <!-- #endif -->
  78. <view class="rd-24rpx bg--w111-fff p-24 mb-24" v-if="sortList.children && sortList.children.length">
  79. <scroll-view scroll-x="true" class="white-nowrap vertical-middle w-full" show-scrollbar="false">
  80. <view class="inline-block mr-24" v-for="(item, index) in sortList.children" :key="index">
  81. <view class="flex-col flex-center" @tap="changeSort(item, index)">
  82. <view class="picture w-90 h-90 rd-50-p111-" :class="{ select: curSort == index }">
  83. <image :src="item.pic" class="w-full h-full rd-50-p111-"></image>
  84. </view>
  85. <text class="fs-24 pt-14" :class="{ 'font-num': curSort == index }">{{ item.cate_name }}</text>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. </view>
  90. <waterfallsFlow ref="waterfallsFlow" :wfList="goodList" :goDetail="'goDetail'" @itemTap="goDetail"></waterfallsFlow>
  91. <Loading :loaded="loaded" :loading="loading"></Loading>
  92. <view v-if="goodList.length == 0 && loaded">
  93. <emptyPage title="暂无商品,去看点别的吧~"></emptyPage>
  94. </view>
  95. </view>
  96. <couponWindow :window="isCouponShow" @onColse="couponClose" :couponImage="couponObj.image" :couponList="couponObj.list"></couponWindow>
  97. <view class="">
  98. {{ site_config }}
  99. </view>
  100. <!-- #ifndef APP-PLUS -->
  101. <view v-if="configData && configData.record_No" class="site-config" @click="goICP(configData.icp_url)">{{ configData.record_No }}</view>
  102. <view class="site-config" v-if="configData && configData.network_security" @click="goICP(configData.network_security_url)">
  103. <image class="ban" src="/static/images/beian.png" alt="" srcset="" />
  104. {{ configData.network_security }}
  105. </view>
  106. <!-- #endif -->
  107. <view class="pb-safe" :style="[pdHeights]" v-if="isFooter"></view>
  108. <pageFooter :configData="footerConfigData" @newDataStatus="newDataStatus"></pageFooter>
  109. </view>
  110. </view>
  111. <!-- #ifdef APP -->
  112. <app-update ref="appUpdate" :force="true" :tabbar="false"></app-update>
  113. <!-- #endif -->
  114. </view>
  115. <view v-else>
  116. <view class="error-network">
  117. <image :src="imgHost + '/statics/images/error-network.gif'"></image>
  118. <view class="title">{{ $t(`网络连接断开`) }}</view>
  119. <view class="con">
  120. <view class="label">{{ $t(`请检查情况`) }}:</view>
  121. <view class="item">· {{ $t(`在设置中是否已开启网络权限`) }}</view>
  122. <view class="item">· {{ $t(`当前是否处于弱网环境`) }}</view>
  123. <view class="item">· {{ $t(`版本是否过低,升级试试吧`) }}</view>
  124. </view>
  125. <view class="btn" @click="reconnect">{{ $t(`重新连接`) }}</view>
  126. </view>
  127. </view>
  128. </view>
  129. </template>
  130. <script>
  131. const app = getApp();
  132. import colors from '@/mixins/color';
  133. import couponWindow from '@/components/couponWindow/index';
  134. import { getCouponV2, getCouponNewUser, getCrmebCopyRight } from '@/api/api.js';
  135. import { getShare } from '@/api/public.js';
  136. import userInfor from './components/userInfor';
  137. import homeComb from './components/homeComb';
  138. import newVip from './components/newVip';
  139. import headerSerch from './components/headerSerch';
  140. import swipers from './components/swipers';
  141. import coupon from './components/coupon';
  142. import articleList from './components/articleList';
  143. import bargain from './components/bargain';
  144. import blankPage from './components/blankPage';
  145. import combination from './components/combination';
  146. import customerService from './components/customerService';
  147. import goodList from './components/goodList';
  148. import guide from './components/guide';
  149. import liveBroadcast from './components/liveBroadcast';
  150. import menus from './components/menus';
  151. import news from './components/news';
  152. import pictureCube from './components/pictureCube';
  153. import promotionList from './components/promotionList';
  154. import seckill from './components/seckill';
  155. import swiperBg from './components/swiperBg';
  156. import tabNav from './components/tabNav';
  157. import titles from './components/titles';
  158. import ranking from './components/ranking';
  159. import presale from './components/presale';
  160. import pointsMall from './components/pointsMall';
  161. // #ifndef APP
  162. import richText from './components/richText';
  163. import videos from './components/videos';
  164. // #endif
  165. import signIn from './components/signIn';
  166. import hotspot from './components/hotspot';
  167. import follow from './components/follow';
  168. import waterfallsFlow from '@/components/WaterfallsFlow/WaterfallsFlow.vue';
  169. import emptyPage from '@/components/emptyPage.vue';
  170. // #ifdef MP
  171. import { getTempIds } from '@/api/api.js';
  172. import { SUBSCRIBE_MESSAGE } from '@/config/cache';
  173. // #endif
  174. import { mapGetters, mapMutations } from 'vuex';
  175. import { getDiy, getDiyVersion } from '@/api/api.js';
  176. import { getCartCounts } from '@/api/order.js';
  177. import { getCategoryList, getProductslist } from '@/api/store.js';
  178. import { goShopDetail } from '@/libs/order.js';
  179. import { toLogin } from '@/libs/login.js';
  180. import { HTTP_REQUEST_URL } from '@/config/app';
  181. import pageFooter from '@/components/pageFooter/index.vue';
  182. import Loading from '@/components/Loading/index.vue';
  183. import Cache from '@/utils/cache';
  184. import appUpdate from '@/components/update/app-update.vue';
  185. export default {
  186. computed: {
  187. // #ifdef MP
  188. appletStyle() {
  189. return {
  190. top: this.getHeight.menuButtonInfo.bottom + 8 + 'px',
  191. right: '10px'
  192. };
  193. },
  194. // #endif
  195. pageStyle() {
  196. return {
  197. backgroundColor: this.bgColor,
  198. backgroundImage: this.bgPic ? `url(${this.bgPic})` : '',
  199. minHeight: this.windowHeight + 'px'
  200. };
  201. },
  202. pdHeights() {
  203. let H = `${this.pdHeight * 2 + 100}rpx`;
  204. return {
  205. height: this.isFooter ? H : '100rpx'
  206. };
  207. },
  208. ...mapGetters(['isLogin', 'uid', 'cartNum'])
  209. },
  210. mixins: [colors],
  211. components: {
  212. Loading,
  213. pageFooter,
  214. couponWindow,
  215. homeComb,
  216. newVip,
  217. userInfor,
  218. headerSerch,
  219. swipers,
  220. coupon,
  221. articleList,
  222. bargain,
  223. blankPage,
  224. combination,
  225. customerService,
  226. goodList,
  227. guide,
  228. liveBroadcast,
  229. menus,
  230. pictureCube,
  231. news,
  232. promotionList,
  233. seckill,
  234. swiperBg,
  235. tabNav,
  236. titles,
  237. ranking,
  238. presale,
  239. pointsMall,
  240. // #ifndef APP
  241. richText,
  242. videos,
  243. // #endif
  244. signIn,
  245. hotspot,
  246. follow,
  247. waterfallsFlow,
  248. emptyPage,
  249. // #ifdef APP
  250. appUpdate
  251. // #endif
  252. },
  253. data() {
  254. return {
  255. styleConfig: [],
  256. loading: false,
  257. loadend: false,
  258. loadTitle: '下拉加载更多', //提示语
  259. page: 1,
  260. limit: this.$config.LIMIT,
  261. numConfig: 0,
  262. code: '',
  263. isCouponShow: false,
  264. couponObj: {},
  265. couponObjs: {
  266. show: false
  267. },
  268. shareInfo: {},
  269. sortList: '',
  270. sortAll: [],
  271. goodPage: 1,
  272. goodList: [],
  273. sid: 0,
  274. curSort: 0,
  275. sortMpTop: 0,
  276. loaded: false,
  277. loading: false,
  278. domOffsetTop: 50,
  279. // #ifdef APP-PLUS || MP
  280. isFixed: true,
  281. // #endif
  282. // #ifdef H5
  283. isFixed: false,
  284. // #endif
  285. site_config: '',
  286. errorNetwork: false, // 是否断网
  287. isHeaderSerch: false,
  288. showHomeComb: false,
  289. showCateNav: false,
  290. homeCombData: {},
  291. headerSerchCombData: {},
  292. cateNavData: {},
  293. footerConfigData: {},
  294. bgColor: '',
  295. bgPic: '',
  296. bgTabVal: '',
  297. pageShow: true,
  298. windowHeight: 0,
  299. imgHost: HTTP_REQUEST_URL,
  300. isShowAuth: false,
  301. isScrolled: false,
  302. product_video_status: false,
  303. confirm_video_status: false,
  304. positionTop: 0,
  305. isFooter: false,
  306. pdHeight: 0, //自定义底部导航上下边距和
  307. entryData: {
  308. store_id: '',
  309. latitude: '',
  310. longitude: '',
  311. select_store_id: ''
  312. },
  313. goodsIndex: [],
  314. promotionIndex: [],
  315. belongIndex: 0, // 进店规则归属门店排序位置;
  316. isBelongStore: false, //判断是否为归属门店;
  317. getHeight: this.$util.getWXStatusHeight(),
  318. myApplet: true,
  319. configData: Cache.get('BASIC_CONFIG')
  320. };
  321. },
  322. onLoad(options) {
  323. let that = this;
  324. uni.hideTabBar();
  325. that.getOptions(options);
  326. this.$nextTick(function () {
  327. uni.getSystemInfo({
  328. success: function (res) {
  329. that.windowHeight = res.windowHeight;
  330. }
  331. });
  332. });
  333. const { state, scope } = options;
  334. this.diyData();
  335. // #ifdef H5
  336. this.setOpenShare();
  337. // #endif
  338. // #ifdef MP
  339. this.getTempIds();
  340. // #endif
  341. getShare().then((res) => {
  342. this.shareInfo = res.data;
  343. });
  344. this.getCopyRight();
  345. this.$eventHub.$on('confirm_video_status', () => {
  346. if (this.confirm_video_status) {
  347. return;
  348. }
  349. this.confirm_video_status = true;
  350. let flag = true;
  351. // #ifdef H5
  352. flag = window.self == window.top;
  353. // #endif
  354. if (!flag) {
  355. return;
  356. }
  357. uni.showModal({
  358. content: '当前使用移动网络,是否继续播放视频?',
  359. success: (res) => {
  360. if (res.confirm) {
  361. // 监听
  362. this.SET_AUTOPLAY(true);
  363. this.$eventHub.$emit('product_video_observe');
  364. }
  365. }
  366. });
  367. });
  368. },
  369. onUnload() {
  370. // 清除监听
  371. uni.$off('activeFn');
  372. },
  373. watch: {
  374. isLogin: {
  375. deep: true, //深度监听设置为 true
  376. handler: function (newV, oldV) {
  377. // 优惠券弹窗
  378. var newDates = new Date().toLocaleDateString();
  379. if (newV) {
  380. try {
  381. var oldDate = uni.getStorageSync('oldDate') || '';
  382. } catch {}
  383. if (oldDate != newDates) {
  384. this.getCoupon();
  385. }
  386. }
  387. }
  388. }
  389. },
  390. onShow() {
  391. uni.removeStorageSync('form_type_cart');
  392. // 优惠券弹窗
  393. if (this.isLogin) {
  394. this.getCoupon();
  395. this.getCartNum();
  396. }
  397. // #ifdef MP
  398. if (wx.canIUse('checkIsAddedToMyMiniProgram')) {
  399. this.checkMyApplet();
  400. } else {
  401. this.myApplet = true;
  402. }
  403. // #endif
  404. },
  405. onPullDownRefresh() {
  406. this.diyData();
  407. uni.stopPullDownRefresh();
  408. },
  409. methods: {
  410. ...mapMutations(['SET_AUTOPLAY', 'SET_NEARBY']),
  411. checkMyApplet() {
  412. wx.checkIsAddedToMyMiniProgram({
  413. success: (res) => {
  414. if (res.added) {
  415. this.myApplet = false;
  416. } else {
  417. this.myApplet = true;
  418. }
  419. },
  420. fail: () => {
  421. this.myApplet = true;
  422. }
  423. });
  424. },
  425. getCartNum: function () {
  426. getCartCounts()
  427. .then((res) => {
  428. this.$store.commit('indexData/setCartNum', res.data.count + '');
  429. let cartNum = res.data.count;
  430. if (cartNum > 0) {
  431. uni.setTabBarBadge({
  432. index: 3,
  433. text: cartNum > 99 ? '99+' : cartNum + ''
  434. });
  435. } else {
  436. uni.hideTabBarRedDot({
  437. index: 3
  438. });
  439. }
  440. })
  441. .catch((err) => {
  442. return this.$util.Tips({
  443. title: err.msg
  444. });
  445. });
  446. },
  447. storeTap(id) {
  448. this.entryData.select_store_id = id;
  449. this.entryData.store_id = '';
  450. uni.removeStorageSync('rulesStoreId');
  451. },
  452. getCopyRight() {
  453. getCrmebCopyRight()
  454. .then((res) => {
  455. let data = res.data;
  456. uni.setStorageSync('wechatStatus', data.wechat_status);
  457. if (!data.copyrightContext && !data.copyrightImage) {
  458. data.copyrightImage = '/static/images/support.png';
  459. }
  460. uni.setStorageSync('copyNameInfo', data.copyrightContext);
  461. uni.setStorageSync('copyImageInfo', data.copyrightImage);
  462. // #ifdef MP
  463. uni.setStorageSync(
  464. 'MPSiteData',
  465. JSON.stringify({
  466. site_logo: data.site_logo,
  467. site_name: data.site_name
  468. })
  469. );
  470. // #endif
  471. })
  472. .catch((err) => {
  473. return this.$util.Tips({
  474. title: err.msg
  475. });
  476. });
  477. },
  478. getOptions(options) {
  479. let that = this;
  480. // #ifdef MP
  481. if (options.scene) {
  482. let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
  483. //记录推广人uid
  484. if (value.spid) app.globalData.spid = value.spid;
  485. }
  486. // #endif
  487. if (options.spid) app.globalData.spid = options.spid;
  488. },
  489. // 重新链接
  490. reconnect() {
  491. this.diyData();
  492. getShare().then((res) => {
  493. this.shareInfo = res.data;
  494. });
  495. },
  496. goICP(url) {
  497. // #ifdef H5
  498. window.open(url);
  499. // #endif
  500. // #ifdef MP
  501. uni.navigateTo({
  502. url: `/pages/annex/web_view/index?url=${url}`
  503. });
  504. // #endif
  505. },
  506. bindHeighta(data) {
  507. // #ifdef APP-PLUS
  508. this.sortMpTop = data.top + data.height;
  509. // #endif
  510. },
  511. bindHeight(data) {
  512. uni.hideLoading();
  513. this.domOffsetTop = data.top;
  514. },
  515. // 去商品详情
  516. goGoodsDetail(item) {
  517. goShopDetail(item, this.uid).then((res) => {
  518. uni.navigateTo({
  519. url: `/pages/goods_details/index?id=${item.id}`
  520. });
  521. });
  522. },
  523. // 分类点击
  524. changeSort(item, index) {
  525. if (this.curSort == index) return;
  526. this.curSort = index;
  527. this.sid = item.id;
  528. this.goodList = [];
  529. this.goodPage = 1;
  530. this.loaded = false;
  531. this.getGoodsList();
  532. },
  533. /**
  534. * @param data {
  535. classPage: 0 分类id
  536. microPage: 0 微页面id
  537. type: 1 0 微页面 1 商品分类
  538. }*/
  539. bindSortId(data) {
  540. this.styleConfig = [];
  541. if (data.type == 1) {
  542. this.getProductList(data.classPage);
  543. } else {
  544. this.sortList = [];
  545. this.getMicroPage(data.microPage, true);
  546. }
  547. },
  548. /**
  549. * 获取DIY
  550. * @param {number} id
  551. * @param {boolean} type 区分是否是微页面
  552. */
  553. getMicroPage(id, type) {
  554. let that = this;
  555. that.styleConfig = [];
  556. uni.showLoading({
  557. title: '加载中...'
  558. });
  559. getDiy(id)
  560. .then((res) => {
  561. uni.hideLoading();
  562. let data = res.data;
  563. let diyArr = that.objToArr(res.data.value);
  564. diyArr = diyArr.filter((item) => !item.isHide);
  565. diyArr.forEach((item, index) => {
  566. if (['headerSerch', 'homeComb'].includes(item.name)) {
  567. diyArr.splice(index, 1);
  568. }
  569. });
  570. this.styleConfig = diyArr;
  571. })
  572. .catch((err) => {
  573. return that.$util.Tips({
  574. title: err
  575. });
  576. uni.hideLoading();
  577. });
  578. },
  579. getProductList(data) {
  580. let tempObj = '';
  581. this.curSort = 0;
  582. this.loaded = false;
  583. if (this.sortAll.length > 0) {
  584. this.sortAll.forEach((el, index) => {
  585. if (el.id == data) {
  586. this.$set(this, 'sortList', el);
  587. this.sid = el.children.length ? el.children[0].id : '';
  588. }
  589. });
  590. this.goodList = [];
  591. this.goodPage = 1;
  592. this.$nextTick(() => {
  593. if (this.sortList != '') this.getGoodsList();
  594. });
  595. } else {
  596. getCategoryList().then((res) => {
  597. this.sortAll = res.data;
  598. res.data.forEach((el, index) => {
  599. if (el.id == data) {
  600. this.sortList = el;
  601. this.sid = el.children.length ? el.children[0].id : '';
  602. }
  603. });
  604. this.goodList = [];
  605. this.goodPage = 1;
  606. this.$nextTick(() => {
  607. if (this.sortList != '') this.getGoodsList();
  608. });
  609. });
  610. }
  611. },
  612. // 商品列表
  613. getGoodsList() {
  614. if (this.loading || this.loaded) return;
  615. this.loading = true;
  616. getProductslist({
  617. sid: this.sid,
  618. keyword: '',
  619. priceOrder: '',
  620. salesOrder: '',
  621. news: 0,
  622. page: this.goodPage,
  623. limit: 10,
  624. cid: this.sortList.id
  625. }).then((res) => {
  626. this.loading = false;
  627. this.loaded = res.data.length < 10;
  628. this.goodPage++;
  629. this.goodList = this.goodList.concat(res.data);
  630. });
  631. },
  632. // 新用户优惠券
  633. getNewCoupon() {
  634. const oldUser = uni.getStorageSync('oldUser') || 0;
  635. if (!oldUser) {
  636. getCouponNewUser().then((res) => {
  637. const { data } = res;
  638. if (data.show) {
  639. if (data.list.length) {
  640. this.isCouponShow = true;
  641. this.couponObj = data;
  642. uni.setStorageSync('oldUser', 1);
  643. }
  644. } else {
  645. uni.setStorageSync('oldUser', 1);
  646. }
  647. });
  648. }
  649. },
  650. // 优惠券弹窗
  651. getCoupon() {
  652. const tagDate = uni.getStorageSync('tagDate') || '',
  653. nowDate = new Date().toLocaleDateString();
  654. if (tagDate === nowDate) {
  655. this.getNewCoupon();
  656. } else {
  657. getCouponV2().then((res) => {
  658. const { data } = 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. getTempIds() {
  697. let messageTmplIds = wx.getStorageSync(SUBSCRIBE_MESSAGE);
  698. if (!messageTmplIds) {
  699. getTempIds().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).sort();
  708. let m = obj.map((key) => data[key]);
  709. return m;
  710. },
  711. setDiyData(data) {
  712. this.errorNetwork = false;
  713. if (data.is_bg_color) {
  714. this.bgColor = data.color_picker;
  715. }
  716. if (data.is_bg_pic) {
  717. this.bgPic = data.bg_pic;
  718. this.bgTabVal = data.bg_tab_val;
  719. }
  720. this.pageShow = data.is_show;
  721. uni.setNavigationBarTitle({
  722. title: data.title
  723. });
  724. let temp = [];
  725. let goodsIndex = [];
  726. let promotionIndex = [];
  727. let lastArr = this.objToArr(data.value);
  728. lastArr.forEach((item, index, arr) => {
  729. if (item.name == 'pageFoot') {
  730. this.footerConfigData = item;
  731. }
  732. if (item.name === 'homeComb' && !item.isHide) {
  733. this.showHomeComb = true;
  734. this.homeCombData = item;
  735. if (item.searchConfig.tabVal) {
  736. this.positionTop = uni.getSystemInfoSync().statusBarHeight + 43;
  737. }
  738. }
  739. if (item.name == 'headerSerch' && !item.isHide) {
  740. this.isHeaderSerch = true;
  741. this.headerSerchCombData = item;
  742. }
  743. if (item.name == 'tabNav' && !item.isHide) {
  744. this.showCateNav = true;
  745. this.cateNavData = item;
  746. }
  747. if (item.name == 'goodList' && !item.isHide) {
  748. goodsIndex.push(index);
  749. }
  750. if (item.name == 'promotionList' && !item.isHide) {
  751. promotionIndex.push(index);
  752. }
  753. if (!item.isHide) {
  754. temp.push(item);
  755. }
  756. });
  757. function sortNumber(a, b) {
  758. return a.timestamp - b.timestamp;
  759. }
  760. temp.sort(sortNumber);
  761. this.styleConfig = temp;
  762. this.goodsIndex = goodsIndex;
  763. this.promotionIndex = promotionIndex;
  764. },
  765. getDiyData() {
  766. getDiy(0)
  767. .then((res) => {
  768. uni.setStorageSync('diyData', JSON.stringify(res.data));
  769. this.setDiyData(res.data);
  770. })
  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. }
  784. // #endif
  785. });
  786. },
  787. diyData() {
  788. let diyData = uni.getStorageSync('diyData');
  789. if (diyData) {
  790. getDiyVersion(0).then((res) => {
  791. let diyVersion = uni.getStorageSync('diyVersion');
  792. if (res.data.version + '0' === diyVersion) {
  793. this.setDiyData(JSON.parse(diyData));
  794. } else {
  795. uni.setStorageSync('diyVersion', res.data.version + '0');
  796. this.getDiyData();
  797. }
  798. });
  799. } else {
  800. this.getDiyData();
  801. }
  802. },
  803. changeLogin() {
  804. this.getIsLogin();
  805. },
  806. getIsLogin() {
  807. toLogin();
  808. },
  809. changeBarg(item) {
  810. if (!this.isLogin) {
  811. this.getIsLogin();
  812. } else {
  813. uni.navigateTo({
  814. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&spid=${this.$store.state.app.uid}`
  815. });
  816. }
  817. },
  818. goDetail(item) {
  819. goShopDetail(item, this.$store.state.app.uid).then((res) => {
  820. uni.navigateTo({
  821. url: `/pages/goods_details/index?id=${item.id}`
  822. });
  823. });
  824. },
  825. newDataStatus(val, num) {
  826. this.isFooter = val ? true : false;
  827. this.pdHeight = num;
  828. },
  829. // #ifdef H5
  830. // 微信分享;
  831. setOpenShare: function () {
  832. let that = this;
  833. let uid = this.uid ? this.uid : 0;
  834. if (that.$wechat.isWeixin()) {
  835. getShare().then((res) => {
  836. let data = res.data;
  837. let configAppMessage = {
  838. desc: data.synopsis,
  839. title: data.title,
  840. link: location.href + '?spid=' + uid,
  841. imgUrl: data.img
  842. };
  843. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline'], configAppMessage);
  844. });
  845. }
  846. }
  847. // #endif
  848. },
  849. onReachBottom() {
  850. if (this.goodList.length) {
  851. this.getGoodsList();
  852. }
  853. },
  854. onPageScroll(e) {
  855. if (e.scrollTop > 20) {
  856. this.myApplet = false;
  857. }
  858. // #ifdef H5
  859. if (this.isHeaderSerch) {
  860. if (e.scrollTop > this.domOffsetTop) {
  861. this.isFixed = true;
  862. }
  863. if (e.scrollTop < this.domOffsetTop) {
  864. this.$nextTick(() => {
  865. this.isFixed = false;
  866. });
  867. }
  868. } else {
  869. this.isFixed = false;
  870. }
  871. // #endif
  872. if (e.scrollTop > 10) {
  873. this.isScrolled = true;
  874. } else {
  875. this.isScrolled = false;
  876. }
  877. uni.$emit('scroll');
  878. uni.$emit('onPageScroll', e.scrollTop);
  879. },
  880. //#ifdef MP
  881. onShareAppMessage() {
  882. let uid = this.uid ? this.uid : 0;
  883. if (this.shareInfo.img) {
  884. return {
  885. title: this.shareInfo.title,
  886. path: '/pages/index/index?spid=' + uid,
  887. imageUrl: this.shareInfo.img,
  888. desc: this.shareInfo.synopsis
  889. };
  890. } else {
  891. return {
  892. title: this.shareInfo.title,
  893. path: '/pages/index/index?spid=' + uid
  894. // imageUrl: this.shareInfo.img,
  895. // desc: this.shareInfo.synopsis
  896. };
  897. }
  898. },
  899. //分享到朋友圈
  900. onShareTimeline: function () {
  901. return {
  902. title: this.shareInfo.title,
  903. path: '/pages/index/index',
  904. imageUrl: this.shareInfo.img,
  905. desc: this.shareInfo.synopsis
  906. };
  907. }
  908. //#endif
  909. };
  910. </script>
  911. <style lang="scss">
  912. .page {
  913. // padding-bottom: 50px;
  914. overflow-y: scroll;
  915. overflow-x: hidden;
  916. }
  917. .myApplet {
  918. position: relative;
  919. &::after {
  920. position: absolute;
  921. right: 55px;
  922. top: -5px;
  923. content: '';
  924. width: 0;
  925. height: 0;
  926. border-left: 7px solid transparent;
  927. border-right: 7px solid transparent;
  928. border-bottom: 7px solid #fff;
  929. }
  930. }
  931. .pictrue_log_class {
  932. background-color: var(--view-theme);
  933. }
  934. .ysize {
  935. background-size: 100%;
  936. }
  937. .fullsize {
  938. background-size: 100% 100%;
  939. }
  940. .repeat {
  941. background-repeat: repeat;
  942. }
  943. .noRepeat {
  944. background-repeat: no-repeat;
  945. }
  946. .error-network {
  947. position: fixed;
  948. left: 0;
  949. top: 0;
  950. display: flex;
  951. flex-direction: column;
  952. align-items: center;
  953. width: 100%;
  954. height: 100%;
  955. padding-top: 40rpx;
  956. background: #fff;
  957. image {
  958. width: 414rpx;
  959. height: 336rpx;
  960. }
  961. .title {
  962. position: relative;
  963. top: -40rpx;
  964. font-size: 32rpx;
  965. color: #666;
  966. }
  967. .con {
  968. font-size: 24rpx;
  969. color: #999;
  970. .label {
  971. margin-bottom: 20rpx;
  972. }
  973. .item {
  974. margin-bottom: 20rpx;
  975. }
  976. }
  977. .btn {
  978. display: flex;
  979. align-items: center;
  980. justify-content: center;
  981. width: 508rpx;
  982. height: 86rpx;
  983. margin-top: 100rpx;
  984. border: 1px solid #d74432;
  985. color: #e93323;
  986. font-size: 30rpx;
  987. border-radius: 120rpx;
  988. }
  989. }
  990. .sort-scroll {
  991. background-color: #fff;
  992. }
  993. .sort-product {
  994. margin-top: 20rpx;
  995. }
  996. .site-config {
  997. margin: 40rpx 0;
  998. font-size: 24rpx;
  999. text-align: center;
  1000. color: #666;
  1001. display: flex;
  1002. align-items: center;
  1003. justify-content: center;
  1004. .ban {
  1005. width: 22rpx;
  1006. height: 24rpx;
  1007. margin-right: 10rpx;
  1008. }
  1009. &.fixed {
  1010. position: fixed;
  1011. bottom: 69px;
  1012. left: 0;
  1013. width: 100%;
  1014. }
  1015. }
  1016. .select {
  1017. border: 1px solid var(--view-theme);
  1018. }
  1019. </style>