Initial commit

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 12:02:35 +08:00
co-authored by Claude Opus 5
commit d999a5c0e6
643 changed files with 178681 additions and 0 deletions
@@ -0,0 +1,559 @@
<template>
<div class="tag-box">
<!--操作栏-->
<div class="action-bar">
<el-button
type="primary"
size="small"
icon="el-icon-search"
@click="getList('status')"
style="margin-right: 20px"
>搜索</el-button
>
<el-button
type="primary"
size="small"
@click="addAndEdit('add')"
style="margin-right: 20px"
>新增</el-button
>
<!-- <el-button
type="danger"
size="small"
icon="el-icon-menu"
:disabled="isBatch"
plain
@click="openBatch"
>批量操作</el-button
> -->
</div>
<!--数据表格-->
<el-table
:data="tableData"
style="width: 100%"
border
v-loading="loading"
element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading"
ref="multipleTable"
height="600"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
v-if="isBatch"
width="55"
fixed="left"
align="center"
></el-table-column>
<el-table-column prop="id" label="ID" align="center" min-width="210">
<template slot-scope="scope">
<span>{{ scope.row.id || "未知" }}</span>
</template>
</el-table-column>
<el-table-column
prop="createdAt"
label="创建时间"
align="center"
min-width="180"
>
<template slot-scope="scope">
<span>{{ changeTime(scope.row.createdAt) }}</span>
</template>
</el-table-column>
<el-table-column prop="title" label="标题" align="center" min-width="250">
<template slot-scope="scope">
<span>{{ scope.row.title || "-" }}</span>
</template>
</el-table-column>
<el-table-column prop="desc" label="描述" align="center" min-width="350">
<template slot-scope="scope">
<span>{{ scope.row.desc || "-" }}</span>
</template>
</el-table-column>
<el-table-column
prop="recommendNum"
label="推荐个数"
align="center"
min-width="150"
>
<template slot-scope="scope">
<span>{{ scope.row.recommendNum || 0 }}</span>
</template>
</el-table-column>
<el-table-column
prop="discount"
label="折扣"
align="center"
min-width="150"
>
<template slot-scope="scope">
<span>{{ scope.row.discount / 10 || 0 }}</span>
</template>
</el-table-column>
<el-table-column
prop="sortCode"
label="排序"
align="center"
min-width="150"
>
<template slot-scope="scope">
<span>{{ scope.row.sortCode || 0 }}</span>
</template>
</el-table-column>
<el-table-column
prop="status"
label="状态"
align="center"
min-width="120"
>
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.status == 1">开启</el-tag>
<el-tag v-else>关闭</el-tag>
</template>
</el-table-column>
<el-table-column
prop="updatedAt"
label="修改时间"
align="center"
min-width="180"
>
<template slot-scope="scope">
<span>{{ changeTime(scope.row.updatedAt) }}</span>
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
min-width="180"
fixed="right"
>
<template slot-scope="scope">
<el-button
size="mini"
type="success"
icon="el-icon-edit"
@click="addAndEdit(scope.row)"
>编辑</el-button
>
<el-button
size="mini"
type="danger"
icon="el-icon-delete"
@click="del(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<div style="margin: 10px 0" v-if="isBatch">
<el-button @click="giveUpBatch" type="danger" size="mini"
>取消批量操作</el-button
>
<el-button @click="openBatchDelete" type="primary" size="mini"
>批量删除</el-button
>
</div>
<!--分页组件-->
<!-- <el-pagination
:page-sizes="[10, 15, 20, 30]"
:current-page="params.pageNumber"
:page-size="params.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
background
@size-change="changeSize"
@current-change="changeCurrent"
></el-pagination> -->
<!-- 新增、修改 -->
<el-dialog
:title="dialogTitle"
:visible.sync="dialogVisible"
width="500px"
@before-close="handleClose"
@close="handleClose"
>
<el-form :model="form" label-width="100px" :rules="rules" ref="form">
<el-form-item label="标题" prop="title" style="width: 400px">
<el-input v-model="form.title"></el-input>
</el-form-item>
<el-form-item label="描述" prop="desc" style="width: 400px">
<el-input type="textarea" :rows="5" v-model="form.desc"></el-input>
</el-form-item>
<el-form-item label="推荐个数" prop="recommendNum" style="width: 400px">
<el-input v-model.number="form.recommendNum"></el-input>
</el-form-item>
<div class="itemBox">
<el-form-item label="折扣" prop="discount" style="width: 400px">
<el-input
v-model="form.discount"
placeholder="请输入1~10的值"
></el-input>
</el-form-item>
<div class="itemTip">折扣规则:1折为10%,1.5折为15%</div>
</div>
<el-form-item label="排序" prop="sortCode" style="width: 400px">
<el-input v-model.number="form.sortCode"></el-input>
</el-form-item>
<el-form-item label="状态" prop="status" style="width: 400px">
<el-select
v-model="form.status"
placeholder="请选择状态"
style="width: 400px"
>
<el-option
v-for="(subSection, index) in statuses"
:key="index"
:label="subSection.label"
:value="subSection.value"
>
</el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">取 消</el-button>
<el-button type="primary" @click="onSubmit()">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import API from "@/api";
import { uniteDate } from "@/utils/validator.js";
export default {
data() {
return {
// 表格数据加载动画
loading: false,
// 列表数据
tableData: [],
total: 0,
// params: {
// pageNumber: 1,
// pageSize: 10,
// },
rules: {
title: [{ required: true, message: "请输入标题", trigger: "blur" }],
},
dialogTitle: "",
dialogVisible: false,
statuses: [
{
label: "关闭",
value: 0,
},
{
label: "开启",
value: 1,
},
],
form: {
id: undefined,
title: "", // 标题
desc: "", // 描述
recommendNum: 0, // 推荐个数
discount: 0, // 折扣
status: 0, // 状态
sortCode: 0, // 排序
},
isBatch: false,
dataIds: [],
batchUpdateDialog: false,
batchStatus: 0,
};
},
created() {
this.getList();
},
methods: {
getList() {
// if (type === "status") {
// this.params.pageNumber = 1;
// }
API.getDiscountAreaList(this.params)
.then((res) => {
if (res.code === 200 && res.data) {
this.tableData = res.data.list;
this.total = res.data.total;
} else {
this.tableData = [];
}
if (this.isBatch) {
this.restoreCheckedState();
}
this.loading = false;
})
.catch(() => {
this.loading = false;
});
},
// 新增标签配置
addAndEdit(param) {
this.dialogVisible = true; // 打开新增、编辑对话框
if (param === "add") {
this.dialogTitle = "新增";
} else {
this.dialogTitle = "编辑";
// 把数据回显给表单
this.form.id = param.id;
this.form.title = param.title;
this.form.desc = param.desc;
this.form.recommendNum = param.recommendNum;
this.form.discount = param.discount / 10;
this.form.status = param.status;
this.form.sortCode = param.sortCode;
}
},
// 新增、修改提交
onSubmit() {
if (this.dialogTitle === "新增") {
this.add();
} else {
this.edit();
}
},
// 新增方法
add() {
this.$refs["form"].validate((valid) => {
if (valid) {
this.form.discount = this.form.discount * 10;
API.addDiscountArea(this.form).then((res) => {
if (res.code === 200) {
this.$message({
type: "success",
message: "新增成功",
});
this.dialogVisible = false;
this.getList();
} else {
this.$message({
type: "error",
message: "新增失败",
});
}
});
} else {
return false;
}
});
},
// 修改方法
edit() {
this.$refs["form"].validate((valid) => {
if (valid) {
this.form.discount = this.form.discount * 10;
API.updateDiscountArea(this.form).then((res) => {
if (res.code === 200) {
this.$message({
type: "success",
message: "编辑成功",
});
this.dialogVisible = false;
this.getList();
} else {
this.$message({
type: "error",
message: "编辑失败",
});
}
});
} else {
return false;
}
});
},
del(param) {
this.$confirm(
`确认是否删除<span style='color:blue'>${param.title}</span>, 是否继续?`,
"提示",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
dangerouslyUseHTMLString: true,
}
)
.then(() => {
let delData = {
id: param.id,
};
API.deleteDiscountArea(delData).then((res) => {
if (res.code === 200) {
this.$message({
type: "success",
message: "删除成功!",
});
} else {
this.$message({
type: "success",
message: res.msg || res.tip || res.data || "删除失败!",
});
}
this.getList();
});
})
.catch(() => {
this.$message({
type: "info",
message: "已取消删除",
});
});
},
// 关闭窗口清除数据
handleClose() {
this.form.id = undefined;
this.form.title = "";
this.form.desc = "";
this.form.recommendNum = 0;
this.form.discount = 0;
this.form.status = 0;
this.form.sortCode = 0;
this.isBatch = false;
this.dataIds = [];
this.batchStatus = 0;
this.batchUpdateDialog = false;
this.$refs.multipleTable.clearSelection();
this.dialogVisible = false;
},
// 分页条数改变回调
changeSize(size) {
this.params.pageSize = size;
this.getList();
},
// 分页页码改变回调
changeCurrent(pageNumber) {
this.params.pageNumber = pageNumber;
this.getList();
},
// 更换时间格式
changeTime(time) {
return uniteDate(time);
},
// *******************批量操作*********************
// 翻页时的勾选回显
restoreCheckedState() {
/**
* ①获取到当前数据表格中已经被选中的数据
*/
const indexs = this.tableData
.map((item) => {
let flag = false;
this.dataIds.forEach((value) => {
value.id === item.id ? (flag = true) : "";
});
if (flag) {
return item;
}
})
.filter((item) => item);
/**
* ②回显当前数据表格中已经被勾选过的数据
*/
this.$nextTick(() => {
indexs.forEach((rows) => {
this.$refs.multipleTable.toggleRowSelection(rows);
});
});
},
// 批量操作窗口
openBatch() {
this.isBatch = true;
},
// 取消批量操作
giveUpBatch() {
this.isBatch = false;
this.dataIds = [];
this.$refs.multipleTable.clearSelection();
},
// 打开批量删除窗口
openBatchDelete() {
if (this.dataIds.length === 0)
return this.$message.error("请至少选择一条数据");
const ids = this.dataIds.map((item) => item.id);
// 确认删除提示
this.$confirm("确定删除吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
const req = {
id: ids,
};
API.deleteUserFavorOption(req).then((res) => {
if (res.code === 200) {
this.getList();
this.handleClose();
this.$message.success("批量删除成功");
} else {
this.$message.error(res.msg);
}
});
})
.catch(() => {
this.$message.success("取消成功");
});
},
// 处理勾选时的数据
handleSelectionChange(objArr) {
/**
* 1.取消勾选时,将添加的数据从this.dataIds这个数据表里去除;
* ① 获取到当前数据列表中未勾选的数据;
* ② 从this.dataIds这个数据表中移除未勾选的数据;
*/
// ①获取到当前数据列表中未勾选的数据;
const tempTableData = JSON.parse(JSON.stringify(this.tableData));
objArr.forEach((item) => {
this.tableData.forEach((value, index) => {
if (item === value) {
tempTableData.splice(index, 1);
}
});
});
// ②从this.dataIds这个数据表中移除未勾选的数据;
tempTableData.forEach((item) => {
this.dataIds.forEach((value, index) => {
if (item.id === value.id) {
this.dataIds.splice(index, 1);
}
});
});
// 2.添加数组数据,需要去重
this.dataIds = this.dataIds.concat(objArr);
const tempDatas = new Set(this.dataIds);
this.dataIds = Array.from(tempDatas);
},
},
};
</script>
<style lang="scss" scoped>
.dialog-footer {
position: relative;
left: 50%;
-webkit-transform: translate(-50%);
transform: translate(-50%);
}
/deep/ .el-form-item__content {
display: flex;
}
/deep/ .el-select {
width: 100%;
}
.form-flex-box {
display: flex;
.el-form-item {
flex: 1;
}
}
.itemBox {
position: relative;
.itemTip {
font-size: 14px;
color: red;
position: absolute;
left: 100px;
bottom: -20px;
}
}
</style>