index.vue 24 KB

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