index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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. if(!this.isLogin){
  338. this.$wechat.oAuth('snsapi_userinfo', location.href)
  339. }
  340. // #endif
  341. // #ifdef MP
  342. this.getTempIds();
  343. // #endif
  344. getShare().then((res) => {
  345. this.shareInfo = res.data;
  346. });
  347. this.getCopyRight();
  348. this.$eventHub.$on('confirm_video_status', () => {
  349. if (this.confirm_video_status) {
  350. return;
  351. }
  352. this.confirm_video_status = true;
  353. let flag = true;
  354. // #ifdef H5
  355. flag = window.self == window.top;
  356. // #endif
  357. if (!flag) {
  358. return;
  359. }
  360. uni.showModal({
  361. content: '当前使用移动网络,是否继续播放视频?',
  362. success: (res) => {
  363. if (res.confirm) {
  364. // 监听
  365. this.SET_AUTOPLAY(true);
  366. this.$eventHub.$emit('product_video_observe');
  367. }
  368. }
  369. });
  370. });
  371. },
  372. onUnload() {
  373. // 清除监听
  374. uni.$off('activeFn');
  375. },
  376. watch: {
  377. isLogin: {
  378. deep: true, //深度监听设置为 true
  379. handler: function (newV, oldV) {
  380. // 优惠券弹窗
  381. var newDates = new Date().toLocaleDateString();
  382. if (newV) {
  383. try {
  384. var oldDate = uni.getStorageSync('oldDate') || '';
  385. } catch {}
  386. if (oldDate != newDates) {
  387. this.getCoupon();
  388. }
  389. }
  390. }
  391. }
  392. },
  393. onShow() {
  394. uni.removeStorageSync('form_type_cart');
  395. // 优惠券弹窗
  396. if (this.isLogin) {
  397. this.getCoupon();
  398. this.getCartNum();
  399. }
  400. // #ifdef MP
  401. if (wx.canIUse('checkIsAddedToMyMiniProgram')) {
  402. this.checkMyApplet();
  403. } else {
  404. this.myApplet = true;
  405. }
  406. // #endif
  407. },
  408. onPullDownRefresh() {
  409. this.diyData();
  410. uni.stopPullDownRefresh();
  411. },
  412. methods: {
  413. ...mapMutations(['SET_AUTOPLAY', 'SET_NEARBY']),
  414. checkMyApplet() {
  415. wx.checkIsAddedToMyMiniProgram({
  416. success: (res) => {
  417. if (res.added) {
  418. this.myApplet = false;
  419. } else {
  420. this.myApplet = true;
  421. }
  422. },
  423. fail: () => {
  424. this.myApplet = true;
  425. }
  426. });
  427. },
  428. getCartNum: function () {
  429. getCartCounts()
  430. .then((res) => {
  431. this.$store.commit('indexData/setCartNum', res.data.count + '');
  432. let cartNum = res.data.count;
  433. if (cartNum > 0) {
  434. uni.setTabBarBadge({
  435. index: 3,
  436. text: cartNum > 99 ? '99+' : cartNum + ''
  437. });
  438. } else {
  439. uni.hideTabBarRedDot({
  440. index: 3
  441. });
  442. }
  443. })
  444. .catch((err) => {
  445. return this.$util.Tips({
  446. title: err.msg
  447. });
  448. });
  449. },
  450. storeTap(id) {
  451. this.entryData.select_store_id = id;
  452. this.entryData.store_id = '';
  453. uni.removeStorageSync('rulesStoreId');
  454. },
  455. getCopyRight() {
  456. getCrmebCopyRight()
  457. .then((res) => {
  458. let data = res.data;
  459. uni.setStorageSync('wechatStatus', data.wechat_status);
  460. if (!data.copyrightContext && !data.copyrightImage) {
  461. data.copyrightImage = '/static/images/support.png';
  462. }
  463. uni.setStorageSync('copyNameInfo', data.copyrightContext);
  464. uni.setStorageSync('copyImageInfo', data.copyrightImage);
  465. // #ifdef MP
  466. uni.setStorageSync(
  467. 'MPSiteData',
  468. JSON.stringify({
  469. site_logo: data.site_logo,
  470. site_name: data.site_name
  471. })
  472. );
  473. // #endif
  474. })
  475. .catch((err) => {
  476. return this.$util.Tips({
  477. title: err.msg
  478. });
  479. });
  480. },
  481. getOptions(options) {
  482. let that = this;
  483. // #ifdef MP
  484. if (options.scene) {
  485. let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
  486. //记录推广人uid
  487. if (value.spid) app.globalData.spid = value.spid;
  488. }
  489. // #endif
  490. if (options.spid) app.globalData.spid = options.spid;
  491. },
  492. // 重新链接
  493. reconnect() {
  494. this.diyData();
  495. getShare().then((res) => {
  496. this.shareInfo = res.data;
  497. });
  498. },
  499. goICP(url) {
  500. // #ifdef H5
  501. window.open(url);
  502. // #endif
  503. // #ifdef MP
  504. uni.navigateTo({
  505. url: `/pages/annex/web_view/index?url=${url}`
  506. });
  507. // #endif
  508. },
  509. bindHeighta(data) {
  510. // #ifdef APP-PLUS
  511. this.sortMpTop = data.top + data.height;
  512. // #endif
  513. },
  514. bindHeight(data) {
  515. uni.hideLoading();
  516. this.domOffsetTop = data.top;
  517. },
  518. // 去商品详情
  519. goGoodsDetail(item) {
  520. goShopDetail(item, this.uid).then((res) => {
  521. uni.navigateTo({
  522. url: `/pages/goods_details/index?id=${item.id}`
  523. });
  524. });
  525. },
  526. // 分类点击
  527. changeSort(item, index) {
  528. if (this.curSort == index) return;
  529. this.curSort = index;
  530. this.sid = item.id;
  531. this.goodList = [];
  532. this.goodPage = 1;
  533. this.loaded = false;
  534. this.getGoodsList();
  535. },
  536. /**
  537. * @param data {
  538. classPage: 0 分类id
  539. microPage: 0 微页面id
  540. type: 1 0 微页面 1 商品分类
  541. }*/
  542. bindSortId(data) {
  543. this.styleConfig = [];
  544. if (data.type == 1) {
  545. this.getProductList(data.classPage);
  546. } else {
  547. this.sortList = [];
  548. this.getMicroPage(data.microPage, true);
  549. }
  550. },
  551. /**
  552. * 获取DIY
  553. * @param {number} id
  554. * @param {boolean} type 区分是否是微页面
  555. */
  556. getMicroPage(id, type) {
  557. let that = this;
  558. that.styleConfig = [];
  559. uni.showLoading({
  560. title: '加载中...'
  561. });
  562. getDiy(id)
  563. .then((res) => {
  564. uni.hideLoading();
  565. let data = res.data;
  566. let diyArr = that.objToArr(res.data.value);
  567. diyArr = diyArr.filter((item) => !item.isHide);
  568. diyArr.forEach((item, index) => {
  569. if (['headerSerch', 'homeComb'].includes(item.name)) {
  570. diyArr.splice(index, 1);
  571. }
  572. });
  573. this.styleConfig = diyArr;
  574. })
  575. .catch((err) => {
  576. return that.$util.Tips({
  577. title: err
  578. });
  579. uni.hideLoading();
  580. });
  581. },
  582. getProductList(data) {
  583. let tempObj = '';
  584. this.curSort = 0;
  585. this.loaded = false;
  586. if (this.sortAll.length > 0) {
  587. this.sortAll.forEach((el, index) => {
  588. if (el.id == data) {
  589. this.$set(this, 'sortList', el);
  590. this.sid = el.children.length ? el.children[0].id : '';
  591. }
  592. });
  593. this.goodList = [];
  594. this.goodPage = 1;
  595. this.$nextTick(() => {
  596. if (this.sortList != '') this.getGoodsList();
  597. });
  598. } else {
  599. getCategoryList().then((res) => {
  600. this.sortAll = res.data;
  601. res.data.forEach((el, index) => {
  602. if (el.id == data) {
  603. this.sortList = el;
  604. this.sid = el.children.length ? el.children[0].id : '';
  605. }
  606. });
  607. this.goodList = [];
  608. this.goodPage = 1;
  609. this.$nextTick(() => {
  610. if (this.sortList != '') this.getGoodsList();
  611. });
  612. });
  613. }
  614. },
  615. // 商品列表
  616. getGoodsList() {
  617. if (this.loading || this.loaded) return;
  618. this.loading = true;
  619. getProductslist({
  620. sid: this.sid,
  621. keyword: '',
  622. priceOrder: '',
  623. salesOrder: '',
  624. news: 0,
  625. page: this.goodPage,
  626. limit: 10,
  627. cid: this.sortList.id
  628. }).then((res) => {
  629. this.loading = false;
  630. this.loaded = res.data.length < 10;
  631. this.goodPage++;
  632. this.goodList = this.goodList.concat(res.data);
  633. });
  634. },
  635. // 新用户优惠券
  636. getNewCoupon() {
  637. const oldUser = uni.getStorageSync('oldUser') || 0;
  638. if (!oldUser) {
  639. getCouponNewUser().then((res) => {
  640. const { data } = res;
  641. if (data.show) {
  642. if (data.list.length) {
  643. this.isCouponShow = true;
  644. this.couponObj = data;
  645. uni.setStorageSync('oldUser', 1);
  646. }
  647. } else {
  648. uni.setStorageSync('oldUser', 1);
  649. }
  650. });
  651. }
  652. },
  653. // 优惠券弹窗
  654. getCoupon() {
  655. const tagDate = uni.getStorageSync('tagDate') || '',
  656. nowDate = new Date().toLocaleDateString();
  657. if (tagDate === nowDate) {
  658. this.getNewCoupon();
  659. } else {
  660. getCouponV2().then((res) => {
  661. const { data } = res;
  662. if (data.list.length) {
  663. this.isCouponShow = true;
  664. this.couponObj = data;
  665. uni.setStorageSync('tagDate', new Date().toLocaleDateString());
  666. } else {
  667. this.getNewCoupon();
  668. }
  669. });
  670. }
  671. },
  672. // 优惠券弹窗关闭
  673. couponClose() {
  674. this.isCouponShow = false;
  675. if (!uni.getStorageSync('oldUser')) {
  676. this.getNewCoupon();
  677. }
  678. },
  679. onLoadFun() {
  680. this.isShowAuth = false;
  681. },
  682. // #ifdef H5
  683. // 获取url后面的参数
  684. getQueryString(name) {
  685. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  686. var reg_rewrite = new RegExp('(^|/)' + name + '/([^/]*)(/|$)', 'i');
  687. var r = window.location.search.substr(1).match(reg);
  688. var q = window.location.pathname.substr(1).match(reg_rewrite);
  689. if (r != null) {
  690. return unescape(r[2]);
  691. } else if (q != null) {
  692. return unescape(q[2]);
  693. } else {
  694. return null;
  695. }
  696. },
  697. // #endif
  698. // #ifdef MP
  699. getTempIds() {
  700. let messageTmplIds = wx.getStorageSync(SUBSCRIBE_MESSAGE);
  701. if (!messageTmplIds) {
  702. getTempIds().then((res) => {
  703. if (res.data) wx.setStorageSync(SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  704. });
  705. }
  706. },
  707. // #endif
  708. // 对象转数组
  709. objToArr(data) {
  710. let obj = Object.keys(data).sort();
  711. let m = obj.map((key) => data[key]);
  712. return m;
  713. },
  714. setDiyData(data) {
  715. this.errorNetwork = false;
  716. if (data.is_bg_color) {
  717. this.bgColor = data.color_picker;
  718. }
  719. if (data.is_bg_pic) {
  720. this.bgPic = data.bg_pic;
  721. this.bgTabVal = data.bg_tab_val;
  722. }
  723. this.pageShow = data.is_show;
  724. uni.setNavigationBarTitle({
  725. title: data.title
  726. });
  727. let temp = [];
  728. let goodsIndex = [];
  729. let promotionIndex = [];
  730. let lastArr = this.objToArr(data.value);
  731. lastArr.forEach((item, index, arr) => {
  732. if (item.name == 'pageFoot') {
  733. this.footerConfigData = item;
  734. }
  735. if (item.name === 'homeComb' && !item.isHide) {
  736. this.showHomeComb = true;
  737. this.homeCombData = item;
  738. if (item.searchConfig.tabVal) {
  739. this.positionTop = uni.getSystemInfoSync().statusBarHeight + 43;
  740. }
  741. }
  742. if (item.name == 'headerSerch' && !item.isHide) {
  743. this.isHeaderSerch = true;
  744. this.headerSerchCombData = item;
  745. }
  746. if (item.name == 'tabNav' && !item.isHide) {
  747. this.showCateNav = true;
  748. this.cateNavData = item;
  749. }
  750. if (item.name == 'goodList' && !item.isHide) {
  751. goodsIndex.push(index);
  752. }
  753. if (item.name == 'promotionList' && !item.isHide) {
  754. promotionIndex.push(index);
  755. }
  756. if (!item.isHide) {
  757. temp.push(item);
  758. }
  759. });
  760. function sortNumber(a, b) {
  761. return a.timestamp - b.timestamp;
  762. }
  763. temp.sort(sortNumber);
  764. this.styleConfig = temp;
  765. this.goodsIndex = goodsIndex;
  766. this.promotionIndex = promotionIndex;
  767. },
  768. getDiyData() {
  769. getDiy(0)
  770. .then((res) => {
  771. uni.setStorageSync('diyData', JSON.stringify(res.data));
  772. this.setDiyData(res.data);
  773. })
  774. .catch((error) => {
  775. // #ifdef APP-PLUS
  776. if (error.status) {
  777. uni.hideLoading();
  778. if (this.errorNetwork) {
  779. uni.showToast({
  780. title: '请开启网络连接',
  781. icon: 'none',
  782. duration: 2000
  783. });
  784. }
  785. this.errorNetwork = true;
  786. }
  787. // #endif
  788. });
  789. },
  790. diyData() {
  791. let diyData = uni.getStorageSync('diyData');
  792. if (diyData) {
  793. getDiyVersion(0).then((res) => {
  794. let diyVersion = uni.getStorageSync('diyVersion');
  795. if (res.data.version + '0' === diyVersion) {
  796. this.setDiyData(JSON.parse(diyData));
  797. } else {
  798. uni.setStorageSync('diyVersion', res.data.version + '0');
  799. this.getDiyData();
  800. }
  801. });
  802. } else {
  803. this.getDiyData();
  804. }
  805. },
  806. changeLogin() {
  807. this.getIsLogin();
  808. },
  809. getIsLogin() {
  810. toLogin();
  811. },
  812. changeBarg(item) {
  813. if (!this.isLogin) {
  814. this.getIsLogin();
  815. } else {
  816. uni.navigateTo({
  817. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&spid=${this.$store.state.app.uid}`
  818. });
  819. }
  820. },
  821. goDetail(item) {
  822. goShopDetail(item, this.$store.state.app.uid).then((res) => {
  823. uni.navigateTo({
  824. url: `/pages/goods_details/index?id=${item.id}`
  825. });
  826. });
  827. },
  828. newDataStatus(val, num) {
  829. this.isFooter = val ? true : false;
  830. this.pdHeight = num;
  831. },
  832. // #ifdef H5
  833. // 微信分享;
  834. setOpenShare: function () {
  835. let that = this;
  836. let uid = this.uid ? this.uid : 0;
  837. if (that.$wechat.isWeixin()) {
  838. getShare().then((res) => {
  839. let data = res.data;
  840. let configAppMessage = {
  841. desc: data.synopsis,
  842. title: data.title,
  843. link: location.href + '?spid=' + uid,
  844. imgUrl: data.img
  845. };
  846. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline'], configAppMessage);
  847. });
  848. }
  849. }
  850. // #endif
  851. },
  852. onReachBottom() {
  853. if (this.goodList.length) {
  854. this.getGoodsList();
  855. }
  856. },
  857. onPageScroll(e) {
  858. if (e.scrollTop > 20) {
  859. this.myApplet = false;
  860. }
  861. // #ifdef H5
  862. if (this.isHeaderSerch) {
  863. if (e.scrollTop > this.domOffsetTop) {
  864. this.isFixed = true;
  865. }
  866. if (e.scrollTop < this.domOffsetTop) {
  867. this.$nextTick(() => {
  868. this.isFixed = false;
  869. });
  870. }
  871. } else {
  872. this.isFixed = false;
  873. }
  874. // #endif
  875. if (e.scrollTop > 10) {
  876. this.isScrolled = true;
  877. } else {
  878. this.isScrolled = false;
  879. }
  880. uni.$emit('scroll');
  881. uni.$emit('onPageScroll', e.scrollTop);
  882. },
  883. //#ifdef MP
  884. onShareAppMessage() {
  885. let uid = this.uid ? this.uid : 0;
  886. if (this.shareInfo.img) {
  887. return {
  888. title: this.shareInfo.title,
  889. path: '/pages/index/index?spid=' + uid,
  890. imageUrl: this.shareInfo.img,
  891. desc: this.shareInfo.synopsis
  892. };
  893. } else {
  894. return {
  895. title: this.shareInfo.title,
  896. path: '/pages/index/index?spid=' + uid
  897. // imageUrl: this.shareInfo.img,
  898. // desc: this.shareInfo.synopsis
  899. };
  900. }
  901. },
  902. //分享到朋友圈
  903. onShareTimeline: function () {
  904. return {
  905. title: this.shareInfo.title,
  906. path: '/pages/index/index',
  907. imageUrl: this.shareInfo.img,
  908. desc: this.shareInfo.synopsis
  909. };
  910. }
  911. //#endif
  912. };
  913. </script>
  914. <style lang="scss">
  915. .page {
  916. // padding-bottom: 50px;
  917. overflow-y: scroll;
  918. overflow-x: hidden;
  919. }
  920. .myApplet {
  921. position: relative;
  922. &::after {
  923. position: absolute;
  924. right: 55px;
  925. top: -5px;
  926. content: '';
  927. width: 0;
  928. height: 0;
  929. border-left: 7px solid transparent;
  930. border-right: 7px solid transparent;
  931. border-bottom: 7px solid #fff;
  932. }
  933. }
  934. .pictrue_log_class {
  935. background-color: var(--view-theme);
  936. }
  937. .ysize {
  938. background-size: 100%;
  939. }
  940. .fullsize {
  941. background-size: 100% 100%;
  942. }
  943. .repeat {
  944. background-repeat: repeat;
  945. }
  946. .noRepeat {
  947. background-repeat: no-repeat;
  948. }
  949. .error-network {
  950. position: fixed;
  951. left: 0;
  952. top: 0;
  953. display: flex;
  954. flex-direction: column;
  955. align-items: center;
  956. width: 100%;
  957. height: 100%;
  958. padding-top: 40rpx;
  959. background: #fff;
  960. image {
  961. width: 414rpx;
  962. height: 336rpx;
  963. }
  964. .title {
  965. position: relative;
  966. top: -40rpx;
  967. font-size: 32rpx;
  968. color: #666;
  969. }
  970. .con {
  971. font-size: 24rpx;
  972. color: #999;
  973. .label {
  974. margin-bottom: 20rpx;
  975. }
  976. .item {
  977. margin-bottom: 20rpx;
  978. }
  979. }
  980. .btn {
  981. display: flex;
  982. align-items: center;
  983. justify-content: center;
  984. width: 508rpx;
  985. height: 86rpx;
  986. margin-top: 100rpx;
  987. border: 1px solid #d74432;
  988. color: #e93323;
  989. font-size: 30rpx;
  990. border-radius: 120rpx;
  991. }
  992. }
  993. .sort-scroll {
  994. background-color: #fff;
  995. }
  996. .sort-product {
  997. margin-top: 20rpx;
  998. }
  999. .site-config {
  1000. margin: 40rpx 0;
  1001. font-size: 24rpx;
  1002. text-align: center;
  1003. color: #666;
  1004. display: flex;
  1005. align-items: center;
  1006. justify-content: center;
  1007. .ban {
  1008. width: 22rpx;
  1009. height: 24rpx;
  1010. margin-right: 10rpx;
  1011. }
  1012. &.fixed {
  1013. position: fixed;
  1014. bottom: 69px;
  1015. left: 0;
  1016. width: 100%;
  1017. }
  1018. }
  1019. .select {
  1020. border: 1px solid var(--view-theme);
  1021. }
  1022. </style>