index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import {
  2. login
  3. } from "@/api/auth/login"
  4. import {
  5. adList
  6. } from "@/api/website"
  7. import {
  8. noticesList
  9. } from "@/api/cms/notice"
  10. import {
  11. floors,
  12. floatLayer,
  13. apiDefaultSearchWords
  14. } from "@/api/pc"
  15. import {
  16. mapGetters
  17. } from "vuex"
  18. import {
  19. goodsPage,
  20. timeList
  21. } from "@/api/seckill"
  22. import CountDown from "vue2-countdown"
  23. export default {
  24. name: "index",
  25. components: {
  26. CountDown
  27. },
  28. data: () => {
  29. return {
  30. loadingAd: true,
  31. loadingFloor: true,
  32. adList: [],
  33. adLeftList: [],
  34. adRightList: [],
  35. adCenterList: [],
  36. floorList: [],
  37. floatLayer: {
  38. is_show: false,
  39. link: {
  40. url: ""
  41. }
  42. },
  43. indexFloatLayerNum: 0,
  44. isSub: false,
  45. siteId: 0,
  46. listData: [],
  47. seckillTimeMachine: {
  48. currentTime: 0,
  49. startTime: 0,
  50. endTime: 0
  51. },
  52. seckillText: "距离结束",
  53. backgroundColor: "", // 顶部banner背景颜色
  54. keyword: "",
  55. defaultSearchWords: "",
  56. isShow: false
  57. }
  58. },
  59. watch: {},
  60. created() {
  61. this.getAdList()
  62. this.getBigAdList()
  63. this.getSmallAdList()
  64. this.getCategoryBelowList()
  65. this.getFloors()
  66. this.getFloatLayer()
  67. if(this.addonIsExit && this.addonIsExit.seckill == 1){
  68. this.getTimeList()
  69. }
  70. },
  71. mounted() {
  72. window.addEventListener("scroll", this.handleScroll)
  73. },
  74. computed: {
  75. ...mapGetters(["defaultHeadImage", "addonIsExit", "defaultGoodsImage", "member", "siteInfo", "cartCount"]),
  76. optionLeft() {
  77. return {
  78. direction: 2,
  79. limitMoveNum: 2
  80. }
  81. }
  82. },
  83. methods: {
  84. countDownS_cb() {},
  85. countDownE_cb() {
  86. this.seckillText = "活动已结束"
  87. },
  88. getAdList() {
  89. adList({
  90. keyword: "NS_PC_INDEX"
  91. })
  92. .then(res => {
  93. this.adList = res.data.adv_list
  94. this.$store.dispatch("app/is_show", {
  95. is_show:this.adList.length
  96. }).then(res => {})
  97. for (let i = 0; i < this.adList.length; i++) {
  98. if (this.adList[i].adv_url) this.adList[i].adv_url = JSON.parse(this.adList[i].adv_url)
  99. }
  100. this.backgroundColor = this.adList[0].background
  101. this.loadingAd = false
  102. })
  103. .catch(err => {
  104. this.loadingAd = false
  105. })
  106. },
  107. handleChange(curr, pre) {
  108. this.backgroundColor = this.adList[curr].background
  109. },
  110. /**
  111. * 广告位大图
  112. */
  113. getBigAdList() {
  114. adList({
  115. keyword: "NS_PC_INDEX_MID_LEFT"
  116. })
  117. .then(res => {
  118. this.adLeftList = res.data.adv_list
  119. for (let i = 0; i < this.adLeftList.length; i++) {
  120. if (this.adLeftList[i].adv_url) this.adLeftList[i].adv_url = JSON.parse(this.adLeftList[i].adv_url)
  121. }
  122. this.loadingAd = false
  123. })
  124. .catch(err => {
  125. this.loadingAd = false
  126. })
  127. },
  128. /**
  129. * 广告位小图
  130. */
  131. getSmallAdList() {
  132. adList({
  133. keyword: "NS_PC_INDEX_MID_RIGHT"
  134. })
  135. .then(res => {
  136. this.adRightList = res.data.adv_list
  137. for (let i = 0; i < this.adRightList.length; i++) {
  138. if (this.adRightList[i].adv_url) this.adRightList[i].adv_url = JSON.parse(this.adRightList[i].adv_url)
  139. }
  140. this.loadingAd = false
  141. })
  142. .catch(err => {
  143. this.loadingAd = false
  144. })
  145. },
  146. getCategoryBelowList() {
  147. adList({
  148. keyword: "NS_PC_INDEX_CATEGORY_BELOW"
  149. })
  150. .then(res => {
  151. this.adCenterList = res.data.adv_list
  152. for (let i = 0; i < this.adCenterList.length; i++) {
  153. if (this.adCenterList[i].adv_url) this.adCenterList[i].adv_url = JSON.parse(this.adCenterList[i].adv_url)
  154. }
  155. this.loadingAd = false
  156. })
  157. .catch(err => {
  158. this.loadingAd = false
  159. })
  160. },
  161. /**
  162. * 限时秒杀
  163. */
  164. getTimeList() {
  165. timeList()
  166. .then(res => {
  167. if (res.code == 0 && res.data) {
  168. let time = new Date(res.timestamp * 1000)
  169. let currentTimes = time.getHours() * 60 * 60 + time.getMinutes() * 60 + time.getSeconds()
  170. res.data.list.forEach((v, k) => {
  171. if (v.seckill_start_time <= currentTimes && currentTimes < v.seckill_end_time) {
  172. let seckillId = v.seckill_id
  173. this.getGoodsList(seckillId)
  174. let endTime = parseInt(time.getTime() / 1000) + (v.seckill_end_time - currentTimes)
  175. this.seckillTimeMachine = {
  176. currentTime: res.timestamp,
  177. startTime: res.timestamp,
  178. endTime: endTime
  179. }
  180. }
  181. })
  182. }
  183. })
  184. .catch(err => {
  185. // this.$message.error(err.message)
  186. })
  187. },
  188. /**
  189. * 秒杀商品
  190. */
  191. getGoodsList(id) {
  192. goodsPage({
  193. page_size: 0,
  194. seckill_id: id,
  195. site_id: this.siteId
  196. })
  197. .then(res => {
  198. if (res.code == 0 && res.data.list) {
  199. this.listData = res.data.list
  200. }
  201. })
  202. .catch(err => {})
  203. },
  204. /**
  205. * 图片加载失败
  206. */
  207. imageError(index) {
  208. this.listData[index].sku_image = this.defaultGoodsImage
  209. },
  210. /**
  211. * 图片加载失败
  212. */
  213. adLeftImageError(index) {
  214. this.adLeftList[index].adv_image = this.defaultGoodsImage
  215. },
  216. /**
  217. * 图片加载失败
  218. */
  219. adRightImageError(index) {
  220. this.adRightList[index].adv_image = this.defaultGoodsImage
  221. },
  222. adCenterImageError(index) {
  223. this.adCenterList[index].adv_image = this.defaultGoodsImage
  224. },
  225. getFloors() {
  226. floors()
  227. .then(res => {
  228. this.floorList = res.data;
  229. })
  230. .catch(err => {
  231. console.log(err)
  232. })
  233. },
  234. getFloatLayer() {
  235. floatLayer()
  236. .then(res => {
  237. if (res.code == 0 && res.data) {
  238. this.floatLayer = res.data
  239. if(this.floatLayer.is_show == 1){
  240. this.floatLayer.link = JSON.parse(this.floatLayer.url)
  241. // 弹框形式,首次弹出 1,每次弹出 0
  242. if (!this.floatLayer.img_url) return
  243. var index_popwindow_count = this.$store.state.app.indexFloatLayerNum;
  244. if (parseInt(this.floatLayer.number) >= 1) {
  245. //缓存计数 == 弹出总数 禁止弹出
  246. if(index_popwindow_count >= parseInt(this.floatLayer.number)){
  247. this.floatLayer.is_show_type = false
  248. }else{
  249. this.floatLayer.is_show_type = true
  250. }
  251. } else if (parseInt(this.floatLayer.number) == 0) {
  252. this.floatLayer.is_show_type = true
  253. }
  254. }else{
  255. this.floatLayer.is_show_type = false
  256. }
  257. }
  258. })
  259. .catch(err => err)
  260. },
  261. closeFloat() {
  262. var index_popwindow_count = this.$store.state.app.indexFloatLayerNum;
  263. if(parseInt(this.floatLayer.number) == 0){
  264. this.$store.commit("app/SET_FLOAT_LAYER", 0)
  265. }else if(parseInt(this.floatLayer.number) >= 1 && index_popwindow_count != parseInt(this.floatLayer.number)) {
  266. var count_num = index_popwindow_count + 1;
  267. this.$store.commit("app/SET_FLOAT_LAYER", count_num)
  268. }else if(index_popwindow_count == parseInt(this.floatLayer.number)){
  269. this.$store.commit("app/SET_FLOAT_LAYER", this.floatLayer.number)
  270. }
  271. this.floatLayer.is_show_type = false
  272. this.$forceUpdate()
  273. // this.$store.commit("app/SET_FLOAT_LAYER", -1)
  274. },
  275. // 监听滚动条
  276. handleScroll() {
  277. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
  278. if (scrollTop >= 680) {
  279. this.isShow = true
  280. } else {
  281. this.isShow = false
  282. }
  283. },
  284. destroyed() {
  285. // 离开该页面需要移除这个监听的事件,不然会报错
  286. window.removeEventListener("scroll", this.handleScroll)
  287. }
  288. }
  289. }