Merge pull request '合并' (#5) from branch_lyj into main

pull/6/head
py4fbma29 7 months ago
commit 648ef08f1f

@ -11,8 +11,8 @@
export default { export default {
name: 'AppMain', name: 'AppMain',
computed: { computed: {
// .......key() { // key() {
// return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date() // 111 11 return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date()
// } // }
} }
} }

@ -1,13 +1,18 @@
<template>  <template>
<!-- 使用HomeAdvertiseDetail组件并传递一个名为isEdit的prop值为false -->
<home-advertise-detail :isEdit="false"></home-advertise-detail> <home-advertise-detail :isEdit="false"></home-advertise-detail>
</template> </template>
<script> <script>
import HomeAdvertiseDetail from './components/HomeAdvertiseDetail' // HomeAdvertiseDetail
export default { import HomeAdvertiseDetail from './components/HomeAdvertiseDetail'
name: 'addHomeAdvertise',
components: { HomeAdvertiseDetail }
}
</script>
<style></style>
//
export default {
// addHomeAdvertise
name: 'addHomeAdvertise',
// 使
components: { HomeAdvertiseDetail }
}
</script>
<style></style>

@ -1,15 +1,19 @@
<template>  <template> 
<el-card class="form-container" shadow="never"> <el-card class="form-container" shadow="never">
<!-- 表单容器使用Element UI的卡片组件 -->
<el-form :model="homeAdvertise" <el-form :model="homeAdvertise"
:rules="rules" :rules="rules"
ref="homeAdvertiseFrom" ref="homeAdvertiseFrom"
label-width="150px" label-width="150px"
size="small"> size="small">
<!-- 表单绑定数据模型和验证规则引用名称为'homeAdvertiseFrom' -->
<el-form-item label="广告名称:" prop="name"> <el-form-item label="广告名称:" prop="name">
<el-input v-model="homeAdvertise.name" class="input-width"></el-input> <el-input v-model="homeAdvertise.name" class="input-width"></el-input>
<!-- 输入框绑定到homeAdvertise.name用于输入广告名称 -->
</el-form-item> </el-form-item>
<el-form-item label="广告位置:"> <el-form-item label="广告位置:">
<el-select v-model="homeAdvertise.type"> <el-select v-model="homeAdvertise.type">
<!-- 下拉选择框绑定到homeAdvertise.type用于选择广告位置 -->
<el-option <el-option
v-for="type in typeOptions" v-for="type in typeOptions"
:key="type.value" :key="type.value"
@ -23,27 +27,33 @@
type="datetime" type="datetime"
placeholder="选择日期" placeholder="选择日期"
v-model="homeAdvertise.startTime"></el-date-picker> v-model="homeAdvertise.startTime"></el-date-picker>
<!-- 日期选择器绑定到homeAdvertise.startTime用于选择开始时间 -->
</el-form-item> </el-form-item>
<el-form-item label="到期时间:" prop="endTime"> <el-form-item label="到期时间:" prop="endTime">
<el-date-picker <el-date-picker
type="datetime" type="datetime"
placeholder="选择日期" placeholder="选择日期"
v-model="homeAdvertise.endTime"></el-date-picker> v-model="homeAdvertise.endTime"></el-date-picker>
<!-- 日期选择器绑定到homeAdvertise.endTime用于选择到期时间 -->
</el-form-item> </el-form-item>
<el-form-item label="上线/下线:"> <el-form-item label="上线/下线:">
<el-radio-group v-model="homeAdvertise.status"> <el-radio-group v-model="homeAdvertise.status">
<!-- 单选按钮组绑定到homeAdvertise.status用于选择广告状态上线或下线 -->
<el-radio :label="0">下线</el-radio> <el-radio :label="0">下线</el-radio>
<el-radio :label="1">上线</el-radio> <el-radio :label="1">上线</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="广告图片:"> <el-form-item label="广告图片:">
<single-upload v-model="homeAdvertise.pic"></single-upload> <single-upload v-model="homeAdvertise.pic"></single-upload>
<!-- 自定义上传组件绑定到homeAdvertise.pic用于上传广告图片 -->
</el-form-item> </el-form-item>
<el-form-item label="排序:"> <el-form-item label="排序:">
<el-input v-model="homeAdvertise.sort" class="input-width"></el-input> <el-input v-model="homeAdvertise.sort" class="input-width"></el-input>
<!-- 输入框绑定到homeAdvertise.sort用于输入广告排序 -->
</el-form-item> </el-form-item>
<el-form-item label="广告链接:" prop="url"> <el-form-item label="广告链接:" prop="url">
<el-input v-model="homeAdvertise.url" class="input-width"></el-input> <el-input v-model="homeAdvertise.url" class="input-width"></el-input>
<!-- 输入框绑定到homeAdvertise.url用于输入广告链接 -->
</el-form-item> </el-form-item>
<el-form-item label="广告备注:"> <el-form-item label="广告备注:">
<el-input <el-input
@ -53,18 +63,21 @@
placeholder="请输入内容" placeholder="请输入内容"
v-model="homeAdvertise.note"> v-model="homeAdvertise.note">
</el-input> </el-input>
<!-- 文本域绑定到homeAdvertise.note用于输入广告备注 -->
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit('homeAdvertiseFrom')"></el-button> <el-button type="primary" @click="onSubmit('homeAdvertiseFrom')"></el-button>
<!-- 提交按钮点击时调用submitForm方法 -->
<el-button v-if="!isEdit" @click="resetForm('homeAdvertiseFrom')"></el-button> <el-button v-if="!isEdit" @click="resetForm('homeAdvertiseFrom')"></el-button>
<!-- 重置按钮点击时调用resetForm方法 -->
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
</template> </template>
<script> <script>
import SingleUpload from '@/components/Upload/singleUpload' import SingleUpload from '@/components/Upload/singleUpload' //
import {createHomeAdvertise, getHomeAdvertise, updateHomeAdvertise} from '@/api/homeAdvertise' import {createHomeAdvertise, getHomeAdvertise, updateHomeAdvertise} from '@/api/homeAdvertise' // API
const defaultTypeOptions = [ const defaultTypeOptions = [ // 广
{ {
label: 'PC首页轮播', label: 'PC首页轮播',
value: 0 value: 0
@ -74,7 +87,7 @@
value: 1 value: 1
} }
]; ];
const defaultHomeAdvertise = { const defaultHomeAdvertise = { // 广
name: null, name: null,
type: 1, type: 1,
pic: null, pic: null,
@ -86,18 +99,18 @@
sort: 0 sort: 0
}; };
export default { export default {
name: 'HomeAdvertiseDetail', name: 'HomeAdvertiseDetail', //
components:{SingleUpload}, components:{SingleUpload}, //
props: { props: { // isEdit
isEdit: { isEdit: {
type: Boolean, type: Boolean,
default: false default: false
} }
}, },
data() { data() { //
return { return {
homeAdvertise: null, homeAdvertise: null, // 广
rules: { rules: { //
name: [ name: [
{required: true, message: '请输入广告名称', trigger: 'blur'}, {required: true, message: '请输入广告名称', trigger: 'blur'},
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'} {min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
@ -115,42 +128,42 @@
{required: true, message: '请选择广告图片', trigger: 'blur'} {required: true, message: '请选择广告图片', trigger: 'blur'}
] ]
}, },
typeOptions: Object.assign({}, defaultTypeOptions) typeOptions: Object.assign({}, defaultTypeOptions) // 广
} }
}, },
created(){ created(){ //
if (this.isEdit) { if (this.isEdit) { // 广homeAdvertise
getHomeAdvertise(this.$route.query.id).then(response => { getHomeAdvertise(this.$route.query.id).then(response => {
this.homeAdvertise = response.data; this.homeAdvertise = response.data;
}); });
}else{ }else{ // homeAdvertise
this.homeAdvertise = Object.assign({},defaultHomeAdvertise); this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
} }
}, },
methods: { methods: { //
onSubmit(formName) { onSubmit(formName) { //
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => { //
if (valid) { if (valid) { // API
this.$confirm('是否提交数据', '提示', { this.$confirm('是否提交数据', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
if (this.isEdit) { if (this.isEdit) { // 广API
updateHomeAdvertise(this.$route.query.id, this.homeAdvertise).then(response => { updateHomeAdvertise(this.$route.query.id, this.homeAdvertise).then(response => {
this.$refs[formName].resetFields(); this.$refs[formName].resetFields(); //
this.$message({ this.$message({ //
message: '修改成功', message: '修改成功',
type: 'success', type: 'success',
duration:1000 duration:1000
}); });
this.$router.back(); this.$router.back(); //
}); });
} else { } else { // 广API
createHomeAdvertise(this.homeAdvertise).then(response => { createHomeAdvertise(this.homeAdvertise).then(response => {
this.$refs[formName].resetFields(); this.$refs[formName].resetFields(); //
this.homeAdvertise = Object.assign({},defaultHomeAdvertise); this.homeAdvertise = Object.assign({},defaultHomeAdvertise); // homeAdvertise
this.$message({ this.$message({ //
message: '提交成功', message: '提交成功',
type: 'success', type: 'success',
duration:1000 duration:1000
@ -159,26 +172,26 @@
} }
}); });
} else { } else { //
this.$message({ this.$message({
message: '验证失败', message: '验证失败',
type: 'error', type: 'error',
duration:1000 duration:1000
}); });
return false; return false; //
} }
}); });
}, },
resetForm(formName) { resetForm(formName) { //
this.$refs[formName].resetFields(); this.$refs[formName].resetFields(); //
this.homeAdvertise = Object.assign({},defaultHomeAdvertise); this.homeAdvertise = Object.assign({},defaultHomeAdvertise); // homeAdvertise
} }
} }
} }
</script> </script>
<style scoped> <style scoped> // scoped
.input-width { .input-width { //
width: 70%; width: 70%; // 70%
} }
</style> </style>

@ -1,9 +1,13 @@
<template>  <template> 
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索区域 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 筛选搜索文本 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 查询按钮 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +15,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 重置按钮 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -18,11 +23,14 @@
重置 重置
</el-button> </el-button>
</div> </div>
<!-- 表单布局用于输入筛选条件 -->
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 广告名称筛选项 -->
<el-form-item label="广告名称:"> <el-form-item label="广告名称:">
<el-input v-model="listQuery.name" class="input-width" placeholder="广告名称"></el-input> <el-input v-model="listQuery.name" class="input-width" placeholder="广告名称"></el-input>
</el-form-item> </el-form-item>
<!-- 广告位置筛选项 -->
<el-form-item label="广告位置:"> <el-form-item label="广告位置:">
<el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
<el-option v-for="item in typeOptions" <el-option v-for="item in typeOptions"
@ -32,6 +40,7 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 到期时间筛选项 -->
<el-form-item label="到期时间:"> <el-form-item label="到期时间:">
<el-date-picker <el-date-picker
class="input-width" class="input-width"
@ -44,36 +53,48 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作区域 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- 操作图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 数据列表文本 -->
<span>数据列表</span> <span>数据列表</span>
<!-- 添加广告按钮 -->
<el-button size="mini" class="btn-add" @click="handleAdd()">广</el-button> <el-button size="mini" class="btn-add" @click="handleAdd()">广</el-button>
</el-card> </el-card>
<!-- 表格展示区域 -->
<div class="table-container"> <div class="table-container">
<el-table ref="homeAdvertiseTable" <el-table ref="homeAdvertiseTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 选择框列 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 编号列 -->
<el-table-column label="编号" width="120" align="center"> <el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 广告名称列 -->
<el-table-column label="广告名称" align="center"> <el-table-column label="广告名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 广告位置列 -->
<el-table-column label="广告位置" width="120" align="center"> <el-table-column label="广告位置" width="120" align="center">
<template slot-scope="scope">{{scope.row.type | formatType}}</template> <template slot-scope="scope">{{scope.row.type | formatType}}</template>
</el-table-column> </el-table-column>
<!-- 广告图片列 -->
<el-table-column label="广告图片" width="120" align="center"> <el-table-column label="广告图片" width="120" align="center">
<template slot-scope="scope"><img style="height: 80px" :src="scope.row.pic"></template> <template slot-scope="scope"><img style="height: 80px" :src="scope.row.pic"></template>
</el-table-column> </el-table-column>
<!-- 时间列 -->
<el-table-column label="时间" width="220" align="center"> <el-table-column label="时间" width="220" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<p>开始时间{{scope.row.startTime | formatTime}}</p> <p>开始时间{{scope.row.startTime | formatTime}}</p>
<p>到期时间{{scope.row.endTime | formatTime}}</p> <p>到期时间{{scope.row.endTime | formatTime}}</p>
</template> </template>
</el-table-column> </el-table-column>
<!-- 上线/下线状态列 -->
<el-table-column label="上线/下线" width="120" align="center"> <el-table-column label="上线/下线" width="120" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@ -84,18 +105,23 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 点击次数列 -->
<el-table-column label="点击次数" width="120" align="center"> <el-table-column label="点击次数" width="120" align="center">
<template slot-scope="scope">{{scope.row.clickCount}}</template> <template slot-scope="scope">{{scope.row.clickCount}}</template>
</el-table-column> </el-table-column>
<!-- 生成订单列 -->
<el-table-column label="生成订单" width="120" align="center"> <el-table-column label="生成订单" width="120" align="center">
<template slot-scope="scope">{{scope.row.orderCount}}</template> <template slot-scope="scope">{{scope.row.orderCount}}</template>
</el-table-column> </el-table-column>
<!-- 操作列 -->
<el-table-column label="操作" width="120" align="center"> <el-table-column label="操作" width="120" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 编辑按钮 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑 @click="handleUpdate(scope.$index, scope.row)">编辑
</el-button> </el-button>
<!-- 删除按钮 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除 @click="handleDelete(scope.$index, scope.row)">删除
@ -104,10 +130,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 这是一个包含批量操作和分页功能的容器 div -->
<div class="batch-operate-container"> <div class="batch-operate-container">
<!-- el-select 组件用于选择批量操作的类型设置了 small 尺寸并使用 v-model 双向绑定数据到 operateType 变量placeholder 用于显示默认提示文本 -->
<el-select <el-select
size="small" size="small"
v-model="operateType" placeholder="批量操作"> v-model="operateType" placeholder="批量操作">
<!-- 使用 v-for 循环遍历 operates 数组来生成 el-option 选项每个选项的 key 根据 item.value 来设置label 显示文本取自 item.labelvalue 值取自 item.value -->
<el-option <el-option
v-for="item in operates" v-for="item in operates"
:key="item.value" :key="item.value"
@ -115,6 +144,7 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<!-- el-button 组件是一个按钮设置了左边距为 20 像素添加了 search-button 类名绑定了点击事件 handleBatchOperate()按钮类型为 primary通常是主要操作按钮的样式尺寸为 small -->
<el-button <el-button
style="margin-left: 20px" style="margin-left: 20px"
class="search-button" class="search-button"
@ -124,6 +154,7 @@
确定 确定
</el-button> </el-button>
</div> </div>
<!-- 这是一个用于分页功能展示的容器 div -->
<div class="pagination-container"> <div class="pagination-container">
<el-pagination <el-pagination
background background
@ -139,169 +170,200 @@
</div> </div>
</template> </template>
<script> <script>
import {fetchList,updateStatus,deleteHomeAdvertise} from '@/api/homeAdvertise'; // '@/api/homeAdvertise'广
import {formatDate} from '@/utils/date'; import {fetchList, updateStatus, deleteHomeAdvertise} from '@/api/homeAdvertise';
const defaultListQuery = { // '@/utils/date'
pageNum: 1, import {formatDate} from '@/utils/date';
pageSize: 5,
name: null, //
type: null, const defaultListQuery = {
endTime:null pageNum: 1,
}; pageSize: 5,
const defaultTypeOptions = [ name: null,
{ type: null,
label: 'PC首页轮播', endTime: null
value: 0 };
}, // 广PCAPP
{ const defaultTypeOptions = [
label: 'APP首页轮播', {
value: 1 label: 'PC首页轮播',
value: 0
},
{
label: 'APP首页轮播',
value: 1
}
];
export default {
name: 'homeAdvertiseList',
data() {
return {
//
listQuery: Object.assign({}, defaultListQuery),
// 广
typeOptions: Object.assign({}, defaultTypeOptions),
// 广null
list: null,
// 广null
total: null,
// false
listLoading: false,
// 广
multipleSelection: [],
//
operates: [
{
label: "删除",
value: 0
}
],
// null
operateType: null
} }
]; },
export default { created() {
name: 'homeAdvertiseList', // 广
data() { this.getList();
return { },
listQuery: Object.assign({}, defaultListQuery), filters: {
typeOptions: Object.assign({}, defaultTypeOptions), // 广
list: null, formatType(type) {
total: null, if (type === 1) {
listLoading: false, return 'APP首页轮播';
multipleSelection: [], } else {
operates: [ return 'PC首页轮播';
{
label: "删除",
value: 0
}
],
operateType: null
} }
}, },
created() { //
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
},
methods: {
//
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
//
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters:{ //
formatType(type){ handleSelectionChange(val) {
if(type===1){ this.multipleSelection = val;
return 'APP首页轮播';
}else{
return 'PC首页轮播';
}
},
formatTime(time){
if(time==null||time===''){
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
}, },
methods: { //
handleResetSearch() { handleSizeChange(val) {
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery.pageNum = 1;
}, this.listQuery.pageSize = val;
handleSearchList() { this.getList();
this.listQuery.pageNum = 1; },
this.getList(); //
}, handleCurrentChange(val) {
handleSelectionChange(val){ this.listQuery.pageNum = val;
this.multipleSelection = val; this.getList();
}, },
handleSizeChange(val) { // 广
this.listQuery.pageNum = 1; handleUpdateStatus(index, row) {
this.listQuery.pageSize = val; this.$confirm('是否要修改上线/下线状态?', '提示', {
this.getList(); confirmButtonText: '确定',
}, cancelButtonText: '取消',
handleCurrentChange(val) { type: 'warning'
this.listQuery.pageNum = val; }).then(() => {
this.getList(); updateStatus(row.id, {status: row.status}).then(response => {
}, this.getList();
handleUpdateStatus(index,row){
this.$confirm('是否要修改上线/下线状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateStatus(row.id,{status:row.status}).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '修改成功!'
});
});
}).catch(() => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '已取消操作!' message: '修改成功!'
}); });
this.getList();
}); });
}, }).catch(() => {
handleDelete(index,row){ this.$message({
this.deleteHomeAdvertise(row.id); type: 'success',
}, message: '已取消操作!'
handleBatchOperate(){ });
if (this.multipleSelection < 1) { this.getList();
this.$message({ });
message: '请选择一条记录', },
type: 'warning', // 广广
duration: 1000 handleDelete(index, row) {
}); this.deleteHomeAdvertise(row.id);
return; },
} //
let ids = []; handleBatchOperate() {
for (let i = 0; i < this.multipleSelection.length; i++) { if (this.multipleSelection < 1) {
ids.push(this.multipleSelection[i].id); this.$message({
} message: '请选择一条记录',
if(this.operateType===0){ type: 'warning',
// duration: 1000
this.deleteHomeAdvertise(ids); });
}else { return;
}
let ids = [];
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id);
}
if (this.operateType === 0) {
//
this.deleteHomeAdvertise(ids);
} else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
// 广广
handleAdd() {
this.$router.push({path: '/sms/addAdvertise'})
},
// 广广广id
handleUpdate(index, row) {
this.$router.push({path: '/sms/updateAdvertise', query: {id: row.id}})
},
// 广true
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
})
},
// 广
deleteHomeAdvertise(ids) {
this.$confirm('是否要删除该广告?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params = new URLSearchParams();
params.append("ids", ids);
deleteHomeAdvertise(params).then(response => {
this.getList();
this.$message({ this.$message({
message: '请选择批量操作类型', type: 'success',
type: 'warning', message: '删除成功!'
duration: 1000
});
}
},
handleAdd(){
this.$router.push({path: '/sms/addAdvertise'})
},
handleUpdate(index,row){
this.$router.push({path: '/sms/updateAdvertise', query: {id: row.id}})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
})
},
deleteHomeAdvertise(ids){
this.$confirm('是否要删除该广告?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
deleteHomeAdvertise(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
}); });
}) });
} })
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.input-width { <!-- 带有scoped属性的style标签里面样式仅作用于当前组件 -->
width: 203px; .input-width {
} <!-- 定义类选择器样式设置宽度为203px -->
width: 203px;
}
</style> </style>

@ -1,13 +1,17 @@
<template>  <template>
<!-- 在模板中使用了名为home-advertise-detail的自定义组件并传递了一个名为isEdit且值为true的属性可能用于控制该组件处于编辑状态相关的展示或功能 -->
<home-advertise-detail :isEdit="true"></home-advertise-detail> <home-advertise-detail :isEdit="true"></home-advertise-detail>
</template> </template>
<script> <script>
import HomeAdvertiseDetail from './components/HomeAdvertiseDetail' // HomeAdvertiseDetail'./components/HomeAdvertiseDetail'
export default { import HomeAdvertiseDetail from './components/HomeAdvertiseDetail'
name: 'updateHomeAdvertise', export default {
components: { HomeAdvertiseDetail } name: 'updateHomeAdvertise',
} // HomeAdvertiseDetail使使
components: { HomeAdvertiseDetail }
}
</script> </script>
<style></style> <style></style>

