index.js 1.5 KB
import api from '@/api/api'
import {
  httpGet,
  httpPost
} from '@/api/fetch-api.js'

export default {
  data() {
    return {
      key: 'value',
      page: 1,
      size: 10,
      total: 0,
      typeCode: "",
      bannerList: [],
      typeList: [],
      productList: [],
    }
  },
  components: {},
  methods: {
    toProduct(item) {
      this.$router.push({
        path: "/product/detail",
        query: {
          c: item.productCode
        }
      })
    },
    toMyFavorite() {
      this.$router.push({
        path: "/favorite"
      })
    },
    // 请求banner列表
    queryBannerList() {
      httpGet({
        url: api.bannerList,
        data: {}
      }).then((result) => {
        this.bannerList = result && result.bannerImages || [];
      })
    },
    // 请求type列表
    queryTypeList() {
      httpGet({
        url: api.typeList,
        data: {}
      }).then((result) => {
        this.typeList = result;
      })
    },
    // 请求产品列表
    queryProductList() {
      httpGet({
        url: api.productList,
        data: {
          page: this.page,
          size: this.size,
          typeCode: this.typeCode
        }
      }).then((result) => {
        this.productList = result.list;
        this.total = result.total;
        console.log("this.productList:", this.productList);
      })
    },
    initData() {
      this.queryBannerList();
      this.queryTypeList();
      this.queryProductList();
    }
  },
  mounted() {},
  created() {
    this.initData();
  }
}