初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

View File

@@ -0,0 +1,324 @@
import {
mapGetters
} from "vuex"
import {
cartList
} from "@/api/goods/cart"
export default {
data: () => {
return {
cartList: [], // 购物车
checkAll: false,
totalPrice: "0.00",
totalCount: 0,
invalidGoods: [], // 失效商品集合
loading: true,
modifyNum: 1, // 防止数量跳动
}
},
created() {
this.getCartList()
},
computed: {
...mapGetters(["defaultGoodsImage"])
},
middleware: 'auth',
methods: {
// 获取购物车数据
getCartList() {
cartList({}).then(res => {
if (res.code >= 0 && res.data.length) {
this.handleCartList(res.data)
}
this.loading = false
}).catch(res => {
this.loading = false
})
},
// 处理购物车数据结构
handleCartList(data) {
this.invalidGoods = []
this.cartList = []
var temp = {}
data.forEach((item, index) => {
if (item.goods_state == 1) {
item.checked = true
if (temp["site_" + item.site_id] != undefined) {
temp["site_" + item.site_id].cartList.push(item)
} else {
temp["site_" + item.site_id] = {
siteId: item.site_id,
siteName: item.site_name,
checked: true,
cartList: [item]
}
}
} else {
this.invalidGoods.push(item)
}
})
this.invalidGoods.forEach(v => {
if (v.sku_spec_format) {
v.sku_spec_format = JSON.parse(v.sku_spec_format)
} else {
v.sku_spec_format = []
}
})
Object.keys(temp).forEach(key => {
this.cartList.push(temp[key])
})
this.calculationTotalPrice()
this.cartList.forEach(v => {
v.cartList.forEach(k => {
if (k.sku_spec_format) {
k.sku_spec_format = JSON.parse(k.sku_spec_format)
} else {
k.sku_spec_format = []
}
})
})
},
// 单选
singleElection(siteIndex, index) {
this.calculationTotalPrice()
},
// 店铺全选
siteAllElection(index) {
this.cartList[index].cartList.forEach(item => {
item.checked = this.cartList[index].checked
})
this.calculationTotalPrice()
},
// 全选
allElection() {
if (this.cartList.length) {
this.cartList.forEach(siteItem => {
siteItem.checked = this.checkAll
siteItem.cartList.forEach(item => {
item.checked = this.checkAll
})
})
}
this.calculationTotalPrice()
},
// 计算购物车总价
calculationTotalPrice() {
if (this.cartList.length) {
let totalPrice = 0,
totalCount = 0,
siteAllElectionCount = 0
this.cartList.forEach(siteItem => {
let siteGoodsCount = 0
siteItem.cartList.forEach(item => {
if (item.checked) {
siteGoodsCount += 1
totalCount += 1
totalPrice += item.discount_price * item.num
}
})
if (siteItem.cartList.length == siteGoodsCount) {
siteItem.checked = true
siteAllElectionCount += 1
} else {
siteItem.checked = false
}
})
this.totalPrice = totalPrice.toFixed(2)
this.totalCount = totalCount
this.checkAll = this.cartList.length == siteAllElectionCount
} else {
this.totalPrice = "0.00"
this.totalCount = 0
}
this.modifyNum = 1;
},
// 删除单个
deleteCart(siteIndex, cartIndex) {
this.$confirm("确定要删除该商品吗?", "提示信息", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.$store.dispatch("cart/delete_cart", {
cart_id: this.cartList[siteIndex].cartList[cartIndex].cart_id.toString()
}).then(res => {
if (res.code >= 0) {
this.cartList[siteIndex].cartList.splice(cartIndex, 1)
if (this.cartList[siteIndex].cartList.length == 0) this.cartList.splice(siteIndex, 1)
this.calculationTotalPrice()
this.$message({
type: "success",
message: "删除成功"
})
} else {
this.$message({
message: res.message,
type: "warning"
})
}
}).catch(err => {
this.$message.error(err.message)
})
})
},
// 删除选择的购物车
deleteCartSelected() {
var cartIds = []
var selectedItem = []
this.cartList.forEach((siteItem, siteIndex) => {
siteItem.cartList.forEach((item, cartIndex) => {
if (item.checked) {
cartIds.push(item.cart_id)
selectedItem.push({
siteIndex: siteIndex,
cartIndex: cartIndex,
siteId: siteItem.siteId,
cartId: item.cart_id
})
}
})
})
if (cartIds.length == 0) {
this.$message({
message: "请选择要删除的商品",
type: "warning"
})
return
}
this.$confirm("确定要删除选择的商品吗?", "提示信息", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.$store.dispatch("cart/delete_cart", {
cart_id: cartIds.toString()
}).then(res => {
if (res.code >= 0) {
selectedItem.forEach(selectedItem => {
this.cartList.forEach((siteItem, siteIndex) => {
siteItem.cartList.forEach((item, cartIndex) => {
if (selectedItem.cartId == item.cart_id) {
siteItem.cartList.splice(cartIndex, 1)
}
if (siteItem.cartList.length == 0) {
this.cartList.splice(siteIndex, 1)
}
})
})
})
this.calculationTotalPrice()
this.$message({
type: "success",
message: "删除成功"
})
} else {
this.$message({
message: res.message,
type: "warning"
})
}
}).catch(err => {
this.$message.error(err.message)
})
})
},
// 清空失效商品
clearInvalidGoods() {
this.$confirm("确认要清空这些商品吗?", "提示信息", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
var cartIds = []
this.invalidGoods.forEach(goodsItem => {
cartIds.push(goodsItem.cart_id)
})
if (cartIds.length) {
this.$store.dispatch("cart/delete_cart", {
cart_id: cartIds.toString()
}).then(res => {
if (res.code >= 0) {
this.invalidGoods = []
this.$message({
type: "success",
message: "删除成功"
})
} else {
this.$message({
message: res.message,
type: "warning"
})
}
}).catch(err => {
this.$message.error(err.message)
})
}
})
},
// 变更购物车数量
cartNumChange(num, params) {
if (num < 1 || !num) num = 1;
// 防止数量跳动
this.modifyNum = 0;
this.$store.dispatch("cart/edit_cart_num", {
num,
cart_id: this.cartList[params.siteIndex].cartList[params.cartIndex].cart_id
}).then(res => {
if (res.code >= 0) {
this.cartList[params.siteIndex].cartList[params.cartIndex].num = num;
this.calculationTotalPrice();
} else {
this.$message({
message: res.message,
type: "warning"
});
this.modifyNum = 1;
}
}).catch(err => {
this.$message.error(err.message);
this.modifyNum = 1;
})
},
// 结算
settlement() {
if (this.totalCount > 0) {
let cart_ids = []
this.cartList.forEach(siteItem => {
siteItem.cartList.forEach(item => {
if (item.checked) {
cart_ids.push(item.cart_id)
}
})
})
if (cart_ids.length > 100) {
this.$message({
message: '购物车最多支持100个商品一起购买',
type: "warning"
});
return;
}
var data = {
cart_ids: cart_ids.toString()
}
this.$store.dispatch("order/setOrderCreateData", data)
this.$router.push({
path: "/order/payment"
})
}
},
imageError(siteIndex, cartIndex) {
this.cartList[siteIndex].cartList[cartIndex].sku_image = this.defaultGoodsImage
},
imageErrorInvalid(index) {
this.invalidGoods[index].sku_image = this.defaultGoodsImage
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,258 @@
import {
goodsSkuPage,
brandPage
} from "@/api/goods/goods"
import {
mapGetters
} from "vuex"
import {
goodsCategoryInfo,
goodsCategoryList
} from "@/api/goods/goodscategory"
export default {
data: () => {
return {
goodsList: [],
total: 0,
keyword: "",
catewords: '',
currentPage: 1,
pageSize: 25,
is_free_shipping: 0,
filters: {
category_id: 0,
category_level: 0,
brand_id: 0,
min_price: "",
max_price: "",
order: "",
sort: "desc",
coupon: 0
},
loading: true,
first_index: 0,
categoryList: [],
selectCategoryId: 0,
// 全部商品分类链接
categoryAll: {
id: 0,
level: 0,
isAllow: true // 是否允许选中
},
brandList: [], // 品牌列表
brandInitialList: [],
currentInitial: "", // 当前选择品牌分区
choosedBrand: "", // 已选择的品牌,
isShowMoreBrand: false // 是否展开更多品牌
}
},
created() {
this.keyword = this.$route.query.keyword || ""
if (this.$route.query.keyword && process.client) window.document.title = `${this.$route.query.keyword} - ${this.siteInfo.site_name}`
this.filters.category_id = this.$route.query.category_id || ""
this.filters.category_level = this.$route.query.level || ""
this.filters.brand_id = this.$route.query.brand_id || ""
this.filters.coupon = this.$route.query.coupon || 0
this.getBrandList();
this.getGoodsList();
if (this.$route.query.category_id && this.$route.query.category_id > 0) {
this.categorySearch();
} else {
// 查询一级商品分类
this.getGoodsCategoryList();
}
},
computed: {
salesArrowDirection() {
let className = this.filters.order === 'sale_num' && this.filters.sort === 'desc' ? 'arrow-down' : 'arrow-up';
return className;
},
priceArrowDirection() {
let className = this.filters.order === 'discount_price' && this.filters.sort === 'desc' ? 'arrow-down' :
'arrow-up';
return className;
},
...mapGetters(["defaultGoodsImage", "siteInfo"])
},
methods: {
// 商品分类搜索
categorySearch() {
goodsCategoryInfo({
category_id: this.filters.category_id
}).then(res => {
if (res.code == 0 && res.data) {
let data = res.data;
this.catewords = data.category_full_name;
this.first_index = data.category_id_1;
this.categoryList = data.child_list;
this.selectCategoryId = this.filters.category_id;
// 设置全部的链接地址
switch (data.level) {
case 1:
this.categoryAll.level = 1;
this.categoryAll.id = data.category_id_1;
this.categoryAll.isAllow = true;
break;
case 2:
this.categoryAll.level = 1;
this.categoryAll.id = data.category_id_1;
this.categoryAll.isAllow = true;
if (this.categoryList[0].level == 3) {
this.categoryAll.level = 2;
this.categoryAll.id = data.category_id_2;
}
break;
case 3:
this.categoryAll.level = 2;
this.categoryAll.id = data.category_id_2;
this.categoryAll.isAllow = false;
break;
}
for (let i = 0; i < this.categoryList.length; i++) {
let item = this.categoryList[i];
if (item.category_id == this.categoryAll.id) {
this.categoryAll.id = 0;
this.categoryAll.isAllow = false; // 匹配到了分类,禁止选中 全部
break;
}
}
if (process.client) window.document.title = `${data.category_name} - ${this.siteInfo.site_name}`
}
})
},
// 一级商品分类列表
getGoodsCategoryList() {
goodsCategoryList({}).then(res => {
if (res.code == 0 && res.data) {
// 设置全部的链接地址
this.categoryAll.level = 1;
this.categoryAll.id = 0;
this.categoryAll.isAllow = true;
this.categoryList = res.data;
}
})
},
getGoodsList() {
const params = {
page: this.currentPage,
page_size: this.pageSize,
keyword: this.keyword,
...this.filters
}
goodsSkuPage(params || {}).then(res => {
const {
count,
page_count,
list
} = res.data
this.total = count
this.goodsList = list
this.loading = false
}).catch(err => {
this.loading = false
})
},
handlePageSizeChange(size) {
this.pageSize = size
this.getGoodsList()
},
handleCurrentPageChange(page) {
this.currentPage = page
this.getGoodsList()
},
handlePriceRange() {
if (Number(this.filters.min_price) > Number(this.filters.max_price)) {
// es6解构赋值
[this.filters.min_price, this.filters.max_price] = [this.filters.max_price, this.filters.min_price]
}
this.getGoodsList()
},
changeSort(type) {
if (this.filters.order === type) {
this.$set(this.filters, "sort", this.filters.sort === "desc" ? "asc" : "desc")
} else {
this.$set(this.filters, "order", type)
this.$set(this.filters, "sort", "desc")
}
this.getGoodsList()
},
getBrandList() {
brandPage({
page: 1,
page_size: 0
}).then(res => {
if (res.code >= 0 && res.data) {
this.brandList = res.data.list;
if (this.filters.brand_id) {
for (var i = 0; i < this.brandList.length; i++) {
if (this.brandList[i].brand_id == this.filters.brand_id) {
this.choosedBrand = this.brandList[i];
}
}
}
}
});
},
handleChangeInitial(initial) {
this.currentInitial = initial
},
onChooseBrand(brand) {
this.choosedBrand = brand
this.filters.brand_id = brand.brand_id
this.getGoodsList()
},
closeBrand() {
this.choosedBrand = ""
this.filters.brand_id = ""
this.getGoodsList()
},
showPrice(data) {
let price = data.discount_price;
if (data.member_price && parseFloat(data.member_price) < parseFloat(price)) price = data.member_price;
return price;
}
},
watch: {
is_free_shipping: function (val) {
this.filters.is_free_shipping = val ? 1 : ""
this.getGoodsList()
},
$route: function (curr) {
this.currentPage = 1
if (curr.query.keyword && process.client) window.document.title = `${curr.query.keyword} - ${this.siteInfo.site_name}`
if (curr.query.level && curr.query.category_id > 0) {
this.filters.category_level = curr.query.level
this.filters.category_id = curr.query.category_id
this.getGoodsList()
this.categorySearch()
} else {
this.getGoodsCategoryList();
this.first_index = 0
this.selectCategoryId = 0
if (process.client) window.document.title = `${this.siteInfo.site_name}`
}
if (curr.query.category_id == undefined || curr.query.category_id == 0) {
this.catewords = ""
this.keyword = curr.query.keyword
this.filters.category_id = curr.query.category_id || ""
this.filters.category_level = curr.query.level || ""
this.filters.brand_id = curr.query.brand_id || ""
this.getGoodsList()
}
}
}
}