@ -1,9 +1,14 @@
<template>  <template>
<!-- 页面整体的外层容器用于布局和包裹内部各部分内容 -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索区域的卡片容器设置无阴影效果 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 显示搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索的文字提示 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 用于触发查询搜索的按钮绑定对应点击事件设置样式等属性 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 用于重置筛选条件的按钮绑定对应点击事件设置样式等属性 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 行内表单绑定数据模型设置尺寸标签宽度等属性 -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 品牌名称输入框的表单项 -->
<el-form-item label="品牌名称:"> <el-form-item label="品牌名称:">
<!-- 输入框双向绑定品牌名称数据设置类名和占位提示 -->
<el-input v-model="listQuery.brandName" class="input-width" placeholder="品牌名称"></el-input> <el-input v-model="listQuery.brandName" class="input-width" placeholder="品牌名称"></el-input>
</el-form-item> </el-form-item>
<!-- 推荐状态选择框的表单项 -->
<el-form-item label="推荐状态:"> <el-form-item label="推荐状态:">
<!-- 下拉选择框双向绑定推荐状态数据设置占位提示等属性 -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 循环生成下拉选项 -->
<el-option v-for="item in recommendOptions" <el-option v-for="item in recommendOptions"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
@ -35,40 +47,51 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作区域的卡片容器无阴影效果 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<span>数据列表</span> <span>数据列表</span>
<!-- 用于触发选择品牌操作的按钮绑定点击事件 -->
<el-button size="mini" class="btn-add" @click="handleSelectBrand()"></el-button> <el-button size="mini" class="btn-add" @click="handleSelectBrand()"></el-button>
</el-card> </el-card>
<!-- 放置数据表格的容器 -->
<div class="table-container"> <div class="table-container">
<!-- 数据表格组件绑定数据设置宽度等属性还有选择改变等相关事件 -->
<el-table ref="homeBrandTable" <el-table ref="homeBrandTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 显示选择框的表格列 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 显示编号的表格列 -->
<el-table-column label="编号" width="120" align="center"> <el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 显示品牌名称的表格列 -->
<el-table-column label="品牌名称" align="center"> <el-table-column label="品牌名称" align="center">
<template slot-scope="scope">{{scope.row.brandName}}</template> <template slot-scope="scope">{{scope.row.brandName}}</template>
</el-table-column> </el-table-column>
<!-- 通过开关显示是否推荐的表格列绑定状态改变事件 -->
<el-table-column label="是否推荐" width="200" align="center"> <el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)" @change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1" :active-value="1"
:inactive-value="0" :inactive-value="0"
v-model="scope.row.recommendStatus"> v-model="scope.row.recommendStatus">
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 显示排序的表格列 -->
<el-table-column label="排序" width="160" align="center"> <el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column> </el-table-column>
<!-- 显示状态的表格列使用过滤器格式化内容 -->
<el-table-column label="状态" width="160" align="center"> <el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template> <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column> </el-table-column>
<!-- 显示操作按钮的表格列 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -83,10 +106,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 批量操作相关选择框和按钮的容器 -->
<div class="batch-operate-container"> <div class="batch-operate-container">
<!-- 选择批量操作类型的下拉框双向绑定操作类型数据 -->
<el-select <el-select
size="small" size="small"
v-model="operateType" placeholder="批量操作"> v-model="operateType" placeholder="批量操作">
<!-- 循环生成下拉选项 -->
<el-option <el-option
v-for="item in operates" v-for="item in operates"
:key="item.value" :key="item.value"
@ -94,6 +120,7 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<!-- 触发批量操作的按钮设置样式类型等属性绑定点击事件 -->
<el-button <el-button
style="margin-left: 20px" style="margin-left: 20px"
class="search-button" class="search-button"
@ -103,7 +130,9 @@
确定 确定
</el-button> </el-button>
</div> </div>
<!-- 分页组件的容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置背景各类事件绑定页面尺寸等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -115,19 +144,26 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 选择品牌的对话框组件设置标题可见性绑定宽度等属性 -->
<el-dialog title="选择品牌" :visible.sync="selectDialogVisible" width="40%"> <el-dialog title="选择品牌" :visible.sync="selectDialogVisible" width="40%">
<!-- 对话框内的品牌名称搜索输入框绑定数据设置样式等属性 -->
<el-input v-model="dialogData.listQuery.keyword" <el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px" style="width: 250px;margin-bottom: 20px"
size="small" size="small"
placeholder="品牌名称搜索"> placeholder="品牌名称搜索">
<!-- 输入框后的搜索按钮绑定点击事件 -->
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button> <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input> </el-input>
<!-- 对话框内展示品牌相关数据的表格设置数据绑定选择改变事件等属性 -->
<el-table :data="dialogData.list" <el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border> @selection-change="handleDialogSelectionChange" border>
<!-- 显示选择框的表格列 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 显示品牌名称的表格列 -->
<el-table-column label="品牌名称"align="center"> <el-table-column label="品牌名称"align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 显示相关商品和评价数量信息的表格列 -->
<el-table-column label="相关" width="220" align="center"> <el-table-column label="相关" width="220" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
商品<span class="color-main">{{scope.row.productCount}}</span> 商品<span class="color-main">{{scope.row.productCount}}</span>
@ -135,7 +171,9 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 对话框内的分页组件容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置背景各类事件绑定页面尺寸等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleDialogSizeChange" @size-change="handleDialogSizeChange"
@ -149,23 +187,30 @@
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div slot="footer"> <div slot="footer">
<!-- 对话框取消按钮点击隐藏对话框 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button> <el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 对话框确认按钮绑定点击事件 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button> <el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- 设置排序的对话框组件设置标题可见性绑定宽度等属性 -->
<el-dialog title="设置排序" <el-dialog title="设置排序"
:visible.sync="sortDialogVisible" :visible.sync="sortDialogVisible"
width="40%"> width="40%">
<!-- 对话框内的表单绑定数据模型设置标签宽度等属性 -->
<el-form :model="sortDialogData" <el-form :model="sortDialogData"
label-width="150px"> label-width="150px">
<!-- 排序输入框的表单项 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input> <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer"> <span slot="footer">
<el-button @click="sortDialogVisible = false" size="small"> </el-button> <!-- 对话框取消按钮点击隐藏对话框 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button> <el-button @click="sortDialogVisible = false" size="small"> </el-button>
</span> <!-- 对话框确认按钮绑定点击事件 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>

@ -1,14 +1,21 @@
<template>  <template>
<!-- 在模板中使用了coupon-detail组件并传递isEdit属性值为false可能用于区分添加或编辑操作 -->
<coupon-detail :isEdit="false"></coupon-detail> <coupon-detail :isEdit="false"></coupon-detail>
</template> </template>
<script> <script>
import CouponDetail from './components/CouponDetail' // CouponDetail'./components/CouponDetail'
export default { import CouponDetail from './components/CouponDetail';
name: 'addCoupon', export default {
components: { CouponDetail } // addCoupon
} name: 'addCoupon',
// CouponDetail使使
components: { CouponDetail }
}
</script> </script>
<style scoped> <style scoped>
<!-- 带有scoped属性的style标签里面样式仅作用于当前组件目前为空 -->
</style> </style>

