jiangchengfeiyi-Web/src/views/Commodity/MerchandiseCenter.vue

403 lines
13 KiB
Vue
Raw Normal View History

2024-10-23 09:55:22 +00:00
<template>
<div>
2024-10-27 11:05:39 +00:00
<div>
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商品名称" v-model="username"></el-input>
2024-10-24 08:04:12 +00:00
<el-form-item label="商品类型" style="width: 200px; margin-right: 10px;display: inline-block">
2024-10-29 11:52:21 +00:00
<el-select v-model="types" placeholder="请选择">type
<el-option label="材料包" value="材料包" />type
2024-10-27 11:05:39 +00:00
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="积分兑换" />
2024-10-24 08:04:12 +00:00
</el-select>
</el-form-item>
<el-form-item label="商品状态" style="width: 200px;margin-right: 10px;display: inline-block">
<el-select v-model="Region" placeholder="请选择">
2024-10-27 11:05:39 +00:00
<el-option label="已上架" value="上架" />
<el-option label="已下架" value="下架" />
2024-10-24 08:04:12 +00:00
</el-select>
</el-form-item>
2024-10-27 11:05:39 +00:00
<el-button class="ml-5" type="primary" @click="load" style="height: 25px;">搜索</el-button>
<el-button type="warning" @click="reset" style="height:25px">重置</el-button>
2024-10-24 08:04:12 +00:00
</div>
<div style="margin: 15px 0">
<el-popconfirm
class="ml-5"
confirm-button-text='确定'
cancel-button-text='取消'
icon="InfoFilled"
icon-color="red"
title="您确定批量删除这些数据吗?"
@confirm="delBatch"
width=180
>
<template #reference>
<el-button style="height: 25px" class="ml-5" type="danger">批量删除 <el-icon style="margin-left: 5px;"><Remove /></el-icon></el-button>
</template>
</el-popconfirm>
2024-10-23 09:55:22 +00:00
</div>
<el-table :data="tableData" border stripe header-cell-class-name="headerBg" :cell-style="{textAlign: 'center'}"
2024-10-27 11:05:39 +00:00
@selection-change="handleSelectionChange" :header-cell-style="{'text-align': 'center'}"
>
2024-10-23 09:55:22 +00:00
<el-table-column type="selection" width="55"></el-table-column>
2024-10-27 11:05:39 +00:00
<el-table-column label="商品编号" width="80">
<template #default="scope">
<div>
2024-10-29 11:52:21 +00:00
<span style="align-items: center">{{ scope.row.id }}</span>
2024-10-27 11:05:39 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="商品图片">
<template #default="scope">
<div>
2024-10-29 11:52:21 +00:00
<img :src="scope.row.goodImg" alt="" style="height: 50px;">
2024-10-27 11:05:39 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="商品名称">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.name }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品价格" width="180">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.price }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品类型">
<template #default="scope">
<div>
2024-10-29 11:52:21 +00:00
<span style="margin-left: 10px">{{ scope.row.type }}</span>
2024-10-27 11:05:39 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="商品数量">
<template #default="scope">
<div>
2024-10-29 11:52:21 +00:00
<span style="margin-left: 10px">{{ scope.row.inventory }}</span>
2024-10-27 11:05:39 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="商品状态">
<template #default="scope">
<div>
2024-10-29 11:52:21 +00:00
<span style="margin-left: 10px">{{ scope.row.isShelvesisShelves }}</span>
2024-10-27 11:05:39 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="250px">
<template #default="scope">
<el-button size="small" @click="handleView(scope.$index, scope.row)">
详情
</el-button>
<el-button size="small" @click="handleRevise(scope.$index, scope.row)">
编辑
</el-button>
<el-button size="small" @click="handleOff(scope.$index, scope.row)">
{{scope.row.attribute}}
</el-button>
<el-button
size="small"
type="danger"
@click="handleDelete(scope.$index, scope.row)"
>
删除
</el-button>
2024-10-23 09:55:22 +00:00
<el-popconfirm
confirm-button-text='确定'
cancel-button-text='取消'
icon="el-icon-info"
icon-color="red"
title="您确定删除吗?"
>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<div style="padding: 10px 0">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="pageNum"
:page-size="pageSize"
:page-sizes="[2, 5, 10, 20]"
:small="null"
:disabled="null"
:background="null"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
/>
</div>
</div>
2024-10-27 11:05:39 +00:00
<el-dialog v-model="detailDialogVisible" title="商品详情">
<el-form label-width="100px">
<el-form-item label="商品编号">
2024-10-29 11:52:21 +00:00
<el-input v-model="selectedProduct.id" disabled></el-input>
2024-10-27 11:05:39 +00:00
</el-form-item>
<el-form-item label="商品图片">
2024-10-29 11:52:21 +00:00
<div v-if="selectedProduct.goodImg">
<img :src="selectedProduct.goodImg" alt="类别图标" class="thumbnail" style="width: 100px; height: 100px;"/>
2024-10-27 11:05:39 +00:00
</div>
</el-form-item>
<el-form-item label="商品名称">
<el-input v-model="selectedProduct.name" disabled></el-input>
</el-form-item>
<el-form-item label="商品价格">
<el-input v-model="selectedProduct.price" disabled></el-input>
</el-form-item>
<el-form-item label="商品类型">
2024-10-29 11:52:21 +00:00
<el-select v-model="selectedProduct.type" placeholder="请选择" disabled>
2024-10-27 11:05:39 +00:00
<el-option label="材料包" value="材料包" />
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="积分兑换" />
</el-select>
</el-form-item>
<el-form-item label="商品数量">
2024-10-29 11:52:21 +00:00
<el-input v-model="selectedProduct.inventory" disabled></el-input>
2024-10-27 11:05:39 +00:00
</el-form-item>
<el-form-item label="商品状态">
2024-10-29 11:52:21 +00:00
<el-select v-model="selectedProduct.isShelves" placeholder="请选择" disabled>
2024-10-27 11:05:39 +00:00
<el-option label="上架" value="上架" />
<el-option label="下架" value="下架" />
</el-select>
</el-form-item>
<el-form-item label="是否为限定产品">
<el-select v-model="selectedProduct.region" placeholder="请选择" disabled>
<el-option label="是" value="是" />
<el-option label="否" value="否" />
</el-select>
</el-form-item>
<el-form-item label="商品标签">
<el-input v-model="selectedProduct.label" disabled></el-input>
</el-form-item>
<el-form-item label="商品描述">
2024-10-29 11:52:21 +00:00
<el-input type="textarea" v-model="selectedProduct.introDetailintroDetail" disabled></el-input>
2024-10-27 11:05:39 +00:00
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="detailDialogVisible = false">取消</el-button>
</span>
</template>
</el-dialog>
<el-dialog v-model="editDialogVisible" title="商品编辑">
<el-form label-width="100px">
<el-form-item label="商品编号">
2024-10-29 11:52:21 +00:00
<el-input v-model="editForm.id"></el-input>
2024-10-27 11:05:39 +00:00
</el-form-item>
<el-form-item label="商品图片">
<el-upload action="#" list-type="picture" :auto-upload="false">
<el-icon><Plus /></el-icon>
<template #file="{ file }">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
</template>
</el-upload>
</el-form-item>
<el-form-item label="商品名称">
<el-input v-model="editForm.name"></el-input>
</el-form-item>
<el-form-item label="商品价格">
<el-input v-model="editForm.price"></el-input>
</el-form-item>
<el-form-item label="商品类型">
2024-10-29 11:52:21 +00:00
<el-select v-model="editForm.type" placeholder="请选择">
2024-10-27 11:05:39 +00:00
<el-option label="材料包" value="材料包" />
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="定制" />
</el-select>
</el-form-item>
<el-form-item label="商品数量">
2024-10-29 11:52:21 +00:00
<el-input v-model="editForm.inventory"></el-input>
2024-10-27 11:05:39 +00:00
</el-form-item>
<el-form-item label="商品状态">
2024-10-29 11:52:21 +00:00
<el-select v-model="editForm.isShelves" disabled>
2024-10-27 11:05:39 +00:00
<el-option label="上架" value="上架" />
<el-option label="下架" value="下架" />
</el-select>
</el-form-item>
<el-form-item label="是否为限定产品">
<el-select v-model="editForm.region" placeholder="请选择">
<el-option label="是" value="是" />
<el-option label="否" value="否" />
</el-select>
</el-form-item>
<el-form-item label="商品标签">
<el-input v-model="editForm.label"></el-input>
</el-form-item>
<el-form-item label="商品描述">
2024-10-29 11:52:21 +00:00
<el-input type="textarea" v-model="editForm.introDetail"></el-input>
2024-10-27 11:05:39 +00:00
</el-form-item>
</el-form>
2024-10-23 09:55:22 +00:00
<template #footer>
2024-10-27 11:05:39 +00:00
<span class="dialog-footer">
<el-button @click="editDialogVisible = false">取消</el-button>
<el-button type="primary" @click="saveEdit">保存</el-button>
</span>
2024-10-23 09:55:22 +00:00
</template>
</el-dialog>
</template>
<script setup lang="ts">
2024-10-24 08:04:12 +00:00
import { ElMessage } from 'element-plus';
2024-10-27 11:05:39 +00:00
import { ref, onMounted } from 'vue';
2024-10-29 11:52:21 +00:00
import myAxios from "@/api/myAxios";
2024-10-27 11:05:39 +00:00
const pageNum = ref(0);
const pageSize = ref(0);
const total = ref(0);
2024-10-29 11:52:21 +00:00
const id = ref([]);
2024-10-23 09:55:22 +00:00
onMounted(() => {
2024-10-27 11:05:39 +00:00
load();
});
2024-10-23 09:55:22 +00:00
const handleSelectionChange = (row: any) => {
2024-10-29 11:52:21 +00:00
id.value = JSON.parse(JSON.stringify(row));
2024-10-27 11:05:39 +00:00
};
const username = ref('');
const detailDialogVisible = ref(false);
const editDialogVisible = ref(false);
2024-10-29 11:52:21 +00:00
const types = ref('');
2024-10-27 11:05:39 +00:00
const Region = ref('');
let selectedProduct = ref('');
2024-10-31 08:25:23 +00:00
const loading = ref(false)
2024-10-27 11:05:39 +00:00
let editForm = ref({
2024-10-29 11:52:21 +00:00
id: '',
goodImg: '',
2024-10-27 11:05:39 +00:00
name: '',
price: '',
2024-10-29 11:52:21 +00:00
type: '',
inventory: '',
isShelves: '',
2024-10-27 11:05:39 +00:00
attribute:'',
region: '',
label: '',
2024-10-29 11:52:21 +00:00
introDetail: '',
2024-10-27 11:05:39 +00:00
});
const handleView = (index: number, row: any) => {
selectedProduct = row;
detailDialogVisible.value = true;
};
const handleRevise = (index: number, row: any) => {
selectedProduct = row;
editDialogVisible.value = true;
editForm.value = row;
};
const handleOff = (index: number, row: any) => {
if (row.attribute === '上架') {
2024-10-29 11:52:21 +00:00
row.isShelves = '上架';
2024-10-27 11:05:39 +00:00
row.attribute = '下架';
} else if (row.attribute === '下架') {
2024-10-29 11:52:21 +00:00
row.isShelves = '下架';
2024-10-27 11:05:39 +00:00
row.attribute = '上架';
}
};
2024-10-29 11:52:21 +00:00
onMounted(() => {
getTableData()
})
2024-10-27 11:05:39 +00:00
const handleDelete = (index: number, row: any) => {
const confirmDelete = window.confirm('您确定要删除该商品吗?');
if (confirmDelete) {
tableData.value = tableData.value.filter((item, i) => i!== index);
ElMessage({
message: '删除成功',
type: 'success',
});
}
};
2024-10-29 11:52:21 +00:00
const searchParams: any = ref({})
2024-10-31 08:25:23 +00:00
const getTableData = async () => {
loading.value = true;
try {
const res = await myAxios.post('/api/goods/update', {...tableData.value });
if (res.data.code === 1) {
tableData.value = res.data.data.records;
} else {
ElMessage({
message: '获取数据失败',
});
}
} catch (error) {
2024-10-29 11:52:21 +00:00
ElMessage({
2024-10-31 08:25:23 +00:00
message: '发生错误',
});
} finally {
loading.value = false;
2024-10-29 11:52:21 +00:00
}
}
2024-10-27 11:05:39 +00:00
2024-10-27 12:30:10 +00:00
const tableData = ref([
2024-10-27 11:05:39 +00:00
{
2024-10-29 11:52:21 +00:00
id: '',
goodImg: '',
name: '',
price: '',
type: '',
inventory: '',//库存
isShelves: '',
region: '',
label: '',//
introDetail: '',//商品详情介绍
attribute:'',
2024-10-27 11:05:39 +00:00
},
2024-10-27 12:30:10 +00:00
]);
2024-10-27 11:05:39 +00:00
const reset = () => {
username.value = '';
2024-10-29 11:52:21 +00:00
types.value = '';
2024-10-27 11:05:39 +00:00
Region.value = '';
};
const saveEdit = () => {
2024-10-29 11:52:21 +00:00
const indexToUpdate = tableData.findIndex(item => item.id === editForm.value.id);
2024-10-27 11:05:39 +00:00
if (indexToUpdate!== -1) {
tableData[indexToUpdate] = {
...tableData[indexToUpdate],
...editForm.value,
};
ElMessage({
message: '编辑成功',
type: 'success',
});
editDialogVisible.value = false;
};
};
2024-10-23 09:55:22 +00:00
const load = async () => {
await instance.get('/admin/findAllUsers').then(res => {
2024-10-27 11:05:39 +00:00
console.log(res.data.data);
res.data.data.forEach(item => {
console.log(item);
});
tableData.value = res.data.data;
});
};
2024-10-24 08:04:12 +00:00
const delBatchSuccess = () => {
ElMessage({
message: '批量删除成功',
type: 'success',
2024-10-27 11:05:39 +00:00
});
};
2024-10-24 08:04:12 +00:00
const delBatch = async () => {
await instance.post('').then(res => {
2024-10-27 11:05:39 +00:00
if (res.data.code === '200') {
load();
} else {
2024-10-24 08:04:12 +00:00
ElMessage({
message: '批量删除失败',
2024-10-27 11:05:39 +00:00
type: 'error',
});
2024-10-24 08:04:12 +00:00
}
2024-10-27 11:05:39 +00:00
});
};
2024-10-23 09:55:22 +00:00
</script>
<style scoped>
2024-10-27 11:05:39 +00:00
.headerBg {
background-color: #eee!important;
2024-10-23 09:55:22 +00:00
}
</style>