| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- import {
- login
- } from "@/api/auth/login"
- import {
- adList
- } from "@/api/website"
- import {
- noticesList
- } from "@/api/cms/notice"
- import {
- floors,
- floatLayer,
- apiDefaultSearchWords
- } from "@/api/pc"
- import {
- mapGetters
- } from "vuex"
- import {
- goodsPage,
- timeList
- } from "@/api/seckill"
- import CountDown from "vue2-countdown"
- export default {
- name: "index",
- components: {
- CountDown
- },
- data: () => {
- return {
- loadingAd: true,
- loadingFloor: true,
- adList: [],
- adLeftList: [],
- adRightList: [],
- adCenterList: [],
- floorList: [],
- floatLayer: {
- is_show: false,
- link: {
- url: ""
- }
- },
- indexFloatLayerNum: 0,
- isSub: false,
- siteId: 0,
- listData: [],
- seckillTimeMachine: {
- currentTime: 0,
- startTime: 0,
- endTime: 0
- },
- seckillText: "距离结束",
- backgroundColor: "", // 顶部banner背景颜色
- keyword: "",
- defaultSearchWords: "",
- isShow: false
- }
- },
- watch: {},
- created() {
- this.getAdList()
- this.getBigAdList()
- this.getSmallAdList()
- this.getCategoryBelowList()
- this.getFloors()
- this.getFloatLayer()
- if(this.addonIsExit && this.addonIsExit.seckill == 1){
- this.getTimeList()
- }
- },
- mounted() {
- window.addEventListener("scroll", this.handleScroll)
- },
- computed: {
- ...mapGetters(["defaultHeadImage", "addonIsExit", "defaultGoodsImage", "member", "siteInfo", "cartCount"]),
- optionLeft() {
- return {
- direction: 2,
- limitMoveNum: 2
- }
- }
- },
- methods: {
- countDownS_cb() {},
- countDownE_cb() {
- this.seckillText = "活动已结束"
- },
- getAdList() {
- adList({
- keyword: "NS_PC_INDEX"
- })
- .then(res => {
- this.adList = res.data.adv_list
- this.$store.dispatch("app/is_show", {
- is_show:this.adList.length
- }).then(res => {})
- for (let i = 0; i < this.adList.length; i++) {
- if (this.adList[i].adv_url) this.adList[i].adv_url = JSON.parse(this.adList[i].adv_url)
- }
- this.backgroundColor = this.adList[0].background
- this.loadingAd = false
- })
- .catch(err => {
- this.loadingAd = false
- })
- },
- handleChange(curr, pre) {
- this.backgroundColor = this.adList[curr].background
- },
- /**
- * 广告位大图
- */
- getBigAdList() {
- adList({
- keyword: "NS_PC_INDEX_MID_LEFT"
- })
- .then(res => {
- this.adLeftList = res.data.adv_list
- for (let i = 0; i < this.adLeftList.length; i++) {
- if (this.adLeftList[i].adv_url) this.adLeftList[i].adv_url = JSON.parse(this.adLeftList[i].adv_url)
- }
- this.loadingAd = false
- })
- .catch(err => {
- this.loadingAd = false
- })
- },
- /**
- * 广告位小图
- */
- getSmallAdList() {
- adList({
- keyword: "NS_PC_INDEX_MID_RIGHT"
- })
- .then(res => {
- this.adRightList = res.data.adv_list
- for (let i = 0; i < this.adRightList.length; i++) {
- if (this.adRightList[i].adv_url) this.adRightList[i].adv_url = JSON.parse(this.adRightList[i].adv_url)
- }
- this.loadingAd = false
- })
- .catch(err => {
- this.loadingAd = false
- })
- },
- getCategoryBelowList() {
- adList({
- keyword: "NS_PC_INDEX_CATEGORY_BELOW"
- })
- .then(res => {
- this.adCenterList = res.data.adv_list
- for (let i = 0; i < this.adCenterList.length; i++) {
- if (this.adCenterList[i].adv_url) this.adCenterList[i].adv_url = JSON.parse(this.adCenterList[i].adv_url)
- }
- this.loadingAd = false
- })
- .catch(err => {
- this.loadingAd = false
- })
- },
- /**
- * 限时秒杀
- */
- getTimeList() {
- timeList()
- .then(res => {
- if (res.code == 0 && res.data) {
- let time = new Date(res.timestamp * 1000)
- let currentTimes = time.getHours() * 60 * 60 + time.getMinutes() * 60 + time.getSeconds()
- res.data.list.forEach((v, k) => {
- if (v.seckill_start_time <= currentTimes && currentTimes < v.seckill_end_time) {
- let seckillId = v.seckill_id
- this.getGoodsList(seckillId)
- let endTime = parseInt(time.getTime() / 1000) + (v.seckill_end_time - currentTimes)
- this.seckillTimeMachine = {
- currentTime: res.timestamp,
- startTime: res.timestamp,
- endTime: endTime
- }
- }
- })
- }
- })
- .catch(err => {
- // this.$message.error(err.message)
- })
- },
- /**
- * 秒杀商品
- */
- getGoodsList(id) {
- goodsPage({
- page_size: 0,
- seckill_id: id,
- site_id: this.siteId
- })
- .then(res => {
- if (res.code == 0 && res.data.list) {
- this.listData = res.data.list
- }
- })
- .catch(err => {})
- },
- /**
- * 图片加载失败
- */
- imageError(index) {
- this.listData[index].sku_image = this.defaultGoodsImage
- },
- /**
- * 图片加载失败
- */
- adLeftImageError(index) {
- this.adLeftList[index].adv_image = this.defaultGoodsImage
- },
- /**
- * 图片加载失败
- */
- adRightImageError(index) {
- this.adRightList[index].adv_image = this.defaultGoodsImage
- },
- adCenterImageError(index) {
- this.adCenterList[index].adv_image = this.defaultGoodsImage
- },
- getFloors() {
- floors()
- .then(res => {
- this.floorList = res.data;
- })
- .catch(err => {
- console.log(err)
- })
- },
- getFloatLayer() {
- floatLayer()
- .then(res => {
- if (res.code == 0 && res.data) {
- this.floatLayer = res.data
- if(this.floatLayer.is_show == 1){
- this.floatLayer.link = JSON.parse(this.floatLayer.url)
- // 弹框形式,首次弹出 1,每次弹出 0
- if (!this.floatLayer.img_url) return
- var index_popwindow_count = this.$store.state.app.indexFloatLayerNum;
- if (parseInt(this.floatLayer.number) >= 1) {
- //缓存计数 == 弹出总数 禁止弹出
- if(index_popwindow_count >= parseInt(this.floatLayer.number)){
- this.floatLayer.is_show_type = false
- }else{
- this.floatLayer.is_show_type = true
- }
- } else if (parseInt(this.floatLayer.number) == 0) {
- this.floatLayer.is_show_type = true
- }
- }else{
- this.floatLayer.is_show_type = false
- }
- }
- })
- .catch(err => err)
- },
- closeFloat() {
- var index_popwindow_count = this.$store.state.app.indexFloatLayerNum;
- if(parseInt(this.floatLayer.number) == 0){
- this.$store.commit("app/SET_FLOAT_LAYER", 0)
- }else if(parseInt(this.floatLayer.number) >= 1 && index_popwindow_count != parseInt(this.floatLayer.number)) {
- var count_num = index_popwindow_count + 1;
- this.$store.commit("app/SET_FLOAT_LAYER", count_num)
- }else if(index_popwindow_count == parseInt(this.floatLayer.number)){
- this.$store.commit("app/SET_FLOAT_LAYER", this.floatLayer.number)
- }
- this.floatLayer.is_show_type = false
- this.$forceUpdate()
- // this.$store.commit("app/SET_FLOAT_LAYER", -1)
- },
- // 监听滚动条
- handleScroll() {
- var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
- if (scrollTop >= 680) {
- this.isShow = true
- } else {
- this.isShow = false
- }
- },
- destroyed() {
- // 离开该页面需要移除这个监听的事件,不然会报错
- window.removeEventListener("scroll", this.handleScroll)
- }
- }
- }
|