@ -1,12 +1,16 @@
<template>  <template>
<!-- el-card组件作为表单的容器设置了类名和无阴影效果 -->
<el-card class="form-container" shadow="never"> <el-card class="form-container" shadow="never">
<!-- el-form表单组件绑定了数据模型coupon设置了验证规则表单引用标签宽度和尺寸等属性 -->
<el-form :model="coupon" <el-form :model="coupon"
:rules="rules" :rules="rules"
ref="couponFrom" ref="couponFrom"
label-width="150px" label-width="150px"
size="small"> size="small">
<!-- 优惠券类型的表单项使用el-select下拉选择框来选择类型 -->
<el-form-item label="优惠券类型:"> <el-form-item label="优惠券类型:">
<el-select v-model="coupon.type"> <el-select v-model="coupon.type">
<!-- 通过v-for循环生成下拉选项 -->
<el-option <el-option
v-for="type in typeOptions" v-for="type in typeOptions"
:key="type.value" :key="type.value"
@ -15,11 +19,14 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 优惠券名称的表单项使用el-input输入框输入名称设置了数据绑定和类名 -->
<el-form-item label="优惠券名称:" prop="name"> <el-form-item label="优惠券名称:" prop="name">
<el-input v-model="coupon.name" class="input-width"></el-input> <el-input v-model="coupon.name" class="input-width"></el-input>
</el-form-item> </el-form-item>
<!-- 适用平台的表单项用el-select下拉选择框选择平台 -->
<el-form-item label="适用平台:"> <el-form-item label="适用平台:">
<el-select v-model="coupon.platform"> <el-select v-model="coupon.platform">
<!-- 通过v-for循环生成下拉选项 -->
<el-option <el-option
v-for="item in platformOptions" v-for="item in platformOptions"
:key="item.value" :key="item.value"
@ -28,33 +35,40 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 总发行量的表单项用el-input输入框输入发行量设置了数据绑定和占位提示等属性 -->
<el-form-item label="总发行量:" prop="publishCount"> <el-form-item label="总发行量:" prop="publishCount">
<el-input v-model.number="coupon.publishCount" placeholder="只能输入正整数" class="input-width"></el-input> <el-input v-model.number="coupon.publishCount" placeholder="只能输入正整数" class="input-width"></el-input>
</el-form-item> </el-form-item>
<!-- 面额的表单项用el-input输入框输入面额设置了数据绑定占位提示和后缀文本等属性 -->
<el-form-item label="面额:" prop="amount"> <el-form-item label="面额:" prop="amount">
<el-input v-model.number="coupon.amount" placeholder="面值只能是数值限2位小数" class="input-width"> <el-input v-model.number="coupon.amount" placeholder="面值只能是数值限2位小数" class="input-width">
<template slot="append"></template> <template slot="append"></template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- 每人限领的表单项用el-input输入框输入限领数量设置了数据绑定和后缀文本等属性 -->
<el-form-item label="每人限领:"> <el-form-item label="每人限领:">
<el-input v-model="coupon.perLimit" placeholder="只能输入正整数" class="input-width"> <el-input v-model="coupon.perLimit" placeholder="只能输入正整数" class="input-width">
<template slot="append"></template> <template slot="append"></template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- 使用门槛的表单项用el-input输入框输入门槛金额设置了数据绑定前后缀文本等属性 -->
<el-form-item label="使用门槛:" prop="minPoint"> <el-form-item label="使用门槛:" prop="minPoint">
<el-input v-model.number="coupon.minPoint" placeholder="只能输入正整数" class="input-width"> <el-input v-model.number="coupon.minPoint" placeholder="只能输入正整数" class="input-width">
<template slot="prepend"></template> <template slot="prepend"></template>
<template slot="append">元可用</template> <template slot="append">元可用</template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- 领取日期的表单项用el-date-picker日期选择器选择日期设置了数据绑定和类名等属性 -->
<el-form-item label="领取日期:" prop="enableTime"> <el-form-item label="领取日期:" prop="enableTime">
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.enableTime" class="input-width"></el-date-picker> <el-date-picker type="date" placeholder="选择日期" v-model="coupon.enableTime" class="input-width"></el-date-picker>
</el-form-item> </el-form-item>
<!-- 有效期的表单项通过两个el-date-picker日期选择器分别选择开始和结束日期 -->
<el-form-item label="有效期:"> <el-form-item label="有效期:">
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.startTime" style="width: 150px"></el-date-picker> <el-date-picker type="date" placeholder="选择日期" v-model="coupon.startTime" style="width: 150px"></el-date-picker>
<span style="margin-left: 20px;margin-right: 20px"></span> <span style="margin-left: 20px;margin-right: 20px"></span>
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.endTime" style="width: 150px"></el-date-picker> <el-date-picker type="date" placeholder="选择日期" v-model="coupon.endTime" style="width: 150px"></el-date-picker>
</el-form-item> </el-form-item>
<!-- 可使用商品的表单项用el-radio-group单选按钮组选择使用类型 -->
<el-form-item label="可使用商品:"> <el-form-item label="可使用商品:">
<el-radio-group v-model="coupon.useType"> <el-radio-group v-model="coupon.useType">
<el-radio-button :label="0">全场通用</el-radio-button> <el-radio-button :label="0">全场通用</el-radio-button>
@ -62,21 +76,27 @@
<el-radio-button :label="2">指定商品</el-radio-button> <el-radio-button :label="2">指定商品</el-radio-button>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<!-- 当可使用商品类型为指定分类时显示的内容包含分类选择器添加按钮和展示关联分类关系的表格 -->
<el-form-item v-show="coupon.useType===1"> <el-form-item v-show="coupon.useType===1">
<!-- el-cascader分类选择器用于选择分类设置了可清除占位提示等属性 -->
<el-cascader <el-cascader
clearable clearable
placeholder="请选择分类名称" placeholder="请选择分类名称"
v-model="selectProductCate" v-model="selectProductCate"
:options="productCateOptions"> :options="productCateOptions">
</el-cascader> </el-cascader>
<!-- 添加分类关联的按钮绑定点击事件 -->
<el-button @click="handleAddProductCategoryRelation()"></el-button> <el-button @click="handleAddProductCategoryRelation()"></el-button>
<!-- 展示已添加的分类关联关系的表格设置了数据绑定等属性 -->
<el-table ref="productCateRelationTable" <el-table ref="productCateRelationTable"
:data="coupon.productCategoryRelationList" :data="coupon.productCategoryRelationList"
style="width: 100%;margin-top: 20px" style="width: 100%;margin-top: 20px"
border> border>
<!-- 显示分类名称的表格列 -->
<el-table-column label="分类名称" align="center"> <el-table-column label="分类名称" align="center">
<template slot-scope="scope">{{scope.row.parentCategoryName}}>{{scope.row.productCategoryName}}</template> <template slot-scope="scope">{{scope.row.parentCategoryName}}>{{scope.row.productCategoryName}}</template>
</el-table-column> </el-table-column>
<!-- 显示操作按钮删除的表格列 -->
<el-table-column label="操作" align="center" width="100"> <el-table-column label="操作" align="center" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -87,7 +107,9 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-form-item> </el-form-item>
<!-- 当可使用商品类型为指定商品时显示的内容包含商品选择框添加按钮和展示关联商品关系的表格 -->
<el-form-item v-show="coupon.useType===2"> <el-form-item v-show="coupon.useType===2">
<!-- el-select商品选择框设置了可过滤远程搜索等属性 -->
<el-select <el-select
v-model="selectProduct" v-model="selectProduct"
filterable filterable
@ -96,6 +118,7 @@
placeholder="商品名称/商品货号" placeholder="商品名称/商品货号"
:remote-method="searchProductMethod" :remote-method="searchProductMethod"
:loading="selectProductLoading"> :loading="selectProductLoading">
<!-- 通过v-for循环生成商品选项 -->
<el-option <el-option
v-for="item in selectProductOptions" v-for="item in selectProductOptions"
:key="item.productId" :key="item.productId"
@ -105,17 +128,22 @@
<span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.productSn }}</span> <span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.productSn }}</span>
</el-option> </el-option>
</el-select> </el-select>
<!-- 添加商品关联的按钮绑定点击事件 -->
<el-button @click="handleAddProductRelation()"></el-button> <el-button @click="handleAddProductRelation()"></el-button>
<!-- 展示已添加的商品关联关系的表格设置了数据绑定等属性 -->
<el-table ref="productRelationTable" <el-table ref="productRelationTable"
:data="coupon.productRelationList" :data="coupon.productRelationList"
style="width: 100%;margin-top: 20px" style="width: 100%;margin-top: 20px"
border> border>
<!-- 显示商品名称的表格列 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template> <template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column> </el-table-column>
<!-- 显示商品货号的表格列 -->
<el-table-column label="货号" align="center" width="120" > <el-table-column label="货号" align="center" width="120" >
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> <template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column> </el-table-column>
<!-- 显示操作按钮删除的表格列 -->
<el-table-column label="操作" align="center" width="100"> <el-table-column label="操作" align="center" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -126,6 +154,7 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-form-item> </el-form-item>
<!-- 备注的表单项用el-input输入框输入备注内容设置了类名类型为文本域等属性 -->
<el-form-item label="备注:"> <el-form-item label="备注:">
<el-input <el-input
class="input-width" class="input-width"
@ -135,241 +164,276 @@
v-model="coupon.note"> v-model="coupon.note">
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- 提交和重置按钮所在的表单项 -->
<el-form-item> <el-form-item>
<!-- 提交按钮设置类型为primary绑定点击事件 -->
<el-button type="primary" @click="onSubmit('couponFrom')"></el-button> <el-button type="primary" @click="onSubmit('couponFrom')"></el-button>
<!-- 重置按钮根据条件判断是否显示绑定点击事件 -->
<el-button v-if="!isEdit" @click="resetForm('couponFrom')"></el-button> <el-button v-if="!isEdit" @click="resetForm('couponFrom')"></el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
</template> </template>
<script> <script>
import {createCoupon,getCoupon,updateCoupon} from '@/api/coupon'; // '@/api/coupon'
import {fetchSimpleList as fetchProductList} from '@/api/product'; import {createCoupon, getCoupon, updateCoupon} from '@/api/coupon';
import {fetchListWithChildren} from '@/api/productCate' // '@/api/product'fetchProductList
const defaultCoupon = { import {fetchSimpleList as fetchProductList} from '@/api/product';
type: 0, // '@/api/productCate'
name: null, import {fetchListWithChildren} from '@/api/productCate';
platform: 0,
amount: null, //
perLimit: 1, const defaultCoupon = {
minPoint: null, type: 0,
startTime: null, name: null,
endTime: null, platform: 0,
useType: 0, amount: null,
note: null, perLimit: 1,
publishCount: null, minPoint: null,
productRelationList: [], startTime: null,
productCategoryRelationList: [] endTime: null,
}; useType: 0,
const defaultTypeOptions = [ note: null,
{ publishCount: null,
label: '全场赠券', productRelationList: [],
value: 0 productCategoryRelationList: []
}, };
{ //
label: '会员赠券', const defaultTypeOptions = [
value: 1 {
}, label: '全场赠券',
{ value: 0
label: '购物赠券', },
value: 2 {
}, label: '会员赠券',
{ value: 1
label: '注册赠券', },
value: 3 {
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
// PC
const defaultPlatformOptions = [
{
label: '全平台',
value: 0
},
{
label: '移动平台',
value: 1
},
{
label: 'PC平台',
value: 2
}
];
export default {
name: 'CouponDetail',
// isEditfalse
props: {
isEdit: {
type: Boolean,
default: false
} }
]; },
const defaultPlatformOptions = [ data() {
{ return {
label: '全平台', //
value: 0 coupon: Object.assign({}, defaultCoupon),
}, //
{ typeOptions: Object.assign({}, defaultTypeOptions),
label: '移动平台', //
value: 1 platformOptions: Object.assign({}, defaultPlatformOptions),
}, //
{ rules: {
label: 'PC平台', name: [
value: 2 {required: true, message: '请输入优惠券名称', trigger: 'blur'},
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
],
publishCount: [
{type: 'number', required: true, message: '只能输入正整数', trigger: 'blur'}
],
amount: [
{type: 'number', required: true, message: '面值只能是数值0.01-10000限2位小数', trigger: 'blur'}
],
minPoint: [
{type: 'number', required: true, message: '只能输入正整数', trigger: 'blur'}
]
},
// null
selectProduct: null,
// false
selectProductLoading: false,
//
selectProductOptions: [],
// null
selectProductCate: null,
//
productCateOptions: []
} }
]; },
export default { created() {
name: 'CouponDetail', // coupon
props: { if (this.isEdit) {
isEdit: { getCoupon(this.$route.query.id).then(response => {
type: Boolean, this.coupon = response.data;
default: false });
} }
}, //
data() { this.getProductCateList();
return { },
coupon: Object.assign({}, defaultCoupon), methods: {
typeOptions: Object.assign({}, defaultTypeOptions), //
platformOptions: Object.assign({}, defaultPlatformOptions), onSubmit(formName) {
rules: { this.$refs[formName].validate((valid) => {
name: [ if (valid) {
{required: true, message: '请输入优惠券名称', trigger: 'blur'}, this.$confirm('是否提交数据', '提示', {
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'} confirmButtonText: '确定',
], cancelButtonText: '取消',
publishCount: [ type: 'warning'
{type: 'number',required: true, message: '只能输入正整数', trigger: 'blur'} }).then(() => {
], if (this.isEdit) {
amount: [ updateCoupon(this.$route.query.id, this.coupon).then(response => {
{type: 'number',required: true,message: '面值只能是数值0.01-10000限2位小数',trigger: 'blur'} this.$refs[formName].resetFields();
], this.$message({
minPoint: [ message: '修改成功',
{type: 'number',required: true,message: '只能输入正整数',trigger: 'blur'} type: 'success',
] duration: 1000
},
selectProduct:null,
selectProductLoading: false,
selectProductOptions:[],
selectProductCate: null,
productCateOptions: []
}
},
created(){
if(this.isEdit){
getCoupon(this.$route.query.id).then(response=>{
this.coupon=response.data;
});
}
this.getProductCateList();
},
methods:{
onSubmit(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.$confirm('是否提交数据', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if(this.isEdit){
updateCoupon(this.$route.query.id,this.coupon).then(response=>{
this.$refs[formName].resetFields();
this.$message({
message: '修改成功',
type: 'success',
duration:1000
});
this.$router.back();
}); });
}else{ this.$router.back();
createCoupon(this.coupon).then(response=>{ });
this.$refs[formName].resetFields(); } else {
this.$message({ createCoupon(this.coupon).then(response => {
message: '提交成功', this.$refs[formName].resetFields();
type: 'success', this.$message({
duration:1000 message: '提交成功',
}); type: 'success',
this.$router.back(); duration: 1000
}); });
} this.$router.back();
}); });
} else {
this.$message({
message: '验证失败',
type: 'error',
duration:1000
});
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
this.coupon = Object.assign({},defaultCoupon);
},
searchProductMethod(query){
if (query !== '') {
this.loading = true;
fetchProductList({keyword:query}).then(response=>{
this.loading=false;
let productList = response.data;
this.selectProductOptions = [];
for(let i=0;i<productList.length;i++){
let item = productList[i];
this.selectProductOptions.push({productId:item.id,productName:item.name,productSn:item.productSn});
} }
}); });
} else { } else {
this.selectProductOptions = [];
}
},
handleAddProductRelation(){
if(this.selectProduct===null){
this.$message({ this.$message({
message: '请先选择商品', message: '验证失败',
type: 'warning' type: 'error',
duration: 1000
}); });
return return false;
} }
this.coupon.productRelationList.push(this.getProductById(this.selectProduct)); });
this.selectProduct=null; },
}, // coupon
handleDeleteProductRelation(index,row){ resetForm(formName) {
this.coupon.productRelationList.splice(index,1); this.$refs[formName].resetFields();
}, this.coupon = Object.assign({}, defaultCoupon);
handleAddProductCategoryRelation(){ },
if(this.selectProductCate===null||this.selectProductCate.length===0){ //
this.$message({ searchProductMethod(query) {
message: '请先选择商品分类', if (query!== '') {
type: 'warning' this.loading = true;
}); fetchProductList({keyword: query}).then(response => {
return this.loading = false;
} let productList = response.data;
this.coupon.productCategoryRelationList.push(this.getProductCateByIds(this.selectProductCate)); this.selectProductOptions = [];
this.selectProductCate=[]; for (let i = 0; i < productList.length; i++) {
}, let item = productList[i];
handleDeleteProductCateRelation(index,row){ this.selectProductOptions.push({productId: item.id, productName: item.name, productSn: item.productSn});
this.coupon.productCategoryRelationList.splice(index,1);
},
getProductById(id){
for(let i=0;i<this.selectProductOptions.length;i++){
if(id===this.selectProductOptions[i].productId){
return this.selectProductOptions[i];
} }
});
} else {
this.selectProductOptions = [];
}
},
//
handleAddProductRelation() {
if (this.selectProduct === null) {
this.$message({
message: '请先选择商品',
type: 'warning'
});
return
}
this.coupon.productRelationList.push(this.getProductById(this.selectProduct));
this.selectProduct = null;
},
//
handleDeleteProductRelation(index, row) {
this.coupon.productRelationList.splice(index, 1);
},
//
handleAddProductCategoryRelation() {
if (this.selectProductCate === null || this.selectProductCate.length === 0) {
this.$message({
message: '请先选择商品分类',
type: 'warning'
});
return
}
this.coupon.productCategoryRelationList.push(this.getProductCateByIds(this.selectProductCate));
this.selectProductCate = [];
},
//
handleDeleteProductCateRelation(index, row) {
this.coupon.productCategoryRelationList.splice(index, 1);
},
// idid
getProductById(id) {
for (let i = 0; i < this.selectProductOptions.length; i++) {
if (id === this.selectProductOptions[i].productId) {
return this.selectProductOptions[i];
} }
return null; }
}, return null;
getProductCateList() { },
fetchListWithChildren().then(response => { //
let list = response.data; getProductCateList() {
this.productCateOptions = []; fetchListWithChildren().then(response => {
for (let i = 0; i < list.length; i++) { let list = response.data;
let children = []; this.productCateOptions = [];
if (list[i].children != null && list[i].children.length > 0) { for (let i = 0; i < list.length; i++) {
for (let j = 0; j < list[i].children.length; j++) { let children = [];
children.push({label: list[i].children[j].name, value: list[i].children[j].id}); if (list[i].children!= null && list[i].children.length > 0) {
} for (let j = 0; j < list[i].children.length; j++) {
children.push({label: list[i].children[j].name, value: list[i].children[j].id});
} }
this.productCateOptions.push({label: list[i].name, value: list[i].id, children: children});
} }
}); this.productCateOptions.push({label: list[i].name, value: list[i].id, children: children});
}, }
getProductCateByIds(ids){ });
let name; },
let parentName; // idid
for (let i = 0; i < this.productCateOptions.length; i++) { getProductCateByIds(ids) {
if (this.productCateOptions[i].value === ids[0]) { let name;
parentName = this.productCateOptions[i].label; let parentName;
for (let j = 0; j < this.productCateOptions[i].children.length; j++) { for (let i = 0; i < this.productCateOptions.length; i++) {
if (this.productCateOptions[i].children[j].value === ids[1]) { if (this.productCateOptions[i].value === ids[0]) {
name = this.productCateOptions[i].children[j].label; parentName = this.productCateOptions[i].label;
} for (let j = 0; j < this.productCateOptions[i].children.length; j++) {
if (this.productCateOptions[i].children[j].value === ids[1]) {
name = this.productCateOptions[i].children[j].label;
} }
} }
} }
return {productCategoryId: ids[1], productCategoryName: name, parentCategoryName: parentName};
} }
return {productCategoryId: ids[1], productCategoryName: name, parentCategoryName: parentName};
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.input-width { <!-- 带有scoped属性的style标签意味着里面定义的样式仅作用于当前组件内的元素 -->
width: 60%; .input-width {
} <!-- 定义了一个类选择器样式作用是将应用该类的元素宽度设置为其父元素宽度的60% -->
width: 60%;
}
</style> </style>

@ -1,45 +1,79 @@
<template>  <template>
<!-- 整体的外层容器用于布局包裹内部各部分内容 -->
<div class="app-container"> <div class="app-container">
<!-- 用于表格布局的容器 -->
<div class="table-layout"> <div class="table-layout">
<!-- el-row行组件里面放置多个列用于显示表格标题 -->
<el-row> <el-row>
<!-- el-col列组件设置占4格宽度显示名称标题 -->
<el-col :span="4" class="table-cell-title">名称</el-col> <el-col :span="4" class="table-cell-title">名称</el-col>
<!-- el-col列组件设置占4格宽度显示优惠券类型标题 -->
<el-col :span="4" class="table-cell-title">优惠券类型</el-col> <el-col :span="4" class="table-cell-title">优惠券类型</el-col>
<!-- el-col列组件设置占4格宽度显示可使用商品标题 -->
<el-col :span="4" class="table-cell-title">可使用商品</el-col> <el-col :span="4" class="table-cell-title">可使用商品</el-col>
<!-- el-col列组件设置占4格宽度显示使用门槛标题 -->
<el-col :span="4" class="table-cell-title">使用门槛</el-col> <el-col :span="4" class="table-cell-title">使用门槛</el-col>
<!-- el-col列组件设置占4格宽度显示面值标题 -->
<el-col :span="4" class="table-cell-title">面值</el-col> <el-col :span="4" class="table-cell-title">面值</el-col>
<!-- el-col列组件设置占4格宽度显示状态标题 -->
<el-col :span="4" class="table-cell-title">状态</el-col> <el-col :span="4" class="table-cell-title">状态</el-col>
</el-row> </el-row>
<!-- el-row行组件里面放置多个列用于显示对应优惠券的具体信息使用了过滤器来格式化显示内容 -->
<el-row> <el-row>
<!-- el-col列组件设置占4格宽度显示优惠券名称 -->
<el-col :span="4" class="table-cell">{{coupon.name}}</el-col> <el-col :span="4" class="table-cell">{{coupon.name}}</el-col>
<!-- el-col列组件设置占4格宽度显示格式化后的优惠券类型 -->
<el-col :span="4" class="table-cell">{{coupon.type | formatType}}</el-col> <el-col :span="4" class="table-cell">{{coupon.type | formatType}}</el-col>
<!-- el-col列组件设置占4格宽度显示格式化后的可使用商品类型 -->
<el-col :span="4" class="table-cell">{{coupon.useType | formatUseType}}</el-col> <el-col :span="4" class="table-cell">{{coupon.useType | formatUseType}}</el-col>
<!-- el-col列组件设置占4格宽度按格式显示使用门槛 -->
<el-col :span="4" class="table-cell">{{coupon.minPoint}}元可用</el-col> <el-col :span="4" class="table-cell">{{coupon.minPoint}}元可用</el-col>
<!-- el-col列组件设置占4格宽度显示优惠券面值 -->
<el-col :span="4" class="table-cell">{{coupon.amount}}</el-col> <el-col :span="4" class="table-cell">{{coupon.amount}}</el-col>
<!-- el-col列组件设置占4格宽度显示格式化后的状态 -->
<el-col :span="4" class="table-cell">{{coupon.endTime | formatStatus}}</el-col> <el-col :span="4" class="table-cell">{{coupon.endTime | formatStatus}}</el-col>
</el-row> </el-row>
<!-- el-row行组件里面放置多个列用于显示表格另一部分标题 -->
<el-row> <el-row>
<!-- el-col列组件设置占4格宽度显示有效期标题 -->
<el-col :span="4" class="table-cell-title">有效期</el-col> <el-col :span="4" class="table-cell-title">有效期</el-col>
<!-- el-col列组件设置占4格宽度显示总发行量标题 -->
<el-col :span="4" class="table-cell-title">总发行量</el-col> <el-col :span="4" class="table-cell-title">总发行量</el-col>
<!-- el-col列组件设置占4格宽度显示已领取标题 -->
<el-col :span="4" class="table-cell-title">已领取</el-col> <el-col :span="4" class="table-cell-title">已领取</el-col>
<!-- el-col列组件设置占4格宽度显示待领取标题 -->
<el-col :span="4" class="table-cell-title">待领取</el-col> <el-col :span="4" class="table-cell-title">待领取</el-col>
<!-- el-col列组件设置占4格宽度显示已使用标题 -->
<el-col :span="4" class="table-cell-title">已使用</el-col> <el-col :span="4" class="table-cell-title">已使用</el-col>
<!-- el-col列组件设置占4格宽度显示未使用标题 -->
<el-col :span="4" class="table-cell-title">未使用</el-col> <el-col :span="4" class="table-cell-title">未使用</el-col>
</el-row> </el-row>
<!-- el-row行组件里面放置多个列用于显示对应优惠券相关数量等具体信息使用了日期格式化等过滤器 -->
<el-row> <el-row>
<!-- el-col列组件设置占4格宽度按格式显示有效期使用了日期格式化过滤器 -->
<el-col :span="4" class="table-cell" style="font-size: 13px"> <el-col :span="4" class="table-cell" style="font-size: 13px">
{{coupon.startTime|formatDate}}{{coupon.endTime|formatDate}} {{coupon.startTime|formatDate}}{{coupon.endTime|formatDate}}
</el-col> </el-col>
<!-- el-col列组件设置占4格宽度显示总发行量 -->
<el-col :span="4" class="table-cell">{{coupon.publishCount}}</el-col> <el-col :span="4" class="table-cell">{{coupon.publishCount}}</el-col>
<!-- el-col列组件设置占4格宽度显示已领取数量 -->
<el-col :span="4" class="table-cell">{{coupon.receiveCount}}</el-col> <el-col :span="4" class="table-cell">{{coupon.receiveCount}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.publishCount-coupon.receiveCount}}</el-col> <!-- el-col列组件设置占4格宽度通过计算显示待领取数量 -->
<el-col :span="4" class="table-cell">{{coupon.publishCount - coupon.receiveCount}}</el-col>
<!-- el-col列组件设置占4格宽度显示已使用数量 -->
<el-col :span="4" class="table-cell">{{coupon.useCount}}</el-col> <el-col :span="4" class="table-cell">{{coupon.useCount}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.publishCount-coupon.useCount}}</el-col> <!-- el-col列组件设置占4格宽度通过计算显示未使用数量 -->
<el-col :span="4" class="table-cell">{{coupon.publishCount - coupon.useCount}}</el-col>
</el-row> </el-row>
</div> </div>
<!-- 筛选搜索区域的卡片容器设置无阴影效果 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 显示搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索文字提示 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 用于触发查询搜索的按钮绑定点击事件设置样式等属性 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -47,6 +81,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 用于重置筛选条件的按钮绑定点击事件设置样式等属性 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -55,8 +90,11 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 行内表单绑定数据模型设置尺寸标签宽度等属性 -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 对应使用状态选择框的表单项 -->
<el-form-item label="使用状态:"> <el-form-item label="使用状态:">
<!-- 下拉选择框双向绑定使用状态数据设置占位提示等属性通过循环生成下拉选项 -->
<el-select v-model="listQuery.useStatus" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.useStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in useTypeOptions" <el-option v-for="item in useTypeOptions"
:key="item.value" :key="item.value"
@ -65,41 +103,54 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 对应订单编号输入框的表单项 -->
<el-form-item label="订单编号:"> <el-form-item label="订单编号:">
<!-- 输入框双向绑定订单编号数据设置类名和占位提示 -->
<el-input v-model="listQuery.orderSn" class="input-width" placeholder="订单编号"></el-input> <el-input v-model="listQuery.orderSn" class="input-width" placeholder="订单编号"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 放置数据表格的容器 -->
<div class="table-container"> <div class="table-container">
<!-- 数据表格组件绑定数据设置宽度等属性以及加载状态 -->
<el-table ref="couponHistoryTable" <el-table ref="couponHistoryTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 显示优惠码的表格列 -->
<el-table-column label="优惠码" width="160" align="center"> <el-table-column label="优惠码" width="160" align="center">
<template slot-scope="scope">{{scope.row.couponCode}}</template> <template slot-scope="scope">{{scope.row.couponCode}}</template>
</el-table-column> </el-table-column>
<!-- 显示领取会员的表格列 -->
<el-table-column label="领取会员" width="140" align="center"> <el-table-column label="领取会员" width="140" align="center">
<template slot-scope="scope">{{scope.row.memberNickname}}</template> <template slot-scope="scope">{{scope.row.memberNickname}}</template>
</el-table-column> </el-table-column>
<!-- 显示领取方式的表格列使用过滤器格式化内容 -->
<el-table-column label="领取方式" width="100" align="center"> <el-table-column label="领取方式" width="100" align="center">
<template slot-scope="scope">{{scope.row.getType | formatGetType}}</template> <template slot-scope="scope">{{scope.row.getType | formatGetType}}</template>
</el-table-column> </el-table-column>
<!-- 显示领取时间的表格列使用日期格式化过滤器 -->
<el-table-column label="领取时间" width="160" align="center"> <el-table-column label="领取时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatTime}}</template> <template slot-scope="scope">{{scope.row.createTime | formatTime}}</template>
</el-table-column> </el-table-column>
<!-- 显示当前状态的表格列使用过滤器格式化内容 -->
<el-table-column label="当前状态" width="140" align="center"> <el-table-column label="当前状态" width="140" align="center">
<template slot-scope="scope">{{scope.row.useStatus | formatCouponHistoryUseType}}</template> <template slot-scope="scope">{{scope.row.useStatus | formatCouponHistoryUseType}}</template>
</el-table-column> </el-table-column>
<!-- 显示使用时间的表格列使用日期格式化过滤器 -->
<el-table-column label="使用时间" width="160" align="center"> <el-table-column label="使用时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.useTime | formatTime}}</template> <template slot-scope="scope">{{scope.row.useTime | formatTime}}</template>
</el-table-column> </el-table-column>
<!-- 显示订单编号的表格列做了空值处理 -->
<el-table-column label="订单编号" align="center"> <el-table-column label="订单编号" align="center">
<template slot-scope="scope">{{scope.row.orderSn===null?'N/A':scope.row.orderSn}}</template> <template slot-scope="scope">{{scope.row.orderSn===null?'N/A':scope.row.orderSn}}</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 分页组件的容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置背景各类事件绑定页面尺寸等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -114,200 +165,231 @@
</div> </div>
</template> </template>
<script> <script>
import {formatDate} from '@/utils/date'; // '@/utils/date'formatDate
import {getCoupon} from '@/api/coupon'; import {formatDate} from '@/utils/date';
import {fetchList as fetchCouponHistoryList} from '@/api/couponHistory'; // '@/api/coupon'getCoupon
import {getCoupon} from '@/api/coupon';
// '@/api/couponHistory'fetchCouponHistoryList
import {fetchList as fetchCouponHistoryList} from '@/api/couponHistory';
const defaultTypeOptions = [ //
{ const defaultTypeOptions = [
label: '全场赠券', {
value: 0 label: '全场赠券',
value: 0
},
{
label: '会员赠券',
value: 1
},
{
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
// 使
const defaultListQuery = {
pageNum: 1,
pageSize: 10,
useStatus: null,
orderSn: null,
couponId: null
};
// 使使使
const defaultUseTypeOptions = [
{
label: "未使用",
value: 0
},
{
label: "已使用",
value: 1
},
{
label: "已过期",
value: 2
}
];
export default {
name: 'couponHistoryList',
data() {
return {
//
coupon: {},
//
listQuery: Object.assign({}, defaultListQuery),
// 使
useTypeOptions: Object.assign({}, defaultUseTypeOptions),
// null
list: null,
// null
total: null,
// false
listLoading: false
}
},
created() {
// coupon
getCoupon(this.$route.query.id).then(response => {
this.coupon = response.data;
});
// id
this.listQuery.couponId = this.$route.query.id;
//
this.getList();
},
filters: {
//
formatType(type) {
for (let i = 0; i < defaultTypeOptions.length; i++) {
if (type === defaultTypeOptions[i].value) {
return defaultTypeOptions[i].label;
}
}
return '';
}, },
{ // 使
label: '会员赠券', formatUseType(useType) {
value: 1 if (useType === 0) {
return '全场通用';
} else if (useType === 1) {
return '指定分类';
} else {
return '指定商品';
}
}, },
{ //
label: '购物赠券', formatPlatform(platform) {
value: 2 if (platform === 1) {
return '移动平台';
} else if (platform === 2) {
return 'PC平台';
} else {
return '全平台';
}
}, },
{ //
label: '注册赠券', formatDate(time) {
value: 3 if (time == null || time === '') {
} return 'N/A';
]; }
const defaultListQuery = { let date = new Date(time);
pageNum: 1, return formatDate(date, 'yyyy-MM-dd')
pageSize: 10,
useStatus: null,
orderSn: null,
couponId: null
};
const defaultUseTypeOptions= [
{
label: "未使用",
value: 0
}, },
{ //
label: "已使用", formatStatus(endTime) {
value: 1 let now = new Date().getTime();
if (endTime > now) {
return '未过期'
} else {
return '已过期';
}
}, },
{ //
label: "已过期", formatGetType(type) {
value: 2 if (type === 1) {
} return '主动获取';
]; } else {
export default { return '后台赠送';
name: 'couponHistoryList', }
data() { },
return { // 使
coupon: {}, formatCouponHistoryUseType(useType) {
listQuery: Object.assign({}, defaultListQuery), if (useType === 0) {
useTypeOptions:Object.assign({},defaultUseTypeOptions), return '未使用';
list:null, } else if (useType === 1) {
total:null, return '已使用';
listLoading:false } else {
return '已过期';
}
},
//
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
} }
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
}, },
created() { },
getCoupon(this.$route.query.id).then(response => { methods: {
this.coupon = response.data; // true
getList() {
this.listLoading = true;
fetchCouponHistoryList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
}); });
this.listQuery.couponId=this.$route.query.id; },
// id
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
this.listQuery.couponId = this.$route.query.id;
},
//
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters: { //
formatType(type) { handleSizeChange(val) {
for (let i = 0; i < defaultTypeOptions.length; i++) { this.listQuery.pageNum = 1;
if (type === defaultTypeOptions[i].value) { this.listQuery.pageSize = val;
return defaultTypeOptions[i].label; this.getList();
}
}
return '';
},
formatUseType(useType) {
if (useType === 0) {
return '全场通用';
} else if (useType === 1) {
return '指定分类';
} else {
return '指定商品';
}
},
formatPlatform(platform) {
if (platform === 1) {
return '移动平台';
} else if (platform === 2) {
return 'PC平台';
} else {
return '全平台';
}
},
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
},
formatStatus(endTime) {
let now = new Date().getTime();
if (endTime > now) {
return '未过期'
} else {
return '已过期';
}
},
formatGetType(type) {
if(type===1){
return '主动获取';
}else{
return '后台赠送';
}
},
formatCouponHistoryUseType(useType) {
if (useType === 0) {
return '未使用';
} else if (useType === 1) {
return '已使用';
} else {
return '已过期';
}
},
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
}, },
methods: { //
getList(){ handleCurrentChange(val) {
this.listLoading=true; this.listQuery.pageNum = val;
fetchCouponHistoryList(this.listQuery).then(response=>{ this.getList();
this.listLoading=false;
this.list=response.data.list;
this.total=response.data.total;
});
},
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
this.listQuery.couponId=this.$route.query.id;
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
}
} }
} }
}
</script> </script>
<style scoped>
.app-container {
width: 80%;
margin: 20px auto;
}
.filter-container {
margin-top: 20px;
}
.table-layout {
margin-top: 20px;
border-left: 1px solid #DCDFE6;
border-top: 1px solid #DCDFE6;
}
.table-cell { <style scoped>
height: 60px; <!-- 定义类名为app-container的样式设置宽度外边距使其水平居中 -->
line-height: 40px; .app-container {
border-right: 1px solid #DCDFE6; width: 80%;
border-bottom: 1px solid #DCDFE6; margin: 20px auto;
padding: 10px; }
font-size: 14px; <!-- 定义类名为filter-container的样式设置上边距 -->
color: #606266; .filter-container {
text-align: center; margin-top: 20px;
overflow: hidden; }
} <!-- 定义类名为table-layout的样式设置上边距左边框上边框 -->
.table-layout {
.table-cell-title { margin-top: 20px;
border-right: 1px solid #DCDFE6; border-left: 1px solid #DCDFE6;
border-bottom: 1px solid #DCDFE6; border-top: 1px solid #DCDFE6;
padding: 10px; }
background: #F2F6FC; <!-- 定义类名为table-cell的样式设置高度行高边框内边距字体大小颜色文本对齐溢出处理等属性 -->
text-align: center; .table-cell {
font-size: 14px; height: 60px;
color: #303133; line-height: 40px;
} border-right: 1px solid #DCDFE6;
border-bottom: 1px solid #DCDFE6;
padding: 10px;
font-size: 14px;
color: #606266;
text-align: center;
overflow: hidden;
}
<!-- 定义类名为table-cell-title的样式设置边框内边距背景色文本对齐字体大小颜色等属性 -->
.table-cell-title {
border-right: 1px solid #DCDFE6;
border-bottom: 1px solid #DCDFE6;
padding: 10px;
background: #F2F6FC;
text-align: center;
font-size: 14px;
color: #303133;
}
</style> </style>

