Files
kangyuan-mobile/pages/index/aiStore.vue
T

625 lines
16 KiB
Vue

<template>
<s-pages
title="AI店铺"
navPreset="blue"
tabbar="/pages/index/aiStore"
:showLeftButton="false"
>
<view class="ai-store-page h100 flex-column">
<view class="top-area">
<view class="tab-header">
<view
v-for="(tab, i) in nav"
:key="tab.id"
class="tab-item"
:class="{ active: index === i }"
@click="navChange(i)"
>
{{ tab.name }}
</view>
<view class="tab-line" :style="{ left: index === 0 ? '25%' : '75%' }"></view>
</view>
<view class="search-wrap flex-center" v-if="index === 0">
<view class="search-input flex1 flex-center">
<uni-icons class="m-r-16" type="search" color="#9AA7C7" size="18" />
<uni-easyinput
class="flex1"
v-model="searchText"
type="text"
placeholder="搜索想要的商品"
:inputBorder="false"
:styles="{ color: '#333', fontSize: '28rpx' }"
placeholderStyle="color:#9AA7C7;font-size:28rpx;"
@blur="search"
@clear="clearSearch"
/>
</view>
<view class="search-btn flex-center" @click="search">
<uni-icons type="search" color="#FFFFFF" size="18" />
</view>
</view>
<view class="notice-card" v-if="mesArr.length && index === 0">
<view class="notice-marquee-viewport">
<view class="notice-marquee-track" :class="{ 'is-scroll': mesArr.length > 1 }">
<view class="notice-marquee-content">
<view
v-for="(line, i) in mesArr"
:key="line.id || i"
class="notice-item notice-marquee-item flex-center h100"
>
<view class="notice-icon flex-center shrink">
<uni-icons type="person-filled" color="#2556EC" size="16" />
</view>
<view class="notice-text lineOne" v-html="line.messageContent"></view>
</view>
</view>
<view class="notice-marquee-content" v-if="mesArr.length > 1" aria-hidden="true">
<view
v-for="(line, i) in mesArr"
:key="`dup-${line.id || i}`"
class="notice-item notice-marquee-item flex-center h100"
>
<view class="notice-icon flex-center shrink">
<uni-icons type="person-filled" color="#2556EC" size="16" />
</view>
<view class="notice-text lineOne" v-html="line.messageContent"></view>
</view>
</view>
</view>
</view>
</view>
<view class="m-t-16 m-b-8" v-if="timeRound.length && index === 0">
<scroll-view scroll-x class="time-scroll">
<view class="flex">
<view
v-for="(item, i) in timeRound"
:key="item.id || i"
class="timeNav m-r-20"
:class="{ activeTime: selectedTimeId === item.id }"
@click="changeTimeRound(item, i)"
>
{{ item.name }}
</view>
</view>
</scroll-view>
</view>
<view style="padding: 80rpx 0 120rpx" v-if="index === 1">
<view style="position: relative">
<view class="shop-summary-card">
<view class="shop-summary-top flex-row">
<view class="shop-summary-icon-wrap shrink flex-center">
<image class="shop-summary-icon" src="/static/index/shop1.png" mode="aspectFit" />
</view>
<view class="shop-summary-info flex1">
<view class="shop-summary-title">{{ shopSummary.title }}</view>
<view class="shop-summary-id">ID:{{ shopSummary.shopId }}</view>
<!-- <view class="shop-summary-id">商品总数:{{ shopSummary.total }}</view> -->
</view>
</view>
<view class="shop-summary-bottom" v-if="index === 1">
<view class="shop-summary-metrics flex-center">
<view class="metric flex1">
<view class="metric-label">总收益</view>
<view class="metric-value">{{ $fen2yuan(shopSummary.totalEarnings) }}</view>
</view>
<view class="metric-divider"></view>
<view class="metric flex1">
<view class="metric-label">店铺数量</view>
<view class="metric-value">{{ shopSummary.shopCount }}</view>
</view>
<view class="metric-divider"></view>
<view class="metric flex1">
<view class="metric-label">店铺等级</view>
<view class="metric-value size30">{{ shopSummary.level || 0 }}</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="list-wrap flex1" :style="{ marginTop: index === 1 ? '110rpx' : '0' }">
<card_pages
ref="pageCommodity"
:navList="nav"
:currentTab="index"
@upCallback="getData"
:height="height"
:oneShow="true"
>
<template #content>
<aistore_tab1
v-if="index === 0"
:list="dataList"
@addCar="addCar"
@update="update"
@shipment="shipment"
/>
<aistore_tab2
v-if="index === 1"
:list="dataList"
:source="index"
@addCar="addCar"
@update="update"
@shipment="shipment"
/>
</template>
</card_pages>
</view>
</view>
<view v-if="payShow">
<card_payment
ref="paymentRef"
@updataList="clearSearch"
@updatePrice="updatePrice"
:addShow="addShow"
:minSalesCountShow="navName === '折扣区'"
:bottomOffset="tabbarBottomOffset"
/>
</view>
</s-pages>
</template>
<script setup>
import { ref, watch } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import * as api from '@/sheep/api/ai/index';
import card_pages from '@/components/card_pages/card_pages';
import card_payment from '@/components/card_payment/card_payment';
import aistore_tab1 from './components/aistore_tab1.vue';
import aistore_tab2 from './components/aistore_tab2.vue';
const searchText = ref('');
const search = () => {
pageCommodity.value?.downCallback();
};
const clearSearch = () => {
searchText.value = '';
pageCommodity.value?.downCallback();
};
const timeRound = ref([]);
const selectedTimeId = ref(null);
const navName = ref('');
const mesArr = ref([]);
function changeTimeRound(e) {
navName.value = e.name;
selectedTimeId.value = e?.id ?? null;
pageCommodity.value?.downCallback();
}
function getSpuTimeList() {
api.getSpuTimeList({}).then((res) => {
if (res.code === 0) {
timeRound.value = res.data || [];
selectedTimeId.value = timeRound.value?.[0]?.id ?? null;
navName.value = timeRound.value?.[0]?.name ?? '';
}
});
}
const getCartList = async () => {
const res = await api.getShopCartList({});
if (res.code === 0) {
payShow.value = index.value === 0 && Boolean(res.data.length || addShow.value);
}
};
const getMessageList = async () => {
const res = await api.getMessageList({ pageNo: 1, pageSize: 10 }).catch(() => ({ code: -1 }));
mesArr.value = res?.code === 0 ? res?.data || [] : [];
};
onLoad((options) => {
const tab = Number(options?.tab);
if (tab === 1) {
navChange(1);
}
});
onShow(() => {
getSpuTimeList();
getCartList();
getMessageList();
});
const update = () => {
pageCommodity.value?.downCallback();
};
const system = uni.getSystemInfoSync();
const tabbarBottomOffset = uni.upx2px(100);
const paymentBarReserve = uni.upx2px(148);
const baseHeight =
system.windowHeight -
system.statusBarHeight -
uni.upx2px(88) -
uni.upx2px(76) -
uni.upx2px(48) -
uni.upx2px(20);
const index = ref(0);
const height = ref(`${baseHeight}px`);
const payShow = ref(false);
const addShow = ref(false);
watch(
() => payShow.value,
() => {
const extra = payShow.value ? paymentBarReserve : 0;
height.value = `${baseHeight - extra}px`;
},
{ immediate: true },
);
const nav = ref([
{ name: '选品广场', id: 1 },
{ name: '我的店铺', id: 2 },
]);
const pageCommodity = ref(null);
const dataList = ref([]);
const getData = async (mescroll) => {
if (mescroll?.dataObj?.index !== index.value) return;
let res = null;
if (index.value) {
res = await api.getMyShop({
pageNo: mescroll?.num || 1,
pageSize: mescroll?.size || 10,
keyWord: searchText.value || undefined,
status: mescroll?.params?.status,
});
} else {
res = await api.getSpuPage({
pageNo: mescroll?.num || 1,
pageSize: mescroll?.size || 10,
keyWord: searchText.value,
timeId: selectedTimeId.value,
...mescroll.params,
});
}
if (res.code !== 0) {
pageCommodity.value?.getState(false);
return;
}
let curPageData = [];
if (index.value) {
const root = res?.data || {};
if ((mescroll?.num || 1) === 1) {
shopSummary.value = {
title: '我的店铺',
totalEarnings: root?.totalRevenue ?? 0,
shopCount: root?.numberOfStores ?? 0,
level: root?.shopRating ?? 0,
total: root?.total ?? 0,
shopId: root?.shopId ?? '',
};
}
const list = Array.isArray(root?.storeList) ? root.storeList : [];
curPageData = list.map((it) => {
console.log(it)
const agencyTime = String(it?.agencyTime || '').trim();
const dateOnly = agencyTime ? agencyTime.split('T')[0].split(' ')[0] : '';
return {
skuId: it?.skuId ?? '',
name: it?.aiShopCommodityName ?? '',
createTime: dateOnly,
progress: 0,
earnings: it?.totalRevenue ?? 0,
totalRevenue: it?.totalRevenue ?? 0,
userPayPrice: it?.userPayPrice ?? 0,
leaf: it?.greenCredits ?? 0,
cover: it?.picUrl ?? '',
};
});
} else {
curPageData = res.data?.list || [];
}
if (mescroll?.num === 1) dataList.value = [];
dataList.value = dataList.value.concat(curPageData);
pageCommodity.value?.getState(true, curPageData.length);
};
const paymentRef = ref(null);
const addCar = (data) => {
payShow.value = index.value === 0;
addShow.value = true;
setTimeout(() => {
paymentRef.value?.addCar(data);
}, 500);
};
const navChange = (i) => {
index.value = i;
dataList.value = [];
pageCommodity.value?.downCallback();
if (index.value === 0) {
getCartList();
} else {
payShow.value = false;
}
};
const updatePrice = (val) => {
addShow.value = val;
getCartList();
};
function shipment() {
pageCommodity.value?.downCallback();
}
const shopSummary = ref({
title: '我的店铺',
totalEarnings: 0,
shopCount: 0,
level: 0,
total: 0,
});
const formatAmount = (value) => {
const num = Number(value);
if (!Number.isFinite(num)) return '0.00';
const fixed = num.toFixed(2);
const [intPart, decPart] = fixed.split('.');
const withComma = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return `${withComma}.${decPart}`;
};
</script>
<style lang="scss" scoped>
.ai-store-page {
min-height: 100vh;
}
.top-area {
padding: 24rpx 24rpx;
background: #2556ec;
border-radius: 0 0 30rpx 30rpx;
}
.tab-header {
position: relative;
display: flex;
justify-content: center;
margin-top: 12rpx;
}
.tab-item {
width: 50%;
text-align: center;
font-size: 34rpx;
line-height: 48rpx;
padding: 16rpx 0 22rpx;
color: rgba(255, 255, 255, 0.7);
&.active {
color: #ffffff;
font-weight: 700;
}
}
.tab-line {
position: absolute;
bottom: 6rpx;
width: 72rpx;
height: 6rpx;
background: #fff;
border-radius: 6rpx;
transform: translateX(-50%);
transition: left 0.25s ease;
}
.search-wrap {
margin-top: 22rpx;
padding: 0 10rpx;
}
.search-input {
height: 76rpx;
background: #ffffff;
border-radius: 40rpx;
padding: 0 28rpx;
}
.search-btn {
width: 76rpx;
height: 76rpx;
margin-left: 18rpx;
border-radius: 38rpx;
background: linear-gradient(to bottom right, #2c8cfa 0%, #3d5efb 100%);
}
.notice-card {
margin-top: 18rpx;
padding: 20rpx 40rpx;
}
.notice-item {
height: 50rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.95);
}
.notice-icon {
width: 34rpx;
height: 34rpx;
border-radius: 50%;
background: rgba(37, 86, 236, 0.12);
margin-right: 16rpx;
}
.notice-text {
flex: 1;
font-size: 22rpx;
color: #111111;
line-height: 50rpx;
}
.notice-marquee-viewport {
overflow: hidden;
height: 50rpx;
display: flex;
align-items: center;
border-radius: 30rpx;
}
.notice-marquee-track {
display: inline-flex;
align-items: center;
transform: translateX(0);
will-change: transform;
&.is-scroll {
animation: notice-marquee-move 16s linear infinite;
}
}
.notice-marquee-content {
display: inline-flex;
align-items: center;
flex-shrink: 0;
}
.notice-marquee-item {
flex-shrink: 0;
margin-right: 20rpx;
}
@keyframes notice-marquee-move {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
.time-scroll {
width: 100%;
white-space: nowrap;
}
.timeNav {
display: inline-flex;
align-items: center;
height: 56rpx;
padding: 0 22rpx;
border-radius: 28rpx;
font-size: 28rpx;
color: rgba(255, 255, 255, 0.85);
background: rgba(255, 255, 255, 0.15);
}
.activeTime {
color: #2556ec;
background: #ffffff;
font-weight: 700;
}
.list-wrap {
margin-top: 18rpx;
background: #f1f5ff;
border-radius: 30rpx 30rpx 0 0;
padding: 0 24rpx;
overflow: hidden;
}
:deep(.ai-button1) {
background: linear-gradient(to bottom right, #2c8cfa 0%, #3d5efb 100%) !important;
}
.shop-summary-card {
width: 94% !important;
border-radius: 26rpx;
overflow: hidden;
position: absolute;
top: -60rpx;
left: 3%;
width: 100%;
box-sizing: border-box;
box-shadow: 0 8rpx 22rpx rgba(38, 107, 246, 0.45);
background: linear-gradient(135deg, #2c8cfa 0%, #3d5efb 100%);
}
.shop-summary-top {
padding: 30rpx 28rpx;
// background: linear-gradient(135deg, #2c8cfa 0%, #3d5efb 100%);
}
.shop-summary-icon-wrap {
width: 88rpx;
height: 88rpx;
border-radius: 24rpx;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(8rpx);
margin-right: 20rpx;
}
.shop-summary-icon {
width: 54rpx;
height: 54rpx;
}
.shop-summary-title {
font-size: 34rpx;
font-weight: 700;
color: #ffffff;
line-height: 44rpx;
}
.shop-summary-id {
margin-top: 6rpx;
font-size: 24rpx;
color: rgba(255, 255, 255, 0.85);
line-height: 32rpx;
}
.shop-summary-bottom {
background: rgba(255, 255, 255, 0.96);
padding: 22rpx 18rpx;
border-radius: 30rpx 30rpx 0 0;
// position: relative;
}
.shop-summary-metrics {
align-items: stretch;
// position: absolute;
}
.metric {
text-align: center;
}
.metric-label {
font-size: 24rpx;
color: #2c63ff;
line-height: 34rpx;
}
.metric-value {
margin-top: 10rpx;
font-size: 40rpx;
font-weight: 800;
color: #111111;
line-height: 44rpx;
}
.metric-divider {
width: 1rpx;
background: rgba(155, 170, 199, 0.55);
margin: 12rpx 0;
}
</style>