Files
kangyuan-mobile/pages/index/aiStore.vue
T
2026-06-01 17:26:13 +08:00

360 lines
8.8 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">
<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="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>
<view class="list-wrap flex1">
<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 === '折扣区'"
/>
</view>
</s-pages>
</template>
<script setup>
import { ref, watch } from 'vue';
import { 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('');
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 = Boolean(res.data.length || addShow.value);
}
};
onShow(() => {
getSpuTimeList();
getCartList();
});
const update = () => {
pageCommodity.value?.downCallback();
};
const system = uni.getSystemInfoSync();
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 ? uni.upx2px(128) : 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.getOrderPage({
pageNo: mescroll?.num || 1,
pageSize: mescroll?.size || 10,
keyWord: searchText.value,
});
} 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 list = res.data.list || [];
const arr = [];
list.forEach((e) => {
e.items1 = JSON.parse(JSON.stringify(e.items));
if (e?.items?.length) {
e.items.forEach((item) => {
item.skuArr = item.items;
item.status = e.status;
item.id = item.spuId;
item.spuId = e.payOrderId;
item.shoppingPlazaId = e.roundTimeId;
item.items1 = e.items1;
arr.push(item);
});
}
});
if (arr.length) {
arr.forEach((e) => {
if (e.skuArr && e.skuArr.length) {
e.skuArr.forEach((item) => {
item.propertyText = '';
if (item?.properties) {
item.properties.forEach((e1) => {
item.propertyText += e1.valueName + ' ';
});
}
});
}
});
}
curPageData = arr;
} 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 = true;
addShow.value = true;
setTimeout(() => {
paymentRef.value?.addCar(data);
}, 500);
};
const navChange = (i) => {
index.value = i;
dataList.value = [];
pageCommodity.value?.downCallback();
payShow.value = !index.value;
};
const updatePrice = (val) => {
addShow.value = val;
getCartList();
};
function shipment() {
pageCommodity.value?.downCallback();
}
</script>
<style lang="scss" scoped>
.ai-store-page {
min-height: 100vh;
background: #2556ec;
}
.top-area {
padding: 24rpx 24rpx 0;
}
.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%);
}
.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;
}
</style>