@ -1,9 +1,14 @@
<template>  <template>
<!-- 页面整体的外层容器用于布局包裹内部各部分内容 -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索区域的卡片容器设置无阴影效果 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 显示搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索文字提示 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 用于触发查询搜索的按钮绑定点击事件设置样式等属性 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 用于重置筛选条件的按钮绑定点击事件设置样式等属性 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 行内表单绑定数据模型设置尺寸标签宽度等属性 -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 优惠券名称输入框的表单项 -->
<el-form-item label="优惠券名称:"> <el-form-item label="优惠券名称:">
<!-- 输入框双向绑定优惠券名称数据设置类名和占位提示 -->
<el-input v-model="listQuery.name" class="input-width" placeholder="优惠券名称"></el-input> <el-input v-model="listQuery.name" class="input-width" placeholder="优惠券名称"></el-input>
</el-form-item> </el-form-item>
<!-- 优惠券类型选择框的表单项 -->
<el-form-item label="优惠券类型:"> <el-form-item label="优惠券类型:">
<!-- 下拉选择框双向绑定优惠券类型数据设置占位提示等属性 -->
<el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
<!-- 通过循环生成下拉选项 -->
<el-option v-for="item in typeOptions" <el-option v-for="item in typeOptions"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
@ -35,54 +47,72 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作区域的卡片容器设置无阴影效果 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<span>数据列表</span> <span>数据列表</span>
<!-- 用于触发添加操作的按钮绑定点击事件 -->
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button> <el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card> </el-card>
<!-- 放置数据表格的容器 -->
<div class="table-container"> <div class="table-container">
<!-- 数据表格组件绑定数据设置宽度等属性还有选择改变等相关事件 -->
<el-table ref="couponTable" <el-table ref="couponTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 显示选择框的表格列 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 显示编号的表格列 -->
<el-table-column label="编号" width="100" align="center"> <el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 显示优惠券名称的表格列 -->
<el-table-column label="优惠劵名称" align="center"> <el-table-column label="优惠劵名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 显示优惠券类型的表格列使用过滤器格式化内容 -->
<el-table-column label="优惠券类型" width="100" align="center"> <el-table-column label="优惠券类型" width="100" align="center">
<template slot-scope="scope">{{scope.row.type | formatType}}</template> <template slot-scope="scope">{{scope.row.type | formatType}}</template>
</el-table-column> </el-table-column>
<!-- 显示可使用商品类型的表格列使用过滤器格式化内容 -->
<el-table-column label="可使用商品" width="100" align="center"> <el-table-column label="可使用商品" width="100" align="center">
<template slot-scope="scope">{{scope.row.useType | formatUseType}}</template> <template slot-scope="scope">{{scope.row.useType | formatUseType}}</template>
</el-table-column> </el-table-column>
<!-- 显示使用门槛的表格列 -->
<el-table-column label="使用门槛" width="140" align="center"> <el-table-column label="使用门槛" width="140" align="center">
<template slot-scope="scope">{{scope.row.minPoint}}元可用</template> <template slot-scope="scope">{{scope.row.minPoint}}元可用</template>
</el-table-column> </el-table-column>
<!-- 显示面值的表格列 -->
<el-table-column label="面值" width="100" align="center"> <el-table-column label="面值" width="100" align="center">
<template slot-scope="scope">{{scope.row.amount}}</template> <template slot-scope="scope">{{scope.row.amount}}</template>
</el-table-column> </el-table-column>
<!-- 显示适用平台的表格列使用过滤器格式化内容 -->
<el-table-column label="适用平台" width="100" align="center"> <el-table-column label="适用平台" width="100" align="center">
<template slot-scope="scope">{{scope.row.platform | formatPlatform}}</template> <template slot-scope="scope">{{scope.row.platform | formatPlatform}}</template>
</el-table-column> </el-table-column>
<!-- 显示有效期的表格列使用日期格式化等过滤器 -->
<el-table-column label="有效期" width="180" align="center"> <el-table-column label="有效期" width="180" align="center">
<template slot-scope="scope">{{scope.row.startTime|formatDate}}{{scope.row.endTime|formatDate}}</template> <template slot-scope="scope">{{scope.row.startTime|formatDate}}{{scope.row.endTime|formatDate}}</template>
</el-table-column> </el-table-column>
<!-- 显示状态的表格列使用过滤器根据结束时间判断并格式化状态 -->
<el-table-column label="状态" width="100" align="center"> <el-table-column label="状态" width="100" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatStatus}}</template> <template slot-scope="scope">{{scope.row.endTime | formatStatus}}</template>
</el-table-column> </el-table-column>
<!-- 显示操作按钮的表格列 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 查看按钮绑定点击事件 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleView(scope.$index, scope.row)">查看</el-button> @click="handleView(scope.$index, scope.row)">查看</el-button>
<!-- 编辑按钮绑定点击事件 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleUpdate(scope.$index, scope.row)"> @click="handleUpdate(scope.$index, scope.row)">
编辑</el-button> 编辑</el-button>
<!-- 删除按钮绑定点击事件 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除</el-button> @click="handleDelete(scope.$index, scope.row)">删除</el-button>
@ -90,7 +120,9 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 分页组件的容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置背景各类事件绑定页面尺寸等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -105,147 +137,176 @@
</div> </div>
</template> </template>
<script> <script>
import {fetchList,deleteCoupon} from '@/api/coupon'; // '@/api/coupon'
import {formatDate} from '@/utils/date'; import {fetchList, deleteCoupon} from '@/api/coupon';
const defaultListQuery = { // '@/utils/date'formatDate
pageNum: 1, import {formatDate} from '@/utils/date';
pageSize: 10,
name: null, //
type: null const defaultListQuery = {
}; pageNum: 1,
const defaultTypeOptions=[ pageSize: 10,
{ name: null,
label: '全场赠券', type: null
value: 0 };
//
const defaultTypeOptions = [
{
label: '全场赠券',
value: 0
},
{
label: '会员赠券',
value: 1
},
{
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
export default {
name: 'couponList',
data() {
return {
//
listQuery: Object.assign({}, defaultListQuery),
//
typeOptions: Object.assign({}, defaultTypeOptions),
// null
list: null,
// null
total: null,
// false
listLoading: false,
//
multipleSelection: []
}
},
created() {
//
this.getList();
},
filters: {
//
formatType(type) {
for (let i = 0; i < defaultTypeOptions.length; i++) {
if (type === defaultTypeOptions[i].value) {
return defaultTypeOptions[i].label;
}
}
return '';
},
// 使
formatUseType(useType) {
if (useType === 0) {
return '全场通用';
} else if (useType === 1) {
return '指定分类';
} else {
return '指定商品';
}
}, },
{ //
label: '会员赠券', formatPlatform(platform) {
value: 1 if (platform === 1) {
return '移动平台';
} else if (platform === 2) {
return 'PC平台';
} else {
return '全平台';
}
}, },
{ //
label: '购物赠券', formatDate(time) {
value: 2 if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
}, },
{ //
label: '注册赠券', formatStatus(endTime) {
value: 3 let now = new Date().getTime();
} let endDate = new Date(endTime);
]; if (endDate > now) {
export default { return '未过期'
name:'couponList', } else {
data() { return '已过期';
return {
listQuery:Object.assign({},defaultListQuery),
typeOptions:Object.assign({},defaultTypeOptions),
list:null,
total:null,
listLoading:false,
multipleSelection:[]
} }
}
},
methods: {
//
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
}, },
created(){ //
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters:{ //
formatType(type){ handleSelectionChange(val) {
for(let i=0;i<defaultTypeOptions.length;i++){ this.multipleSelection = val;
if(type===defaultTypeOptions[i].value){
return defaultTypeOptions[i].label;
}
}
return '';
},
formatUseType(useType){
if(useType===0){
return '全场通用';
}else if(useType===1){
return '指定分类';
}else{
return '指定商品';
}
},
formatPlatform(platform){
if(platform===1){
return '移动平台';
}else if(platform===2){
return 'PC平台';
}else{
return '全平台';
}
},
formatDate(time){
if(time==null||time===''){
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
},
formatStatus(endTime){
let now = new Date().getTime();
let endDate = new Date(endTime);
if(endDate>now){
return '未过期'
}else{
return '已过期';
}
}
}, },
methods:{ //
handleResetSearch() { handleSizeChange(val) {
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery.pageNum = 1;
}, this.listQuery.pageSize = val;
handleSearchList() { this.getList();
this.listQuery.pageNum = 1; },
this.getList(); //
}, handleCurrentChange(val) {
handleSelectionChange(val){ this.listQuery.pageNum = val;
this.multipleSelection = val; this.getList();
}, },
handleSizeChange(val) { //
this.listQuery.pageNum = 1; handleAdd() {
this.listQuery.pageSize = val; this.$router.push({path: '/sms/addCoupon'})
this.getList(); },
}, // id
handleCurrentChange(val) { handleView(index, row) {
this.listQuery.pageNum = val; this.$router.push({path: '/sms/couponHistory', query: {id: row.id}})
this.getList(); },
}, // id
handleAdd(){ handleUpdate(index, row) {
this.$router.push({path: '/sms/addCoupon'}) this.$router.push({path: '/sms/updateCoupon', query: {id: row.id}})
}, },
handleView(index, row) { //
this.$router.push({path: '/sms/couponHistory', query: {id: row.id}}) handleDelete(index, row) {
}, this.$confirm('是否进行删除操作?', '提示', {
handleUpdate(index, row) { confirmButtonText: '确定',
this.$router.push({path: '/sms/updateCoupon', query: {id: row.id}}) cancelButtonText: '取消',
}, type: 'warning'
handleDelete(index, row) { }).then(() => {
this.$confirm('是否进行删除操作?', '提示', { deleteCoupon(row.id).then(response => {
confirmButtonText: '确定', this.$message({
cancelButtonText: '取消', type: 'success',
type: 'warning' message: '删除成功!'
}).then(() => {
deleteCoupon(row.id).then(response=>{
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
}); });
}) this.getList();
},
getList(){
this.listLoading=true;
fetchList(this.listQuery).then(response=>{
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
}); });
} })
},
// true
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
} }
} }
}
</script> </script>
<style scoped> <style scoped>
<!-- scoped属性使样式仅作用于当前组件.input-width类设置元素宽度为203px -->
.input-width { .input-width {
width: 203px; width: 203px;
} }

@ -1,14 +1,21 @@
<template>  <template>
<!-- 在模板中使用了coupon-detail组件并传递isEdit属性值为true可能用于告知该组件当前处于编辑模式 -->
<coupon-detail :isEdit="true"></coupon-detail> <coupon-detail :isEdit="true"></coupon-detail>
</template> </template>
<script> <script>
import CouponDetail from './components/CouponDetail' // './components/CouponDetail'CouponDetail
export default { import CouponDetail from './components/CouponDetail';
name: 'updateCoupon', export default {
components: { CouponDetail } // updateCoupon
} name: 'updateCoupon',
// CouponDetail使使
components: { CouponDetail }
}
</script> </script>
<style scoped> <style scoped>
<!-- 带有scoped属性的style标签里面样式仅作用于当前组件目前为空 -->
</style> </style>

@ -1,9 +1,14 @@
<template>  <template>
<!-- 整个页面的外层容器用于对内部各部分内容进行整体布局 -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索区域的卡片容器设置了无阴影效果 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 显示搜索图标用于提示此处可进行搜索操作 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索文字明确此处功能 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 用于触发查询搜索操作的按钮设置了按钮样式类型为主要按钮绑定了点击事件handleSearchList -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 用于触发重置筛选条件操作的按钮设置了按钮样式与右侧有一定间距绑定了点击事件handleResetSearch -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,42 +25,75 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 行内表单用于设置筛选条件绑定了数据模型listQuery设置了表单尺寸和标签宽度 -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 对应活动名称输入框的表单项 -->
<el-form-item label="活动名称:"> <el-form-item label="活动名称:">
<!-- 输入框双向绑定listQuery.keyword数据设置了类名占位提示以及可清除内容的属性 -->
<el-input v-model="listQuery.keyword" class="input-width" placeholder="活动名称" clearable></el-input> <el-input v-model="listQuery.keyword" class="input-width" placeholder="活动名称" clearable></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作区域的卡片容器同样设置了无阴影效果 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<span>数据列表</span> <span>数据列表</span>
<!-- 用于触发添加活动操作的按钮设置了按钮尺寸类名绑定了点击事件handleAdd -->
<el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加活动</el-button> <el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加活动</el-button>
<!-- 用于触发查看秒杀时间段列表操作的按钮设置了按钮尺寸类名绑定了点击事件handleShowSessionList -->
<el-button size="mini" class="btn-add" @click="handleShowSessionList()"></el-button> <el-button size="mini" class="btn-add" @click="handleShowSessionList()"></el-button>
</el-card> </el-card>
<!-- 放置数据表格的容器 -->
<div class="table-container"> <div class="table-container">
<!-- 数据表格组件绑定了数据list设置了宽度加载状态以及边框等属性 -->
<el-table ref="flashTable" <el-table ref="flashTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 显示选择框的表格列用于多选操作设置了宽度和对齐方式 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 显示编号的表格列设置了宽度和对齐方式 -->
<el-table-column label="编号" width="100" align="center"> <el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的id字段内容 -->
{{scope.row.id}}
</template>
</el-table-column> </el-table-column>
<!-- 显示活动标题的表格列内容居中对齐 -->
<el-table-column label="活动标题" align="center"> <el-table-column label="活动标题" align="center">
<template slot-scope="scope">{{scope.row.title}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的title字段内容 -->
{{scope.row.title}}
</template>
</el-table-column> </el-table-column>
<!-- 显示活动状态的表格列设置了宽度和对齐方式使用了过滤器formatActiveStatus来格式化显示内容 -->
<el-table-column label="活动状态" width="140" align="center"> <el-table-column label="活动状态" width="140" align="center">
<template slot-scope="scope">{{scope.row |formatActiveStatus}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用过滤器对对应行数据进行格式化后显示 -->
{{scope.row | formatActiveStatus}}
</template>
</el-table-column> </el-table-column>
<!-- 显示开始时间的表格列设置了宽度和对齐方式使用了日期格式化过滤器formatDate -->
<el-table-column label="开始时间" width="140" align="center"> <el-table-column label="开始时间" width="140" align="center">
<template slot-scope="scope">{{scope.row.startDate | formatDate}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用日期格式化过滤器对对应行数据中的时间进行格式化后显示 -->
{{scope.row.startDate | formatDate}}
</template>
</el-table-column> </el-table-column>
<!-- 显示结束时间的表格列设置了宽度和对齐方式同样使用了日期格式化过滤器formatDate -->
<el-table-column label="结束时间" width="140" align="center"> <el-table-column label="结束时间" width="140" align="center">
<template slot-scope="scope">{{scope.row.endDate | formatDate}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用日期格式化过滤器对对应行数据中的时间进行格式化后显示 -->
{{scope.row.endDate | formatDate}}
</template>
</el-table-column> </el-table-column>
<!-- 显示上线/下线操作的表格列设置了宽度和对齐方式里面包含一个开关组件 -->
<el-table-column label="上线/下线" width="200" align="center"> <el-table-column label="上线/下线" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 开关组件用于切换上线/下线状态绑定了状态改变的事件handleStatusChange设置了激活值和未激活值双向绑定对应行数据中的status字段 -->
<el-switch <el-switch
@change="handleStatusChange(scope.$index, scope.row)" @change="handleStatusChange(scope.$index, scope.row)"
:active-value="1" :active-value="1"
@ -63,17 +102,21 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 显示操作按钮的表格列设置了宽度和对齐方式 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 用于触发设置商品操作的按钮设置了按钮尺寸类型为文本按钮绑定了点击事件handleSelectSession -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleSelectSession(scope.$index, scope.row)">设置商品 @click="handleSelectSession(scope.$index, scope.row)">设置商品
</el-button> </el-button>
<!-- 用于触发编辑操作的按钮设置了按钮尺寸类型为文本按钮绑定了点击事件handleUpdate -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleUpdate(scope.$index, scope.row)"> @click="handleUpdate(scope.$index, scope.row)">
编辑 编辑
</el-button> </el-button>
<!-- 用于触发删除操作的按钮设置了按钮尺寸类型为文本按钮绑定了点击事件handleDelete -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除 @click="handleDelete(scope.$index, scope.row)">删除
@ -82,7 +125,10 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 分页组件的容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置了背景显示页面尺寸改变和当前页码改变的事件绑定以及布局当前页码每页显示数量可选的页面尺寸和数据总条数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -94,16 +140,22 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 弹出对话框组件用于添加活动的相关操作设置了标题对话框显示状态的双向绑定以及宽度属性 -->
<el-dialog <el-dialog
title="添加活动" title="添加活动"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
width="40%"> width="40%">
<!-- 表单组件用于在对话框内收集添加活动的相关信息绑定了数据模型flashPromotion设置了表单引用标签宽度和尺寸等属性 -->
<el-form :model="flashPromotion" <el-form :model="flashPromotion"
ref="flashPromotionForm" ref="flashPromotionForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- 对应活动标题输入框的表单项 -->
<el-form-item label="活动标题:"> <el-form-item label="活动标题:">
<!-- 输入框双向绑定flashPromotion.title数据设置了宽度 -->
<el-input v-model="flashPromotion.title" style="width: 250px"></el-input> <el-input v-model="flashPromotion.title" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 对应开始时间选择框的表单项使用了日期选择器组件 -->
<el-form-item label="开始时间:"> <el-form-item label="开始时间:">
<el-date-picker <el-date-picker
v-model="flashPromotion.startDate" v-model="flashPromotion.startDate"
@ -111,6 +163,7 @@
placeholder="请选择时间"> placeholder="请选择时间">
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
<!-- 对应结束时间选择框的表单项同样使用了日期选择器组件 -->
<el-form-item label="结束时间:"> <el-form-item label="结束时间:">
<el-date-picker <el-date-picker
v-model="flashPromotion.endDate" v-model="flashPromotion.endDate"
@ -118,178 +171,221 @@
placeholder="请选择时间"> placeholder="请选择时间">
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
<!-- 对应上线/下线选择的表单项使用了单选按钮组组件 -->
<el-form-item label="上线/下线"> <el-form-item label="上线/下线">
<el-radio-group v-model="flashPromotion.status"> <el-radio-group v-model="flashPromotion.status">
<!-- 上线单选按钮选项 -->
<el-radio :label="1">上线</el-radio> <el-radio :label="1">上线</el-radio>
<!-- 下线单选按钮选项 -->
<el-radio :label="0">下线</el-radio> <el-radio :label="0">下线</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 对话框底部的操作按钮区域使用了插槽footer -->
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="small"> </el-button> <!-- 取消按钮点击可关闭对话框设置了按钮尺寸 -->
<el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button> <el-button @click="dialogVisible = false" size="small"> </el-button>
</span> <!-- 确定按钮点击可触发确认添加活动的相关逻辑设置了按钮类型为主要按钮尺寸为小尺寸 -->
<el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button>
</span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import {fetchList, updateStatus, deleteFlash, createFlash, updateFlash} from '@/api/flash'; // '@/api/flash'
import {formatDate} from '@/utils/date'; import {fetchList, updateStatus, deleteFlash, createFlash, updateFlash} from '@/api/flash';
// '@/utils/date'formatDate
import {formatDate} from '@/utils/date';
const defaultListQuery = { //
pageNum: 1, const defaultListQuery = {
pageSize: 5, pageNum: 1,
keyword: null pageSize: 5,
}; keyword: null
const defaultFlashPromotion = { };
id: null, //
title: null, const defaultFlashPromotion = {
startDate: null, id: null,
endDate: null, title: null,
status: 0 startDate: null,
}; endDate: null,
export default { status: 0
name: 'flashPromotionList', };
data() {
return { export default {
listQuery: Object.assign({}, defaultListQuery), name: 'flashPromotionList',
list: null, data() {
total: null, return {
listLoading: false, // defaultListQuery
dialogVisible: false, listQuery: Object.assign({}, defaultListQuery),
flashPromotion: Object.assign({}, defaultFlashPromotion), // null
isEdit: false list: null,
// null
total: null,
// falsetrue
listLoading: false,
// /false
dialogVisible: false,
// defaultFlashPromotion
flashPromotion: Object.assign({}, defaultFlashPromotion),
// truefalsefalse
isEdit: false
}
},
created() {
//
this.getList();
},
filters: {
//
formatActiveStatus(row) {
//
let nowDate = new Date();
//
let startDate = new Date(row.startDate);
//
let endDate = new Date(row.endDate);
//
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
return '活动进行中';
}
//
else if (nowDate.getTime() > endDate.getTime()) {
return '活动已结束';
}
//
else {
return '活动未开始';
} }
}, },
created() { // 'N/A'
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
//
let date = new Date(time);
// formatDate 'yyyy-MM-dd'
return formatDate(date, 'yyyy-MM-dd')
}
},
methods: {
// 便
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// 1
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters: { // 1
formatActiveStatus(row) { handleSizeChange(val) {
let nowDate = new Date(); this.listQuery.pageNum = 1;
let startDate = new Date(row.startDate); this.listQuery.pageSize = val;
let endDate = new Date(row.endDate); this.getList();
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
return '活动进行中';
} else if (nowDate.getTime() > endDate.getTime()) {
return '活动已结束';
} else {
return '活动未开始';
}
},
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
}
}, },
methods: { //
handleResetSearch() { handleCurrentChange(val) {
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery.pageNum = val;
}, this.getList();
handleSearchList() { },
this.listQuery.pageNum = 1; // true
this.getList(); handleAdd() {
}, this.dialogVisible = true;
handleSizeChange(val) { this.isEdit = false;
this.listQuery.pageNum = 1; this.flashPromotion = Object.assign({}, defaultFlashPromotion);
this.listQuery.pageSize = val; },
this.getList(); // '/sms/flashSession'
}, handleShowSessionList() {
handleCurrentChange(val) { this.$router.push({path: '/sms/flashSession'})
this.listQuery.pageNum = val; },
this.getList(); //
}, handleStatusChange(index, row) {
handleAdd() { this.$confirm('是否要修改该状态?', '提示', {
this.dialogVisible = true; confirmButtonText: '确定',
this.isEdit = false; cancelButtonText: '取消',
this.flashPromotion = Object.assign({},defaultFlashPromotion); type: 'warning'
}, }).then(() => {
handleShowSessionList() { updateStatus(row.id, {status: row.status}).then(response => {
this.$router.push({path: '/sms/flashSession'}) this.$message({
}, type: 'success',
handleStatusChange(index, row) { message: '修改成功!'
this.$confirm('是否要修改该状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateStatus(row.id, {status: row.status}).then(response => {
this.$message({
type: 'success',
message: '修改成功!'
});
}); });
}).catch(() => { });
}).catch(() => {
this.$message({
type: 'info',
message: '取消修改'
});
this.getList();
});
},
//
handleDelete(index, row) {
this.$confirm('是否要删除该活动?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteFlash(row.id).then(response => {
this.$message({ this.$message({
type: 'info', type: 'success',
message: '取消修改' message: '删除成功!'
}); });
this.getList(); this.getList();
}); });
}, });
handleDelete(index, row) { },
this.$confirm('是否要删除该活动?', '提示', { // true便
confirmButtonText: '确定', handleUpdate(index, row) {
cancelButtonText: '取消', this.dialogVisible = true;
type: 'warning' this.isEdit = true;
}).then(() => { this.flashPromotion = Object.assign({}, row);
deleteFlash(row.id).then(response => { },
//
handleDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateFlash(this.flashPromotion.id, this.flashPromotion).then(response => {
this.$message({ this.$message({
type: 'success', message: '修改成功!',
message: '删除成功!' type: 'success'
}); });
this.dialogVisible = false;
this.getList(); this.getList();
}); })
}); } else {
}, createFlash(this.flashPromotion).then(response => {
handleUpdate(index, row) { this.$message({
this.dialogVisible = true; message: '添加成功!',
this.isEdit = true; type: 'success'
this.flashPromotion = Object.assign({},row); });
}, this.dialogVisible = false;
handleDialogConfirm() { this.getList();
this.$confirm('是否要确认?', '提示', { })
confirmButtonText: '确定', }
cancelButtonText: '取消', })
type: 'warning' },
}).then(() => { // '/sms/selectSession' id
if (this.isEdit) { handleSelectSession(index, row) {
updateFlash(this.flashPromotion.id,this.flashPromotion).then(response => { this.$router.push({path: '/sms/selectSession', query: {flashPromotionId: row.id}})
this.$message({ },
message: '修改成功!', // truefalse
type: 'success' getList() {
}); this.listLoading = true;
this.dialogVisible =false; fetchList(this.listQuery).then(response => {
this.getList(); this.listLoading = false;
}) this.list = response.data.list;
} else { this.total = response.data.total;
createFlash(this.flashPromotion).then(response => { });
this.$message({
message: '添加成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
}
})
},
handleSelectSession(index,row){
this.$router.push({path:'/sms/selectSession',query:{flashPromotionId:row.id}})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
}
} }
} }
}
</script> </script>
<style></style> <style></style>

