index.vue 32 KB

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