s-coupon-get.vue,detail-tabbar.vue,详情加入购物车,其他模块优化

This commit is contained in:
落日晚风
2023-12-11 17:42:50 +08:00
parent c5b1f3ac93
commit ef26268c8e
17 changed files with 1836 additions and 1767 deletions
+16 -3
View File
@@ -12,8 +12,8 @@ export default {
},
}),
append: (data) =>
request({
url: 'cart',
request2({
url: '/app-api/trade/cart/add',
method: 'POST',
custom: {
showSuccess: true,
@@ -21,9 +21,22 @@ export default {
},
data: {
...data,
type: 'inc',
// type: 'inc',
},
}),
// append: (data) =>
// request({
// url: 'cart',
// method: 'POST',
// custom: {
// showSuccess: true,
// successMsg: '已添加到购物车~',
// },
// data: {
// ...data,
// type: 'inc',
// },
// }),
// 删除购物车
delete: (ids) =>
request2({
+13 -2
View File
@@ -33,10 +33,21 @@ export default {
},
}),
get: (id) =>
request({
url: 'coupon/get/' + id,
request2({
url: 'promotion/coupon/take',
method: 'POST',
data: {
templateId: id
},
params: {
templateId: id
},
}),
// get: (id) =>
// request({
// url: 'coupon/get/' + id,
// method: 'POST',
// }),
listByGoods: (id) =>
request({
url: 'coupon/listByGoods/' + id,
+79 -73
View File
@@ -2,79 +2,85 @@ import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
// 商品详情
detail: (id, params = {}) =>
request2({
url: 'product/spu/get-detail?id=' + id,
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品详情
detail: (id, params = {}) =>
request({
url: '/app-api/product/spu/get-detail?id=' + id,
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品列表
list: (params) =>
request2({
url: 'product/spu/page',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品列表
list: (params) =>
request({
url: '/app-api/product/spu/page',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品查询
ids: (params = {}) =>
request({
url: 'goods/goods/ids',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品查询
ids: (params = {}) =>
request({
url: 'goods/goods/ids',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品评价列表
comment: (id, params = {}) =>
request2({
url: 'product/comment/list?spuId=' + id,
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品评价类型
getType: (id) =>
request({
url: 'goods/comment/getType/' + id,
method: 'GET',
custom: {
showLoading: false,
showError: false,
},
}),
// 活动商品查询
// 商品查询
activity: (params = {}) =>
request({
url: 'goods/goods/activity',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
activityList: (params = {}) =>
request({
url: 'goods/goods/activityList',
method: 'GET',
params,
}),
};
// 商品评价列表
comment: (id, params = {}) =>
request({
url: '/app-api/product/comment/list?spuId=' + id,
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品评价类型
getType: (id) =>
request({
url: 'goods/comment/getType/' + id,
method: 'GET',
custom: {
showLoading: false,
showError: false,
},
}),
// 活动商品查询
// 商品查询
activity: (params = {}) =>
request({
url: 'goods/goods/activity',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
activityList: (params = {}) =>
request({
url: 'goods/goods/activityList',
method: 'GET',
params,
}),
// 检查是否收藏商品
exits: (id) =>
request({
url: '/app-api/product/favorite/exits?spuId=' + id,
method: 'GET',
}),
};
+14 -8
View File
@@ -65,18 +65,24 @@ export default {
// 解决 SpringMVC 接受 List<Item> 参数的问题
delete data2.items
for (let i = 0; i < data.items.length; i++) {
// data2['items[' + i + '' + '].skuId'] = data.items[i].skuId + '';
// data2['items[' + i + '' + '].count'] = data.items[i].count + '';
// data2['items[' + i + '' + '].cartId'] = data.items[i].cartId + '';
data2['items' + `%5B${i}%5D` + '.skuId'] = data.items[i].skuId + '';
data2['items' + `%5B${i}%5D` + '.count'] = data.items[i].count + '';
data2['items' + `%5B${i}%5D` + '.cartId'] = data.items[i].cartId + '';
// 此处转码问题,待解决方案
// data2[encodeURIComponent('items[' + i + '' + '].skuId')] = data.items[i].skuId + '';
// data2[encodeURIComponent('items[' + i + '' + '].count')] = data.items[i].count + '';
// data2[encodeURIComponent('items[' + i + '' + '].cartId')] = data.items[i].cartId + '';
// data2['items' + `[${i}]` + '.skuId'] = data.items[i].skuId + '';
// data2['items' + `[${i}]` + '.count'] = data.items[i].count + '';
// data2['items' + `[${i}]` + '.cartId'] = data.items[i].cartId + '';
// data2['items' + `%5B${i}%5D` + '.skuId'] = data.items[i].skuId + '';
// data2['items' + `%5B${i}%5D` + '.count'] = data.items[i].count + '';
// data2['items' + `%5B${i}%5D` + '.cartId'] = data.items[i].cartId + '';
}
console.log(data2, '对比数据')
console.log(data2, '手动转码的参数')
return request2({
url: 'trade/order/settlement',
method: 'GET',
// data,
// data: data2,
params: data2
})
},
+14 -14
View File
@@ -1,18 +1,18 @@
import request from '@/sheep/request';
const CommentApi = {
// 获得商品评价分页
getCommentPage: (spuId, pageNo, pageSize, type) => {
return request({
url: '/app-api/product/comment/page',
method: 'GET',
params: {
spuId,
pageNo,
pageSize,
type
},
});
},
// 获得商品评价分页
getCommentPage: (spuId, pageNo, pageSize, type) => {
return request({
url: '/app-api/product/comment/page',
method: 'GET',
params: {
spuId,
pageNo,
pageSize,
type
},
});
},
};
export default CommentApi;
export default CommentApi;
+27 -17
View File
@@ -1,20 +1,30 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
// 获得优惠劵模板列表
getCouponTemplateListByIds: (ids) => {
return request({
url: '/app-api/promotion/coupon-template/list-by-ids',
method: 'GET',
params: { ids },
});
},
// 获得优惠劵模版列表
getCouponTemplateList: (spuId, productScope, count) => {
return request({
url: '/app-api/promotion/coupon-template/list',
method: 'GET',
params: { spuId, productScope, count },
});
},
};
// 获得优惠劵模板列表
getCouponTemplateListByIds: (ids) => {
return request({
url: '/app-api/promotion/coupon-template/list-by-ids',
method: 'GET',
params: {
ids
},
});
},
// 获得优惠劵模版列表
getCouponTemplateList: (params) => {
return request2({
url: `promotion/coupon/match-list?price=${params.price}&spuIds=${params.spuIds}&skuIds=${params.skuIds}&categoryIds=${params.categoryIds}`,
method: 'GET',
// params,
});
},
// getCouponTemplateList: (spuId, productScope, count) => {
// return request({
// url: '/app-api/promotion/coupon-template/list',
// method: 'GET',
// params: { spuId, productScope, count },
// });
// },
};
+45 -123
View File
@@ -1,11 +1,10 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
import $platform from '@/sheep/platform';
export default {
getUnused: () =>
request2({
url: 'promotion/coupon/get-unused-count',
request({
url: '/app-api/promotion/coupon/get-unused-count',
method: 'GET',
custom: {
showLoading: false,
@@ -13,8 +12,8 @@ export default {
},
}),
profile: () =>
request2({
url: 'member/user/get',
request({
url: '/app-api/member/user/get',
method: 'GET',
custom: {
showLoading: false,
@@ -22,7 +21,7 @@ export default {
},
}),
balance: () =>
request2({
request({
url: '/app-api/pay/wallet/get',
method: 'GET',
custom: {
@@ -30,28 +29,9 @@ export default {
auth: true,
},
}),
// profile: () =>
// request({
// url: '/user/api/user/profile',
// method: 'GET',
// custom: {
// showLoading: false,
// auth: true,
// },
// }),
// update: (data) =>
// request({
// url: '/user/api/user/update',
// method: 'POST',
// custom: {
// showSuccess: true,
// auth: true,
// },
// data,
// }),
update: (data) =>
request2({
url: 'member/user/update',
request({
url: '/app-api/member/user/update',
method: 'PUT',
custom: {
showSuccess: true,
@@ -196,90 +176,48 @@ export default {
}),
address: {
// default: () =>
// request({
// url: 'user/address/default',
// method: 'GET',
// custom: {
// showError: false,
// },
// }),
default: () =>
request2({
url: 'member/address/get-default',
request({
url: '/app-api/member/address/get-default',
method: 'GET',
custom: {
showError: false,
},
}),
list: () =>
request2({
url: 'member/address/list',
request({
url: '/app-api/member/address/list',
method: 'GET',
custom: {},
}),
// list: () =>
// request({
// url: 'user/address',
// method: 'GET',
// custom: {},
// }),
create: (data) =>
request2({
url: 'member/address/create',
request({
url: '/app-api/member/address/create',
method: 'POST',
data,
custom: {
showSuccess: true,
},
}),
// create: (data) =>
// request({
// url: 'user/address',
// method: 'POST',
// data,
// custom: {
// showSuccess: true,
// },
// }),
update: (data) =>
request2({
url: 'member/address/update',
request({
url: '/app-api/member/address/update',
method: 'PUT',
data,
custom: {
showSuccess: true,
},
}),
// update: (id, data) =>
// request({
// url: 'user/address/' + id,
// method: 'PUT',
// data,
// custom: {
// showSuccess: true,
// },
// }),
detail: (id) =>
request2({
url: 'member/address/get?id=' + id,
request({
url: '/app-api/member/address/get?id=' + id,
method: 'GET',
}),
// detail: (id) =>
// request({
// url: 'user/address/' + id,
// method: 'GET',
// }),
delete: (id) =>
request2({
url: 'member/address/delete?id=' + id,
request({
url: '/app-api/member/address/delete?id=' + id,
method: 'DELETE',
}),
// delete: (id) =>
// request({
// url: 'user/address/' + id,
// method: 'DELETE',
// }),
},
invoice: {
list: () =>
@@ -319,17 +257,29 @@ export default {
},
favorite: {
list: (params) =>
request2({
url: 'product/favorite/page',
request({
url: '/app-api/product/favorite/page',
method: 'GET',
params,
}),
do: (id) =>
request({
url: 'user/goodsLog/favorite',
url: '/app-api/product/favorite/create',
method: 'POST',
data: {
goods_id: id,
spuId: id,
},
custom: {
showSuccess: true,
auth: true,
},
}),
dos: (id) =>
request({
url: '/app-api/product/favorite/delete',
method: 'DELETE',
data: {
spuId: id,
},
custom: {
showSuccess: true,
@@ -338,8 +288,8 @@ export default {
}),
// 取消收藏
cancel: (id) =>
request2({
url: 'product/favorite/delete-list',
request({
url: '/app-api/product/favorite/delete-list',
method: 'DELETE',
data: {
spuIds: id.split(',').map(item => item * 1),
@@ -350,18 +300,6 @@ export default {
auth: true,
},
}),
// cancel: (id) =>
// request({
// url: 'user/goodsLog/favorite',
// method: 'POST',
// data: {
// goods_ids: id,
// },
// custom: {
// showSuccess: true,
// auth: true,
// },
// }),
},
view: {
list: (params) =>
@@ -383,28 +321,21 @@ export default {
},
wallet: {
log: (params) =>
request2({
request({
// url: 'member/point/record/page',
url: 'pay/wallet-transaction/page',
url: '/app-api/pay/wallet-transaction/page',
method: 'GET',
params,
custom: {},
}),
log2: (params) =>
request2({
url: 'member/point/record/page',
request({
url: '/app-api/member/point/record/page',
// url: 'pay/wallet-transaction/page',
method: 'GET',
params,
custom: {},
}),
// log: (params) =>
// request({
// url: '/user/api/walletLog',
// method: 'GET',
// params,
// custom: {},
// }),
},
account: {
info: (params) =>
@@ -429,18 +360,9 @@ export default {
}),
},
//数量接口
// data: () =>
// request({
// url: 'user/user/data',
// method: 'GET',
// custom: {
// showLoading: false,
// auth: true,
// },
// }),
data: () =>
request2({
url: 'trade/order/get-count',
request({
url: '/app-api/trade/order/get-count',
method: 'GET',
custom: {
showLoading: false,
@@ -448,8 +370,8 @@ export default {
},
}),
data2: () =>
request2({
url: 'trade/after-sale/get-applying-count',
request({
url: '/app-api/trade/after-sale/get-applying-count',
method: 'GET',
custom: {
showLoading: false,
+98 -102
View File
@@ -1,108 +1,104 @@
<template>
<su-popup
:show="show"
type="bottom"
round="20"
@close="emits('close')"
showClose
backgroundColor="#f2f2f2"
>
<view class="model-box">
<view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠券</view>
<scroll-view
class="model-content"
scroll-y
:scroll-with-animation="false"
:enable-back-to-top="true"
>
<view class="subtitle ss-m-l-20">可使用优惠券</view>
<view v-for="item in state.couponInfo" :key="item.id">
<s-coupon-list :data="item">
<template #default>
<button
class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
:class="
<su-popup :show="show" type="bottom" round="20" @close="emits('close')" showClose backgroundColor="#f2f2f2">
<view class="model-box">
<view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠券</view>
<scroll-view class="model-content" scroll-y :scroll-with-animation="false" :enable-back-to-top="true">
<view class="subtitle ss-m-l-20">可使用优惠券</view>
<view v-for="item in state.couponInfo" :key="item.id">
<s-coupon-list :data="item">
<template #default>
<button class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center" :class="
item.get_status != 'can_get' && item.get_status != 'can_use' ? 'boder-btn' : ''
"
@click.stop="getBuy(item.id)"
:disabled="item.get_status != 'can_get' && item.get_status != 'can_use'"
>
{{ item.get_status_text }}
</button>
</template>
</s-coupon-list>
</view>
</scroll-view>
</view>
</su-popup>
" @click.stop="getBuy(item.id)">
<!-- 此处对接领取优惠券先将限制解除 -->
<!-- :disabled="item.get_status != 'can_get' && item.get_status != 'can_use'" -->
{{ item.get_status_text }}
</button>
</template>
</s-coupon-list>
</view>
</scroll-view>
</view>
</su-popup>
</template>
<script setup>
import { computed, reactive } from 'vue';
const props = defineProps({
modelValue: {
type: Object,
default() {},
},
show: {
type: Boolean,
default: false,
},
});
const emits = defineEmits(['get', 'close']);
const state = reactive({
couponInfo: computed(() => props.modelValue),
currentValue: -1,
couponId: '',
});
const getBuy = (id) => {
emits('get', id);
};
//立即领取
import {
computed,
reactive
} from 'vue';
const props = defineProps({
modelValue: {
type: Object,
default () {},
},
show: {
type: Boolean,
default: false,
},
});
const emits = defineEmits(['get', 'close']);
const state = reactive({
couponInfo: computed(() => props.modelValue),
currentValue: -1,
couponId: '',
});
const getBuy = (id) => {
console.log('应该是详情页领取优惠券')
emits('get', id);
};
//立即领取
</script>
<style lang="scss" scoped>
.model-box {
height: 60vh;
.title {
font-size: 36rpx;
height: 80rpx;
font-weight: bold;
color: #333333;
}
.subtitle {
font-size: 26rpx;
font-weight: 500;
color: #333333;
}
}
.model-content {
height: 54vh;
}
.modal-footer {
width: 100%;
height: 120rpx;
background: #fff;
}
.confirm-btn {
width: 710rpx;
margin-left: 20rpx;
height: 80rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
border-radius: 40rpx;
color: #fff;
}
// 优惠券按钮
.card-btn {
// width: 144rpx;
padding: 0 16rpx;
height: 50rpx;
border-radius: 40rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
color: #ffffff;
font-size: 24rpx;
font-weight: 400;
}
.boder-btn {
background: linear-gradient(90deg, var(--ui-BG-Main-opacity-4), var(--ui-BG-Main-light));
color: #fff !important;
}
</style>
.model-box {
height: 60vh;
.title {
font-size: 36rpx;
height: 80rpx;
font-weight: bold;
color: #333333;
}
.subtitle {
font-size: 26rpx;
font-weight: 500;
color: #333333;
}
}
.model-content {
height: 54vh;
}
.modal-footer {
width: 100%;
height: 120rpx;
background: #fff;
}
.confirm-btn {
width: 710rpx;
margin-left: 20rpx;
height: 80rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
border-radius: 40rpx;
color: #fff;
}
// 优惠券按钮
.card-btn {
// width: 144rpx;
padding: 0 16rpx;
height: 50rpx;
border-radius: 40rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
color: #ffffff;
font-size: 24rpx;
font-weight: 400;
}
.boder-btn {
background: linear-gradient(90deg, var(--ui-BG-Main-opacity-4), var(--ui-BG-Main-light));
color: #fff !important;
}
</style>
@@ -1,13 +1,9 @@
<template>
<view class="ss-m-20" :style="{ opacity: disabled ? '0.5' : '1' }">
<view class="content">
<!-- <view
class="tag ss-flex ss-row-center"
:class="
<view class="tag ss-flex ss-row-center" :class="
data.status == 'expired' || data.status == 'used' ? 'disabled-bg-color' : 'info-bg-color'
"
>{{ data.type_text }}</view
> -->
">{{ data.type_text }}</view>
<view class="title ss-m-x-30 ss-p-t-18">
<view class="ss-flex ss-row-between">
<view class="value-text ss-flex-1 ss-m-r-10" :class="
+3 -1
View File
@@ -55,7 +55,8 @@ const http = new Request({
method: 'GET',
header: {
Accept: 'text/json',
'Content-Type': 'application/json;charset=UTF-8',
'Content-Type': 'application/json',
// ;charset=UTF-8
platform: $platform.name,
},
// #ifdef APP-PLUS
@@ -97,6 +98,7 @@ http.interceptors.request.use(
config.header['tenant-id'] = '1';
config.header['Authorization'] = 'Bearer test247';
}
// console.log(config, '看参数')
return config;
},
(error) => {
+110 -98
View File
@@ -1,108 +1,120 @@
import { defineStore } from 'pinia';
import {
defineStore
} from 'pinia';
import cartApi from '@/sheep/api/cart';
const cart = defineStore({
id: 'cart',
state: () => ({
list: [], // 购物车列表
selectedIds: [], // 已选列表
isAllSelected: false, //是否全选
cartSelectedTotalPrice: '0.00', // 选中项总金额
}),
getters: {
totalPriceSelected: (state) => {
let price = 0;
if (!state.selectedIds.length) return price.toFixed(2);
state.list.forEach((item) => {
price += state.selectedIds.includes(item.id)
? Number(item.sku.price/100) * item.count
: 0;
});
return price.toFixed(2);
},
},
actions: {
// 获取购物车列表
async getList() {
const { data, code } = await cartApi.list();
if (code === 0) {
this.list = data.validList;
}
},
// 添加购物车
async add(goodsInfo) {
const { error } = await cartApi.append({
goods_id: goodsInfo.goods_id,
goods_num: goodsInfo.goods_num,
goods_sku_price_id: goodsInfo.id,
});
if (error === 0) {
this.getList();
}
},
id: 'cart',
state: () => ({
list: [], // 购物车列表
selectedIds: [], // 已选列表
isAllSelected: false, //是否全选
cartSelectedTotalPrice: '0.00', // 选中项总金额
}),
getters: {
totalPriceSelected: (state) => {
let price = 0;
if (!state.selectedIds.length) return price.toFixed(2);
state.list.forEach((item) => {
price += state.selectedIds.includes(item.id) ?
Number(item.sku.price / 100) * item.count :
0;
});
return price.toFixed(2);
},
},
actions: {
// 获取购物车列表
async getList() {
const {
data,
code
} = await cartApi.list();
if (code === 0) {
this.list = data.validList;
}
},
// 添加购物车
async add(goodsInfo) {
console.log()
const {
code
} = await cartApi.append({
// goods_id: goodsInfo.goods_id,
// goods_num: goodsInfo.goods_num,
// goods_sku_price_id: goodsInfo.id,
count: goodsInfo.goods_num,
skuId: goodsInfo.id,
});
if (code === 0) {
this.getList();
}
},
// 更新购物车
async update(goodsInfo) {
const { error } = await cartApi.update({
id: goodsInfo.goods_id,
count: goodsInfo.goods_num,
goods_sku_price_id: goodsInfo.goods_sku_price_id,
});
if (error === 0) {
// this.getList();
}
},
// 更新购物车
async update(goodsInfo) {
const {
error
} = await cartApi.update({
id: goodsInfo.goods_id,
count: goodsInfo.goods_num,
goods_sku_price_id: goodsInfo.goods_sku_price_id,
});
if (error === 0) {
// this.getList();
}
},
// 移除购物车
async delete(ids) {
if (typeof ids === 'array') {
ids = ids.join(',');
}
const { code } = await cartApi.delete(ids);
if (code === 0) {
this.selectAll(false);
this.getList();
}
},
// 移除购物车
async delete(ids) {
if (typeof ids === 'array') {
ids = ids.join(',');
}
const {
code
} = await cartApi.delete(ids);
if (code === 0) {
this.selectAll(false);
this.getList();
}
},
// 选择购物车商品
selectSingle(goodsId) {
if (!this.selectedIds.includes(goodsId)) {
this.selectedIds.push(goodsId);
} else {
this.selectedIds.splice(this.selectedIds.indexOf(goodsId), 1);
}
this.isAllSelected = this.selectedIds.length === this.list.length;
},
// 选择购物车商品
selectSingle(goodsId) {
if (!this.selectedIds.includes(goodsId)) {
this.selectedIds.push(goodsId);
} else {
this.selectedIds.splice(this.selectedIds.indexOf(goodsId), 1);
}
this.isAllSelected = this.selectedIds.length === this.list.length;
},
// 全选
selectAll(flag) {
this.isAllSelected = flag;
if (!flag) {
this.selectedIds = [];
} else {
this.list.forEach((item) => {
this.selectedIds.push(item.id);
});
}
},
// 全选
selectAll(flag) {
this.isAllSelected = flag;
if (!flag) {
this.selectedIds = [];
} else {
this.list.forEach((item) => {
this.selectedIds.push(item.id);
});
}
},
// 清空购物车
emptyList() {
this.list = [];
this.selectedIds = [];
this.isAllSelected = false;
this.cartSelectedTotalPrice = '0.00';
},
},
persist: {
enabled: true,
strategies: [
{
key: 'cart-store',
},
],
},
// 清空购物车
emptyList() {
this.list = [];
this.selectedIds = [];
this.isAllSelected = false;
this.cartSelectedTotalPrice = '0.00';
},
},
persist: {
enabled: true,
strategies: [{
key: 'cart-store',
}, ],
},
});
export default cart;
export default cart;