@ -1,52 +1,95 @@
<template>  <template>
<!-- 整个页面的外层容器用于对内部各部分内容进行整体布局 -->
<div class="app-container"> <div class="app-container">
<!-- 操作区域的卡片容器设置了无阴影效果 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<span>数据列表</span> <span>数据列表</span>
<!-- 用于触发添加操作的按钮设置了按钮尺寸类名绑定了点击事件handleSelectProduct并且与左侧有一定间距 -->
<el-button size="mini" class="btn-add" @click="handleSelectProduct()" style="margin-left: 20px">添加</el-button> <el-button size="mini" class="btn-add" @click="handleSelectProduct()" style="margin-left: 20px">添加</el-button>
</el-card> </el-card>
<!-- 放置数据表格的容器用于展示商品相关数据列表 -->
<div class="table-container"> <div class="table-container">
<!-- 数据表格组件绑定了数据list设置了表格引用宽度加载状态以及边框等属性 -->
<el-table ref="productRelationTable" <el-table ref="productRelationTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 显示编号的表格列设置了宽度和对齐方式 -->
<el-table-column label="编号" width="100" align="center"> <el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的id字段内容 -->
{{scope.row.id}}
</template>
</el-table-column> </el-table-column>
<!-- 显示商品名称的表格列内容居中对齐显示的是每行数据中关联商品对象里的name字段 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.product.name}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中关联商品对象里的name字段内容 -->
{{scope.row.product.name}}
</template>
</el-table-column> </el-table-column>
<!-- 显示货号的表格列设置了宽度和对齐方式展示格式为NO.加上商品的货号 -->
<el-table-column label="货号" width="140" align="center"> <el-table-column label="货号" width="140" align="center">
<template slot-scope="scope">NO.{{scope.row.product.productSn}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内按照特定格式显示对应行数据中关联商品对象里的productSn字段内容 -->
NO.{{scope.row.product.productSn}}
</template>
</el-table-column> </el-table-column>
<!-- 显示商品价格的表格列设置了宽度和对齐方式展示格式为加上商品价格 -->
<el-table-column label="商品价格" width="100" align="center"> <el-table-column label="商品价格" width="100" align="center">
<template slot-scope="scope">{{scope.row.product.price}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内按照特定格式显示对应行数据中关联商品对象里的price字段内容 -->
{{scope.row.product.price}}
</template>
</el-table-column> </el-table-column>
<!-- 显示剩余数量的表格列设置了宽度和对齐方式直接显示商品的剩余数量 -->
<el-table-column label="剩余数量" width="100" align="center"> <el-table-column label="剩余数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.product.stock}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中关联商品对象里的stock字段内容 -->
{{scope.row.product.stock}}
</template>
</el-table-column> </el-table-column>
<!-- 显示秒杀价格的表格列设置了宽度和对齐方式根据秒杀价格是否为空进行不同展示若不为空则显示加上秒杀价格 -->
<el-table-column label="秒杀价格" width="100" align="center"> <el-table-column label="秒杀价格" width="100" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 使用v-if指令判断秒杀价格是否不为空如果是则按照特定格式显示 -->
<p v-if="scope.row.flashPromotionPrice!==null"> <p v-if="scope.row.flashPromotionPrice!==null">
{{scope.row.flashPromotionPrice}} {{scope.row.flashPromotionPrice}}
</p> </p>
</template> </template>
</el-table-column> </el-table-column>
<!-- 显示秒杀数量的表格列设置了宽度和对齐方式直接显示商品的秒杀数量 -->
<el-table-column label="秒杀数量" width="100" align="center"> <el-table-column label="秒杀数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.flashPromotionCount}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的flashPromotionCount字段内容 -->
{{scope.row.flashPromotionCount}}
</template>
</el-table-column> </el-table-column>
<!-- 显示限购数量的表格列设置了宽度和对齐方式直接显示商品的限购数量 -->
<el-table-column label="限购数量" width="100" align="center"> <el-table-column label="限购数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.flashPromotionLimit}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的flashPromotionLimit字段内容 -->
{{scope.row.flashPromotionLimit}}
</template>
</el-table-column> </el-table-column>
<!-- 显示排序的表格列设置了宽度和对齐方式直接显示商品的排序值 -->
<el-table-column label="排序" width="100" align="center"> <el-table-column label="排序" width="100" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的sort字段内容 -->
{{scope.row.sort}}
</template>
</el-table-column> </el-table-column>
<!-- 显示操作按钮的表格列设置了宽度和对齐方式 -->
<el-table-column label="操作" width="100" align="center"> <el-table-column label="操作" width="100" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 用于触发编辑操作的按钮设置了按钮尺寸类型为文本按钮绑定了点击事件handleUpdate -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑 @click="handleUpdate(scope.$index, scope.row)">编辑
</el-button> </el-button>
<!-- 用于触发删除操作的按钮设置了按钮尺寸类型为文本按钮绑定了点击事件handleDelete -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除 @click="handleDelete(scope.$index, scope.row)">删除
@ -55,7 +98,10 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 分页组件的容器用于对商品数据列表进行分页操作 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置了背景显示页面尺寸改变和当前页码改变的事件绑定以及布局当前页码每页显示数量可选的页面尺寸和数据总条数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -67,27 +113,47 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 弹出对话框组件用于选择商品操作设置了标题对话框显示状态的双向绑定以及宽度属性 -->
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%"> <el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<!-- 输入框组件用于在对话框内输入关键词进行商品搜索双向绑定了dialogData.listQuery.keyword数据设置了宽度外边距尺寸以及占位提示等属性并且包含一个搜索图标按钮 -->
<el-input v-model="dialogData.listQuery.keyword" <el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px" style="width: 250px;margin-bottom: 20px"
size="small" size="small"
placeholder="商品名称搜索"> placeholder="商品名称搜索">
<!-- 搜索图标按钮放置在输入框的尾部点击可触发handleSelectSearch事件 -->
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button> <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input> </el-input>
<!-- 数据表格组件用于在对话框内展示搜索到的商品列表绑定了数据dialogData.list并设置了选择改变的事件绑定以及边框属性 -->
<el-table :data="dialogData.list" <el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border> @selection-change="handleDialogSelectionChange" border>
<!-- 显示选择框的表格列用于多选操作设置了宽度和对齐方式 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 显示商品名称的表格列内容居中对齐直接显示商品的名称 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内显示对应行数据中的name字段内容 -->
{{scope.row.name}}
</template>
</el-table-column> </el-table-column>
<!-- 显示货号的表格列设置了宽度和对齐方式展示格式为NO.加上商品的货号 -->
<el-table-column label="货号" width="160" align="center"> <el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内按照特定格式显示对应行数据中的productSn字段内容 -->
NO.{{scope.row.productSn}}
</template>
</el-table-column> </el-table-column>
<!-- 显示价格的表格列设置了宽度和对齐方式展示格式为加上商品价格 -->
<el-table-column label="价格" width="120" align="center"> <el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内按照特定格式显示对应行数据中的price字段内容 -->
{{scope.row.price}}
</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 分页组件的容器用于对对话框内的商品列表进行分页操作 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- 分页组件设置了背景显示页面尺寸改变和当前页码改变的事件绑定以及布局当前页码每页显示数量可选的页面尺寸和数据总条数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleDialogSizeChange" @size-change="handleDialogSizeChange"
@ -99,213 +165,266 @@
:total="dialogData.total"> :total="dialogData.total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 用于清除浮动确保后续元素布局正常 -->
<div style="clear: both;"></div> <div style="clear: both;"></div>
<!-- 对话框底部的操作按钮区域使用了插槽footer -->
<div slot="footer"> <div slot="footer">
<!-- 取消按钮点击可关闭对话框设置了按钮尺寸 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button> <el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 确定按钮点击可触发确认选择商品的相关逻辑设置了按钮类型为主要按钮尺寸为小尺寸 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button> <el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- 弹出对话框组件用于编辑秒杀商品信息操作设置了标题对话框显示状态的双向绑定以及宽度属性 -->
<el-dialog title="编辑秒杀商品信息" <el-dialog title="编辑秒杀商品信息"
:visible.sync="editDialogVisible" :visible.sync="editDialogVisible"
width="40%"> width="40%">
<!-- 表单组件用于在对话框内展示和编辑秒杀商品的相关信息绑定了数据模型flashProductRelation设置了表单引用标签宽度和尺寸等属性 -->
<el-form :model="flashProductRelation" <el-form :model="flashProductRelation"
ref="flashProductRelationForm" ref="flashProductRelationForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- 对应商品名称展示的表单项此处直接展示商品名称不可编辑 -->
<el-form-item label="商品名称:"> <el-form-item label="商品名称:">
<span>{{flashProductRelation.product.name}}</span> <span>{{flashProductRelation.product.name}}</span>
</el-form-item> </el-form-item>
<!-- 对应货号展示的表单项此处直接展示货号不可编辑 -->
<el-form-item label="货号:"> <el-form-item label="货号:">
<span>NO.{{flashProductRelation.product.productSn}}</span> <span>NO.{{flashProductRelation.product.productSn}}</span>
</el-form-item> </el-form-item>
<!-- 对应商品价格展示的表单项此处直接展示商品价格不可编辑 -->
<el-form-item label="商品价格:"> <el-form-item label="商品价格:">
<span>{{flashProductRelation.product.price}}</span> <span>{{flashProductRelation.product.price}}</span>
</el-form-item> </el-form-item>
<!-- 对应秒杀价格输入框的表单项使用输入框组件双向绑定flashProductRelation.flashPromotionPrice数据设置了类名并在输入框头部添加符号 -->
<el-form-item label="秒杀价格:"> <el-form-item label="秒杀价格:">
<el-input v-model="flashProductRelation.flashPromotionPrice" class="input-width"> <el-input v-model="flashProductRelation.flashPromotionPrice" class="input-width">
<template slot="prepend"></template> <template slot="prepend"></template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- 对应剩余数量展示的表单项此处直接展示剩余数量不可编辑 -->
<el-form-item label="剩余数量:"> <el-form-item label="剩余数量:">
<span>{{flashProductRelation.product.stock}}</span> <span>{{flashProductRelation.product.stock}}</span>
</el-form-item> </el-form-item>
<!-- 对应秒杀数量输入框的表单项使用输入框组件双向绑定flashProductRelation.flashPromotionCount数据设置了类名 -->
<el-form-item label="秒杀数量:"> <el-form-item label="秒杀数量:">
<el-input v-model="flashProductRelation.flashPromotionCount" class="input-width"></el-input> <el-input v-model="flashProductRelation.flashPromotionCount" class="input-width"></el-input>
</el-form-item> </el-form-item>
<!-- 对应限购数量输入框的表单项使用输入框组件双向绑定flashProductRelation.flashPromotionLimit数据设置了类名 -->
<el-form-item label="限购数量:"> <el-form-item label="限购数量:">
<el-input v-model="flashProductRelation.flashPromotionLimit" class="input-width"></el-input> <el-input v-model="flashProductRelation.flashPromotionLimit" class="input-width"></el-input>
</el-form-item> </el-form-item>
<!-- 对应排序输入框的表单项使用输入框组件双向绑定flashProductRelation.sort数据设置了类名 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<el-input v-model="flashProductRelation.sort" class="input-width"></el-input> <el-input v-model="flashProductRelation.sort" class="input-width"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 对话框底部的操作按钮区域使用了插槽footer -->
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="editDialogVisible = false" size="small"> </el-button> <!-- 取消按钮点击可关闭对话框设置了按钮尺寸 -->
<el-button type="primary" @click="handleEditDialogConfirm()" size="small"> </el-button> <el-button @click="editDialogVisible = false" size="small"> </el-button>
</span> <!-- 确定按钮点击可触发确认编辑秒杀商品信息的相关逻辑设置了按钮类型为主要按钮尺寸为小尺寸 -->
<el-button type="primary" @click="handleEditDialogConfirm()" size="small"> </el-button>
</span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import {fetchList,createFlashProductRelation,deleteFlashProductRelation,updateFlashProductRelation} from '@/api/flashProductRelation'; // '@/api/flashProductRelation'
import {fetchList as fetchProductList} from '@/api/product'; import {fetchList, createFlashProductRelation, deleteFlashProductRelation, updateFlashProductRelation} from '@/api/flashProductRelation';
const defaultListQuery = { // '@/api/product''fetchProductList'
pageNum: 1, import {fetchList as fetchProductList} from '@/api/product';
pageSize: 5,
flashPromotionId: null, // IDID
flashPromotionSessionId: null const defaultListQuery = {
}; pageNum: 1,
export default { pageSize: 5,
name:'flashPromotionProductRelationList', flashPromotionId: null,
data() { flashPromotionSessionId: null
return { };
listQuery: Object.assign({}, defaultListQuery),
export default {
name: 'flashPromotionProductRelationList',
data() {
return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// null
list: null,
// null
total: null,
// falsetrue
listLoading: false,
// /false
dialogVisible: false,
// false
selectDialogVisible: false,
//
dialogData: {
list: null, list: null,
total: null, total: null,
listLoading: false, multipleSelection: [],
dialogVisible: false, listQuery: {
selectDialogVisible:false, keyword: null,
dialogData:{ pageNum: 1,
list: null, pageSize: 5
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
pageNum: 1,
pageSize: 5
}
},
editDialogVisible:false,
flashProductRelation:{
product:{}
} }
},
// false
editDialogVisible: false,
//
flashProductRelation: {
product: {}
} }
}
},
created() {
// ID
this.listQuery.flashPromotionId = this.$route.query.flashPromotionId;
// ID
this.listQuery.flashPromotionSessionId = this.$route.query.flashPromotionSessionId;
//
this.getList();
},
methods: {
//
handleSizeChange(val) {
this.listQuery.pageNum = 1; //1
this.listQuery.pageSize = val;
this.getList(); //
}, },
created(){ //
this.listQuery.flashPromotionId=this.$route.query.flashPromotionId; handleCurrentChange(val) {
this.listQuery.flashPromotionSessionId=this.$route.query.flashPromotionSessionId; this.listQuery.pageNum = val;
this.getList(); this.getList(); //
}, },
methods:{ //
handleSizeChange(val) { handleSelectProduct() {
this.listQuery.pageNum = 1; this.selectDialogVisible = true; //true
this.listQuery.pageSize = val; this.getDialogList(); //
this.getList(); },
}, //
handleCurrentChange(val) { handleUpdate(index, row) {
this.listQuery.pageNum = val; this.editDialogVisible = true; //true
this.getList(); this.flashProductRelation = Object.assign({}, row); //便
}, },
handleSelectProduct(){ //
this.selectDialogVisible=true; handleDelete(index, row) {
this.getDialogList(); this.$confirm('是否要删除该商品?', '提示', {
}, confirmButtonText: '确定',
handleUpdate(index,row){ cancelButtonText: '取消',
this.editDialogVisible = true; type: 'warning'
this.flashProductRelation = Object.assign({},row); }).then(() => { //
}, deleteFlashProductRelation(row.id).then(response => {
handleDelete(index,row){ this.$message({
this.$confirm('是否要删除该商品?', '提示', { type: 'success',
confirmButtonText: '确定', message: '删除成功!'
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteFlashProductRelation(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
}); });
this.getList(); //
}); });
}, });
handleSelectSearch(){ },
this.getDialogList(); //
}, handleSelectSearch() {
handleDialogSizeChange(val) { this.getDialogList(); //
this.dialogData.listQuery.pageNum = 1; },
this.dialogData.listQuery.pageSize = val; //
this.getDialogList(); handleDialogSizeChange(val) {
}, this.dialogData.listQuery.pageNum = 1; //1
handleDialogCurrentChange(val) { this.dialogData.listQuery.pageSize = val; //
this.dialogData.listQuery.pageNum = val; this.getDialogList(); //
this.getDialogList(); },
}, //
handleDialogSelectionChange(val){ handleDialogCurrentChange(val) {
this.dialogData.multipleSelection = val; this.dialogData.listQuery.pageNum = val; //
}, this.getDialogList(); //
handleSelectDialogConfirm(){ },
if (this.dialogData.multipleSelection < 1) { //
handleDialogSelectionChange(val) {
this.dialogData.multipleSelection = val; //
},
//
handleSelectDialogConfirm() {
if (this.dialogData.multipleSelection.length < 1) { //
this.$message({
message: '请选择一条记录', //
type: 'warning',
duration: 1000
});
return;
}
let selectProducts = []; //
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectProducts.push({
productId: this.dialogData.multipleSelection[i].id,
flashPromotionId: this.listQuery.flashPromotionId,
flashPromotionSessionId: this.listQuery.flashPromotionSessionId
});
}
this.$confirm('是否要进行添加操作?', '提示', { //
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => { //
createFlashProductRelation(selectProducts).then(response => {
this.selectDialogVisible = false;
this.dialogData.multipleSelection = [];
this.getList();
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '添加成功!' //
duration: 1000
});
return;
}
let selectProducts = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectProducts.push({
productId:this.dialogData.multipleSelection[i].id,
flashPromotionId:this.listQuery.flashPromotionId,
flashPromotionSessionId:this.listQuery.flashPromotionSessionId
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createFlashProductRelation(selectProducts).then(response=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
}); });
}); });
}, });
handleEditDialogConfirm(){ },
this.$confirm('是否要确认?', '提示', { //
confirmButtonText: '确定', handleEditDialogConfirm() {
cancelButtonText: '取消', this.$confirm('是否要确认?', '提示', { //
type: 'warning' confirmButtonText: '确定',
}).then(() => { cancelButtonText: '取消',
updateFlashProductRelation(this.flashProductRelation.id,this.flashProductRelation).then(response => { type: 'warning'
this.$message({ }).then(() => { //
message: '修改成功!', updateFlashProductRelation(this.flashProductRelation.id, this.flashProductRelation).then(response => {
type: 'success' this.$message({
}); message: '修改成功!', //
this.editDialogVisible =false; type: 'success'
this.getList(); });
}) this.editDialogVisible = false;
}) this.getList();
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
},
getDialogList(){
fetchProductList(this.dialogData.listQuery).then(response=>{
this.dialogData.list=response.data.list;
this.dialogData.total=response.data.total;
}) })
} })
},
//
getList() {
this.listLoading = true; //true
fetchList(this.listQuery).then(response => { //
this.listLoading = false; //false
this.list = response.data.list; //
this.total = response.data.total;
});
},
//
getDialogList() {
fetchProductList(this.dialogData.listQuery).then(response => { //
this.dialogData.list = response.data.list; //
this.dialogData.total = response.data.total;
})
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.operate-container{ <!-- 使用带有scoped属性的style标签表示这里定义的样式仅作用于当前组件内的元素避免样式污染其他组件 -->
margin-top: 0; <!-- 定义类名为operate-container的样式规则 -->
} .operate-container{
.input-width{ <!-- 设置该类所应用元素的上外边距为0用于控制其与上方元素的间距 -->
width: 200px; margin-top: 0;
} }
<!-- 定义类名为input-width的样式规则 -->
.input-width{
<!-- 设置该类所应用元素的宽度为200px通常可用于像输入框等需要统一宽度设置的表单元素 -->
width: 200px;
}
</style> </style>

@ -1,31 +1,60 @@
<template>  <template>
<!-- 整个页面的外层容器用于对内部各部分内容进行整体布局 -->
<div class="app-container"> <div class="app-container">
<!-- el-card组件用于创建一个卡片式的容器设置了无阴影效果并添加了"operate-container"类名通常可用于放置操作相关的元素或内容展示 -->
<el-card shadow="never" class="operate-container"> <el-card shadow="never" class="operate-container">
<!-- 显示一个图标此处使用的是element-ui提供的"el-icon-tickets"图标用于对下方数据列表进行某种示意比如表示和票务商品列表等相关 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 显示文字"数据列表"用于明确下方表格所展示数据的性质 -->
<span>数据列表</span> <span>数据列表</span>
</el-card> </el-card>
<!-- 放置数据表格的容器用于包裹下面的el-table组件使其在页面布局上更加规整 -->
<div class="table-container"> <div class="table-container">
<!-- el-table组件用于创建一个数据表格设置了表格引用为"selectSessionTable"绑定了数据"list"设置表格宽度为占满父容器100%根据"listLoading"的值来显示加载状态如加载动画等并添加了边框样式 -->
<el-table ref="selectSessionTable" <el-table ref="selectSessionTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- el-table-column组件用于定义表格中的列此列用于展示编号信息设置了列的宽度为100像素内容在单元格中居中对齐 -->
<el-table-column label="编号" width="100" align="center"> <el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内通过插值表达式显示对应行数据中的"id"字段内容即展示每一行数据的编号 -->
{{scope.row.id}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示秒杀时间段名称信息内容在单元格中居中对齐 -->
<el-table-column label="秒杀时间段名称" align="center"> <el-table-column label="秒杀时间段名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内通过插值表达式显示对应行数据中的"name"字段内容即展示每一行数据对应的秒杀时间段的名称 -->
{{scope.row.name}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示每日开始时间信息内容在单元格中居中对齐使用了名为"formatTime"的过滤器对时间数据进行格式化后再展示 -->
<el-table-column label="每日开始时间" align="center"> <el-table-column label="每日开始时间" align="center">
<template slot-scope="scope">{{scope.row.startTime | formatTime}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用"formatTime"过滤器对对应行数据中的"startTime"字段时间类型数据进行格式化处理后展示 -->
{{scope.row.startTime | formatTime}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示每日结束时间信息内容在单元格中居中对齐同样使用了名为"formatTime"的过滤器对时间数据进行格式化后再展示 -->
<el-table-column label="每日结束时间" align="center"> <el-table-column label="每日结束时间" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatTime}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用"formatTime"过滤器对对应行数据中的"endTime"字段时间类型数据进行格式化处理后展示 -->
{{scope.row.endTime | formatTime}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示商品数量信息内容在单元格中居中对齐直接展示对应行数据中的"productCount"字段内容即显示每个秒杀时间段对应的商品数量 -->
<el-table-column label="商品数量" align="center"> <el-table-column label="商品数量" align="center">
<template slot-scope="scope">{{scope.row.productCount}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内通过插值表达式显示对应行数据中的"productCount"字段内容即展示每一行数据对应的商品数量 -->
{{scope.row.productCount}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示操作按钮内容在单元格中居中对齐 -->
<el-table-column label="操作" align="center"> <el-table-column label="操作" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- el-button组件用于创建一个按钮设置了按钮尺寸为"mini"小型按钮按钮类型为"text"绑定了点击事件"handleShowRelation"点击按钮可触发相应的操作逻辑此处按钮显示的文字为"商品列表"可能点击后会跳转到展示对应秒杀时间段下商品列表的页面 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleShowRelation(scope.$index, scope.row)">商品列表 @click="handleShowRelation(scope.$index, scope.row)">商品列表
@ -37,47 +66,67 @@
</div> </div>
</template> </template>
<script> <script>
import {fetchSelectList} from '@/api/flashSession'; // '@/api/flashSession'fetchSelectList
import {formatDate} from '@/utils/date'; import {fetchSelectList} from '@/api/flashSession';
export default { // '@/utils/date'formatDate
name: 'selectSessionList', import {formatDate} from '@/utils/date';
data() {
return { export default {
list: null, name: 'selectSessionList',
listLoading: false data() {
} return {
}, // null
created() { list: null,
this.getList(); // falsetruefalse
}, listLoading: false
filters:{ }
formatTime(time) { },
if (time == null || time === '') { created() {
return 'N/A'; //
} this.getList();
let date = new Date(time); },
return formatDate(date, 'hh:mm:ss') filters: {
// formatTime
formatTime(time) {
// null 'N/A'
if (time == null || time === '') {
return 'N/A';
} }
// JavaScriptDate便使
let date = new Date(time);
// formatDate 'hh:mm:ss' Date
return formatDate(date, 'hh:mm:ss')
}
},
methods: {
//
handleShowRelation(index, row) {
// 使Vue Router '/sms/flashProductRelation'
this.$router.push({path: '/sms/flashProductRelation', query: {
flashPromotionId: this.$route.query.flashPromotionId, flashPromotionSessionId: row.id}}) //IDflashPromotionIdIDflashPromotionSessionIdID
}, },
methods: { //
handleShowRelation(index,row){ getList() {
this.$router.push({path:'/sms/flashProductRelation',query:{ // true
flashPromotionId:this.$route.query.flashPromotionId, flashPromotionSessionId:row.id}}) this.listLoading = true;
}, // fetchSelectListIDIDthen
getList() { fetchSelectList({flashPromotionId: this.$route.query.flashPromotionId}).then(response => {
this.listLoading = true; // false
fetchSelectList({flashPromotionId:this.$route.query.flashPromotionId}).then(response => { this.listLoading = false;
this.listLoading = false; // list便
this.list = response.data; this.list = response.data;
}); });
}
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.operate-container { <!-- scoped属性表示该样式作用范围仅限于当前组件内的元素避免样式影响到其他组件中的同名元素起到样式隔离的作用 -->
margin-top: 0; .operate-container {
} <!-- 这是一个CSS样式规则针对类名为operate-container的元素进行样式设置 -->
<!-- margin-top属性用于设置元素的上外边距这里将其值设置为0意味着该元素距离上方相邻元素的间距为0可用于精准控制元素在页面中的垂直布局位置 -->
margin-top: 0;
}
</style> </style>

@ -1,29 +1,55 @@
<template>  <template>
<!-- 整个页面的外层容器用于对内部各部分内容进行整体布局 -->
<div class="app-container"> <div class="app-container">
<!-- el-card组件用于创建一个卡片式的容器设置了无阴影效果shadow="never"并添加了"operate-container"类名通常可用于放置操作相关的元素比如这里放置了添加按钮等 -->
<el-card shadow="never" class="operate-container"> <el-card shadow="never" class="operate-container">
<!-- 显示一个图标此处使用的是element-ui提供的"el-icon-tickets"图标用于对下方数据列表进行某种示意比如暗示和票务商品列表等相关的操作场景 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 显示文字"数据列表"用于明确下方表格所展示数据的性质让用户知晓表格中呈现的是什么内容 -->
<span>数据列表</span> <span>数据列表</span>
<!-- el-button组件用于创建一个按钮设置了按钮尺寸为"mini"小型按钮添加了"btn-add"类名可能用于样式设置等绑定了点击事件"handleAdd"点击该按钮可触发对应的添加操作逻辑 -->
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button> <el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card> </el-card>
<!-- 放置数据表格的容器用于包裹下面的el-table组件使其在页面布局上更加规整将表格与其他元素区分开来 -->
<div class="table-container"> <div class="table-container">
<!-- el-table组件用于创建一个数据表格设置了表格引用为"flashSessionTable"绑定了数据"list"这个数据应该是从组件的data属性或者通过接口获取等方式得到的包含了要展示在表格中的具体数据内容设置表格宽度为占满父容器100%根据"listLoading"的值来显示加载状态如加载动画等方便用户知晓数据是否正在加载中并添加了边框样式 -->
<el-table ref="flashSessionTable" <el-table ref="flashSessionTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- el-table-column组件用于定义表格中的列此列用于展示编号信息设置了列的宽度为100像素内容在单元格中居中对齐 -->
<el-table-column label="编号" width="100" align="center"> <el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内通过slot-scope获取到对应行的数据对象通过插值表达式显示对应行数据中的"id"字段内容即展示每一行数据的编号 -->
{{scope.row.id}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示秒杀时间段名称信息内容在单元格中居中对齐直接展示对应行数据中的"name"字段内容用于显示每个秒杀时间段对应的名称 -->
<el-table-column label="秒杀时间段名称" align="center"> <el-table-column label="秒杀时间段名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内通过插值表达式显示对应行数据中的"name"字段内容即展示每一行数据对应的秒杀时间段的名称 -->
{{scope.row.name}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示每日开始时间信息内容在单元格中居中对齐使用了名为"formatTime"的过滤器应该是在组件的filters选项中定义的用于对时间数据进行格式化处理对时间数据进行格式化后再展示 -->
<el-table-column label="每日开始时间" align="center"> <el-table-column label="每日开始时间" align="center">
<template slot-scope="scope">{{scope.row.startTime | formatTime}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用"formatTime"过滤器对对应行数据中的"startTime"字段时间类型数据进行格式化处理后展示 -->
{{scope.row.startTime | formatTime}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示每日结束时间信息内容在单元格中居中对齐同样使用了名为"formatTime"的过滤器对时间数据进行格式化后再展示 -->
<el-table-column label="每日结束时间" align="center"> <el-table-column label="每日结束时间" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatTime}}</template> <template slot-scope="scope">
<!-- 在表格单元格的作用域内使用"formatTime"过滤器对对应行数据中的"endTime"字段时间类型数据进行格式化处理后展示 -->
{{scope.row.endTime | formatTime}}
</template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示启用状态信息内容在单元格中居中对齐里面包含了一个el-switch组件开关组件用于切换启用/禁用状态 -->
<el-table-column label="启用" align="center"> <el-table-column label="启用" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- el-switch组件用于创建一个开关按钮绑定了状态改变的事件"handleStatusChange"当开关状态改变时会触发该事件传递当前行的索引和整行数据作为参数设置了激活值为1表示启用状态对应的数值未激活值为0表示禁用状态对应的数值双向绑定对应行数据中的"status"字段意味着开关状态的改变会直接更新对应行数据里的这个字段值 -->
<el-switch <el-switch
@change="handleStatusChange(scope.$index, scope.row)" @change="handleStatusChange(scope.$index, scope.row)"
:active-value="1" :active-value="1"
@ -32,12 +58,15 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- el-table-column组件用于定义表格中的列此列用于展示操作按钮设置了列的宽度为180像素内容在单元格中居中对齐 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- el-button组件用于创建一个按钮设置了按钮尺寸为"mini"小型按钮按钮类型为"text"文本样式按钮通常外观上更简洁无背景色等绑定了点击事件"handleUpdate"点击该按钮可触发编辑操作逻辑按钮显示的文字为"编辑" -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑 @click="handleUpdate(scope.$index, scope.row)">编辑
</el-button> </el-button>
<!-- el-button组件用于创建一个按钮设置了按钮尺寸为"mini"小型按钮按钮类型为"text"文本样式按钮通常外观上更简洁无背景色等绑定了点击事件"handleDelete"点击该按钮可触发删除操作逻辑按钮显示的文字为"删除" -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除 @click="handleDelete(scope.$index, scope.row)">删除
@ -46,163 +75,203 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- el-dialog组件用于创建一个弹出式对话框常用于展示表单让用户输入信息或者进行确认等操作设置了对话框的标题为"添加时间段"通过":visible.sync"双向绑定了对话框的显示状态与组件data中的dialogVisible属性相关联改变该属性值可控制对话框的显示与隐藏设置了对话框的宽度为40%相对于屏幕宽度等的占比用于控制对话框大小 -->
<el-dialog <el-dialog
title="添加时间段" title="添加时间段"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
width="40%"> width="40%">
<!-- el-form组件用于创建一个表单绑定了数据模型"flashSession"这个对象应该在组件的data属性中定义用于存储表单中输入的数据等设置了表单引用为"flashSessionForm"可用于后续对表单进行验证等操作时的标识设置了标签宽度为150像素表单整体尺寸为"small"小型尺寸用于统一表单元素的外观大小等风格 -->
<el-form :model="flashSession" <el-form :model="flashSession"
ref="flashSessionForm" ref="flashSessionForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- el-form-item组件用于定义表单中的表单项此表单项对应的标签为"秒杀时间段名称:"用于提示用户此处应输入的内容 -->
<el-form-item label="秒杀时间段名称:"> <el-form-item label="秒杀时间段名称:">
<!-- el-input组件用于创建一个输入框双向绑定了"flashSession.name"数据意味着用户在输入框中输入的内容会实时更新到"flashSession"对象的"name"属性中设置了输入框的宽度为250像素 -->
<el-input v-model="flashSession.name" style="width: 250px"></el-input> <el-input v-model="flashSession.name" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- el-form-item组件用于定义表单中的表单项此表单项对应的标签为"每日开始时间:"用于提示用户此处应选择时间 -->
<el-form-item label="每日开始时间:"> <el-form-item label="每日开始时间:">
<!-- el-time-picker组件用于创建一个时间选择器用户可以通过它选择具体的时间双向绑定了"flashSession.startTime"数据选择的时间会更新到"flashSession"对象的"startTime"属性中设置了占位提示文字为"请选择时间" -->
<el-time-picker <el-time-picker
v-model="flashSession.startTime" v-model="flashSession.startTime"
placeholder="请选择时间"> placeholder="请选择时间">
</el-time-picker> </el-time-picker>
</el-form-item> </el-form-item>
<!-- el-form-item组件用于定义表单中的表单项此表单项对应的标签为"每日结束时间:"用于提示用户此处应选择时间 -->
<el-form-item label="每日结束时间:"> <el-form-item label="每日结束时间:">
<!-- el-time-picker组件用于创建一个时间选择器用户可以通过它选择具体的时间双向绑定了"flashSession.endTime"数据选择的时间会更新到"flashSession"对象的"endTime"属性中设置了占位提示文字为"请选择时间" -->
<el-time-picker <el-time-picker
v-model="flashSession.endTime" v-model="flashSession.endTime"
placeholder="请选择时间"> placeholder="请选择时间">
</el-time-picker> </el-time-picker>
</el-form-item> </el-form-item>
<!-- el-form-item组件用于定义表单中的表单项此表单项对应的标签为"是否启用"用于让用户选择该时间段是否启用 -->
<el-form-item label="是否启用"> <el-form-item label="是否启用">
<!-- el-radio-group组件用于创建一个单选按钮组绑定了"flashSession.status"数据意味着用户选择的单选按钮的值会更新到"flashSession"对象的"status"属性中 -->
<el-radio-group v-model="flashSession.status"> <el-radio-group v-model="flashSession.status">
<!-- el-radio组件用于创建一个单选按钮设置了按钮的标签值为1对应的显示文字为"启用"用户选择该按钮后会将"flashSession.status"的值设为1 -->
<el-radio :label="1">启用</el-radio> <el-radio :label="1">启用</el-radio>
<!-- el-radio组件用于创建一个单选按钮设置了按钮的标签值为0对应的显示文字为"不启用"用户选择该按钮后会将"flashSession.status"的值设为0 -->
<el-radio :label="0">不启用</el-radio> <el-radio :label="0">不启用</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 对话框底部的操作按钮区域使用了插槽"footer"来定义通常用于放置确认取消等按钮 -->
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="small"> </el-button> <!-- el-button组件用于创建一个按钮点击事件绑定了将"dialogVisible"属性设为false的操作即关闭对话框设置了按钮尺寸为"small"小型按钮按钮显示的文字为"取 消" -->
<el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button> <el-button @click="dialogVisible = false" size="small"> </el-button>
</span> <!-- el-button组件用于创建一个按钮设置了按钮类型为"primary"主要按钮通常会有突出的样式比如颜色与其他按钮不同等点击事件绑定了"handleDialogConfirm"方法这个方法应该在组件的methods选项中定义用于处理确认添加等相关逻辑设置了按钮尺寸为"small"小型按钮按钮显示的文字为"确 定" -->
<el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button>
</span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import {fetchList,updateStatus,deleteSession,createSession,updateSession} from '@/api/flashSession'; // '@/api/flashSession'API
import {formatDate} from '@/utils/date'; import {fetchList, updateStatus, deleteSession, createSession, updateSession} from '@/api/flashSession';
const defaultFlashSession={ // '@/utils/date'formatDate使
name:null, import {formatDate} from '@/utils/date';
startTime:null,
endTime:null, //
status:0 const defaultFlashSession = { //
}; name: null,
export default { startTime: null,
name: 'flashPromotionSessionList', endTime: null,
data() { status: 0 //
return { };
list: null,
listLoading: false, export default {
dialogVisible:false, name: 'flashPromotionSessionList',
isEdit:false, data() {
flashSession:Object.assign({},defaultFlashSession) return {
// null便
list: null,
// falsetruefalse
listLoading: false,
// /false
dialogVisible: false,
// truefalsefalse便
isEdit: false,
// defaultFlashSession
flashSession: Object.assign({}, defaultFlashSession)
}
},
created() {
// 使
this.getList();
},
filters: {
// formatTime便
formatTime(time) {
// null 'N/A'
if (time == null || time === '') {
return 'N/A';
} }
// JavaScriptDate便使formatDateDate便
let date = new Date(time);
// formatDate 'hh:mm:ss' Date "12:30:00"
return formatDate(date, 'hh:mm:ss')
}
},
methods: {
//
handleAdd() {
this.dialogVisible = true; //true
this.isEdit = false;
this.flashSession = Object.assign({}, defaultFlashSession); //
}, },
created() { // /
this.getList(); handleStatusChange(index, row) {
this.$confirm('是否要修改该状态?', '提示', { //
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateStatus(row.id, {status: row.status}).then(response => {
this.$message({
type: 'success',
message: '修改成功!' //
});
});
}).catch(() => { //
this.$message({
type: 'info',
message: '取消修改'
});
this.getList(); //
});
}, },
filters:{ // .
formatTime(time) { handleUpdate(index, row) {
if (time == null || time === '') { this.dialogVisible = true; //true
return 'N/A'; this.isEdit = true; //
} this.flashSession = Object.assign({}, row);
let date = new Date(time); this.flashSession.startTime = new Date(row.startTime); //Date便便
return formatDate(date, 'hh:mm:ss') this.flashSession.endTime = new Date(row.endTime);
}
}, },
methods: { // .
handleAdd() { handleDelete(index, row) {
this.dialogVisible = true; this.$confirm('是否要删除该时间段?', '提示', { //
this.isEdit = false; confirmButtonText: '确定',
this.flashSession = Object.assign({},defaultFlashSession); cancelButtonText: '取消',
}, type: 'warning'
handleStatusChange(index,row){ }).then(() => { //
this.$confirm('是否要修改该状态?', '提示', { deleteSession(row.id).then(response => {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateStatus(row.id, {status: row.status}).then(response => {
this.$message({
type: 'success',
message: '修改成功!'
});
});
}).catch(() => {
this.$message({ this.$message({
type: 'info', type: 'success',
message: '取消修改' message: '删除成功!' //
}); });
this.getList(); this.getList(); //使
}); });
}, });
handleUpdate(index,row){ },
this.dialogVisible = true; // .
this.isEdit = true; handleDialogConfirm() {
this.flashSession = Object.assign({},row); this.$confirm('是否要确认?', '提示', { //
this.flashSession.startTime=new Date(row.startTime); confirmButtonText: '确定',
this.flashSession.endTime=new Date(row.endTime); cancelButtonText: '取消',
}, type: 'warning'
handleDelete(index,row){ }).then(() => { //
this.$confirm('是否要删除该时间段?', '提示', { if (this.isEdit) {
confirmButtonText: '确定', updateSession(this.flashSession.id, this.flashSession).then(response => {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteSession(row.id).then(response => {
this.$message({ this.$message({
type: 'success', message: '修改成功!',
message: '删除成功!' type: 'success'
}); });
this.dialogVisible = false;
this.getList(); this.getList();
}); })
}); } else {
}, createSession(this.flashSession).then(response => {
handleDialogConfirm() { this.$message({
this.$confirm('是否要确认?', '提示', { message: '添加成功!', //
confirmButtonText: '确定', type: 'success'
cancelButtonText: '取消', });
type: 'warning' this.dialogVisible = false;
}).then(() => { this.getList(); //
if (this.isEdit) { })
updateSession(this.flashSession.id,this.flashSession).then(response => { }
this.$message({ })
message: '修改成功!', },
type: 'success' //
}); getList() {
this.dialogVisible =false; this.listLoading = true; //true
this.getList(); fetchList({}).then(response => { //fetchList
}) this.listLoading = false; //false
} else { this.list = response.data; //list
createSession(this.flashSession).then(response => { });
this.$message({
message: '添加成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
}
})
},
getList() {
this.listLoading = true;
fetchList({}).then(response => {
this.listLoading = false;
this.list = response.data;
});
}
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.operate-container { <!-- scoped属性表示当前这个style标签内定义的样式作用范围仅限于当前组件内部避免样式影响到其他组件中同名的类或元素起到样式隔离的作用使得样式管理更加清晰和模块化 -->
margin-top: 0; .operate-container {
} <!-- 这是一个CSS选择器用于选中页面中所有应用了operate-container类名的元素接下来在花括号内定义的样式规则就会应用到这些被选中的元素上 -->
<!-- margin-top是CSS的一个属性用于设置元素的上外边距也就是该元素距离其上方相邻元素的间隔距离这里将其值设置为0意味着应用了operate-container类名的元素其上外边距为0像素能精准控制这类元素在页面垂直方向上的布局位置使其更贴合设计需求 -->
margin-top: 0;
}
</style> </style>

@ -1,9 +1,14 @@
<template>  <template>
<!-- 整个应用的容器 -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索的卡片容器设置了阴影效果为无 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索文字 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 查询搜索按钮设置了样式为右浮动类型为主要按钮点击时触发handleSearchList方法按钮大小为小 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 重置按钮设置了样式为右浮动右外边距为15px点击时触发handleResetSearch方法按钮大小为小 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 内联表单绑定了listQuery数据模型表单大小为小标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单项目标签为商品名称 -->
<el-form-item label="商品名称:"> <el-form-item label="商品名称:">
<!-- 输入框双向绑定listQuery.productName数据设置了类名和占位提示文字 -->
<el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input> <el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为推荐状态 -->
<el-form-item label="推荐状态:"> <el-form-item label="推荐状态:">
<!-- 下拉选择框双向绑定listQuery.recommendStatus数据设置了占位提示文字和可清除添加了类名 -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 循环生成下拉选项根据recommendOptions数据中的每个item来生成对应的选项 -->
<el-option v-for="item in recommendOptions" <el-option v-for="item in recommendOptions"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
@ -35,24 +47,34 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作相关的卡片容器设置了阴影效果为无 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- 图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<span>数据列表</span> <!-- 显示数据列表文字 -->
<i>数据列表</i>
<!-- 选择商品按钮设置了按钮大小为迷你点击时触发handleSelectProduct方法 -->
<el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button> <el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button>
</el-card> </el-card>
<!-- 表格容器 -->
<div class="table-container"> <div class="table-container">
<!-- el-table组件绑定了list数据作为表格数据源设置了宽度为100%选择变化时触发handleSelectionChange方法加载状态绑定listLoading显示边框 -->
<el-table ref="newProductTable" <el-table ref="newProductTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 表格列类型为选择列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 表格列标签为编号宽度为120px内容居中对齐通过插槽作用域显示对应行的id数据 -->
<el-table-column label="编号" width="120" align="center"> <el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为商品名称内容居中对齐通过插槽作用域显示对应行的productName数据 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template> <template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为是否推荐宽度为200px内容居中对齐包含一个开关组件开关状态改变时触发handleRecommendStatusStatusChange方法设置了开关的激活值未激活值以及双向绑定对应行的recommendStatus数据 -->
<el-table-column label="是否推荐" width="200" align="center"> <el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@ -63,12 +85,15 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 表格列标签为排序宽度为160px内容居中对齐通过插槽作用域显示对应行的sort数据 -->
<el-table-column label="排序" width="160" align="center"> <el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为状态宽度为160px内容居中对齐通过管道formatRecommendStatus对对应行的recommendStatus数据进行格式化后显示 -->
<el-table-column label="状态" width="160" align="center"> <el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template> <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为操作宽度为180px内容居中对齐包含两个按钮分别点击时触发handleEditSort和handleDelete方法 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -83,10 +108,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 批量操作的容器 -->
<div class="batch-operate-container"> <div class="batch-operate-container">
<!-- 下拉选择框设置了大小为小双向绑定operateType数据设置了占位提示文字 -->
<el-select <el-select
size="small" size="small"
v-model="operateType" placeholder="批量操作"> v-model="operateType" placeholder="批量操作">
<!-- 循环生成下拉选项根据operates数据中的每个item来生成对应的选项 -->
<el-option <el-option
v-for="item in operates" v-for="item in operates"
:key="item.value" :key="item.value"
@ -94,6 +122,7 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<!-- 确定按钮设置了左外边距为20px样式类点击时触发handleBatchOperate方法类型为主要按钮大小为小 -->
<el-button <el-button
style="margin-left: 20px" style="margin-left: 20px"
class="search-button" class="search-button"
@ -103,7 +132,9 @@
确定 确定
</el-button> </el-button>
</div> </div>
<!-- 分页容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置了背景色页面尺寸改变时触发handleSizeChange方法当前页改变时触发handleCurrentChange方法布局样式绑定了当前页每页显示数量可选的每页显示数量列表以及总记录数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -115,27 +146,35 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 选择商品的对话框绑定了显示状态设置了标题和宽度 -->
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%"> <el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<!-- 输入框双向绑定dialogData.listQuery.keyword数据设置了宽度下外边距大小和占位提示文字包含一个搜索按钮点击时触发handleSelectSearch方法 -->
<el-input v-model="dialogData.listQuery.keyword" <el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px" style="width: 250px;margin-bottom: 20px"
size="small" size="small"
placeholder="商品名称搜索"> placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button> <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input> </el-input>
<!-- 表格绑定了dialogData.list数据作为数据源选择变化时触发handleDialogSelectionChange方法显示边框 -->
<el-table :data="dialogData.list" <el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border> @selection-change="handleDialogSelectionChange" border>
<!-- 表格列类型为选择列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 表格列标签为商品名称内容居中对齐通过插槽作用域显示对应行的name数据 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为货号宽度为160px内容居中对齐通过插槽作用域显示对应行的productSn数据格式化为NO. + 货号 -->
<el-table-column label="货号" width="160" align="center"> <el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> <template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为价格宽度为120px内容居中对齐通过插槽作用域显示对应行的price数据格式化为 + 价格 -->
<el-table-column label="价格" width="120" align="center"> <el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template> <template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置了背景色页面尺寸改变时触发handleDialogSizeChange方法当前页改变时触发handleDialogCurrentChange方法布局样式绑定了当前页每页显示数量可选的每页显示数量列表以及总记录数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleDialogSizeChange" @size-change="handleDialogSizeChange"
@ -149,282 +188,331 @@
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div slot="footer"> <div slot="footer">
<!-- 取消按钮设置了大小为小点击时隐藏对话框 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button> <el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 确定按钮设置了大小为小类型为主要按钮点击时触发handleSelectDialogConfirm方法 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button> <el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- 设置排序的对话框绑定了显示状态设置了标题和宽度 -->
<el-dialog title="设置排序" <el-dialog title="设置排序"
:visible.sync="sortDialogVisible" :visible.sync="sortDialogVisible"
width="40%"> width="40%">
<!-- 表单绑定了sortDialogData数据模型设置了标签宽度 -->
<el-form :model="sortDialogData" <el-form :model="sortDialogData"
label-width="150px"> label-width="150px">
<!-- 表单项目标签为排序 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<!-- 输入框双向绑定sortDialogData.sort数据设置了宽度 -->
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input> <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer"> <span slot="footer">
<!-- 取消按钮点击时隐藏对话框设置了大小为小 -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button> <el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- 确定按钮点击时触发handleUpdateSort方法设置了大小为小类型为主要按钮 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button> <el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import {fetchList,updateRecommendStatus,deleteHotProduct,createHotProduct,updateHotProductSort} from '@/api/hotProduct'; // '@/api/hotProduct'
import {fetchList as fetchProductList} from '@/api/product'; import {fetchList, updateRecommendStatus, deleteHotProduct, createHotProduct, updateHotProductSort} from '@/api/hotProduct';
// '@/api/product'fetchListfetchProductList
import {fetchList as fetchProductList} from '@/api/product';
const defaultListQuery = { //
pageNum: 1, const defaultListQuery = {
pageSize: 5, pageNum: 1,
productName: null, pageSize: 5,
recommendStatus: null productName: null,
}; recommendStatus: null
const defaultRecommendOptions = [ };
{ //
label: '未推荐', const defaultRecommendOptions = [
value: 0 {
}, label: '未推荐',
{ value: 0
label: '推荐中', },
value: 1 {
} label: '推荐中',
]; value: 1
export default { }
name: 'hotProductList', ];
data() {
return { // Vue
listQuery: Object.assign({}, defaultListQuery), export default {
recommendOptions: Object.assign({}, defaultRecommendOptions), //
name: 'hotProductList',
data() {
return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// defaultRecommendOptions
recommendOptions: Object.assign({}, defaultRecommendOptions),
// null
list: null,
// null
total: null,
// truefalse
listLoading: false,
//
multipleSelection: [],
//
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// null
operateType: null,
// falsetrue
selectDialogVisible: false,
//
dialogData: {
list: null, list: null,
total: null, total: null,
listLoading: false,
multipleSelection: [], multipleSelection: [],
operates: [ listQuery: {
{ keyword: null,
label: "设为推荐", pageNum: 1,
value: 0 pageSize: 5
}, }
{ },
label: "取消推荐", //
value: 1 sortDialogVisible: false,
}, // id
{ sortDialogData: {sort: 0, id: null}
label: "删除", }
value: 2 },
} //
], created() {
operateType: null, this.getList();
selectDialogVisible:false, },
dialogData:{ // 1
list: null, filters: {
total: null, formatRecommendStatus(status) {
multipleSelection:[], if (status === 1) {
listQuery:{ return '推荐中';
keyword: null, } else {
pageNum: 1, return '未推荐';
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
} }
}
},
methods: {
//
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
}, },
created() { // 1
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters:{ //
formatRecommendStatus(status){ handleSelectionChange(val) {
if(status===1){ this.multipleSelection = val;
return '推荐中'; },
}else{ // 1
return '未推荐'; handleSizeChange(val) {
} this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
//
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// id
handleRecommendStatusStatusChange(index, row) {
this.updateRecommendStatusStatus(row.id, row.recommendStatus);
},
// id
handleDelete(index, row) {
this.deleteProduct(row.id);
},
//
handleBatchOperate() {
if (this.multipleSelection < 1) {
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let ids = []; //
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id);
}
if (this.operateType === 0) {
//
this.updateRecommendStatusStatus(ids, 1);
} else if (this.operateType === 1) {
//
this.updateRecommendStatusStatus(ids, 0);
} else if (this.operateType === 2) {
//
this.deleteProduct(ids);
} else {
this.$message({ //
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
} }
}, },
methods: { //
handleResetSearch() { handleSelectProduct() {
this.listQuery = Object.assign({}, defaultListQuery); this.selectDialogVisible = true;
}, this.getDialogList();
handleSearchList() { },
this.listQuery.pageNum = 1; //
this.getList(); handleSelectSearch() {
}, this.getDialogList();
handleSelectionChange(val){ },
this.multipleSelection = val; // 1
}, handleDialogSizeChange(val) {
handleSizeChange(val) { this.dialogData.listQuery.pageNum = 1;
this.listQuery.pageNum = 1; this.dialogData.listQuery.pageSize = val;
this.listQuery.pageSize = val; this.getDialogList();
this.getList(); },
}, //
handleCurrentChange(val) { handleDialogCurrentChange(val) {
this.listQuery.pageNum = val; this.dialogData.listQuery.pageNum = val;
this.getList(); this.getDialogList();
}, },
handleRecommendStatusStatusChange(index,row){ //
this.updateRecommendStatusStatus(row.id,row.recommendStatus); handleDialogSelectionChange(val) {
}, this.dialogData.multipleSelection = val;
handleDelete(index,row){ },
this.deleteProduct(row.id); //
}, handleSelectDialogConfirm() {
handleBatchOperate(){ if (this.dialogData.multipleSelection < 1) {
if (this.multipleSelection < 1) { this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let selectProducts = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectProducts.push({
productId: this.dialogData.multipleSelection[i].id,
productName: this.dialogData.multipleSelection[i].name
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => { //
createHotProduct(selectProducts).then(response => {
this.selectDialogVisible = false;
this.dialogData.multipleSelection = [];
this.getList();
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '添加成功!'
duration: 1000
}); });
return; });
} });
let ids = []; },
for (let i = 0; i < this.multipleSelection.length; i++) { //
ids.push(this.multipleSelection[i].id); handleEditSort(index, row) {
} this.sortDialogVisible = true;
if (this.operateType === 0) { this.sortDialogData.sort = row.sort; //id
// this.sortDialogData.id = row.id;
this.updateRecommendStatusStatus(ids,1); },
} else if (this.operateType === 1) { //
// handleUpdateSort() { //
this.updateRecommendStatusStatus(ids,0); this.$confirm('是否要修改排序?', '提示', {
} else if(this.operateType===2){ confirmButtonText: '确定',
// cancelButtonText: '取消',
this.deleteProduct(ids); type: 'warning'
}else { }).then(() => { //
updateHotProductSort(this.sortDialogData).then(response => {
this.sortDialogVisible = false;
this.getList();
this.$message({ this.$message({
message: '请选择批量操作类型', type: 'success',
type: 'warning', message: '删除成功!'
duration: 1000
}); });
} });
}, })
handleSelectProduct(){ },
this.selectDialogVisible=true; //
this.getDialogList(); getList() {
}, this.listLoading = true;
handleSelectSearch(){ fetchList(this.listQuery).then(response => { //fetchList
this.getDialogList(); this.listLoading = false;
}, this.list = response.data.list; //
handleDialogSizeChange(val) { this.total = response.data.total;
this.dialogData.listQuery.pageNum = 1; })
this.dialogData.listQuery.pageSize = val; },
this.getDialogList(); //
}, updateRecommendStatusStatus(ids, status) {
handleDialogCurrentChange(val) { this.$confirm('是否要修改推荐状态?', '提示', { //
this.dialogData.listQuery.pageNum = val; confirmButtonText: '确定',
this.getDialogList(); cancelButtonText: '取消',
}, type: 'warning'
handleDialogSelectionChange(val){ }).then(() => {
this.dialogData.multipleSelection = val; let params = new URLSearchParams(); //idURLSearchParams
}, params.append("ids", ids);
handleSelectDialogConfirm(){ params.append("recommendStatus", status);
if (this.dialogData.multipleSelection < 1) { updateRecommendStatus(params).then(response => { //updateRecommendStatus
this.getList();
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '修改成功!' //
duration: 1000
});
return;
}
let selectProducts = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectProducts.push({
productId:this.dialogData.multipleSelection[i].id,
productName:this.dialogData.multipleSelection[i].name
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createHotProduct(selectProducts).then(response=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
}); });
}); });
}, }).catch(() => {
handleEditSort(index,row){ this.$message({
this.sortDialogVisible=true; type: 'success',
this.sortDialogData.sort=row.sort; message: '已取消操作!' //
this.sortDialogData.id=row.id; });
}, this.getList();
handleUpdateSort(){ });
this.$confirm('是否要修改排序?', '提示', { },
confirmButtonText: '确定', //
cancelButtonText: '取消', deleteProduct(ids) {
type: 'warning' this.$confirm('是否要删除该推荐?', '提示', { //
}).then(() => { confirmButtonText: '确定',
updateHotProductSort(this.sortDialogData).then(response=>{ cancelButtonText: '取消',
this.sortDialogVisible=false; type: 'warning'
this.getList(); }).then(() => {
this.$message({ let params = new URLSearchParams(); //idURLSearchParams
type: 'success', params.append("ids", ids);
message: '删除成功!' deleteHotProduct(params).then(response => { //deleteHotProduct
}); this.getList();
});
})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
})
},
updateRecommendStatusStatus(ids,status){
this.$confirm('是否要修改推荐状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
params.append("recommendStatus",status);
updateRecommendStatus(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '修改成功!'
});
});
}).catch(() => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '已取消操作!' message: '删除成功!' //
}); });
this.getList();
}); });
}, })
deleteProduct(ids){ },
this.$confirm('是否要删除该推荐?', '提示', { //
confirmButtonText: '确定', getDialogList() {
cancelButtonText: '取消', fetchProductList(this.dialogData.listQuery).then(response => { //fetchProductList
type: 'warning' this.dialogData.list = response.data.list; //
}).then(() => { this.dialogData.total = response.data.total;
let params=new URLSearchParams(); })
params.append("ids",ids);
deleteHotProduct(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
getDialogList(){
fetchProductList(this.dialogData.listQuery).then(response=>{
this.dialogData.list=response.data.list;
this.dialogData.total=response.data.total;
})
}
} }
} }
}
</script> </script>
<style></style> <style></style>

@ -1,9 +1,14 @@
<template>  <template>
<!-- 整个页面的容器 -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索区域的卡片 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索文字 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 查询搜索按钮点击触发handleSearchList方法按钮样式为小型主色调 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 重置按钮点击触发handleResetSearch方法按钮样式为小型与查询搜索按钮有一定间隔 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 内联表单绑定数据模型为listQuery表单尺寸为小标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 商品名称表单项 -->
<el-form-item label="商品名称:"> <el-form-item label="商品名称:">
<!-- 输入框双向绑定listQuery.productName设置了占位提示文字 -->
<el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input> <el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input>
</el-form-item> </el-form-item>
<!-- 推荐状态表单项 -->
<el-form-item label="推荐状态:"> <el-form-item label="推荐状态:">
<!-- 下拉选择框双向绑定listQuery.recommendStatus有清除功能设置了占位提示文字 -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 循环生成下拉选项每个选项的keylabelvalue根据recommendOptions中的数据来设置 -->
<el-option v-for="item in recommendOptions" <el-option v-for="item in recommendOptions"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
@ -35,26 +47,37 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作区域的卡片 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- 图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 显示数据列表文字 -->
<span>数据列表</span> <span>数据列表</span>
<!-- 选择商品按钮点击触发handleSelectProduct方法按钮尺寸为迷你型 -->
<el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button> <el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button>
</el-card> </el-card>
<!-- 表格容器 -->
<div class="table-container"> <div class="table-container">
<!-- el-table组件绑定数据为list设置宽度为100%监听选择变化事件根据listLoading状态显示加载动画有边框 -->
<el-table ref="newProductTable" <el-table ref="newProductTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 选择列宽度为60px内容居中 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 编号列宽度为120px内容居中通过插槽作用域展示对应行的id数据 -->
<el-table-column label="编号" width="120" align="center"> <el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 商品名称列内容居中通过插槽作用域展示对应行的productName数据 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template> <template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column> </el-table-column>
<!-- 是否推荐列宽度为200px内容居中包含一个开关组件 -->
<el-table-column label="是否推荐" width="200" align="center"> <el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 开关组件监听状态改变事件设置了激活和未激活的值双向绑定对应行的recommendStatus数据 -->
<el-switch <el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)" @change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1" :active-value="1"
@ -63,18 +86,23 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 排序列宽度为160px内容居中通过插槽作用域展示对应行的sort数据 -->
<el-table-column label="排序" width="160" align="center"> <el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column> </el-table-column>
<!-- 状态列宽度为160px内容居中通过管道formatRecommendStatus格式化对应行的recommendStatus数据来展示 -->
<el-table-column label="状态" width="160" align="center"> <el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template> <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column> </el-table-column>
<!-- 操作列宽度为180px内容居中包含设置排序和删除两个按钮 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- 设置排序按钮点击触发handleEditSort方法按钮尺寸为迷你型文本样式 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序 @click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button> </el-button>
<!-- 删除按钮点击触发handleDelete方法按钮尺寸为迷你型文本样式 -->
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除 @click="handleDelete(scope.$index, scope.row)">删除
@ -83,10 +111,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 批量操作容器 -->
<div class="batch-operate-container"> <div class="batch-operate-container">
<!-- 下拉选择框用于选择批量操作类型双向绑定operateType设置了占位提示文字 -->
<el-select <el-select
size="small" size="small"
v-model="operateType" placeholder="批量操作"> v-model="operateType" placeholder="批量操作">
<!-- 循环生成下拉选项每个选项的keylabelvalue根据operates中的数据来设置 -->
<el-option <el-option
v-for="item in operates" v-for="item in operates"
:key="item.value" :key="item.value"
@ -94,6 +125,7 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<!-- 确定按钮点击触发handleBatchOperate方法按钮样式为小型主色调与下拉选择框有一定间隔 -->
<el-button <el-button
style="margin-left: 20px" style="margin-left: 20px"
class="search-button" class="search-button"
@ -103,7 +135,9 @@
确定 确定
</el-button> </el-button>
</div> </div>
<!-- 分页容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置了背景色监听页面尺寸改变和当前页改变事件配置了布局页面尺寸可选页面尺寸列表当前页总数据量等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -115,27 +149,36 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 选择商品的对话框 -->
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%"> <el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<!-- 输入框双向绑定dialogData.listQuery.keyword设置了宽度样式占位提示文字包含一个搜索按钮 -->
<el-input v-model="dialogData.listQuery.keyword" <el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px" style="width: 250px;margin-bottom: 20px"
size="small" size="small"
placeholder="商品名称搜索"> placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button> <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input> </el-input>
<!-- el-table组件用于对话框内展示数据绑定数据为dialogData.list监听选择变化事件有边框 -->
<el-table :data="dialogData.list" <el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border> @selection-change="handleDialogSelectionChange" border>
<!-- 选择列宽度为60px内容居中 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 商品名称列内容居中通过插槽作用域展示对应行的name数据 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 货号列宽度为160px内容居中通过插槽作用域展示对应行的productSn数据格式化展示格式 -->
<el-table-column label="货号" width="160" align="center"> <el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> <template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column> </el-table-column>
<!-- 价格列宽度为120px内容居中通过插槽作用域展示对应行的price数据格式化展示格式 -->
<el-table-column label="价格" width="120" align="center"> <el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template> <template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 对话框内的分页容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置了背景色监听对话框内页面尺寸改变和当前页改变事件配置了布局页面尺寸可选页面尺寸列表当前页总数据量等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleDialogSizeChange" @size-change="handleDialogSizeChange"
@ -149,282 +192,334 @@
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div slot="footer"> <div slot="footer">
<!-- 取消按钮点击隐藏对话框按钮尺寸为小型 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button> <el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 确定按钮点击触发handleSelectDialogConfirm方法按钮尺寸为小型主色调 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button> <el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- 设置排序的对话框 -->
<el-dialog title="设置排序" <el-dialog title="设置排序"
:visible.sync="sortDialogVisible" :visible.sync="sortDialogVisible"
width="40%"> width="40%">
<!-- el-form表单组件绑定数据模型为sortDialogData设置标签宽度 -->
<el-form :model="sortDialogData" <el-form :model="sortDialogData"
label-width="150px"> label-width="150px">
<!-- 排序表单项 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<!-- 输入框双向绑定sortDialogData.sort设置了宽度 -->
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input> <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer"> <span slot="footer">
<!-- 取消按钮点击隐藏对话框按钮尺寸为小型 -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button> <el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- 确定按钮点击触发handleUpdateSort方法按钮尺寸为小型主色调 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button> <el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import {fetchList,updateRecommendStatus,deleteNewProduct,createNewProduct,updateNewProductSort} from '@/api/newProduct'; // '@/api/newProduct'
import {fetchList as fetchProductList} from '@/api/product'; import {fetchList,updateRecommendStatus,deleteNewProduct,createNewProduct,updateNewProductSort} from '@/api/newProduct';
// '@/api/product'fetchListfetchProductList
import {fetchList as fetchProductList} from '@/api/product';
const defaultListQuery = { //
pageNum: 1, const defaultListQuery = {
pageSize: 5, pageNum: 1,
productName: null, pageSize: 5,
recommendStatus: null productName: null,
}; recommendStatus: null
const defaultRecommendOptions = [ };
{ // ''0
label: '未推荐', const defaultRecommendOptions = [
value: 0 {
}, label: '未推荐',
{ value: 0
label: '推荐中', },
value: 1 {
} label: '推荐中',
]; value: 1
export default { }
name: 'newProductList', ];
data() {
return { export default {
listQuery: Object.assign({}, defaultListQuery), name: 'newProductList',
recommendOptions: Object.assign({}, defaultRecommendOptions), data() {
return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// defaultRecommendOptions
recommendOptions: Object.assign({}, defaultRecommendOptions),
// null
list: null,
// null
total: null,
// false
listLoading: false,
//
multipleSelection: [],
// ''0
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// null
operateType: null,
// false
selectDialogVisible:false,
dialogData:{
// null
list: null, list: null,
// null
total: null, total: null,
listLoading: false, //
multipleSelection: [], multipleSelection:[],
operates: [ listQuery:{
{ // null
label: "设为推荐", keyword: null,
value: 0 // 1
}, pageNum: 1,
{ // 5
label: "取消推荐", pageSize: 5
value: 1 }
}, },
{ // false
label: "删除", sortDialogVisible:false,
value: 2 // id
} sortDialogData:{sort:0,id:null}
], }
operateType: null, },
selectDialogVisible:false, created() {
dialogData:{ // getList
list: null, this.getList();
total: null, },
multipleSelection:[], filters:{
listQuery:{ // formatRecommendStatus
keyword: null, formatRecommendStatus(status){
pageNum: 1, if(status===1){ //10''''
pageSize: 5 return '推荐中';
} }else{
}, return '未推荐';
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
} }
}
},
methods: {
// defaultListQuery
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
}, },
created() { // 1getList
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters:{ // multipleSelection
formatRecommendStatus(status){ handleSelectionChange(val){
if(status===1){ this.multipleSelection = val;
return '推荐中'; },
}else{ // 1getList
return '未推荐'; handleSizeChange(val) {
} this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// getList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// updateRecommendStatusStatusid
handleRecommendStatusStatusChange(index,row){
this.updateRecommendStatusStatus(row.id,row.recommendStatus);
},
// deleteProductid
handleDelete(index,row){
this.deleteProduct(row.id);
},
//
handleBatchOperate(){
if (this.multipleSelection < 1) {
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let ids = []; //
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id);
}
if (this.operateType === 0) {
//
this.updateRecommendStatusStatus(ids,1);
} else if (this.operateType === 1) {
//
this.updateRecommendStatusStatus(ids,0);
} else if(this.operateType===2){
//
this.deleteProduct(ids);
}else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
} }
}, },
methods: { // getDialogList
handleResetSearch() { handleSelectProduct(){
this.listQuery = Object.assign({}, defaultListQuery); this.selectDialogVisible=true;
}, this.getDialogList();
handleSearchList() { },
this.listQuery.pageNum = 1; // getDialogList
this.getList(); handleSelectSearch(){
}, this.getDialogList();
handleSelectionChange(val){ },
this.multipleSelection = val; // 1getDialogList
}, handleDialogSizeChange(val) {
handleSizeChange(val) { this.dialogData.listQuery.pageNum = 1;
this.listQuery.pageNum = 1; this.dialogData.listQuery.pageSize = val;
this.listQuery.pageSize = val; this.getDialogList();
this.getList(); },
}, // getDialogList
handleCurrentChange(val) { handleDialogCurrentChange(val) {
this.listQuery.pageNum = val; this.dialogData.listQuery.pageNum = val;
this.getList(); this.getDialogList();
}, },
handleRecommendStatusStatusChange(index,row){ // dialogData.multipleSelection
this.updateRecommendStatusStatus(row.id,row.recommendStatus); handleDialogSelectionChange(val){
}, this.dialogData.multipleSelection = val;
handleDelete(index,row){ },
this.deleteProduct(row.id); //
}, handleSelectDialogConfirm(){
handleBatchOperate(){ if (this.dialogData.multipleSelection < 1) {
if (this.multipleSelection < 1) { this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let selectProducts = []; //
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectProducts.push({
productId:this.dialogData.multipleSelection[i].id,
productName:this.dialogData.multipleSelection[i].name
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createNewProduct(selectProducts).then(response=>{ //createNewProduct
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList(); //
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '添加成功!'
duration: 1000
}); });
return; });
} });
let ids = []; },
for (let i = 0; i < this.multipleSelection.length; i++) { //
ids.push(this.multipleSelection[i].id); handleEditSort(index,row){
} this.sortDialogVisible=true;
if (this.operateType === 0) { this.sortDialogData.sort=row.sort;
// this.sortDialogData.id=row.id; //id便
this.updateRecommendStatusStatus(ids,1); },
} else if (this.operateType === 1) { //
// handleUpdateSort(){
this.updateRecommendStatusStatus(ids,0); this.$confirm('是否要修改排序?', '提示', { //
} else if(this.operateType===2){ confirmButtonText: '确定',
// cancelButtonText: '取消',
this.deleteProduct(ids); type: 'warning'
}else { }).then(() => {
updateNewProductSort(this.sortDialogData).then(response=>{ //updateNewProductSort
this.sortDialogVisible=false;
this.getList(); //
this.$message({ this.$message({
message: '请选择批量操作类型', type: 'success',
type: 'warning', message: '删除成功!'
duration: 1000
}); });
} });
}, })
handleSelectProduct(){ },
this.selectDialogVisible=true; //
this.getDialogList(); getList() {
}, this.listLoading = true; //true
handleSelectSearch(){ fetchList(this.listQuery).then(response => { //fetchList
this.getDialogList(); this.listLoading = false; //false
}, this.list = response.data.list; //
handleDialogSizeChange(val) { this.total = response.data.total;
this.dialogData.listQuery.pageNum = 1; })
this.dialogData.listQuery.pageSize = val; },
this.getDialogList(); //
}, updateRecommendStatusStatus(ids,status){
handleDialogCurrentChange(val) { this.$confirm('是否要修改推荐状态?', '提示', { //
this.dialogData.listQuery.pageNum = val; confirmButtonText: '确定',
this.getDialogList(); cancelButtonText: '取消',
}, type: 'warning'
handleDialogSelectionChange(val){ }).then(() => {
this.dialogData.multipleSelection = val; let params=new URLSearchParams(); //ididURLSearchParams
}, params.append("ids",ids);
handleSelectDialogConfirm(){ params.append("recommendStatus",status);
if (this.dialogData.multipleSelection < 1) { updateRecommendStatus(params).then(response=>{ //updateRecommendStatus
this.getList(); //
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '修改成功!'
duration: 1000
});
return;
}
let selectProducts = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectProducts.push({
productId:this.dialogData.multipleSelection[i].id,
productName:this.dialogData.multipleSelection[i].name
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createNewProduct(selectProducts).then(response=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
}); });
}); });
}, }).catch(() => {
handleEditSort(index,row){ this.$message({ //
this.sortDialogVisible=true; type: 'success',
this.sortDialogData.sort=row.sort; message: '已取消操作!'
this.sortDialogData.id=row.id; });
}, this.getList();
handleUpdateSort(){ });
this.$confirm('是否要修改排序?', '提示', { },
confirmButtonText: '确定', //
cancelButtonText: '取消', deleteProduct(ids){
type: 'warning' this.$confirm('是否要删除该推荐?', '提示', { //
}).then(() => { confirmButtonText: '确定',
updateNewProductSort(this.sortDialogData).then(response=>{ cancelButtonText: '取消',
this.sortDialogVisible=false; type: 'warning'
this.getList(); }).then(() => {
this.$message({ let params=new URLSearchParams(); //ididURLSearchParams
type: 'success', params.append("ids",ids);
message: '删除成功!' deleteNewProduct(params).then(response=>{ //deleteNewProduct
}); this.getList(); //
});
})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
})
},
updateRecommendStatusStatus(ids,status){
this.$confirm('是否要修改推荐状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
params.append("recommendStatus",status);
updateRecommendStatus(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '修改成功!'
});
});
}).catch(() => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '已取消操作!' message: '删除成功!'
}); });
this.getList();
}); });
}, })
deleteProduct(ids){ },
this.$confirm('是否要删除该推荐?', '提示', { //
confirmButtonText: '确定', getDialogList(){
cancelButtonText: '取消', fetchProductList(this.dialogData.listQuery).then(response=>{ //fetchProductList
type: 'warning' this.dialogData.list=response.data.list; //
}).then(() => { this.dialogData.total=response.data.total;
let params=new URLSearchParams(); })
params.append("ids",ids);
deleteNewProduct(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
getDialogList(){
fetchProductList(this.dialogData.listQuery).then(response=>{
this.dialogData.list=response.data.list;
this.dialogData.total=response.data.total;
})
}
} }
} }
}
</script> </script>
<style></style> <style></style>

