| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <template>
- <div class="right-box">
- <a-table
- v-if="isList"
- bordered
- :dataSource="data"
- :columns="mainData.columns"
- :showHeader="false"
- :pagination="false"
- >
- <template #emptyText>暂无商品信息</template>
- <template #bodyCell="{ column, record }">
- <template v-if="column.key === 'goodsName'">
- <div class="goods-name" @click="viewDetail(record)">
- <a-flex align="center">
- <img :src="record.imgUrl" width="60" height="60" style="margin-right: 10px;" />
- <span>{{ record.goodsName }}</span>
- </a-flex>
- <a-flex v-if="foramtTagData(record).length > 0" gutter="small" style="margin-top: 10px; margin-left: 70px;">
- <a-tag
- v-for="(tag, tIndex) in foramtTagData(record)"
- :key="tIndex"
- color="red"
- >{{ tag }}</a-tag>
- </a-flex>
- </div>
- </template>
- <template v-if="column.key === 'soldNum'">
- <div v-if="isLogin">销量: {{ record.soldNum }}</div>
- <div v-else>
- <a-button type="link" @click="toLogin">登录</a-button>
- <span>查看销量</span>
- </div>
- </template>
- <template v-if="column.key === 'goodsPrice'">
- <div v-if="isLogin">价格: ¥ {{ record.goodsPrice }}</div>
- <div v-else>
- <a-button type="link" @click="toLogin">登录</a-button>
- <span>查看价格</span>
- </div>
- </template>
- <template v-if="column.key === 'opetation'">
- <a-flex align="center" justify="space-between">
- <a-button :disabled="!isLogin || disabled" type="primary" @click="handleAddToCart(record)">添加到购物车</a-button>
- <a-button :disabled="!isLogin || disabled" type="primary" @click="handleAddToLike(record)">添加到列表</a-button>
- </a-flex>
- </template>
- </template>
- </a-table>
- <div v-else class="grid-list__box">
- <GridItem
- v-for="item in data"
- :key="item.goodsId"
- :isLogin="isLogin"
- :item="item"
- :disabled="disabled"
- @goods-detail="viewDetail"
- @to-login="toLogin"
- @add-to-cart="handleAddToCart"
- @add-to-like="handleAddToLike"
- />
- </div>
- <div style="margin-top: 10px;">
- <a-pagination
- show-size-changer
- :current="pagination.pageNum"
- :pageSize="pagination.pageSize"
- :total="pagination.total"
- :page-size-options="['6', '12', '24', '26', '48']"
- @change="changePagination"
- />
- </div>
- </div>
- </template>
- <script setup lang="js">
- import { reactive, computed } from 'vue';
- import GridItem from './GridItem.vue';
- import { useUserStore } from '@/store/user';
- const props = defineProps({
- data: {
- type: Array,
- default: () => []
- },
- pagination: {
- type: Object,
- default: () => ({
- pageNum: 1,
- pageSize: 10,
- total: 0
- })
- },
- isList: {
- type: Boolean,
- default: true
- },
- disabled: {
- type: Boolean,
- default: false
- }
- })
- const emits = defineEmits([
- 'change-pagination',
- 'goods-detail',
- 'add-to-cart',
- 'add-to-like',
- 'to-login'
- ]);
- const userStore = useUserStore();
- const isLogin = computed(() => userStore.isLogin);
- const mainData = reactive({
- columns: [
- {
- title: '商品名称',
- dataIndex: 'goodsName',
- key: 'goodsName'
- },
- {
- title: '商品库存',
- dataIndex: 'soldNum',
- key: 'soldNum',
- width: 160
- },
- {
- title: '商品价格',
- dataIndex: 'goodsPrice',
- key: 'goodsPrice',
- width: 160
- },
- {
- title: '操作',
- dataIndex: 'opetation',
- key: 'opetation',
- width: 260
- }
- ]
- })
- const changePagination = (pageNum, pageSize) => {
- emits('change-pagination', {pageNum, pageSize});
- }
- const viewDetail = (record) => {
- emits('goods-detail', record);
- }
- const handleAddToCart = record => {
- emits('add-to-cart', record)
- }
- const handleAddToLike = record => {
- emits('add-to-like', record)
- }
- const toLogin = () => {
- emits('to-login')
- }
- const foramtTagData = record => {
- const tags1 = Array.isArray(record.tags1) ? record.tags1 : [];
- const tags2 = Array.isArray(record.tags2) ? record.tags2 : [];
- return [].concat(tags1, tags2);
- }
- </script>
- <style lang="less" scoped>
- .goods-name {
- color: @theme-color;
- cursor: pointer;
- }
- .grid-list__box {
- width: 100%;
- display: grid;
- gap: 16px;
- grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
- }
- </style>
|