index.vue 26 KB

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