@ -1,9 +1,14 @@
<template>  <template>
<!-- 整个页面的容器用于包裹内部的各个组件 -->
<div class="app-container"> <div class="app-container">
<!-- el-card组件作为筛选搜索区域的容器设置阴影效果为"never"即无阴影 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 使用el-icon-search图标用于表示搜索相关的视觉元素 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示"筛选搜索"的文字提示 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- el-button按钮组件样式设置为右浮动按钮类型为"primary"主要按钮样式通常为主题色等突出显示点击时调用handleSearchList方法按钮大小为"small" -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- el-button按钮组件样式设置为右浮动且距离右边距15px点击时调用handleResetSearch方法按钮大小为"small"用于重置相关操作 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- el-form表单组件设置为行内表单形式绑定的数据模型是listQuery表单尺寸为"small"标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- el-form-item表单项目组件用于输入框的包裹此处对应的标签文本为"专题名称:" -->
<el-form-item label="专题名称:"> <el-form-item label="专题名称:">
<!-- el-input输入框组件双向绑定数据到listQuery.subjectName设置输入框的类名为"input-width"有相应的占位提示文字 -->
<el-input v-model="listQuery.subjectName" class="input-width" placeholder="专题名称"></el-input> <el-input v-model="listQuery.subjectName" class="input-width" placeholder="专题名称"></el-input>
</el-form-item> </el-form-item>
<!-- el-form-item表单项目组件用于下拉选择框的包裹对应的标签文本为"推荐状态:" -->
<el-form-item label="推荐状态:"> <el-form-item label="推荐状态:">
<!-- el-select下拉选择框组件双向绑定数据到listQuery.recommendStatus有相应的占位提示文字可清空选择设置类名为"input-width" -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 通过v-for循环遍历recommendOptions数组生成el-option下拉选项每个选项根据item中的属性设置相应的键显示标签和值 -->
<el-option v-for="item in recommendOptions" <el-option v-for="item in recommendOptions"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
@ -35,24 +47,34 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- el-card组件作为操作相关区域的容器设置阴影效果为"never"即无阴影 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- 使用el-icon-tickets图标用于表示相关操作的视觉元素 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 显示"数据列表"的文字提示 -->
<span>数据列表</span> <span>数据列表</span>
<!-- el-button按钮组件按钮尺寸为"mini"点击时调用handleSelectSubject方法按钮样式类名为"btn-add"用于选择专题操作 -->
<el-button size="mini" class="btn-add" @click="handleSelectSubject()"></el-button> <el-button size="mini" class="btn-add" @click="handleSelectSubject()"></el-button>
</el-card> </el-card>
<!-- 作为表格显示区域的容器 -->
<div class="table-container"> <div class="table-container">
<!-- el-table表格组件引用了ref为"newSubjectTable"绑定的数据为list设置宽度为100%监听行选择变化事件绑定加载状态到listLoading变量显示表格边框 -->
<el-table ref="newSubjectTable" <el-table ref="newSubjectTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- el-table-column表格列组件设置列类型为"selection"用于行选择的复选框列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- el-table-column表格列组件对应的标签为"编号"宽度为120px内容居中对齐通过插槽作用域展示对应行数据中的id属性 -->
<el-table-column label="编号" width="120" align="center"> <el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"专题名称"内容居中对齐通过插槽作用域展示对应行数据中的subjectName属性 -->
<el-table-column label="专题名称" align="center"> <el-table-column label="专题名称" align="center">
<template slot-scope="scope">{{scope.row.subjectName}}</template> <template slot-scope="scope">{{scope.row.subjectName}}</template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"是否推荐"宽度为200px内容居中对齐内部包含一个el-switch开关组件用于切换推荐状态绑定相应的事件和值 -->
<el-table-column label="是否推荐" width="200" align="center"> <el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@ -63,12 +85,15 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"排序"宽度为160px内容居中对齐通过插槽作用域展示对应行数据中的sort属性 -->
<el-table-column label="排序" width="160" align="center"> <el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"状态"宽度为160px内容居中对齐通过过滤器formatRecommendStatus对推荐状态数据进行格式化展示 -->
<el-table-column label="状态" width="160" align="center"> <el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template> <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"操作"宽度为180px内容居中对齐内部包含两个el-button按钮组件分别用于设置排序和删除操作绑定对应的点击事件 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -83,10 +108,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 作为批量操作区域的容器 -->
<div class="batch-operate-container"> <div class="batch-operate-container">
<!-- el-select下拉选择框组件尺寸为"small"双向绑定数据到operateType有相应的占位提示文字 -->
<el-select <el-select
size="small" size="small"
v-model="operateType" placeholder="批量操作"> v-model="operateType" placeholder="批量操作">
<!-- 通过v-for循环遍历operates数组生成el-option下拉选项每个选项根据item中的属性设置相应的键显示标签和值 -->
<el-option <el-option
v-for="item in operates" v-for="item in operates"
:key="item.value" :key="item.value"
@ -94,6 +122,7 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<!-- el-button按钮组件距离左边距20px样式类名为"search-button"点击时调用handleBatchOperate方法按钮类型为"primary"主要按钮样式按钮尺寸为"small"用于确定批量操作 -->
<el-button <el-button
style="margin-left: 20px" style="margin-left: 20px"
class="search-button" class="search-button"
@ -103,7 +132,9 @@
确定 确定
</el-button> </el-button>
</div> </div>
<!-- 作为分页区域的容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置背景色监听页面尺寸变化和当前页变化事件设置分页布局样式绑定每页显示数量可选的每页显示数量数组当前页码以及总数据量等相关属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -115,27 +146,35 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- el-dialog对话框组件标题为"选择专题"对话框显示状态双向绑定到selectDialogVisible变量宽度设置为50% -->
<el-dialog title="选择专题" :visible.sync="selectDialogVisible" width="50%"> <el-dialog title="选择专题" :visible.sync="selectDialogVisible" width="50%">
<!-- el-input输入框组件双向绑定数据到dialogData.listQuery.keyword设置宽度底边距以及尺寸等样式属性有相应的占位提示文字内部包含一个用于搜索操作的el-button按钮 -->
<el-input v-model="dialogData.listQuery.keyword" <el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px" style="width: 250px;margin-bottom: 20px"
size="small" size="small"
placeholder="专题名称搜索"> placeholder="专题名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button> <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input> </el-input>
<!-- el-table表格组件绑定的数据为dialogData.list监听行选择变化事件显示表格边框 -->
<el-table :data="dialogData.list" <el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border> @selection-change="handleDialogSelectionChange" border>
<!-- el-table-column表格列组件设置列类型为"selection"用于行选择的复选框列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- el-table-column表格列组件对应的标签为"专题名称"内容居中对齐通过插槽作用域展示对应行数据中的title属性 -->
<el-table-column label="专题名称" align="center"> <el-table-column label="专题名称" align="center">
<template slot-scope="scope">{{scope.row.title}}</template> <template slot-scope="scope">{{scope.row.title}}</template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"所属分类"宽度为160px内容居中对齐通过插槽作用域展示对应行数据中的categoryName属性 -->
<el-table-column label="所属分类" width="160" align="center"> <el-table-column label="所属分类" width="160" align="center">
<template slot-scope="scope">{{scope.row.categoryName}}</template> <template slot-scope="scope">{{scope.row.categoryName}}</template>
</el-table-column> </el-table-column>
<!-- el-table-column表格列组件对应的标签为"添加时间"宽度为160px内容居中对齐通过过滤器formatTime对时间数据进行格式化展示 -->
<el-table-column label="添加时间" width="160" align="center"> <el-table-column label="添加时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatTime}}</template> <template slot-scope="scope">{{scope.row.createTime | formatTime}}</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置背景色监听对话框内页面尺寸变化和当前页变化事件设置分页布局样式绑定对话框内每页显示数量当前页码以及总数据量等相关属性 -->
<el-pagination <el-pagination
background background
@size-change="handleDialogSizeChange" @size-change="handleDialogSizeChange"
@ -149,291 +188,340 @@
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div slot="footer"> <div slot="footer">
<!-- el-button按钮组件按钮尺寸为"small"点击时关闭对话框设置selectDialogVisible为false -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button> <el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- el-button按钮组件按钮尺寸为"small"按钮类型为"primary"主要按钮样式点击时调用handleSelectDialogConfirm方法用于确定操作 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button> <el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- el-dialog对话框组件标题为"设置排序"对话框显示状态双向绑定到sortDialogVisible变量宽度设置为40% -->
<el-dialog title="设置排序" <el-dialog title="设置排序"
:visible.sync="sortDialogVisible" :visible.sync="sortDialogVisible"
width="40%"> width="40%">
<!-- el-form表单组件绑定的数据模型是sortDialogData标签宽度为150px -->
<el-form :model="sortDialogData" <el-form :model="sortDialogData"
label-width="150px"> label-width="150px">
<!-- el-form-item表单项目组件对应的标签为"排序:"内部包含一个el-input输入框组件用于输入排序相关的值设置输入框宽度 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input> <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer"> <span slot="footer">
<!-- el-button按钮组件点击时关闭对话框设置sortDialogVisible为false按钮尺寸为"small" -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button> <el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- el-button按钮组件按钮类型为"primary"主要按钮样式点击时调用handleUpdateSort方法按钮尺寸为"small"用于确定排序设置操作 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button> <el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import {fetchList,updateRecommendStatus,deleteHomeSubject,createHomeSubject,updateHomeSubjectSort} from '@/api/homeSubject'; // '@/api/homeSubject'
import {fetchList as fetchSubjectList} from '@/api/subject'; import {fetchList,updateRecommendStatus,deleteHomeSubject,createHomeSubject,updateHomeSubjectSort} from '@/api/homeSubject';
import {formatDate} from '@/utils/date'; // '@/api/subject'fetchListfetchSubjectList
import {fetchList as fetchSubjectList} from '@/api/subject';
// '@/utils/date'formatDate
import {formatDate} from '@/utils/date';
const defaultListQuery = { //
pageNum: 1, const defaultListQuery = {
pageSize: 5, pageNum: 1,
subjectName: null, pageSize: 5,
recommendStatus: null subjectName: null,
}; recommendStatus: null
const defaultRecommendOptions = [ };
{ //
label: '未推荐', const defaultRecommendOptions = [
value: 0 {
}, label: '未推荐',
{ value: 0
label: '推荐中', },
value: 1 {
} label: '推荐中',
]; value: 1
export default { }
name: 'homeSubjectList', ];
data() {
return { export default {
listQuery: Object.assign({}, defaultListQuery), name: 'homeSubjectList',
recommendOptions: Object.assign({}, defaultRecommendOptions), data() {
return {
// defaultListQuery便
listQuery: Object.assign({}, defaultListQuery),
// defaultRecommendOptions
recommendOptions: Object.assign({}, defaultRecommendOptions),
// null
list: null,
// null
total: null,
// truefalse
listLoading: false,
//
multipleSelection: [],
//
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// null
operateType: null,
// falsetrue
selectDialogVisible: false,
//
dialogData: {
list: null, list: null,
total: null, total: null,
listLoading: false,
multipleSelection: [], multipleSelection: [],
operates: [ listQuery: {
{ keyword: null,
label: "设为推荐", pageNum: 1,
value: 0 pageSize: 5
}, }
{ },
label: "取消推荐", // falsetrue
value: 1 sortDialogVisible: false,
}, // id
{ sortDialogData: { sort: 0, id: null }
label: "删除", }
value: 2 },
} created() {
], // getList
operateType: null, this.getList();
selectDialogVisible:false, },
dialogData:{ filters: {
list: null, // 1""""
total: null, formatRecommendStatus(status) {
multipleSelection:[], if (status === 1) {
listQuery:{ return '推荐中';
keyword: null, } else {
pageNum: 1, return '未推荐';
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
} }
}, },
created() { // "N/A"
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
},
methods: {
// defaultListQuery
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// 1getList
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters:{ // multipleSelection使
formatRecommendStatus(status){ handleSelectionChange(val) {
if(status===1){ this.multipleSelection = val;
return '推荐中';
}else{
return '未推荐';
}
},
formatTime(time){
if(time==null||time===''){
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
}, },
methods: { // 1getList
handleResetSearch() { handleSizeChange(val) {
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery.pageNum = 1;
}, this.listQuery.pageSize = val;
handleSearchList() { this.getList();
this.listQuery.pageNum = 1; },
this.getList(); // getList
}, handleCurrentChange(val) {
handleSelectionChange(val){ this.listQuery.pageNum = val;
this.multipleSelection = val; this.getList();
}, },
handleSizeChange(val) { // updateRecommendStatusStatusid
this.listQuery.pageNum = 1; handleRecommendStatusStatusChange(index, row) {
this.listQuery.pageSize = val; this.updateRecommendStatusStatus(row.id, row.recommendStatus);
this.getList(); },
}, // deleteSubjectid
handleCurrentChange(val) { handleDelete(index, row) {
this.listQuery.pageNum = val; this.deleteSubject(row.id);
this.getList(); },
}, //
handleRecommendStatusStatusChange(index,row){ //
this.updateRecommendStatusStatus(row.id,row.recommendStatus); handleBatchOperate() {
}, if (this.multipleSelection < 1) { //
handleDelete(index,row){ this.$message({
this.deleteSubject(row.id); message: '请选择一条记录',
}, type: 'warning',
handleBatchOperate(){ duration: 1000
if (this.multipleSelection < 1) { });
return;
}
let ids = []; //
for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id);
}
if (this.operateType === 0) {
//
this.updateRecommendStatusStatus(ids, 1);
} else if (this.operateType === 1) {
//
this.updateRecommendStatusStatus(ids, 0);
} else if (this.operateType === 2) {
//
this.deleteSubject(ids);
} else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
//
handleSelectSubject() {
this.selectDialogVisible = true;
this.dialogData.listQuery.keyword = null;
this.getDialogList();//getDialogList
},
//
handleSelectSearch() {
this.getDialogList(); //getDialogList
},
//
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1; //1
this.dialogData.listQuery.pageSize = val;
this.getDialogList(); //getDialogList
},
//
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList(); //getDialogList
},
// 使
handleDialogSelectionChange(val) {
this.dialogData.multipleSelection = val;
},
//
handleSelectDialogConfirm() {
if (this.dialogData.multipleSelection < 1) {
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let selectSubjects = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectSubjects.push({
subjectId: this.dialogData.multipleSelection[i].id,
subjectName: this.dialogData.multipleSelection[i].title
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createHomeSubject(selectSubjects).then(response => { //// createHomeSubject
this.selectDialogVisible = false;
this.dialogData.multipleSelection = [];
this.getList();
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '添加成功!'
duration: 1000
}); });
return; });
} });
let ids = []; },
for (let i = 0; i < this.multipleSelection.length; i++) { //
ids.push(this.multipleSelection[i].id); handleEditSort(index, row) {
} this.sortDialogVisible = true;
if (this.operateType === 0) { this.sortDialogData.sort = row.sort;
// this.sortDialogData.id = row.id; //id
this.updateRecommendStatusStatus(ids,1); },
} else if (this.operateType === 1) { //
// handleUpdateSort() {
this.updateRecommendStatusStatus(ids,0); this.$confirm('是否要修改排序?', '提示', {
} else if(this.operateType===2){ confirmButtonText: '确定',
// cancelButtonText: '取消',
this.deleteSubject(ids); type: 'warning'
}else { }).then(() => {
updateHomeSubjectSort(this.sortDialogData).then(response => { //updateHomeSubjectSort
this.sortDialogVisible = false;
this.getList();
this.$message({ this.$message({
message: '请选择批量操作类型', type: 'success',
type: 'warning', message: '删除成功!' //updateHomeSubjectSort
duration: 1000
}); });
} });
}, })
handleSelectSubject(){ },
this.selectDialogVisible=true; //
this.dialogData.listQuery.keyword=null; getList() {
this.getDialogList(); this.listLoading = true; //true
}, fetchList(this.listQuery).then(response => { //fetchList
handleSelectSearch(){ this.listLoading = false; //false
this.getDialogList(); this.list = response.data.list; ////
}, this.total = response.data.total;
handleDialogSizeChange(val) { })
this.dialogData.listQuery.pageNum = 1; },
this.dialogData.listQuery.pageSize = val; //
this.getDialogList(); updateRecommendStatusStatus(ids, status) {
}, this.$confirm('是否要修改推荐状态?', '提示', { //
handleDialogCurrentChange(val) { confirmButtonText: '确定',
this.dialogData.listQuery.pageNum = val; cancelButtonText: '取消',
this.getDialogList(); type: 'warning'
}, }).then(() => {
handleDialogSelectionChange(val){ let params = new URLSearchParams(); //URLSearchParamsid
this.dialogData.multipleSelection = val; params.append("ids", ids);
}, params.append("finalRecommendStatus", status);
handleSelectDialogConfirm(){ updateRecommendStatus(params).then(response => { //// updateRecommendStatus
if (this.dialogData.multipleSelection < 1) { this.getList();
this.$message({ this.$message({
message: '请选择一条记录', type: 'success',
type: 'warning', message: '修改成功!' //
duration: 1000
});
return;
}
let selectSubjects = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectSubjects.push({
subjectId:this.dialogData.multipleSelection[i].id,
subjectName:this.dialogData.multipleSelection[i].title
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createHomeSubject(selectSubjects).then(response=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
}); });
}); });
}, }).catch(() => {
handleEditSort(index,row){ this.$message({
this.sortDialogVisible=true; type: 'success',
this.sortDialogData.sort=row.sort; message: '已取消操作!' //
this.sortDialogData.id=row.id; });
}, this.getList();
handleUpdateSort(){ });
this.$confirm('是否要修改排序?', '提示', { },
confirmButtonText: '确定', //
cancelButtonText: '取消', deleteSubject(ids) {
type: 'warning' this.$confirm('是否要删除该推荐?', '提示', { //
}).then(() => { confirmButtonText: '确定',
updateHomeSubjectSort(this.sortDialogData).then(response=>{ cancelButtonText: '取消',
this.sortDialogVisible=false; type: 'warning'
this.getList(); }).then(() => {
this.$message({ let params = new URLSearchParams(); //URLSearchParamsid
type: 'success', params.append("ids", ids);
message: '删除成功!' deleteHomeSubject(params).then(response => { //// deleteHomeSubject
}); this.getList();
});
})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
})
},
updateRecommendStatusStatus(ids,status){
this.$confirm('是否要修改推荐状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
params.append("recommendStatus",status);
updateRecommendStatus(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '修改成功!'
});
});
}).catch(() => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '已取消操作!' message: '删除成功!' //
}); });
this.getList();
}); });
}, })
deleteSubject(ids){ },
this.$confirm('是否要删除该推荐?', '提示', { //
confirmButtonText: '确定', getDialogList() {
cancelButtonText: '取消', fetchSubjectList(this.dialogData.listQuery).then(response => { //fetchSubjectList
type: 'warning' this.dialogData.list = response.data.list; //
}).then(() => { this.dialogData.total = response.data.total;
let params=new URLSearchParams(); })
params.append("ids",ids);
deleteHomeSubject(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
getDialogList(){
fetchSubjectList(this.dialogData.listQuery).then(response=>{
this.dialogData.list=response.data.list;
this.dialogData.total=response.data.total;
})
}
} }
} }
}
</script> </script>
<style></style> <style></style>

Loading…
Cancel
Save