3 #3

Merged
p6hj2n987 merged 1 commits from liran_branch into main 1 year ago

@ -0,0 +1,27 @@
<template>
<home-advertise-detail :isEdit="false"></home-advertise-detail>
</template>
<script>
import HomeAdvertiseDetail from './components/HomeAdvertiseDetail'
export default {
name: 'addHomeAdvertise',
components: { HomeAdvertiseDetail }
}
</script>
<style></style>
#abc
<template>
<!-- 使用HomeAdvertiseDetail组件并传递isEdit属性为false -->
<home-advertise-detail :isEdit="false"></home-advertise-detail>
</template>
import HomeAdvertiseDetail from './components/HomeAdvertiseDetail' // HomeAdvertiseDetail
export default {
name: 'addHomeAdvertise', // addHomeAdvertise
components: { HomeAdvertiseDetail } // HomeAdvertiseDetail
}
<style></style> <!-- 空的样式标签 -->

@ -0,0 +1,421 @@
<template>
<el-card class="form-container" shadow="never">
<el-form :model="homeAdvertise"
:rules="rules"
ref="homeAdvertiseFrom"
label-width="150px"
size="small">
<el-form-item label="广告名称:" prop="name">
<el-input v-model="homeAdvertise.name" class="input-width"></el-input>
</el-form-item>
<el-form-item label="广告位置:">
<el-select v-model="homeAdvertise.type">
<el-option
v-for="type in typeOptions"
:key="type.value"
:label="type.label"
:value="type.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="开始时间:" prop="startTime">
<el-date-picker
type="datetime"
placeholder="选择日期"
v-model="homeAdvertise.startTime"></el-date-picker>
</el-form-item>
<el-form-item label="到期时间:" prop="endTime">
<el-date-picker
type="datetime"
placeholder="选择日期"
v-model="homeAdvertise.endTime"></el-date-picker>
</el-form-item>
<el-form-item label="上线/下线:">
<el-radio-group v-model="homeAdvertise.status">
<el-radio :label="0">下线</el-radio>
<el-radio :label="1">上线</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="广告图片:">
<single-upload v-model="homeAdvertise.pic"></single-upload>
</el-form-item>
<el-form-item label="排序:">
<el-input v-model="homeAdvertise.sort" class="input-width"></el-input>
</el-form-item>
<el-form-item label="广告链接:" prop="url">
<el-input v-model="homeAdvertise.url" class="input-width"></el-input>
</el-form-item>
<el-form-item label="广告备注:">
<el-input
class="input-width"
type="textarea"
:rows="5"
placeholder="请输入内容"
v-model="homeAdvertise.note">
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit('homeAdvertiseFrom')"></el-button>
<el-button v-if="!isEdit" @click="resetForm('homeAdvertiseFrom')"></el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script>
import SingleUpload from '@/components/Upload/singleUpload'
import {createHomeAdvertise, getHomeAdvertise, updateHomeAdvertise} from '@/api/homeAdvertise'
const defaultTypeOptions = [
{
label: 'PC首页轮播',
value: 0
},
{
label: 'APP首页轮播',
value: 1
}
];
const defaultHomeAdvertise = {
name: null,
type: 1,
pic: null,
startTime: null,
endTime: null,
status: 0,
url: null,
note: null,
sort: 0
};
export default {
name: 'HomeAdvertiseDetail',
components:{SingleUpload},
props: {
isEdit: {
type: Boolean,
default: false
}
},
data() {
return {
homeAdvertise: null,
rules: {
name: [
{required: true, message: '请输入广告名称', trigger: 'blur'},
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
],
url: [
{required: true, message: '请输入广告链接', trigger: 'blur'}
],
startTime: [
{required: true, message: '请选择开始时间', trigger: 'blur'}
],
endTime: [
{required: true, message: '请选择到期时间', trigger: 'blur'}
],
pic: [
{required: true, message: '请选择广告图片', trigger: 'blur'}
]
},
typeOptions: Object.assign({}, defaultTypeOptions)
}
},
created(){
if (this.isEdit) {
getHomeAdvertise(this.$route.query.id).then(response => {
this.homeAdvertise = response.data;
});
}else{
this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
}
},
methods: {
onSubmit(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.$confirm('是否提交数据', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateHomeAdvertise(this.$route.query.id, this.homeAdvertise).then(response => {
this.$refs[formName].resetFields();
this.$message({
message: '修改成功',
type: 'success',
duration:1000
});
this.$router.back();
});
} else {
createHomeAdvertise(this.homeAdvertise).then(response => {
this.$refs[formName].resetFields();
this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
this.$message({
message: '提交成功',
type: 'success',
duration:1000
});
});
}
});
} else {
this.$message({
message: '验证失败',
type: 'error',
duration:1000
});
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
}
}
}
</script>
<style scoped>
.input-width {
width: 70%;
}
</style>
#abc
<template>
<!-- 使用el-card组件创建一个卡片式的容器设置其类名为form-container并且阴影效果为never即无阴影 -->
<el-card class="form-container" shadow="never">
<!-- 使用el-form组件创建表单绑定数据模型为homeAdvertise设置表单验证规则为rules
给表单设置ref属性用于后续在JavaScript中获取表单实例标签宽度为150px表单尺寸为small -->
<el-form :model="homeAdvertise"
:rules="rules"
ref="homeAdvertiseFrom"
label-width="150px"
size="small">
<!-- el-form-item用于定义表单中的每一项这里的标签显示为广告名称并通过prop属性关联对应的验证规则 -->
<el-form-item label="广告名称:" prop="name">
<!-- el-input组件用于输入文本通过v-model双向绑定数据到homeAdvertise对象的name属性设置类名为input-width -->
<el-input v-model="homeAdvertise.name" class="input-width"></el-input>
</el-form-item>
<!-- 另一个el-form-item标签显示为广告位置 -->
<el-form-item label="广告位置:">
<!-- el-select组件用于创建下拉选择框通过v-model双向绑定数据到homeAdvertise对象的type属性 -->
<el-select v-model="homeAdvertise.type">
<!-- 通过v-for循环遍历typeOptions数组来生成el-option选项每个选项的keylabelvalue分别对应相应的属性值 -->
<el-option
v-for="type in typeOptions"
:key="type.value"
:label="type.label"
:value="type.value">
</el-option>
</el-select>
</el-form-item>
<!-- el-form-item用于开始时间这一项标签显示为开始时间并通过prop关联对应的验证规则 -->
<el-form-item label="开始时间:" prop="startTime">
<!-- el-date-picker组件用于选择日期和时间类型设置为datetime即日期时间选择器
占位文本为选择日期通过v-model双向绑定数据到homeAdvertise对象的startTime属性 -->
<el-date-picker
type="datetime"
placeholder="选择日期"
v-model="homeAdvertise.startTime"></el-date-picker>
</el-form-item>
<!-- 类似的这是到期时间对应的el-form-item -->
<el-form-item label="到期时间:" prop="endTime">
<!-- el-date-picker用于选择到期时间同样是日期时间选择器绑定到homeAdvertise对象的endTime属性 -->
<el-date-picker
type="datetime"
placeholder="选择日期"
v-model="homeAdvertise.endTime"></el-date-picker>
</el-form-item>
<!-- el-form-item用于上线/下线这一项 -->
<el-form-item label="上线/下线:">
<!-- el-radio-group组件用于创建单选按钮组通过v-model双向绑定数据到homeAdvertise对象的status属性 -->
<el-radio-group v-model="homeAdvertise.status">
<!-- 定义一个单选按钮标签为下线值为0 -->
<el-radio :label="0">下线</el-radio>
<!-- 定义另一个单选按钮标签为上线值为1 -->
<el-radio :label="1">上线</el-radio>
</el-radio-group>
</el-form-item>
<!-- 广告图片对应的el-form-item -->
<el-form-item label="广告图片:">
<!-- 引入了一个名为single-upload的自定义组件通过v-model双向绑定数据到homeAdvertise对象的pic属性 -->
<single-upload v-model="homeAdvertise.pic"></single-upload>
</el-form-item>
<!-- 排序对应的el-form-item -->
<el-form-item label="排序:">
<!-- el-input组件用于输入排序相关的数值绑定到homeAdvertise对象的sort属性设置类名为input-width -->
<el-input v-model="homeAdvertise.sort" class="input-width"></el-input>
</el-form-item>
<!-- 广告链接对应的el-form-item通过prop关联对应的验证规则 -->
<el-form-item label="广告链接:" prop="url">
<!-- el-input组件用于输入广告链接文本绑定到homeAdvertise对象的url属性设置类名为input-width -->
<el-input v-model="homeAdvertise.url" class="input-width"></el-input>
</el-form-item>
<!-- 广告备注对应的el-form-item -->
<el-form-item label="广告备注:">
<!-- el-input组件用于输入多行文本设置为textarea类型设置行数为5占位文本为请输入内容
绑定到homeAdvertise对象的note属性 -->
<el-input
class="input-width"
type="textarea"
:rows="5"
placeholder="请输入内容"
v-model="homeAdvertise.note">
</el-input>
</el-form-item>
<!-- 一个普通的el-form-item用于放置按钮等操作元素 -->
<el-form-item>
<!-- el-button组件按钮类型为primary主要按钮样式点击时调用onSubmit方法并传入'homeAdvertiseFrom'参数 -->
<el-button type="primary" @click="onSubmit('homeAdvertiseFrom')"></el-button>
<!-- 条件渲染的el-button!isEdit为真即处于非编辑状态时显示点击时调用resetForm方法并传入'homeAdvertiseFrom'参数 -->
<el-button v-if="!isEdit" @click="resetForm('homeAdvertiseFrom')"></el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script>
// SingleUpload'@/components/Upload/singleUpload'
import SingleUpload from '@/components/Upload/singleUpload'
// '@/api/homeAdvertise'createHomeAdvertisegetHomeAdvertiseupdateHomeAdvertise
import {createHomeAdvertise, getHomeAdvertise, updateHomeAdvertise} from '@/api/homeAdvertise'
// 广广
const defaultTypeOptions = [
{
label: 'PC首页轮播',
value: 0
},
{
label: 'APP首页轮播',
value: 1
}
];
// homeAdvertise
const defaultHomeAdvertise = {
name: null,
type: 1,
pic: null,
startTime: null,
endTime: null,
status: 0,
url: null,
note: null,
sort: 0
};
export default {
name: 'HomeAdvertiseDetail',
components:{SingleUpload},
props: {
isEdit: {
type: Boolean,
default: false
}
},
data() {
return {
// 广
homeAdvertise: null,
rules: {
name: [
// 广广
{required: true, message: '请输入广告名称', trigger: 'blur'},
// 广2140
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
],
url: [
// 广广
{required: true, message: '请输入广告链接', trigger: 'blur'}
],
startTime: [
//
{required: true, message: '请选择开始时间', trigger: 'blur'}
],
endTime: [
//
{required: true, message: '请选择到期时间', trigger: 'blur'}
],
pic: [
// 广广
{required: true, message: '请选择广告图片', trigger: 'blur'}
]
},
typeOptions: Object.assign({}, defaultTypeOptions)
}
},
created(){
//
if (this.isEdit) {
// getHomeAdvertise广id
// homeAdvertise
getHomeAdvertise(this.$route.query.id).then(response => {
this.homeAdvertise = response.data;
});
}else{
// homeAdvertisehomeAdvertise
this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
}
},
methods: {
onSubmit(formName) {
// validatevalid
this.$refs[formName].validate((valid) => {
if (valid) {
//
this.$confirm('是否提交数据', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
// updateHomeAdvertise广idhomeAdvertise
//
updateHomeAdvertise(this.$route.query.id, this.homeAdvertise).then(response => {
this.$refs[formName].resetFields();
this.$message({
message: '修改成功',
type: 'success',
duration:1000
});
this.$router.back();
});
} else {
// createHomeAdvertise广homeAdvertise
// homeAdvertise
createHomeAdvertise(this.homeAdvertise).then(response => {
this.$refs[formName].resetFields();
this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
this.$message({
message: '提交成功',
type: 'success',
duration:1000
});
});
}
});
} else {
//
this.$message({
message: '验证失败',
type: 'error',
duration:1000
});
return false;
}
});
},
resetForm(formName) {
// resetFieldshomeAdvertise
this.$refs[formName].resetFields();
this.homeAdvertise = Object.assign({},defaultHomeAdvertise);
}
}
}
</script>
<style scoped>
/* 定义类名为input-width的样式设置宽度为70% */
.input-width {
width: 70%;
}
</style>

@ -0,0 +1,637 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="广告名称:">
<el-input v-model="listQuery.name" class="input-width" placeholder="广告名称"></el-input>
</el-form-item>
<el-form-item label="广告位置:">
<el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
<el-option v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="到期时间:">
<el-date-picker
class="input-width"
v-model="listQuery.endTime"
value-format="yyyy-MM-dd"
type="date"
placeholder="请选择时间">
</el-date-picker>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleAdd()">广</el-button>
</el-card>
<div class="table-container">
<el-table ref="homeAdvertiseTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="广告名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="广告位置" width="120" align="center">
<template slot-scope="scope">{{scope.row.type | formatType}}</template>
</el-table-column>
<el-table-column label="广告图片" width="120" align="center">
<template slot-scope="scope"><img style="height: 80px" :src="scope.row.pic"></template>
</el-table-column>
<el-table-column label="时间" width="220" align="center">
<template slot-scope="scope">
<p>开始时间{{scope.row.startTime | formatTime}}</p>
<p>到期时间{{scope.row.endTime | formatTime}}</p>
</template>
</el-table-column>
<el-table-column label="上线/下线" width="120" align="center">
<template slot-scope="scope">
<el-switch
@change="handleUpdateStatus(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.status">
</el-switch>
</template>
</el-table-column>
<el-table-column label="点击次数" width="120" align="center">
<template slot-scope="scope">{{scope.row.clickCount}}</template>
</el-table-column>
<el-table-column label="生成订单" width="120" align="center">
<template slot-scope="scope">{{scope.row.orderCount}}</template>
</el-table-column>
<el-table-column label="操作" width="120" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="batch-operate-container">
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
import {fetchList,updateStatus,deleteHomeAdvertise} from '@/api/homeAdvertise';
import {formatDate} from '@/utils/date';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
name: null,
type: null,
endTime:null
};
const defaultTypeOptions = [
{
label: 'PC首页轮播',
value: 0
},
{
label: 'APP首页轮播',
value: 1
}
];
export default {
name: 'homeAdvertiseList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
typeOptions: Object.assign({}, defaultTypeOptions),
list: null,
total: null,
listLoading: false,
multipleSelection: [],
operates: [
{
label: "删除",
value: 0
}
],
operateType: null
}
},
created() {
this.getList();
},
filters:{
formatType(type){
if(type===1){
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() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
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({
type: 'success',
message: '已取消操作!'
});
this.getList();
});
},
handleDelete(index,row){
this.deleteHomeAdvertise(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.deleteHomeAdvertise(ids);
}else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
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>
<style scoped>
.input-width {
width: 203px;
}
</style>
#abc
<template>
<!-- 定义一个Vue组件的模板部分根元素是一个class为app-container的div -->
<div class="app-container">
<!-- 使用Element UI的el-card组件创建一个筛选搜索的容器设置阴影效果为never -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 使用Element UI的图标组件展示搜索图标 -->
<i class="el-icon-search"></i>
<!-- 显示筛选搜索的文字说明 -->
<span>筛选搜索</span>
<!-- 使用Element UI的按钮组件设置样式为右浮动类型为主要按钮绑定点击事件handleSearchList按钮大小为small用于查询搜索操作 -->
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<!-- 使用Element UI的按钮组件设置样式为右浮动且距右侧15px绑定点击事件handleResetSearch按钮大小为small用于重置操作 -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 使用Element UI的表单组件设置为行内表单绑定数据模型为listQuery表单尺寸为small标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单中的一个表单项用于输入广告名称绑定v-model到listQuery.name设置输入框样式类为input-width并设置占位文本 -->
<el-form-item label="广告名称:">
<el-input v-model="listQuery.name" class="input-width" placeholder="广告名称"></el-input>
</el-form-item>
<!-- 表单中的一个表单项用于选择广告位置绑定v-model到listQuery.type设置占位文本为全部可清空样式类为input-width -->
<el-form-item label="广告位置:">
<el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
<!-- 循环遍历typeOptions数组生成下拉选项每个选项根据对应的item设置keylabel和value属性 -->
<el-option v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<!-- 表单中的一个表单项用于选择到期时间绑定v-model到listQuery.endTime设置日期格式为yyyy-MM-dd类型为日期选择器设置占位文本 -->
<el-form-item label="到期时间:">
<el-date-picker
class="input-width"
v-model="listQuery.endTime"
value-format="yyyy-MM-dd"
type="date"
placeholder="请选择时间">
</el-date-picker>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 使用Element UI的el-card组件创建一个操作相关的容器设置阴影效果为never -->
<el-card class="operate-container" shadow="never">
<!-- 使用Element UI的图标组件展示票务图标 -->
<i class="el-icon-tickets"></i>
<!-- 显示数据列表的文字说明 -->
<span>数据列表</span>
<!-- 使用Element UI的按钮组件设置按钮大小为mini样式类为btn-add绑定点击事件handleAdd用于添加广告操作 -->
<el-button size="mini" class="btn-add" @click="handleAdd()">广</el-button>
</el-card>
<!-- 定义一个用于放置表格的容器div -->
<div class="table-container">
<!-- 使用Element UI的el-table组件展示数据表格绑定数据为list设置宽度为100%监听选择改变事件handleSelectionChange根据listLoading控制加载状态设置表格边框 -->
<el-table ref="homeAdvertiseTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<!-- 定义一个选择列设置宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 定义一个编号列设置宽度为120px内容居中对齐通过插槽作用域展示对应行数据的id属性 -->
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 定义一个广告名称列内容居中对齐通过插槽作用域展示对应行数据的name属性 -->
<el-table-column label="广告名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 定义一个广告位置列设置宽度为120px内容居中对齐通过插槽作用域展示经过formatType过滤器处理后的对应行数据的type属性 -->
<el-table-column label="广告位置" width="120" align="center">
<template slot-scope="scope">{{scope.row.type | formatType}}</template>
</el-table-column>
<!-- 定义一个广告图片列设置宽度为120px内容居中对齐通过插槽作用域展示对应行数据的pic属性对应的图片设置图片高度为80px -->
<el-table-column label="广告图片" width="120" align="center">
<template slot-scope="scope"><img style="height: 80px" :src="scope.row.pic"></template>
</el-table-column>
<!-- 定义一个时间列设置宽度为220px内容居中对齐通过插槽作用域展示对应行数据的开始时间和到期时间经过formatTime过滤器处理 -->
<el-table-column label="时间" width="220" align="center">
<template slot-scope="scope">
<p>开始时间{{scope.row.startTime | formatTime}}</p>
<p>到期时间{{scope.row.endTime | formatTime}}</p>
</template>
</el-table-column>
<!-- 定义一个上线/下线列设置宽度为120px内容居中对齐通过插槽作用域使用el-switch组件来切换对应行数据的status属性绑定相关的事件和属性值 -->
<el-table-column label="上线/下线" width="120" align="center">
<template slot-scope="scope">
<el-switch
@change="handleUpdateStatus(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.status">
</el-switch>
</template>
</el-table-column>
<!-- 定义一个点击次数列设置宽度为120px内容居中对齐通过插槽作用域展示对应行数据的clickCount属性 -->
<el-table-column label="点击次数" width="120" align="center">
<template slot-scope="scope">{{scope.row.clickCount}}</template>
</el-table-column>
<!-- 定义一个生成订单列设置宽度为120px内容居中对齐通过插槽作用域展示对应行数据的orderCount属性 -->
<el-table-column label="生成订单" width="120" align="center">
<template slot-scope="scope">{{scope.row.orderCount}}</template>
</el-table-column>
<!-- 定义一个操作列设置宽度为120px内容居中对齐通过插槽作用域使用按钮组件实现编辑和删除操作绑定对应的点击事件 -->
<el-table-column label="操作" width="120" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 定义一个用于批量操作的容器div -->
<div class="batch-operate-container">
<!-- 使用Element UI的el-select组件创建一个下拉选择框绑定v-model到operateType设置占位文本为批量操作 -->
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<!-- 循环遍历operates数组生成下拉选项每个选项根据对应的item设置keylabel和value属性 -->
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<!-- 使用Element UI的按钮组件设置距左侧20px的样式样式类为search-button绑定点击事件handleBatchOperate类型为主要按钮按钮大小为small用于确定批量操作 -->
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<!-- 定义一个用于放置分页组件的容器div -->
<div class="pagination-container">
<!-- 使用Element UI的el-pagination组件实现分页功能设置背景色监听页面尺寸改变事件handleSizeChange当前页改变事件handleCurrentChange设置相关的布局页面尺寸可选页面尺寸当前页总数据量等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
// @/api/homeAdvertisefetchListupdateStatusdeleteHomeAdvertise广
import {fetchList, updateStatus, deleteHomeAdvertise} from '@/api/homeAdvertise';
// @/utils/dateformatDate
import {formatDate} from '@/utils/date';
// 广广
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
name: null,
type: null,
endTime: null
};
// 广labelvalue广
const defaultTypeOptions = [
{
label: 'PC首页轮播',
value: 0
},
{
label: 'APP首页轮播',
value: 1
}
];
export default {
name: 'homeAdvertiseList',
data() {
return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// 广defaultTypeOptions广
typeOptions: Object.assign({}, defaultTypeOptions),
// 广
list: null,
//
total: null,
//
listLoading: false,
//
multipleSelection: [],
// labelvalue
operates: [
{
label: "删除",
value: 0
}
],
//
operateType: null
}
},
created() {
// getList广
this.getList();
},
filters: {
// formatType广
formatType(type) {
if (type === 1) {
return 'APP首页轮播';
} else {
return 'PC首页轮播';
}
},
// formatTime'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: {
// listQuery
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// 1getList广
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// multipleSelection
handleSelectionChange(val) {
this.multipleSelection = val;
},
// 1getList广
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// getList广
handleCurrentChange(val) {
this.listQuery.pageNum = val;
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({
type: 'success',
message: '已取消操作!'
});
this.getList();
});
},
// 广deleteHomeAdvertise广id
handleDelete(index, row) {
this.deleteHomeAdvertise(row.id);
},
// deleteHomeAdvertiseid
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.deleteHomeAdvertise(ids);
} else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
// 广广/sms/addAdvertise
handleAdd() {
this.$router.push({path: '/sms/addAdvertise'})
},
// 广广/sms/updateAdvertise广id

@ -0,0 +1,32 @@
<template> 
<home-advertise-detail :isEdit="true"></home-advertise-detail>
</template>
<script>
import HomeAdvertiseDetail from './components/HomeAdvertiseDetail'
export default {
name: 'updateHomeAdvertise',
components: { HomeAdvertiseDetail }
}
</script>
<style></style>
#abc
<template>
<!-- 在当前模板中使用名为`home-advertise-detail`的自定义组件
并通过`:isEdit="true"`的方式向该组件传递一个名为`isEdit`的属性值为`true`
意味着当前是处于编辑状态可能用于控制组件内部不同的展示或操作逻辑 -->
<home-advertise-detail :isEdit="true"></home-advertise-detail>
</template>
<script>
// `./components/HomeAdvertiseDetail``HomeAdvertiseDetail`
// 使使
import HomeAdvertiseDetail from './components/HomeAdvertiseDetail'
export default {
name: 'updateHomeAdvertise',
// `components``HomeAdvertiseDetail`
// template使
components: { HomeAdvertiseDetail }
}
</script>
<style></style>

@ -0,0 +1,651 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="品牌名称:">
<el-input v-model="listQuery.brandName" class="input-width" placeholder="品牌名称"></el-input>
</el-form-item>
<el-form-item label="推荐状态:">
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleSelectBrand()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="homeBrandTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="品牌名称" align="center">
<template slot-scope="scope">{{scope.row.brandName}}</template>
</el-table-column>
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.recommendStatus">
</el-switch>
</template>
</el-table-column>
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="batch-operate-container">
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
<el-dialog title="选择品牌" :visible.sync="selectDialogVisible" width="40%">
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="品牌名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="品牌名称"align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="相关" width="220" align="center">
<template slot-scope="scope">
商品<span class="color-main">{{scope.row.productCount}}</span>
评价<span class="color-main">{{scope.row.productCommentCount}}</span>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<el-form :model="sortDialogData"
label-width="150px">
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,updateRecommendStatus,deleteHomeBrand,createHomeBrand,updateHomeBrandSort} from '@/api/homeBrand';
import {fetchList as fetchBrandList} from '@/api/brand';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
brandName: null,
recommendStatus: null
};
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'homeBrandList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
recommendOptions: Object.assign({}, defaultRecommendOptions),
list: null,
total: null,
listLoading: false,
multipleSelection: [],
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
operateType: null,
selectDialogVisible:false,
dialogData:{
list: null,
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
showStatus:1,
pageNum: 1,
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
}
},
created() {
this.getList();
},
filters:{
formatRecommendStatus(status){
if(status===1){
return '推荐中';
}else{
return '未推荐';
}
}
},
methods: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleRecommendStatusStatusChange(index,row){
this.updateRecommendStatusStatus(row.id,row.recommendStatus);
},
handleDelete(index,row){
this.deleteBrand(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.deleteBrand(ids);
}else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
return;
}
},
handleSelectBrand(){
this.selectDialogVisible=true;
this.getDialogList();
},
handleSelectSearch(){
this.getDialogList();
},
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList();
},
handleDialogSelectionChange(val){
this.dialogData.multipleSelection = val;
},
handleSelectDialogConfirm(){
if (this.dialogData.multipleSelection < 1) {
this.$message({
message: '请选择一条记录',
type: 'warning',
duration: 1000
});
return;
}
let selectBrands = [];
for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
selectBrands.push({
brandId:this.dialogData.multipleSelection[i].id,
brandName:this.dialogData.multipleSelection[i].name
});
}
this.$confirm('使用要进行添加操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
createHomeBrand(selectBrands).then(response=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
});
});
},
handleEditSort(index,row){
this.sortDialogVisible=true;
this.sortDialogData.sort=row.sort;
this.sortDialogData.id=row.id;
},
handleUpdateSort(){
this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateHomeBrandSort(this.sortDialogData).then(response=>{
this.sortDialogVisible=false;
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
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({
type: 'success',
message: '已取消操作!'
});
this.getList();
});
},
deleteBrand(ids){
this.$confirm('是否要删除该推荐?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let params=new URLSearchParams();
params.append("ids",ids);
deleteHomeBrand(params).then(response=>{
this.getList();
this.$message({
type: 'success',
message: '删成功!'
});
});
})
},
getDialogList(){
fetchBrandList(this.dialogData.listQuery).then(response=>{
this.dialogData.list=response.data.list;
this.dialogData.total=response.data.total;
})
}
}
}
</script>
<style></style>
#abc
<template>
<!-- 页面的根容器使用了app-container类名 -->
<div class="app-container">
<!-- 筛选搜索的卡片容器设置了阴影效果为无 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 搜索图标 -->
<i class="el-icon-search"></i>
<!-- 筛选搜索的文字提示 -->
<span>筛选搜索</span>
<!-- 查询搜索按钮设置了样式类型点击事件以及尺寸点击后调用handleSearchList方法 -->
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<!-- 重置按钮设置了样式点击事件以及尺寸点击后调用handleResetSearch方法 -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 内联表单绑定了数据模型listQuery设置了尺寸和标签宽度 -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 品牌名称的表单项 -->
<el-form-item label="品牌名称:">
<!-- 输入框双向绑定listQuery.brandName设置了类名和占位符 -->
<el-input v-model="listQuery.brandName" class="input-width" placeholder="品牌名称"></el-input>
</el-form-item>
<!-- 推荐状态的表单项 -->
<el-form-item label="推荐状态:">
<!-- 下拉选择框双向绑定listQuery.recommendStatus设置了占位符可清除以及类名 -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 循环生成下拉选项根据recommendOptions数据来生成每个选项 -->
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 操作相关的卡片容器设置了阴影效果为无 -->
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<!-- 选择品牌按钮设置了尺寸和点击事件点击后调用handleSelectBrand方法 -->
<el-button size="mini" class="btn-add" @click="handleSelectBrand()"></el-button>
</el-card>
<!-- 表格容器 -->
<div class="table-container">
<!-- el-table组件用于展示数据列表绑定了数据设置了宽度选择改变事件加载状态以及边框 -->
<el-table ref="homeBrandTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<!-- 选择列设置了宽度和对齐方式 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 编号列设置了宽度和对齐方式通过插槽作用域展示对应行的id数据 -->
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 品牌名称列设置了对齐方式通过插槽作用域展示对应行的brandName数据 -->
<el-table-column label="品牌名称" align="center">
<template slot-scope="scope">{{scope.row.brandName}}</template>
</el-table-column>
<!-- 是否推荐列设置了宽度和对齐方式通过插槽作用域展示开关组件来切换推荐状态绑定了相应的事件和数据 -->
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.recommendStatus">
</el-switch>
</template>
</el-table-column>
<!-- 排序列设置了宽度和对齐方式通过插槽作用域展示对应行的sort数据 -->
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<!-- 状态列设置了宽度和对齐方式通过插槽作用域展示格式化后的推荐状态数据 -->
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<!-- 操作列设置了宽度和对齐方式通过插槽作用域展示编辑排序和删除按钮并绑定了相应的点击事件 -->
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 批量操作容器 -->
<div class="batch-operate-container">
<!-- 下拉选择框用于选择批量操作类型双向绑定operateType -->
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<!-- 循环生成下拉选项根据operates数据来生成每个选项 -->
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<!-- 确定按钮设置了样式点击事件类型以及尺寸点击后调用handleBatchOperate方法 -->
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<!-- 分页容器 -->
<div class="pagination-container">
<!-- el-pagination组件用于分页功能绑定了相关的事件设置了布局每页显示数量可选的每页显示数量范围当前页码以及总数据量等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
<!-- 选择品牌的对话框组件设置了标题显示状态绑定以及宽度 -->
<el-dialog title="选择品牌" :visible.sync="selectDialogVisible" width="40%">
<!-- 输入框用于在对话框中搜索品牌双向绑定dialogData.listQuery.keyword设置了样式尺寸和占位符还有点击搜索按钮的事件 -->
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="品牌名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<!-- 对话框中的表格用于展示可选择的品牌数据绑定了数据设置了选择改变事件和边框 -->
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<!-- 选择列设置了宽度和对齐方式 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 品牌名称列设置了对齐方式通过插槽作用域展示对应行的name数据 -->
<el-table-column label="品牌名称"align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 相关列设置了宽度和对齐方式通过插槽作用域展示商品数量和评价数量等相关信息 -->
<el-table-column label="相关" width="220" align="center">
<template slot-scope="scope">
商品<span class="color-main">{{scope.row.productCount}}</span>
评价<span class="color-main">{{scope.row.productCommentCount}}</span>
</template>
</el-table-column>
</el-table>
<!-- 对话框中的分页容器 -->
<div class="pagination-container">
<!-- el-pagination组件用于对话框内的分页功能绑定了相关的事件设置了布局当前页码每页显示数量以及总数据量等属性 -->
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<!-- 取消按钮设置了尺寸和点击事件点击后关闭对话框 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 确定按钮设置了尺寸类型和点击事件点击后调用handleSelectDialogConfirm方法 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<!-- 设置排序的对话框组件设置了标题显示状态绑定以及宽度 -->
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<!-- 表单绑定了sortDialogData数据模型设置了标签宽度 -->
<el-form :model="sortDialogData"
label-width="150px">
<!-- 排序的表单项输入框双向绑定sortDialogData.sort设置了宽度 -->
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<!-- 取消按钮设置了尺寸和点击事件点击后关闭对话框 -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- 确定按钮设置了尺寸类型和点击事件点击后调用handleUpdateSort方法 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script></script>

@ -0,0 +1,29 @@
<template> 
<coupon-detail :isEdit="false"></coupon-detail>
</template>
<script>
import CouponDetail from './components/CouponDetail'
export default {
name: 'addCoupon',
components: { CouponDetail }
}
</script>
<style scoped>
</style>
#abc
<template>
<!-- 使用CouponDetail组件来展示添加优惠券的相关界面通过属性绑定将isEdit设置为false表示当前处于添加优惠券非编辑的状态 -->
<coupon-detail :isEdit="false"></coupon-detail>
</template>
<script>
// ./components/CouponDetailCouponDetailCouponDetailVue
import CouponDetail from './components/CouponDetail'
export default {
name: 'addCoupon',
// componentsCouponDetailtemplate使<coupon-detail>
components: { CouponDetail }
}
</script>

@ -0,0 +1,810 @@
<template> 
<el-card class="form-container" shadow="never">
<el-form :model="coupon"
:rules="rules"
ref="couponFrom"
label-width="150px"
size="small">
<el-form-item label="优惠券类型:">
<el-select v-model="coupon.type">
<el-option
v-for="type in typeOptions"
:key="type.value"
:label="type.label"
:value="type.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="优惠券名称:" prop="name">
<el-input v-model="coupon.name" class="input-width"></el-input>
</el-form-item>
<el-form-item label="适用平台:">
<el-select v-model="coupon.platform">
<el-option
v-for="item in platformOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="总发行量:" prop="publishCount">
<el-input v-model.number="coupon.publishCount" placeholder="只能输入正整数" class="input-width"></el-input>
</el-form-item>
<el-form-item label="面额:" prop="amount">
<el-input v-model.number="coupon.amount" placeholder="面值只能是数值限2位小数" class="input-width">
<template slot="append"></template>
</el-input>
</el-form-item>
<el-form-item label="每人限领:">
<el-input v-model="coupon.perLimit" placeholder="只能输入正整数" class="input-width">
<template slot="append"></template>
</el-input>
</el-form-item>
<el-form-item label="使用门槛:" prop="minPoint">
<el-input v-model.number="coupon.minPoint" placeholder="只能输入正整数" class="input-width">
<template slot="prepend"></template>
<template slot="append">元可用</template>
</el-input>
</el-form-item>
<el-form-item label="领取日期:" prop="enableTime">
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.enableTime" class="input-width"></el-date-picker>
</el-form-item>
<el-form-item label="有效期:">
<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>
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.endTime" style="width: 150px"></el-date-picker>
</el-form-item>
<el-form-item label="可使用商品:">
<el-radio-group v-model="coupon.useType">
<el-radio-button :label="0">全场通用</el-radio-button>
<el-radio-button :label="1">指定分类</el-radio-button>
<el-radio-button :label="2">指定商品</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="coupon.useType===1">
<el-cascader
clearable
placeholder="请选择分类名称"
v-model="selectProductCate"
:options="productCateOptions">
</el-cascader>
<el-button @click="handleAddProductCategoryRelation()"></el-button>
<el-table ref="productCateRelationTable"
:data="coupon.productCategoryRelationList"
style="width: 100%;margin-top: 20px"
border>
<el-table-column label="分类名称" align="center">
<template slot-scope="scope">{{scope.row.parentCategoryName}}>{{scope.row.productCategoryName}}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="100">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleDeleteProductCateRelation(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<el-form-item v-show="coupon.useType===2">
<el-select
v-model="selectProduct"
filterable
remote
reserve-keyword
placeholder="商品名称/商品货号"
:remote-method="searchProductMethod"
:loading="selectProductLoading">
<el-option
v-for="item in selectProductOptions"
:key="item.productId"
:label="item.productName"
:value="item.productId">
<span style="float: left">{{ item.productName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.productSn }}</span>
</el-option>
</el-select>
<el-button @click="handleAddProductRelation()"></el-button>
<el-table ref="productRelationTable"
:data="coupon.productRelationList"
style="width: 100%;margin-top: 20px"
border>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column>
<el-table-column label="货号" align="center" width="120" >
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="100">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleDeleteProductRelation(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<el-form-item label="备注:">
<el-input
class="input-width"
type="textarea"
:rows="5"
placeholder="请输入内容"
v-model="coupon.note">
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit('couponFrom')"></el-button>
<el-button v-if="!isEdit" @click="resetForm('couponFrom')"></el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script>
import {createCoupon,getCoupon,updateCoupon} from '@/api/coupon';
import {fetchSimpleList as fetchProductList} from '@/api/product';
import {fetchListWithChildren} from '@/api/productCate'
const defaultCoupon = {
type: 0,
name: null,
platform: 0,
amount: null,
perLimit: 1,
minPoint: null,
startTime: null,
endTime: null,
useType: 0,
note: null,
publishCount: null,
productRelationList: [],
productCategoryRelationList: []
};
const defaultTypeOptions = [
{
label: '全场赠券',
value: 0
},
{
label: '会员赠券',
value: 1
},
{
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
const defaultPlatformOptions = [
{
label: '全平台',
value: 0
},
{
label: '移动平台',
value: 1
},
{
label: 'PC平台',
value: 2
}
];
export default {
name: 'CouponDetail',
props: {
isEdit: {
type: Boolean,
default: false
}
},
data() {
return {
coupon: Object.assign({}, defaultCoupon),
typeOptions: Object.assign({}, defaultTypeOptions),
platformOptions: Object.assign({}, defaultPlatformOptions),
rules: {
name: [
{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'}
]
},
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{
createCoupon(this.coupon).then(response=>{
this.$refs[formName].resetFields();
this.$message({
message: '提交成功',
type: 'success',
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 {
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);
},
getProductById(id){
for(let i=0;i<this.selectProductOptions.length;i++){
if(id===this.selectProductOptions[i].productId){
return this.selectProductOptions[i];
}
}
return null;
},
getProductCateList() {
fetchListWithChildren().then(response => {
let list = response.data;
this.productCateOptions = [];
for (let i = 0; i < list.length; i++) {
let children = [];
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});
}
});
},
getProductCateByIds(ids){
let name;
let parentName;
for (let i = 0; i < this.productCateOptions.length; i++) {
if (this.productCateOptions[i].value === ids[0]) {
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};
}
}
}
</script>
<style scoped>
.input-width {
width: 60%;
}
</style>
#abc
<template>
<!-- 使用el-card组件创建一个表单容器设置阴影效果为无 -->
<el-card class="form-container" shadow="never">
<!-- 创建一个el-form表单组件绑定数据模型为coupon设置验证规则表单引用标签宽度尺寸等属性 -->
<el-form :model="coupon"
:rules="rules"
ref="couponFrom"
label-width="150px"
size="small">
<!-- 优惠券类型选择的表单项 -->
<el-form-item label="优惠券类型:">
<!-- el-select组件用于选择优惠券类型双向绑定v-model到coupon.type -->
<el-select v-model="coupon.type">
<!-- 遍历typeOptions数组生成el-option选项每个选项的键标签值分别对应相应属性 -->
<el-option
v-for="type in typeOptions"
:key="type.value"
:label="type.label"
:value="type.value">
</el-option>
</el-select>
</el-form-item>
<!-- 优惠券名称输入的表单项设置了验证属性prop -->
<el-form-item label="优惠券名称:" prop="name">
<!-- el-input组件用于输入优惠券名称双向绑定v-model到coupon.name -->
<el-input v-model="coupon.name" class="input-width"></el-input>
</el-form-item>
<!-- 适用平台选择的表单项 -->
<el-form-item label="适用平台:">
<el-select v-model="coupon.platform">
<el-option
v-for="item in platformOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<!-- 总发行量输入的表单项设置了验证属性prop限制只能输入正整数 -->
<el-form-item label="总发行量:" prop="publishCount">
<el-input v-model.number="coupon.publishCount" placeholder="只能输入正整数" class="input-width"></el-input>
</el-form-item>
<!-- 面额输入的表单项设置了验证属性prop限制只能输入数值且保留2位小数 -->
<el-form-item label="面额:" prop="amount">
<el-input v-model.number="coupon.amount" placeholder="面值只能是数值限2位小数" class="input-width">
<!-- 在输入框后面添加固定文本 -->
<template slot="append"></template>
</el-input>
</el-form-item>
<!-- 每人限领输入的表单项限制只能输入正整数 -->
<el-form-item label="每人限领:">
<el-input v-model="coupon.perLimit" placeholder="只能输入正整数" class="input-width">
<template slot="append"></template>
</el-input>
</el-form-item>
<!-- 使用门槛输入的表单项设置了验证属性prop限制只能输入正整数 -->
<el-form-item label="使用门槛:" prop="minPoint">
<el-input v-model.number="coupon.minPoint" placeholder="只能输入正整数" class="input-width">
<!-- 在输入框前面添加固定文本 -->
<template slot="prepend"></template>
<!-- 在输入框后面添加固定文本元可用 -->
<template slot="append">元可用</template>
</el-input>
</el-form-item>
<!-- 领取日期选择的表单项设置了验证属性prop -->
<el-form-item label="领取日期:" prop="enableTime">
<!-- el-date-picker组件用于选择日期类型为date双向绑定v-model到coupon.enableTime -->
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.enableTime" class="input-width"></el-date-picker>
</el-form-item>
<!-- 有效期选择的表单项通过两个el-date-picker组件分别选择开始和结束日期 -->
<el-form-item label="有效期:">
<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>
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.endTime" style="width: 150px"></el-date-picker>
</el-form-item>
<!-- 可使用商品选择的表单项通过el-radio-group和el-radio-button组件实现单选 -->
<el-form-item label="可使用商品:">
<el-radio-group v-model="coupon.useType">
<el-radio-button :label="0">全场通用</el-radio-button>
<el-radio-button :label="1">指定分类</el-radio-button>
<el-radio-button :label="2">指定商品</el-radio-button>
</el-radio-group>
</el-form-item>
<!-- 当选择指定分类coupon.useType === 1时显示的表单项 -->
<el-form-item v-show="coupon.useType===1">
<!-- el-cascader组件用于选择分类支持清空占位提示等功能双向绑定v-model到selectProductCate -->
<el-cascader
clearable
placeholder="请选择分类名称"
v-model="selectProductCate"
:options="productCateOptions">
</el-cascader>
<!-- 点击按钮触发handleAddProductCategoryRelation方法添加分类关系 -->
<el-button @click="handleAddProductCategoryRelation()"></el-button>
<!-- el-table组件用于展示已添加的分类关系列表 -->
<el-table ref="productCateRelationTable"
:data="coupon.productCategoryRelationList"
style="width: 100%;margin-top: 20px"
border>
<el-table-column label="分类名称" align="center">
<!-- 自定义表格单元格内容展示展示分类名称的层级结构 -->
<template slot-scope="scope">{{scope.row.parentCategoryName}}>{{scope.row.productCategoryName}}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="100">
<template slot-scope="scope">
<!-- 点击按钮触发handleDeleteProductCateRelation方法删除对应分类关系 -->
<el-button size="mini"
type="text"
@click="handleDeleteProductCateRelation(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<!-- 当选择指定商品coupon.useType === 2时显示的表单项 -->
<el-form-item v-show="coupon.useType===2">
<!-- el-select组件用于选择商品支持过滤远程搜索保留关键字等功能双向绑定v-model到selectProduct -->
<el-select
v-model="selectProduct"
filterable
remote
reserve-keyword
placeholder="商品名称/商品货号"
:remote-method="searchProductMethod"
:loading="selectProductLoading">
<el-option
v-for="item in selectProductOptions"
:key="item.productId"
:label="item.productName"
:value="item.productId">
<span style="float: left">{{ item.productName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.productSn }}</span>
</el-option>
</el-select>
<el-button @click="handleAddProductRelation()"></el-button>
<el-table ref="productRelationTable"
:data="coupon.productRelationList"
style="width: 100%;margin-top: 20px"
border>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column>
<el-table-column label="货号" align="center" width="120" >
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="100">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleDeleteProductRelation(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<!-- 备注输入的表单项使用textarea类型的el-input组件 -->
<el-form-item label="备注:">
<el-input
class="input-width"
type="textarea"
:rows="5"
placeholder="请输入内容"
v-model="coupon.note">
</el-input>
</el-form-item>
<!-- 提交和重置按钮的表单项 -->
<el-form-item>
<!-- 点击提交按钮触发onSubmit方法提交表单数据 -->
<el-button type="primary" @click="onSubmit('couponFrom')"></el-button>
<!-- 当不是编辑状态!isEdit点击重置按钮触发resetForm方法重置表单 -->
<el-button v-if="!isEdit" @click="resetForm('couponFrom')"></el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script>
// '@/api/coupon'createCoupongetCouponupdateCoupon
import {createCoupon, getCoupon, updateCoupon} from '@/api/coupon';
// '@/api/product'fetchProductList
import {fetchSimpleList as fetchProductList} from '@/api/product';
// '@/api/productCate'便
import {fetchListWithChildren} from '@/api/productCate';
//
const defaultCoupon = {
type: 0, // 0typeOptions
name: null, //
platform: 0, // 0platformOptions
amount: null, //
perLimit: 1, // 1
minPoint: null, // 使
startTime: null, //
endTime: null, //
useType: 0, // 使0
note: null, //
publishCount: null, //
productRelationList: [], //
productCategoryRelationList: [] //
};
// labelvalue
const defaultTypeOptions = [
{
label: '全场赠券',
value: 0
},
{
label: '会员赠券',
value: 1
},
{
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
// PC
const defaultPlatformOptions = [
{
label: '全平台',
value: 0
},
{
label: '移动平台',
value: 1
},
{
label: 'PC平台',
value: 2
}
];
export default {
name: 'CouponDetail',
props: {
// isEditfalse
isEdit: {
type: Boolean,
default: false
}
},
data() {
return {
// defaultCoupon便
coupon: Object.assign({}, defaultCoupon),
// defaultTypeOptions
typeOptions: Object.assign({}, defaultTypeOptions),
// defaultPlatformOptions
platformOptions: Object.assign({}, defaultPlatformOptions),
//
rules: {
name: [
{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,
// falsetruefalse
selectProductLoading: false,
//
selectProductOptions: [],
// null
selectProductCate: null,
//
productCateOptions: []
}
},
created() {
// isEditisEdittruegetCouponIDthis.$route.query.idcoupon
if (this.isEdit) {
getCoupon(this.$route.query.id).then(response => {
this.coupon = response.data;
});
}
// getProductCateListproductCateOptions便
this.getProductCateList();
},
methods: {
// formNameisEdit
onSubmit(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.$confirm('是否提交数据', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
// updateCouponIDcoupon
updateCoupon(this.$route.query.id, this.coupon).then(response => {
this.$refs[formName].resetFields();
this.$message({
message: '修改成功',
type: 'success',
duration: 1000
});
this.$router.back();
});
} else {
// createCouponcoupon
createCoupon(this.coupon).then(response => {
this.$refs[formName].resetFields();
this.$message({
message: '提交成功',
type: 'success',
duration: 1000
});
this.$router.back();
});
}
});
} else {
// false
this.$message({
message: '验证失败',
type: 'error',
duration: 1000
});
return false;
}
});
},
// formNameresetFieldscoupondefaultCoupon
resetForm(formName) {
this.$refs[formName].resetFields();
this.coupon = Object.assign({}, defaultCoupon);
},
// querytruefetchProductListfalseselectProductOptions便selectProductOptions
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 {
this.selectProductOptions = [];
}
},
// selectProductnullgetProductByIdcouponproductRelationListselectProductnull
handleAddProductRelation() {
if (this.selectProduct === null) {
this.$message({
message: '请先选择商品',
type: 'warning'
});
return;
}
this.coupon.productRelationList.push(this.getProductById(this.selectProduct));
this.selectProduct = null;
},
// productRelationListindexrowspliceproductRelationList
handleDeleteProductRelation(index, row) {
this.coupon.productRelationList.splice(index, 1);
},
// selectProductCatenull0getProductCateByIdscouponproductCategoryRelationListselectProductCate
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 = [];
},
// productCategoryRelationListindexrowsplice
handleDeleteProductCateRelation(index, row) {
this.coupon.productCategoryRelationList.splice(index, 1);
},
// IDselectProductOptionsIDnullID
getProductById(id) {
for (let i = 0; i < this.selectProductOptions.length; i++) {
if (id === this.selectProductOptions[i].productId) {
return this.selectProductOptions[i];
}
}
return null;
},
// fetchListWithChildrenproductCateOptions
getProductCateList() {
fetchListWithChildren().then(response => {
let list = response.data;
this.productCateOptions = [];
for (let i = 0; i < list.length; i++) {
let children = [];
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});
}
});
},
// IDproductCateOptionsID
getProductCateByIds(ids) {
let name;
let parentName;
for (let i = 0; i < this.productCateOptions.length; i++) {
if (this.productCateOptions[i].value === ids[0]) {
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};
}
}
}
</script>

@ -0,0 +1,642 @@
<template> 
<div class="app-container">
<div class="table-layout">
<el-row>
<el-col :span="4" class="table-cell-title">名称</el-col>
<el-col :span="4" class="table-cell-title">优惠券类型</el-col>
<el-col :span="4" class="table-cell-title">可使用商品</el-col>
<el-col :span="4" class="table-cell-title">使用门槛</el-col>
<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-col :span="4" class="table-cell">{{coupon.name}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.type | formatType}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.useType | formatUseType}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.minPoint}}元可用</el-col>
<el-col :span="4" class="table-cell">{{coupon.amount}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.endTime | formatStatus}}</el-col>
</el-row>
<el-row>
<el-col :span="4" class="table-cell-title">有效期</el-col>
<el-col :span="4" class="table-cell-title">总发行量</el-col>
<el-col :span="4" class="table-cell-title">已领取</el-col>
<el-col :span="4" class="table-cell-title">待领取</el-col>
<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-col :span="4" class="table-cell" style="font-size: 13px">
{{coupon.startTime|formatDate}}{{coupon.endTime|formatDate}}
</el-col>
<el-col :span="4" class="table-cell">{{coupon.publishCount}}</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 :span="4" class="table-cell">{{coupon.useCount}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.publishCount-coupon.useCount}}</el-col>
</el-row>
</div>
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="使用状态:">
<el-select v-model="listQuery.useStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in useTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="订单编号:">
<el-input v-model="listQuery.orderSn" class="input-width" placeholder="订单编号"></el-input>
</el-form-item>
</el-form>
</div>
</el-card>
<div class="table-container">
<el-table ref="couponHistoryTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<el-table-column label="优惠码" width="160" align="center">
<template slot-scope="scope">{{scope.row.couponCode}}</template>
</el-table-column>
<el-table-column label="领取会员" width="140" align="center">
<template slot-scope="scope">{{scope.row.memberNickname}}</template>
</el-table-column>
<el-table-column label="领取方式" width="100" align="center">
<template slot-scope="scope">{{scope.row.getType | formatGetType}}</template>
</el-table-column>
<el-table-column label="领取时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatTime}}</template>
</el-table-column>
<el-table-column label="当前状态" width="140" align="center">
<template slot-scope="scope">{{scope.row.useStatus | formatCouponHistoryUseType}}</template>
</el-table-column>
<el-table-column label="使用时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.useTime | formatTime}}</template>
</el-table-column>
<el-table-column label="订单编号" align="center">
<template slot-scope="scope">{{scope.row.orderSn===null?'N/A':scope.row.orderSn}}</template>
</el-table-column>
</el-table>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
import {formatDate} from '@/utils/date';
import {getCoupon} from '@/api/coupon';
import {fetchList as fetchCouponHistoryList} from '@/api/couponHistory';
const defaultTypeOptions = [
{
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),
list:null,
total:null,
listLoading:false
}
},
created() {
getCoupon(this.$route.query.id).then(response => {
this.coupon = response.data;
});
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 '';
},
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(){
this.listLoading=true;
fetchCouponHistoryList(this.listQuery).then(response=>{
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>
<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 {
height: 60px;
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 {
border-right: 1px solid #DCDFE6;
border-bottom: 1px solid #DCDFE6;
padding: 10px;
background: #F2F6FC;
text-align: center;
font-size: 14px;
color: #303133;
}
</style>
#abc
<template>
<!-- 创建一个类名为app-container的div作为整个页面的容器用于布局和包裹内部的各个模块 -->
<div class="app-container">
<!-- 创建一个用于展示优惠券相关信息表格布局的div -->
<div class="table-layout">
<!-- 使用el-row组件创建行el-col组件用于在行内划分列这里定义了一行展示优惠券不同属性的标题列 -->
<el-row>
<el-col :span="4" class="table-cell-title">名称</el-col>
<el-col :span="4" class="table-cell-title">优惠券类型</el-col>
<el-col :span="4" class="table-cell-title">可使用商品</el-col>
<el-col :span="4" class="table-cell-title">使用门槛</el-col>
<el-col :span="4" class="table-cell-title">面值</el-col>
<el-col :span="4" class="table-cell-title">状态</el-col>
</el-row>
<!-- 又一行el-row用于展示具体优惠券的各项属性值通过双花括号插值表达式绑定对应的数据部分属性使用了过滤器 | formatType等来格式化显示内容 -->
<el-row>
<el-col :span="4" class="table-cell">{{coupon.name}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.type | formatType}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.useType | formatUseType}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.minPoint}}元可用</el-col>
<el-col :span="4" class="table-cell">{{coupon.amount}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.endTime | formatStatus}}</el-col>
</el-row>
<!-- 再次创建一行el-row用于展示优惠券其他属性的标题列 -->
<el-row>
<el-col :span="4" class="table-cell-title">有效期</el-col>
<el-col :span="4" class="table-cell-title">总发行量</el-col>
<el-col :span="4" class="table-cell-title">已领取</el-col>
<el-col :span="4" class="table-cell-title">待领取</el-col>
<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-col :span="4" class="table-cell" style="font-size: 13px">
{{coupon.startTime|formatDate}}{{coupon.endTime|formatDate}}
</el-col>
<el-col :span="4" class="table-cell">{{coupon.publishCount}}</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 :span="4" class="table-cell">{{coupon.useCount}}</el-col>
<el-col :span="4" class="table-cell">{{coupon.publishCount - coupon.useCount}}</el-col>
</el-row>
</div>
<!-- 使用el-card组件创建一个筛选搜索的容器设置阴影效果为无 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 使用一个图标元素这里假设是element-ui的图标类表示搜索图标 -->
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<!-- 点击按钮触发handleSearchList方法进行查询搜索操作按钮设置为主要样式primary小尺寸small并靠右浮动float:right -->
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<!-- 点击按钮触发handleResetSearch方法重置筛选搜索条件按钮靠右浮动且设置了右边距margin-right: 15px小尺寸small -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 创建一个内联表单inline为true绑定数据模型为listQuery设置表单尺寸为小small标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单中使用状态选择的表单项 -->
<el-form-item label="使用状态:">
<el-select v-model="listQuery.useStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in useTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<!-- 表单中订单编号输入的表单项通过v-model双向绑定数据到listQuery.orderSn -->
<el-form-item label="订单编号:">
<el-input v-model="listQuery.orderSn" class="input-width" placeholder="订单编号"></el-input>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 创建一个用于展示优惠券历史记录表格的容器div -->
<div class="table-container">
<!-- 使用el-table组件展示优惠券历史记录数据绑定数据来源为list设置宽度为100%通过v-loading指令绑定加载状态为listLoading显示表格边框 -->
<el-table ref="couponHistoryTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<!-- 定义表格列优惠码设置宽度为160px内容居中对齐 -->
<el-table-column label="优惠码" width="160" align="center">
<template slot-scope="scope">{{scope.row.couponCode}}</template>
</el-table-column>
<!-- 定义表格列领取会员宽度为140px内容居中对齐 -->
<el-table-column label="领取会员" width="140" align="center">
<template slot-scope="scope">{{scope.row.memberNickname}}</template>
</el-table-column>
<!-- 定义表格列领取方式宽度为100px内容居中对齐使用了formatGetType过滤器格式化显示内容 -->
<el-table-column label="领取方式" width="100" align="center">
<template slot-scope="scope">{{scope.row.getType | formatGetType}}</template>
</el-table-column>
<!-- 定义表格列领取时间宽度为160px内容居中对齐使用了formatTime过滤器格式化显示内容 -->
<el-table-column label="领取时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatTime}}</template>
</el-table-column>
<!-- 定义表格列当前状态宽度为140px内容居中对齐使用了formatCouponHistoryUseType过滤器格式化显示内容 -->
<el-table-column label="当前状态" width="140" align="center">
<template slot-scope="scope">{{scope.row.useStatus | formatCouponHistoryUseType}}</template>
</el-table-column>
<!-- 定义表格列使用时间宽度为160px内容居中对齐使用了formatTime过滤器格式化显示内容 -->
<el-table-column label="使用时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.useTime | formatTime}}</template>
</el-table-column>
<!-- 定义表格列订单编号内容居中对齐当值为null时显示N/A -->
<el-table-column label="订单编号" align="center">
<template slot-scope="scope">{{scope.row.orderSn === null? 'N/A' : scope.row.orderSn}}</template>
</el-table-column>
</el-table>
</div>
<!-- 创建一个用于放置分页组件的容器div -->
<div class="pagination-container">
<!-- 使用el-pagination组件实现分页功能设置背景色background绑定页面尺寸改变size-change和当前页改变current-change的事件处理方法配置分页布局当前页每页数量可选页面尺寸列表以及总记录数等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5, 10, 15]"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
// '@/utils/date'formatDate使
import {formatDate} from '@/utils/date';
// '@/api/coupon'getCoupon
import {getCoupon} from '@/api/coupon';
// '@/api/couponHistory'fetchListfetchCouponHistoryList
import {fetchList as fetchCouponHistoryList} from '@/api/couponHistory';
// labelvalue
const defaultTypeOptions = [
{
label: '全场赠券',
value: 0
},
{
label: '会员赠券',
value: 1
},
{
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
//
const defaultListQuery = {
pageNum: 1, // 1
pageSize: 10, // 10
useStatus: null, // 使
orderSn: null, //
couponId: null // ID
};
// 使labelvalue使
const defaultUseTypeOptions = [
{
label: "未使用",
value: 0
},
{
label: "已使用",
value: 1
},
{
label: "已过期",
value: 2
}
];
export default {
name: 'couponHistoryList',
data() {
return {
//
coupon: {},
// Object.assigndefaultListQuery便
listQuery: Object.assign({}, defaultListQuery),
// 使defaultUseTypeOptions使
useTypeOptions: Object.assign({}, defaultUseTypeOptions),
// null
list: null,
// null
total: null,
// falsetruefalse
listLoading: false
}
},
created() {
// getCouponthis.$route.query.idIDcoupon便使
getCoupon(this.$route.query.id).then(response => {
this.coupon = response.data;
});
// couponIdID
this.listQuery.couponId = this.$route.query.id;
// getList
this.getList();
},
filters: {
// formatTypetypedefaultTypeOptions
formatType(type) {
for (let i = 0; i < defaultTypeOptions.length; i++) {
if (type === defaultTypeOptions[i].value) {
return defaultTypeOptions[i].label;
}
}
return '';
},
// formatUseType使useType0便使
formatUseType(useType) {
if (useType === 0) {
return '全场通用';
} else if (useType === 1) {
return '指定分类';
} else {
return '指定商品';
}
},
// formatPlatformplatform1
formatPlatform(platform) {
if (platform === 1) {
return '移动平台';
} else if (platform === 2) {
return 'PC平台';
} else {
return '全平台';
}
},
// formatDatenull'N/A'formatDate'yyyy-MM-dd'使
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
},
// formatStatusendTimenew Date().getTime()
formatStatus(endTime) {
let now = new Date().getTime();
if (endTime > now) {
return '未过期'
} else {
return '已过期';
}
},
// formatGetTypetypetype1
formatGetType(type) {
if (type === 1) {
return '主动获取';
} else {
return '后台赠送';
}
},
// formatCouponHistoryUseType使useType0使使便使
formatCouponHistoryUseType(useType) {
if (useType === 0) {
return '未使用';
} else if (useType === 1) {
return '已使用';
} else {
return '已过期';
}
},
// formatTimeformatDate'yyyy-MM-dd hh:mm:ss'null'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: {
// listLoadingtruefetchCouponHistoryListlistQuerylistLoadingfalselisttotal
getList() {
this.listLoading = true;
fetchCouponHistoryList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
},
// Object.assigndefaultListQuerycouponId便
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
this.listQuery.couponId = this.$route.query.id;
},
// 1getListuseStatus
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// 1valgetList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// valgetList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
}
}
}
</script>

@ -0,0 +1,545 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="优惠券名称:">
<el-input v-model="listQuery.name" class="input-width" placeholder="优惠券名称"></el-input>
</el-form-item>
<el-form-item label="优惠券类型:">
<el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
<el-option v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="couponTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="优惠劵名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="优惠券类型" width="100" align="center">
<template slot-scope="scope">{{scope.row.type | formatType}}</template>
</el-table-column>
<el-table-column label="可使用商品" width="100" align="center">
<template slot-scope="scope">{{scope.row.useType | formatUseType}}</template>
</el-table-column>
<el-table-column label="使用门槛" width="140" align="center">
<template slot-scope="scope">{{scope.row.minPoint}}元可用</template>
</el-table-column>
<el-table-column label="面值" width="100" align="center">
<template slot-scope="scope">{{scope.row.amount}}</template>
</el-table-column>
<el-table-column label="适用平台" width="100" align="center">
<template slot-scope="scope">{{scope.row.platform | formatPlatform}}</template>
</el-table-column>
<el-table-column label="有效期" width="180" align="center">
<template slot-scope="scope">{{scope.row.startTime|formatDate}}{{scope.row.endTime|formatDate}}</template>
</el-table-column>
<el-table-column label="状态" width="100" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatStatus}}</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleView(scope.$index, scope.row)">查看</el-button>
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">
编辑</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
import {fetchList,deleteCoupon} from '@/api/coupon';
import {formatDate} from '@/utils/date';
const defaultListQuery = {
pageNum: 1,
pageSize: 10,
name: null,
type: null
};
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),
list:null,
total:null,
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 '指定商品';
}
},
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() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleAdd(){
this.$router.push({path: '/sms/addCoupon'})
},
handleView(index, row) {
this.$router.push({path: '/sms/couponHistory', query: {id: row.id}})
},
handleUpdate(index, row) {
this.$router.push({path: '/sms/updateCoupon', query: {id: row.id}})
},
handleDelete(index, row) {
this.$confirm('是否进行删除操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteCoupon(row.id).then(response=>{
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
})
},
getList(){
this.listLoading=true;
fetchList(this.listQuery).then(response=>{
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
}
}
}
</script>
<style scoped>
.input-width {
width: 203px;
}
</style>
#abc
<template>
<!-- 创建一个类名为app-container的div作为整个页面的外层容器用于整体布局 -->
<div class="app-container">
<!-- 使用el-card组件创建一个筛选搜索的容器设置阴影效果为无 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 使用element-ui的图标元素el-icon-search表示搜索图标 -->
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<!-- el-button组件用于创建查询搜索按钮设置按钮靠右浮动float:right样式为主要按钮type="primary"尺寸为小size="small"点击按钮触发handleSearchList方法 -->
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<!-- el-button组件用于创建重置按钮设置按钮靠右浮动且右边距为15pxfloat:right; margin-right: 15px尺寸为小size="small"点击按钮触发handleResetSearch方法 -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 创建一个内联表单:inline="true"绑定数据模型为listQuery设置表单尺寸为小size="small"标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单中优惠券名称输入的表单项通过v-model双向绑定数据到listQuery.name设置输入框宽度样式类为input-width添加占位提示文本 -->
<el-form-item label="优惠券名称:">
<el-input v-model="listQuery.name" class="input-width" placeholder="优惠券名称"></el-input>
</el-form-item>
<!-- 表单中优惠券类型选择的表单项通过v-model双向绑定数据到listQuery.type设置占位提示文本为全部支持清空选择clearable输入框宽度样式类为input-width -->
<el-form-item label="优惠券类型:">
<el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
<el-option v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 使用el-card组件创建一个操作相关的容器设置阴影效果为无 -->
<el-card class="operate-container" shadow="never">
<!-- 使用element-ui的图标元素el-icon-tickets表示相关图标 -->
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<!-- el-button组件用于创建添加按钮设置按钮尺寸为迷你size="mini"样式类为btn-add点击按钮触发handleAdd方法 -->
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card>
<!-- 创建一个用于展示优惠券数据表格的容器div -->
<div class="table-container">
<!-- 使用el-table组件展示优惠券数据列表绑定数据来源为list设置宽度为100%监听行选择改变事件@selection-change并绑定handleSelectionChange方法通过v-loading指令绑定加载状态为listLoading显示表格边框 -->
<el-table ref="couponTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<!-- 定义一个选择列type="selection"用于多选操作宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 定义表格列编号宽度为100px内容居中对齐通过插槽slot-scope展示对应行数据中的id属性 -->
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 定义表格列优惠劵名称内容居中对齐通过插槽展示对应行数据中的name属性 -->
<el-table-column label="优惠劵名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 定义表格列优惠券类型宽度为100px内容居中对齐通过双花括号插值表达式绑定对应行数据中的type属性并使用formatType过滤器格式化显示内容 -->
<el-table-column label="优惠券类型" width="100" align="center">
<template slot-scope="scope">{{scope.row.type | formatType}}</template>
</el-table-column>
<!-- 定义表格列可使用商品宽度为100px内容居中对齐通过双花括号插值表达式绑定对应行数据中的useType属性并使用formatUseType过滤器格式化显示内容 -->
<el-table-column label="可使用商品" width="100" align="center">
<template slot-scope="scope">{{scope.row.useType | formatUseType}}</template>
</el-table-column>
<!-- 定义表格列使用门槛宽度为140px内容居中对齐通过插槽展示使用门槛相关文本格式为满XX元可用其中XX为对应行数据中的minPoint属性值 -->
<el-table-column label="使用门槛" width="140" align="center">
<template slot-scope="scope">{{scope.row.minPoint}}元可用</template>
</el-table-column>
<!-- 定义表格列面值宽度为100px内容居中对齐通过插槽展示对应行数据中的amount属性值并添加字作为后缀 -->
<el-table-column label="面值" width="100" align="center">
<template slot-scope="scope">{{scope.row.amount}}</template>
</el-table-column>
<!-- 定义表格列适用平台宽度为100px内容居中对齐通过双花括号插值表达式绑定对应行数据中的platform属性并使用formatPlatform过滤器格式化显示内容 -->
<el-table-column label="适用平台" width="100" align="center">
<template slot-scope="scope">{{scope.row.platform | formatPlatform}}</template>
</el-table-column>
<!-- 定义表格列有效期宽度为180px内容居中对齐通过双花括号插值表达式分别绑定对应行数据中的startTime和endTime属性并使用formatDate过滤器格式化显示日期内容中间用字连接 -->
<el-table-column label="有效期" width="180" align="center">
<template slot-scope="scope">{{scope.row.startTime|formatDate}}{{scope.row.endTime|formatDate}}</template>
</el-table-column>
<!-- 定义表格列状态宽度为100px内容居中对齐通过双花括号插值表达式绑定对应行数据中的endTime属性并使用formatStatus过滤器根据日期判断并格式化显示优惠券状态 -->
<el-table-column label="状态" width="100" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatStatus}}</template>
</el-table-column>
<!-- 定义表格列操作宽度为180px内容居中对齐通过插槽在单元格内放置多个按钮分别点击按钮触发对应的操作方法handleViewhandleUpdatehandleDelete -->
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleView(scope.$index, scope.row)">查看</el-button>
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">
编辑</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 创建一个用于放置分页组件的容器div -->
<div class="pagination-container">
<!-- 使用el-pagination组件实现分页功能设置背景色background绑定页面尺寸改变size-change和当前页改变current-change的事件处理方法配置分页布局当前页每页数量可选页面尺寸列表以及总记录数等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5, 10, 15]"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
// @/api/couponfetchListdeleteCoupon
import {fetchList, deleteCoupon} from '@/api/coupon';
// @/utils/dateformatDate
import {formatDate} from '@/utils/date';
//
const defaultListQuery = {
pageNum: 1,
pageSize: 10,
name: null,
type: null
};
//
const defaultTypeOptions = [
{
label: '全场赠券',
value: 0
},
{
label: '会员赠券',
value: 1
},
{
label: '购物赠券',
value: 2
},
{
label: '注册赠券',
value: 3
}
];
export default
name: 'couponList',
data() {
return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// defaultTypeOptions
typeOptions: Object.assign({}, defaultTypeOptions),
//
list: null,
//
total: null,
//
listLoading: false,
// selection-change
multipleSelection: []
}
},
created() {
// getList
this.getList();
},
filters: {
// formatTypetypedefaultTypeOptions
formatType(type) {
for (let i = 0; i < defaultTypeOptions.length; i++) {
if (type === defaultTypeOptions[i].value) {
return defaultTypeOptions[i].label;
}
}
return '';
},
// formatUseType使useType使
formatUseType(useType) {
if (useType === 0) {
return '全场通用';
} else if (useType === 1) {
return '指定分类';
} else {
return '指定商品';
}
},
// formatPlatformplatform
formatPlatform(platform) {
if (platform === 1) {
return '移动平台';
} else if (platform === 2) {
return 'PC平台';
} else {
return '全平台';
}
},
// formatDatenullN/AformatDate'yyyy-MM-dd'
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
},
// formatStatusendTime
formatStatus(endTime) {
let now = new Date().getTime();
let endDate = new Date(endTime);
if (endDate > now) {
return '未过期'
} else {
return '已过期';
}
}
},
methods:
// defaultListQuery
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// 1getList
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// multipleSelection便
handleSelectionChange(val) {
this.multipleSelection = val;
},
// 1valgetList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// valgetList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// $router.push'/sms/addCoupon'
handleAdd() {
this.$router.push({path: '/sms/addCoupon'})
},
// $router.push'/sms/couponHistory'IDrow.id
handleView(index, row) {
this.$router.push({path: '/sms/couponHistory', query: {id: row.id}})
},
// $router.push'/sms/updateCoupon'IDrow.id
handleUpdate(index, row) {
this.$router.push({path: '/sms/updateCoupon', query: {id: row.id}})
},
// $confirmdeleteCouponIDrow.id$messagegetList
handleDelete(index, row) {
this.$confirm('是否进行删除操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteCoupon(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
})
},
//

@ -0,0 +1,29 @@
<template> 
<coupon-detail :isEdit="true"></coupon-detail>
</template>
<script>
import CouponDetail from './components/CouponDetail'
export default {
name: 'updateCoupon',
components: { CouponDetail }
}
</script>
<style scoped>
</style>
#abc
<template>
<!-- 使用CouponDetail组件来展示编辑优惠券的相关界面通过属性绑定将isEdit设置为true表示当前处于编辑优惠券的状态 -->
<coupon-detail :isEdit="true"></coupon-detail>
</template>
<script>
// ./components/CouponDetailCouponDetailCouponDetailVue
import CouponDetail from './components/CouponDetail'
export default {
name: 'updateCoupon',
// componentsCouponDetailtemplate使<coupon-detail>便
components: { CouponDetail }
}
</script>

@ -0,0 +1,655 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="活动名称:">
<el-input v-model="listQuery.keyword" class="input-width" placeholder="活动名称" clearable></el-input>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加活动</el-button>
<el-button size="mini" class="btn-add" @click="handleShowSessionList()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="flashTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="活动标题" align="center">
<template slot-scope="scope">{{scope.row.title}}</template>
</el-table-column>
<el-table-column label="活动状态" width="140" align="center">
<template slot-scope="scope">{{scope.row |formatActiveStatus}}</template>
</el-table-column>
<el-table-column label="开始时间" width="140" align="center">
<template slot-scope="scope">{{scope.row.startDate | formatDate}}</template>
</el-table-column>
<el-table-column label="结束时间" width="140" align="center">
<template slot-scope="scope">{{scope.row.endDate | formatDate}}</template>
</el-table-column>
<el-table-column label="上线/下线" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.status">
</el-switch>
</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleSelectSession(scope.$index, scope.row)">设置商品
</el-button>
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">
编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="total">
</el-pagination>
</div>
<el-dialog
title="添加活动"
:visible.sync="dialogVisible"
width="40%">
<el-form :model="flashPromotion"
ref="flashPromotionForm"
label-width="150px" size="small">
<el-form-item label="活动标题:">
<el-input v-model="flashPromotion.title" style="width: 250px"></el-input>
</el-form-item>
<el-form-item label="开始时间:">
<el-date-picker
v-model="flashPromotion.startDate"
type="date"
placeholder="请选择时间">
</el-date-picker>
</el-form-item>
<el-form-item label="结束时间:">
<el-date-picker
v-model="flashPromotion.endDate"
type="date"
placeholder="请选择时间">
</el-date-picker>
</el-form-item>
<el-form-item label="上线/下线">
<el-radio-group v-model="flashPromotion.status">
<el-radio :label="1">上线</el-radio>
<el-radio :label="0">下线</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<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>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList, updateStatus, deleteFlash, createFlash, updateFlash} from '@/api/flash';
import {formatDate} from '@/utils/date';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
keyword: null
};
const defaultFlashPromotion = {
id: null,
title: null,
startDate: null,
endDate: null,
status: 0
};
export default {
name: 'flashPromotionList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
list: null,
total: null,
listLoading: false,
dialogVisible: false,
flashPromotion: Object.assign({}, defaultFlashPromotion),
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 '活动未开始';
}
},
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
}
},
methods: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
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();
},
handleAdd() {
this.dialogVisible = true;
this.isEdit = false;
this.flashPromotion = Object.assign({},defaultFlashPromotion);
},
handleShowSessionList() {
this.$router.push({path: '/sms/flashSession'})
},
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();
});
},
handleDelete(index, row) {
this.$confirm('是否要删除该活动?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteFlash(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
handleUpdate(index, row) {
this.dialogVisible = true;
this.isEdit = true;
this.flashPromotion = Object.assign({},row);
},
handleDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateFlash(this.flashPromotion.id,this.flashPromotion).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
} else {
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>
<style></style>
#abc
<template>
<!-- 创建一个类名为 `app-container` `div` 元素作为整个页面的容器用于布局和包裹内部的各个模块 -->
<div class="app-container">
<!-- 使用 `el-card` 组件创建一个筛选搜索的容器设置阴影效果为无 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 使用 `el-icon-search` 图标表示搜索图标 -->
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<!-- 创建一个查询搜索按钮设置按钮靠右浮动样式为主要按钮`type="primary"`尺寸为小`size="small"`点击按钮时触发 `handleSearchList` 方法 -->
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<!-- 创建一个重置按钮设置按钮靠右浮动且右边距为 `15px`尺寸为小`size="small"`点击按钮时触发 `handleResetSearch` 方法 -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 创建一个内联表单`:inline="true"`绑定数据模型为 `listQuery`设置表单尺寸为小`size="small"`标签宽度为 `140px` -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单中活动名称输入的表单项通过 `v-model` 双向绑定数据到 `listQuery.keyword`设置输入框宽度样式类为 `input-width`添加占位提示文本支持清空输入框内容`clearable` -->
<el-form-item label="活动名称:">
<el-input v-model="listQuery.keyword" class="input-width" placeholder="活动名称" clearable></el-input>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 使用 `el-card` 组件创建一个操作相关的容器设置阴影效果为无 -->
<el-card class="operate-container" shadow="never">
<!-- 使用 `el-icon-tickets` 图标表示相关图标 -->
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<!-- 创建一个添加活动的按钮设置按钮尺寸为迷你`size="mini"`样式类为 `btn-add`点击按钮时触发 `handleAdd` 方法设置左边距为 `20px` -->
<el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加活动</el-button>
<!-- 创建一个查看秒杀时间段列表的按钮设置按钮尺寸为迷你`size="mini"`样式类为 `btn-add`点击按钮时触发 `handleShowSessionList` 方法 -->
<el-button size="mini" class="btn-add" @click="handleShowSessionList()"></el-button>
</el-card>
<!-- 创建一个用于展示活动数据表格的容器 `div` -->
<div class="table-container">
<!-- 使用 `el-table` 组件展示活动数据列表绑定数据来源为 `list`设置宽度为 `100%`通过 `v-loading` 指令绑定加载状态为 `listLoading`显示表格边框 -->
<el-table ref="flashTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<!-- 定义一个选择列`type="selection"`用于多选操作宽度为 `60px`内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 定义表格列编号宽度为 `100px`内容居中对齐通过插槽`slot-scope`展示对应行数据中的 `id` 属性 -->
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 定义表格列活动标题内容居中对齐通过插槽展示对应行数据中的 `title` 属性 -->
<el-table-column label="活动标题" align="center">
<template slot-scope="scope">{{scope.row.title}}</template>
</el-table-column>
<!-- 定义表格列活动状态宽度为 `140px`内容居中对齐通过双花括号插值表达式绑定对应行数据并使用 `formatActiveStatus` 过滤器根据时间判断并格式化显示活动状态 -->
<el-table-column label="活动状态" width="140" align="center">
<template slot-scope="scope">{{scope.row |formatActiveStatus}}</template>
</el-table-column>
<!-- 定义表格列开始时间宽度为 `140px`内容居中对齐通过双花括号插值表达式绑定对应行数据中的 `startDate` 属性并使用 `formatDate` 过滤器格式化显示日期内容 -->
<el-table-column label="开始时间" width="140" align="center">
<template slot-scope="scope">{{scope.row.startDate | formatDate}}</template>
</el-table-column>
<!-- 定义表格列结束时间宽度为 `140px`内容居中对齐通过双花括号插值表达式绑定对应行数据中的 `endDate` 属性并使用 `formatDate` 过滤器格式化显示日期内容 -->
<el-table-column label="结束时间" width="140" align="center">
<template slot-scope="scope">{{scope.row.endDate | formatDate}}</template>
</el-table-column>
<!-- 定义表格列上线/下线宽度为 `200px`内容居中对齐在单元格内使用 `el-switch` 组件实现开关功能绑定 `change` 事件到 `handleStatusChange` 方法设置开关的激活值和未激活值双向绑定数据到对应行数据的 `status` 属性 -->
<el-table-column label="上线/下线" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.status">
</el-switch>
</template>
</el-table-column>
<!-- 定义表格列操作宽度为 `180px`内容居中对齐通过插槽在单元格内放置多个按钮分别点击按钮触发对应的操作方法`handleSelectSession``handleUpdate``handleDelete` -->
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleSelectSession(scope.$index, scope.row)">设置商品
</el-button>
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">
编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 创建一个用于放置分页组件的容器 `div` -->
<div class="pagination-container">
<!-- 使用 `el-pagination` 组件实现分页功能设置背景色`background`绑定页面尺寸改变`size-change`和当前页改变`current-change`的事件处理方法配置分页布局当前页每页数量可选页面尺寸列表以及总记录数等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5, 10, 15]"
:total="total">
</el-pagination>
</div>
<!-- 使用 `el-dialog` 组件创建一个对话框用于添加或编辑活动的相关操作绑定对话框的显示状态为 `dialogVisible`设置标题为添加活动宽度为页面宽度的 `40%` -->
<el-dialog
title="添加活动"
:visible.sync="dialogVisible"
width="40%">
<!-- 在对话框内创建一个表单绑定数据模型为 `flashPromotion`设置表单引用为 `flashPromotionForm`标签宽度为 `150px`尺寸为小`size="small"` -->
<el-form :model="flashPromotion"
ref="flashPromotionForm"
label-width="150px" size="small">
<!-- 表单中活动标题输入的表单项通过 `v-model` 双向绑定数据到 `flashPromotion.title`设置输入框宽度为 `250px` -->
<el-form-item label="活动标题:">
<el-input v-model="flashPromotion.title" style="width: 250px"></el-input>
</el-form-item>
<!-- 表单中开始时间选择的表单项使用 `el-date-picker` 组件选择日期双向绑定数据到 `flashPromotion.startDate`设置类型为 `date`添加占位提示文本 -->
<el-form-item label="开始时间:">
<el-date-picker
v-model="flashPromotion.startDate"
type="date"
placeholder="请选择时间">
</el-date-picker>
</el-form-item>
<!-- 表单中结束时间选择的表单项使用 `el-date-picker` 组件选择日期双向绑定数据到 `flashPromotion.endDate`设置类型为 `date`添加占位提示文本 -->
<el-form-item label="结束时间:">
<el-date-picker
v-model="flashPromotion.endDate"
type="date"
placeholder="请选择时间">
</el-date-picker>
</el-form-item>
<!-- 表单中上线/下线选择的表单项使用 `el-radio-group` 组件实现单选功能双向绑定数据到 `flashPromotion.status` -->
<el-form-item label="上线/下线">
<el-radio-group v-model="flashPromotion.status">
<el-radio :label="1">上线</el-radio>
<el-radio :label="0">下线</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<!-- 在对话框的底部插槽`slot="footer"`内添加两个按钮分别用于取消和确定操作点击取消按钮隐藏对话框点击确定按钮触发 `handleDialogConfirm` 方法 -->
<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>
</span>
</el-dialog>
</div>
</template>
<script>
// '@/api/flash'
import {fetchList, updateStatus, deleteFlash, createFlash, updateFlash} from '@/api/flash';
// '@/utils/date'formatDate便
import {formatDate} from '@/utils/date';
//
const defaultListQuery = {
pageNum: 1, // 1
pageSize: 5, // 5
keyword: null //
};
//
const defaultFlashPromotion = {
id: null, // null
title: null, //
startDate: null, //
endDate: null, //
status: 0 // 0线
};
export default {
name: 'flashPromotionList',
data() {
return {
// Object.assigndefaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// null
list: null,
// null
total: null,
// falsetruefalse
listLoading: false,
// /falsetrue
dialogVisible: false,
// defaultFlashPromotion便
flashPromotion: Object.assign({}, defaultFlashPromotion),
// truefalsefalse
isEdit: false
}
},
created() {
// getList
this.getList();
},
filters: {
// formatActiveStatus
formatActiveStatus(row) {
let nowDate = new Date(); //
let startDate = new Date(row.startDate); // Date便
let endDate = new Date(row.endDate); // Date
//
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
return '活动进行中';
}
//
else if (nowDate.getTime() > endDate.getTime()) {
return '活动已结束';
}
//
else {
return '活动未开始';
}
},
// formatDatenull'N/A'formatDate'yyyy-MM-dd'
formatDate(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd')
}
},
methods: {
// defaultListQuery便
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// 1getListkeyword
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// 1valgetList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// valgetList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// dialogVisibletrue使isEditfalseflashPromotiondefaultFlashPromotion
handleAdd() {
this.dialogVisible = true;
this.isEdit = false;
this.flashPromotion = Object.assign({},defaultFlashPromotion);
},
// Vue Routerpush'/sms/flashSession'
handleShowSessionList() {
this.$router.push({path: '/sms/flashSession'})
},
// 线/线updateStatusidgetList
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();
});
},
// deleteFlashidgetList
handleDelete(index, row) {
this.$confirm('是否要删除该活动?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteFlash(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
// dialogVisibletrue使isEdittrueflashPromotionObject.assignrow便
handleUpdate(index, row) {
this.dialogVisible = true;
this.isEdit = true;
this.flashPromotion = Object.assign({},row);
},
// /isEditupdateFlashidflashPromotiongetListcreateFlashflashPromotion
handleDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateFlash(this.flashPromotion.id,this.flashPromotion).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
} else {
createFlash(this.flashPromotion).then(response => {
this.$message({
message: '添加成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
}
})
},
// Vue Routerpush'/sms/selectSession'idquery便使
handleSelectSession(index,row){
this.$router.push({path:'/sms/selectSession',query:{flashPromotionId:row.id}})
},
// listLoadingtruefetchListlistQuerylistLoadingfalselisttotal
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
}
}
}
</script>
<style></style>

@ -0,0 +1,682 @@
<template> 
<div class="app-container">
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleSelectProduct()" style="margin-left: 20px">添加</el-button>
</el-card>
<div class="table-container">
<el-table ref="productRelationTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.product.name}}</template>
</el-table-column>
<el-table-column label="货号" width="140" align="center">
<template slot-scope="scope">NO.{{scope.row.product.productSn}}</template>
</el-table-column>
<el-table-column label="商品价格" width="100" align="center">
<template slot-scope="scope">{{scope.row.product.price}}</template>
</el-table-column>
<el-table-column label="剩余数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.product.stock}}</template>
</el-table-column>
<el-table-column label="秒杀价格" width="100" align="center">
<template slot-scope="scope">
<p v-if="scope.row.flashPromotionPrice!==null">
{{scope.row.flashPromotionPrice}}
</p>
</template>
</el-table-column>
<el-table-column label="秒杀数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.flashPromotionCount}}</template>
</el-table-column>
<el-table-column label="限购数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.flashPromotionLimit}}</template>
</el-table-column>
<el-table-column label="排序" width="100" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<el-table-column label="操作" width="100" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="total">
</el-pagination>
</div>
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<el-dialog title="编辑秒杀商品信息"
:visible.sync="editDialogVisible"
width="40%">
<el-form :model="flashProductRelation"
ref="flashProductRelationForm"
label-width="150px" size="small">
<el-form-item label="商品名称:">
<span>{{flashProductRelation.product.name}}</span>
</el-form-item>
<el-form-item label="货号:">
<span>NO.{{flashProductRelation.product.productSn}}</span>
</el-form-item>
<el-form-item label="商品价格:">
<span>{{flashProductRelation.product.price}}</span>
</el-form-item>
<el-form-item label="秒杀价格:">
<el-input v-model="flashProductRelation.flashPromotionPrice" class="input-width">
<template slot="prepend"></template>
</el-input>
</el-form-item>
<el-form-item label="剩余数量:">
<span>{{flashProductRelation.product.stock}}</span>
</el-form-item>
<el-form-item label="秒杀数量:">
<el-input v-model="flashProductRelation.flashPromotionCount" class="input-width"></el-input>
</el-form-item>
<el-form-item label="限购数量:">
<el-input v-model="flashProductRelation.flashPromotionLimit" class="input-width"></el-input>
</el-form-item>
<el-form-item label="排序:">
<el-input v-model="flashProductRelation.sort" class="input-width"></el-input>
</el-form-item>
</el-form>
<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>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,createFlashProductRelation,deleteFlashProductRelation,updateFlashProductRelation} from '@/api/flashProductRelation';
import {fetchList as fetchProductList} from '@/api/product';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
flashPromotionId: null,
flashPromotionSessionId: null
};
export default {
name:'flashPromotionProductRelationList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
list: null,
total: null,
listLoading: false,
dialogVisible: false,
selectDialogVisible:false,
dialogData:{
list: null,
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
pageNum: 1,
pageSize: 5
}
},
editDialogVisible:false,
flashProductRelation:{
product:{}
}
}
},
created(){
this.listQuery.flashPromotionId=this.$route.query.flashPromotionId;
this.listQuery.flashPromotionSessionId=this.$route.query.flashPromotionSessionId;
this.getList();
},
methods:{
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleSelectProduct(){
this.selectDialogVisible=true;
this.getDialogList();
},
handleUpdate(index,row){
this.editDialogVisible = true;
this.flashProductRelation = Object.assign({},row);
},
handleDelete(index,row){
this.$confirm('是否要删除该商品?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteFlashProductRelation(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
handleSelectSearch(){
this.getDialogList();
},
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList();
},
handleDialogSelectionChange(val){
this.dialogData.multipleSelection = val;
},
handleSelectDialogConfirm(){
if (this.dialogData.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,
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: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateFlashProductRelation(this.flashProductRelation.id,this.flashProductRelation).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
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;
})
}
}
}
</script>
<style scoped>
.operate-container{
margin-top: 0;
}
.input-width{
width: 200px;
}
</style>
#abc
<template>
<!-- 创建一个类名为 `app-container` `div` 元素作为整个页面的容器用于布局和包裹内部的各个模块 -->
<div class="app-container">
<!-- 使用 `el-card` 组件创建一个操作相关的容器设置阴影效果为无 -->
<el-card class="operate-container" shadow="never">
<!-- 使用 `el-icon-tickets` 图标表示相关图标 -->
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<!-- 创建一个添加按钮设置按钮尺寸为迷你`size="mini"`样式类为 `btn-add`点击按钮时触发 `handleSelectProduct` 方法设置左边距为 `20px` -->
<el-button size="mini" class="btn-add" @click="handleSelectProduct()" style="margin-left: 20px">添加</el-button>
</el-card>
<!-- 创建一个用于展示商品相关数据表格的容器 `div` -->
<div class="table-container">
<!-- 使用 `el-table` 组件展示商品数据列表绑定数据来源为 `list`设置宽度为 `100%`通过 `v-loading` 指令绑定加载状态为 `listLoading`显示表格边框 -->
<el-table ref="productRelationTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<!-- 定义表格列编号宽度为 `100px`内容居中对齐通过插槽`slot-scope`展示对应行数据中的 `id` 属性 -->
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 定义表格列商品名称内容居中对齐通过插槽展示对应行数据中 `product` 对象的 `name` 属性 -->
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.product.name}}</template>
</el-table-column>
<!-- 定义表格列货号宽度为 `140px`内容居中对齐通过插槽展示对应行数据中 `product` 对象的 `productSn` 属性并添加前缀 `NO.` -->
<el-table-column label="货号" width="140" align="center">
<template slot-scope="scope">NO.{{scope.row.product.productSn}}</template>
</el-table-column>
<!-- 定义表格列商品价格宽度为 `100px`内容居中对齐通过插槽展示对应行数据中 `product` 对象的 `price` 属性并添加前缀 `` -->
<el-table-column label="商品价格" width="100" align="center">
<template slot-scope="scope">{{scope.row.product.price}}</template>
</el-table-column>
<!-- 定义表格列剩余数量宽度为 `100px`内容居中对齐通过插槽展示对应行数据中 `product` 对象的 `stock` 属性 -->
<el-table-column label="剩余数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.product.stock}}</template>
</el-table-column>
<!-- 定义表格列秒杀价格宽度为 `100px`内容居中对齐通过 `v-if` 指令判断对应行数据中 `flashPromotionPrice` 属性是否不为 `null`如果是则展示该价格并添加前缀 `` -->
<el-table-column label="秒杀价格" width="100" align="center">
<template slot-scope="scope">
<p v-if="scope.row.flashPromotionPrice!==null">
{{scope.row.flashPromotionPrice}}
</p>
</template>
</el-table-column>
<!-- 定义表格列秒杀数量宽度为 `100px`内容居中对齐通过插槽展示对应行数据中的 `flashPromotionCount` 属性 -->
<el-table-column label="秒杀数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.flashPromotionCount}}</template>
</el-table-column>
<!-- 定义表格列限购数量宽度为 `100px`内容居中对齐通过插槽展示对应行数据中的 `flashPromotionLimit` 属性 -->
<el-table-column label="限购数量" width="100" align="center">
<template slot-scope="scope">{{scope.row.flashPromotionLimit}}</template>
</el-table-column>
<!-- 定义表格列排序宽度为 `100px`内容居中对齐通过插槽展示对应行数据中的 `sort` 属性 -->
<el-table-column label="排序" width="100" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<!-- 定义表格列操作宽度为 `100px`内容居中对齐通过插槽在单元格内放置多个按钮分别点击按钮触发对应的操作方法`handleUpdate``handleDelete` -->
<el-table-column label="操作" width="100" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 创建一个用于放置分页组件的容器 `div` -->
<div class="pagination-container">
<!-- 使用 `el-pagination` 组件实现分页功能设置背景色`background`绑定页面尺寸改变`size-change`和当前页改变`current-change`的事件处理方法配置分页布局当前页每页数量可选页面尺寸列表以及总记录数等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:current-page.sync="listQuery.pageNum"
:page-size="listQuery.pageSize"
:page-sizes="[5, 10, 15]"
:total="total">
</el-pagination>
</div>
<!-- 使用 `el-dialog` 组件创建一个对话框用于选择商品的相关操作绑定对话框的显示状态为 `selectDialogVisible`设置标题为选择商品宽度为页面宽度的 `50%` -->
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<!-- 创建一个输入框双向绑定数据到 `dialogData.listQuery.keyword`设置宽度为 `250px`下外边距为 `20px`尺寸为小`size="small"`添加占位提示文本在输入框右侧添加一个搜索图标按钮点击按钮触发 `handleSelectSearch` 方法 -->
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<!-- 使用 `el-table` 组件在对话框内展示可选择的商品列表绑定数据来源为 `dialogData.list`绑定选择改变事件到 `handleDialogSelectionChange` 方法显示表格边框 -->
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<!-- 定义一个选择列`type="selection"`用于多选操作宽度为 `60px`内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 定义表格列商品名称内容居中对齐通过插槽展示对应行数据中的 `name` 属性 -->
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 定义表格列货号宽度为 `160px`内容居中对齐通过插槽展示对应行数据中的 `productSn` 属性并添加前缀 `NO.` -->
<el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<!-- 定义表格列价格宽度为 `120px`内容居中对齐通过插槽展示对应行数据中的 `price` 属性并添加前缀 `` -->
<el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column>
</el-table>
<!-- 在对话框内创建一个用于放置分页组件的容器 `div`用于对选择商品的列表进行分页操作 -->
<div class="pagination-container">
<!-- 使用 `el-pagination` 组件实现分页功能设置背景色`background`绑定页面尺寸改变`size-change`和当前页改变`current-change`的事件处理方法配置分页布局当前页每页数量可选页面尺寸列表以及总记录数等属性这里的相关属性绑定到 `dialogData` 中的对应分页参数 -->
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5, 10, 15]"
:total="dialogData.total">
</el-pagination>
</div>
<!-- 清除浮动确保后续元素布局不受影响 -->
<div style="clear: both;"></div>
<!-- 在对话框的底部插槽`slot="footer"`内添加两个按钮分别用于取消和确定操作点击取消按钮隐藏对话框点击确定按钮触发 `handleSelectDialogConfirm` 方法 -->
<div slot="footer">
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<!-- 使用 `el-dialog` 组件创建一个对话框用于编辑秒杀商品信息的相关操作绑定对话框的显示状态为 `editDialogVisible`设置标题为编辑秒杀商品信息宽度为页面宽度的 `40%` -->
<el-dialog title="编辑秒杀商品信息"
:visible.sync="editDialogVisible"
width="40%">
<!-- 在对话框内创建一个表单绑定数据模型为 `flashProductRelation`设置表单引用为 `flashProductRelationForm`标签宽度为 `150px`尺寸为小`size="small"` -->
<el-form :model="flashProductRelation"
ref="flashProductRelationForm"
label-width="150px" size="small">
<!-- 表单中商品名称显示的表单项通过 `span` 标签展示对应 `flashProductRelation` `product` 对象的 `name` 属性此处为只读展示不进行输入操作 -->
<el-form-item label="商品名称:">
<span>{{flashProductRelation.product.name}}</span>
</el-form-item>
<!-- 表单中货号显示的表单项通过 `span` 标签展示对应 `flashProductRelation` `product` 对象的 `productSn` 属性添加前缀 `NO.`同样为只读展示 -->
<el-form-item label="货号:">
<span>NO.{{flashProductRelation.product.productSn}}</span>
</el-form-item>
<!-- 表单中商品价格显示的表单项通过 `span` 标签展示对应 `flashProductRelation` `product` 对象的 `price` 属性添加前缀 ``也是只读展示 -->
<el-form-item label="商品价格:">
<span>{{flashProductRelation.product.price}}</span>
</el-form-item>
<!-- 表单中秒杀价格输入的表单项通过 `el-input` 组件双向绑定数据到 `flashProductRelation.flashPromotionPrice`设置输入框宽度样式类为 `input-width`并在输入框前添加前缀 `` -->
<el-form-item label="秒杀价格:">
<el-input v-model="flashProductRelation.flashPromotionPrice" class="input-width">
<template slot="prepend"></template>
</el-input>
</el-form-item>
<!-- 表单中剩余数量显示的表单项通过 `span` 标签展示对应 `flashProductRelation` `product` 对象的 `stock` 属性为只读展示 -->
<el-form-item label="剩余数量:">
<span>{{flashProductRelation.product.stock}}</span>
</el-form-item>
<!-- 表单中秒杀数量输入的表单项通过 `el-input` 组件双向绑定数据到 `flashProductRelation.flashPromotionCount`设置输入框宽度样式类为 `input-width` -->
<el-form-item label="秒杀数量:">
<el-input v-model="flashProductRelation.flashPromotionCount" class="input-width"></el-input>
</el-form-item>
<!-- 表单中限购数量输入的表单项通过 `el-input` 组件双向绑定数据到 `flashProductRelation.flashPromotionLimit`设置输入框宽度样式类为 `input-width` -->
<el-form-item label="限购数量:">
<el-input v-model="flashProductRelation.flashPromotionLimit" class="input-width"></el-input>
</el-form-item>
<!-- 表单中排序输入的表单项通过 `el-input` 组件双向绑定数据到 `flashProductRelation.sort`设置输入框宽度样式类为 `input-width` -->
<el-form-item label="排序:">
<el-input v-model="flashProductRelation.sort" class="input-width"></el-input>
</el-form-item>
</el-form>
<!-- 在对话框的底部插槽`slot="footer"`内添加两个按钮分别用于取消和确定操作点击取消按钮隐藏对话框点击确定按钮触发 `handleEditDialogConfirm` 方法 -->
<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>
</span>
</el-dialog>
</div>
</template>
<script>
// '@/api/flashProductRelation'fetchListcreateFlashProductRelationdeleteFlashProductRelationupdateFlashProductRelationAPI
import {fetchList, createFlashProductRelation, deleteFlashProductRelation, updateFlashProductRelation} from '@/api/flashProductRelation';
// '@/api/product'fetchProductList
import {fetchList as fetchProductList} from '@/api/product';
// ID
const defaultListQuery = {
pageNum: 1, //
pageSize: 5, // 5
flashPromotionId: null, // IDnull
flashPromotionSessionId: null // IDnull
};
export default {
name: 'flashPromotionProductRelationList',
data() {
return {
// Object.assigndefaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// nullgetList
list: null,
// null
total: null,
// falsetruefalse
listLoading: false,
// falsetrue
dialogVisible: false,
// falsehandleSelectProducttrue
selectDialogVisible: false,
// nullnull
dialogData: {
list: null,
total: null,
multipleSelection: [],
listQuery: {
keyword: null,
pageNum: 1,
pageSize: 5
}
},
// falsehandleUpdatetrue
editDialogVisible: false,
// product便
flashProductRelation: {
product: {}
}
}
},
created() {
// this.$route.queryflashPromotionIdflashPromotionSessionIdlistQuery
this.listQuery.flashPromotionId = this.$route.query.flashPromotionId;
this.listQuery.flashPromotionSessionId = this.$route.query.flashPromotionSessionId;
// getListlistQuery使
this.getList();
},
methods: {
// 1valgetList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// valgetList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// selectDialogVisibletrue使getDialogList便
handleSelectProduct() {
this.selectDialogVisible = true;
this.getDialogList();
},
// indexroweditDialogVisibletrue使Object.assignrowflashProductRelation便
handleUpdate(index, row) {
this.editDialogVisible = true;
this.flashProductRelation = Object.assign({}, row);
},
// indexrowdeleteFlashProductRelationIDrow.idgetList
handleDelete(index, row) {
this.$confirm('是否要删除该商品?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteFlashProductRelation(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
// getDialogListdialogData.listQuery
handleSelectSearch() {
this.getDialogList();
},
// handleSizeChange1valgetDialogList
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
// handleCurrentChangevalgetDialogList
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList();
},
// valdialogDatamultipleSelection便
handleDialogSelectionChange(val) {
this.dialogData.multipleSelection = val;
},
// dialogData.multipleSelection1IDIDthis.listQuery.flashPromotionIdIDthis.listQuery.flashPromotionSessionIdselectProductscreateFlashProductRelationselectProductsgetList
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({
type: 'success',
message: '添加成功!'
});
});
});
},
// updateFlashProductRelationIDthis.flashProductRelation.idflashProductRelationgetList使
handleEditDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateFlashProductRelation(this.flashProductRelation.id, this.flashProductRelation).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
this.editDialogVisible = false;
this.getList();
});
});
},
// listLoadingtruefetchListlistQuerylistLoadingfalselisttotal
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
},
// fetchProductListdialogData.listQuerydialogDatalistdialogDatatotal便
getDialogList() {
fetchProductList(this.dialogData.listQuery).then(response => {
this.dialogData.list = response.data.list;
this.dialogData.total = response.data.total;
});
}
}
}
</script>

@ -0,0 +1,181 @@
<template> 
<div class="app-container">
<el-card shadow="never" class="operate-container">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
</el-card>
<div class="table-container">
<el-table ref="selectSessionTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="秒杀时间段名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="每日开始时间" align="center">
<template slot-scope="scope">{{scope.row.startTime | formatTime}}</template>
</el-table-column>
<el-table-column label="每日结束时间" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatTime}}</template>
</el-table-column>
<el-table-column label="商品数量" align="center">
<template slot-scope="scope">{{scope.row.productCount}}</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleShowRelation(scope.$index, scope.row)">商品列表
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
import {fetchSelectList} from '@/api/flashSession';
import {formatDate} from '@/utils/date';
export default {
name: 'selectSessionList',
data() {
return {
list: null,
listLoading: false
}
},
created() {
this.getList();
},
filters:{
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'hh:mm:ss')
}
},
methods: {
handleShowRelation(index,row){
this.$router.push({path:'/sms/flashProductRelation',query:{
flashPromotionId:this.$route.query.flashPromotionId, flashPromotionSessionId:row.id}})
},
getList() {
this.listLoading = true;
fetchSelectList({flashPromotionId:this.$route.query.flashPromotionId}).then(response => {
this.listLoading = false;
this.list = response.data;
});
}
}
}
</script>
<style scoped>
.operate-container {
margin-top: 0;
}
</style>
#abc
<template>
<!-- 创建一个类名为 `app-container` `div` 元素作为整个页面的容器用于包裹内部的各个模块实现页面的整体布局 -->
<div class="app-container">
<!-- 使用 `el-card` 组件创建一个操作相关的容器设置阴影效果为无样式类为 `operate-container`可能用于展示页面的标题等操作相关元素 -->
<el-card shadow="never" class="operate-container">
<!-- 使用 `el-icon-tickets` 图标来展示一个特定的图标具体图标样式由对应图标库定义可能用于示意与当前数据列表相关的某种含义比如表示票务列表相关的操作等 -->
<i class="el-icon-tickets"></i>
<span>数据列表</span>
</el-card>
<!-- 创建一个用于展示表格数据的容器 `div`类名为 `table-container`用于将表格与其他元素在布局上进行区分 -->
<div class="table-container">
<!-- 使用 `el-table` 组件来展示数据列表通过 `ref` 属性为表格设置一个引用名称 `selectSessionTable`方便在 JavaScript 代码中通过 `$refs` 来获取该表格实例绑定数据来源为 `list`设置宽度为 `100%`通过 `v-loading` 指令绑定加载状态为 `listLoading`用于在数据加载时显示加载提示例如加载动画等并显示表格边框 -->
<el-table ref="selectSessionTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<!-- 定义表格的列标签为编号宽度设置为 `100px`内容在单元格内居中对齐通过插槽`slot-scope`获取对应行数据中的 `id` 属性值并展示在单元格内 -->
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 定义表格的列标签为秒杀时间段名称内容在单元格内居中对齐通过插槽获取对应行数据中的 `name` 属性值并展示在单元格内用于展示秒杀时间段的名称信息 -->
<el-table-column label="秒杀时间段名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 定义表格的列标签为每日开始时间内容在单元格内居中对齐通过插槽获取对应行数据中的 `startTime` 属性值并使用名为 `formatTime` 的过滤器 Vue `filters` 选项中定义对时间数据进行格式化处理后展示在单元格内将时间转换为更易读的格式 -->
<el-table-column label="每日开始时间" align="center">
<template slot-scope="scope">{{scope.row.startTime | formatTime}}</template>
</el-table-column>
<!-- 定义表格的列标签为每日结束时间内容在单元格内居中对齐通过插槽获取对应行数据中的 `endTime` 属性值并同样使用 `formatTime` 过滤器对时间数据进行格式化处理后展示在单元格内 -->
<el-table-column label="每日结束时间" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatTime}}</template>
</el-table-column>
<!-- 定义表格的列标签为商品数量内容在单元格内居中对齐通过插槽获取对应行数据中的 `productCount` 属性值并展示在单元格内用于展示与秒杀时间段相关的商品数量信息 -->
<el-table-column label="商品数量" align="center">
<template slot-scope="scope">{{scope.row.productCount}}</template>
</el-table-column>
<!-- 定义表格的列标签为操作内容在单元格内居中对齐通过插槽在单元格内放置一个按钮按钮尺寸为迷你`size="mini"`类型为文本按钮`type="text"`点击按钮时触发 `handleShowRelation` 方法并传入当前行的索引`scope.$index`和对应行的数据`scope.row`此处按钮文本为商品列表可能用于跳转到展示与该秒杀时间段相关商品列表的页面 -->
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleShowRelation(scope.$index, scope.row)">商品列表
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
// `@/api/flashSession` `fetchSelectList` API
import {fetchSelectList} from '@/api/flashSession';
// `@/utils/date` `formatDate` 使便
import {formatDate} from '@/utils/date';
export default {
name: 'selectSessionList',
data() {
return {
// `null` `getList` 便
list: null,
// `false` `true` `false`
listLoading: false
}
},
created() {
// `getList` 使
this.getList();
},
filters: {
// `formatTime` `null``''` `N/A` `Date` `formatDate` `hh:mm:ss` ::使
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'hh:mm:ss')
}
},
methods: {
// `index``row` `this.$router.push` `/sms/flashProductRelation` `query` `flashPromotionId` ID `ID``row.id`
handleShowRelation(index, row) {
this.$router.push({path: '/sms/flashProductRelation', query: {
flashPromotionId: this.$route.query.flashPromotionId, flashPromotionSessionId: row.id
}});
},
// `listLoading` `true` `fetchSelectList` `flashPromotionId` `flashPromotionId` `listLoading` `false` `list`
getList() {
this.listLoading = true;
fetchSelectList({flashPromotionId: this.$route.query.flashPromotionId}).then(response => {
this.listLoading = false;
this.list = response.data;
});
}
}
}
</script>

@ -0,0 +1,476 @@
<template> 
<div class="app-container">
<el-card shadow="never" class="operate-container">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="flashSessionTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="秒杀时间段名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="每日开始时间" align="center">
<template slot-scope="scope">{{scope.row.startTime | formatTime}}</template>
</el-table-column>
<el-table-column label="每日结束时间" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatTime}}</template>
</el-table-column>
<el-table-column label="启用" align="center">
<template slot-scope="scope">
<el-switch
@change="handleStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.status">
</el-switch>
</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<el-dialog
title="添加时间段"
:visible.sync="dialogVisible"
width="40%">
<el-form :model="flashSession"
ref="flashSessionForm"
label-width="150px" size="small">
<el-form-item label="秒杀时间段名称:">
<el-input v-model="flashSession.name" style="width: 250px"></el-input>
</el-form-item>
<el-form-item label="每日开始时间:">
<el-time-picker
v-model="flashSession.startTime"
placeholder="请选择时间">
</el-time-picker>
</el-form-item>
<el-form-item label="每日结束时间:">
<el-time-picker
v-model="flashSession.endTime"
placeholder="请选择时间">
</el-time-picker>
</el-form-item>
<el-form-item label="是否启用">
<el-radio-group v-model="flashSession.status">
<el-radio :label="1">启用</el-radio>
<el-radio :label="0">不启用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<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>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,updateStatus,deleteSession,createSession,updateSession} from '@/api/flashSession';
import {formatDate} from '@/utils/date';
const defaultFlashSession={
name:null,
startTime:null,
endTime:null,
status:0
};
export default {
name: 'flashPromotionSessionList',
data() {
return {
list: null,
listLoading: false,
dialogVisible:false,
isEdit:false,
flashSession:Object.assign({},defaultFlashSession)
}
},
created() {
this.getList();
},
filters:{
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'hh:mm:ss')
}
},
methods: {
handleAdd() {
this.dialogVisible = true;
this.isEdit = false;
this.flashSession = Object.assign({},defaultFlashSession);
},
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();
});
},
handleUpdate(index,row){
this.dialogVisible = true;
this.isEdit = true;
this.flashSession = Object.assign({},row);
this.flashSession.startTime=new Date(row.startTime);
this.flashSession.endTime=new Date(row.endTime);
},
handleDelete(index,row){
this.$confirm('是否要删除该时间段?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteSession(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
handleDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateSession(this.flashSession.id,this.flashSession).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
} else {
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>
<style scoped>
.operate-container {
margin-top: 0;
}
</style>
#abc
<template>
<!-- 创建一个类名为 `app-container` `div` 元素作为整个页面内容的外层容器用于组织和布局页面内的各个组件和元素 -->
<div class="app-container">
<!-- 使用 `el-card` 组件创建一个操作相关的容器设置阴影效果为 `never`即无阴影并添加 `operate-container` 样式类该容器可能用于展示页面的一些操作按钮及标题等内容 -->
<el-card shadow="never" class="operate-container">
<!-- 使用 `el-icon-tickets` 图标元素来展示一个特定的图标具体图标样式由所使用的图标库决定在这里可能是用于示意与数据列表相关的某种含义比如表示和票务活动相关的业务场景 -->
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<!-- 创建一个 `el-button` 按钮元素设置按钮尺寸为 `mini`迷你型样式类为 `btn-add`点击按钮时会触发 `handleAdd` 方法按钮文本为添加用于触发添加新的秒杀时间段的操作 -->
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card>
<!-- 创建一个类名为 `table-container` `div` 元素用于包裹下面的 `el-table` 组件起到对表格进行布局划分的作用使其在页面上与其他元素区分开来 -->
<div class="table-container">
<!-- 使用 `el-table` 组件来展示秒杀时间段相关的数据列表通过 `ref` 属性为表格设置一个引用名称 `flashSessionTable`方便在 JavaScript 代码中通过 `$refs` 来获取该表格实例绑定数据来源为 `list`该数据会在 JavaScript 代码中获取并赋值设置表格宽度为 `100%`通过 `v-loading` 指令绑定加载状态为 `listLoading`用于在数据加载过程中显示加载提示例如加载动画等同时显示表格边框 -->
<el-table ref="flashSessionTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<!-- 定义表格的一列设置列标签为编号宽度为 `100px`内容在单元格内居中对齐通过 `slot-scope` 插槽获取对应行数据中的 `id` 属性值并展示在该单元格内用于展示每个秒杀时间段的唯一编号 -->
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 定义表格的一列设置列标签为秒杀时间段名称内容在单元格内居中对齐通过 `slot-scope` 插槽获取对应行数据中的 `name` 属性值并展示在该单元格内用于展示每个秒杀时间段的自定义名称 -->
<el-table-column label="秒杀时间段名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 定义表格的一列设置列标签为每日开始时间内容在单元格内居中对齐通过 `slot-scope` 插槽获取对应行数据中的 `startTime` 属性值并使用名为 `formatTime` 的过滤器 Vue `filters` 选项中定义对时间数据进行格式化处理后展示在该单元格内将时间转换为更易读的格式 `hh:mm:ss` -->
<el-table-column label="每日开始时间" align="center">
<template slot-scope="scope">{{scope.row.startTime | formatTime}}</template>
</el-table-column>
<!-- 定义表格的一列设置列标签为每日结束时间内容在单元格内居中对齐通过 `slot-scope` 插槽获取对应行数据中的 `endTime` 属性值并同样使用 `formatTime` 过滤器对时间数据进行格式化处理后展示在该单元格内 -->
<el-table-column label="每日结束时间" align="center">
<template slot-scope="scope">{{scope.row.endTime | formatTime}}</template>
</el-table-column>
<!-- 定义表格的一列设置列标签为启用内容在单元格内居中对齐在该单元格内放置一个 `el-switch` 开关组件用于切换秒杀时间段的启用状态开关组件绑定 `change` 事件到 `handleStatusChange` 方法传入当前行的索引`scope.$index`和对应行的数据`scope.row`设置 `active-value`开启时的值 `1``inactive-value`关闭时的值 `0`并通过 `v-model` 双向绑定到对应行数据中的 `status` 属性实现状态的可视化切换与数据绑定 -->
<el-table-column label="启用" align="center">
<template slot-scope="scope">
<el-switch
@change="handleStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.status">
</el-switch>
</template>
</el-table-column>
<!-- 定义表格的一列设置列标签为操作宽度为 `180px`内容在单元格内居中对齐通过 `slot-scope` 插槽在单元格内放置两个按钮分别用于编辑和删除对应的秒杀时间段编辑按钮点击时触发 `handleUpdate` 方法传入当前行的索引和对应行的数据删除按钮点击时触发 `handleDelete` 方法同样传入相应参数用于执行对应的数据操作 -->
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleUpdate(scope.$index, scope.row)">编辑
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 使用 `el-dialog` 组件创建一个对话框用于添加或编辑秒杀时间段的相关操作设置对话框标题为添加时间段绑定对话框的显示状态为 `dialogVisible`通过 `:visible.sync` 实现双向绑定 JavaScript 代码中改变该变量值可控制对话框的显示与隐藏设置对话框宽度为页面宽度的 `40%` -->
<el-dialog
title="添加时间段"
:visible.sync="dialogVisible"
width="40%">
<!-- 在对话框内创建一个 `el-form` 表单组件用于收集用户输入的秒杀时间段相关信息绑定数据模型为 `flashSession`该数据对象在 JavaScript 代码中定义和操作设置表单引用为 `flashSessionForm`标签宽度为 `150px`表单尺寸为 `small`小型 -->
<el-form :model="flashSession"
ref="flashSessionForm"
label-width="150px" size="small">
<!-- 创建一个表单项目`el-form-item`设置标签为秒杀时间段名称在该项目内放置一个 `el-input` 输入框组件通过 `v-model` 双向绑定输入框的值到 `flashSession` 对象的 `name` 属性设置输入框宽度为 `250px`用于用户输入秒杀时间段的名称 -->
<el-form-item label="秒杀时间段名称:">
<el-input v-model="flashSession.name" style="width: 250px"></el-input>
</el-form-item>
<!-- 创建一个表单项目设置标签为每日开始时间在该项目内放置一个 `el-time-picker` 时间选择器组件通过 `v-model` 双向绑定时间选择器选择的值到 `flashSession` 对象的 `startTime` 属性设置占位提示文本为请选择时间用于用户选择秒杀时间段的每日开始时间 -->
<el-form-item label="每日开始时间:">
<el-time-picker
v-model="flashSession.startTime"
placeholder="请选择时间">
</el-time-picker>
</el-form-item>
<!-- 创建一个表单项目设置标签为每日结束时间在该项目内放置一个 `el-time-picker` 时间选择器组件通过 `v-model` 双向绑定时间选择器选择的值到 `flashSession` 对象的 `endTime` 属性设置占位提示文本为请选择时间用于用户选择秒杀时间段的每日结束时间 -->
<el-form-item label="每日结束时间:">
<el-time-picker
v-model="flashSession.endTime"
placeholder="请选择时间">
</el-time-picker>
</el-form-item>
<!-- 创建一个表单项目设置标签为是否启用在该项目内放置一个 `el-radio-group` 单选框组组件通过 `v-model` 双向绑定单选框组的值到 `flashSession` 对象的 `status` 属性用于用户选择该秒杀时间段是否启用单选框组内包含两个 `el-radio` 单选框分别对应启用`label` 值为 `1`和不启用`label` 值为 `0`两种状态 -->
<el-form-item label="是否启用">
<el-radio-group v-model="flashSession.status">
<el-radio :label="1">启用</el-radio>
<el-radio :label="0">不启用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<!-- 在对话框的底部插槽`slot="footer"`内添加两个按钮分别用于取消和确定操作取消按钮点击时将 `dialogVisible` 设置为 `false`隐藏对话框确定按钮点击时触发 `handleDialogConfirm` 方法用于执行添加或编辑操作并根据操作结果处理后续逻辑 -->
<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>
</span>
</el-dialog>
</div>
</template>
<script>
// '@/api/flashSession' API
// fetchList
// updateStatus
// deleteSession ID
// createSession
// updateSession ID
import {fetchList, updateStatus, deleteSession, createSession, updateSession} from '@/api/flashSession';
// '@/utils/date'formatDate使便
import {formatDate} from '@/utils/date';
// defaultFlashSession
// namenull
// startTimenull
// endTimenull
// status00
const defaultFlashSession = {
name: null,
startTime: null,
endTime: null,
status: 0
};
export default {
name: 'flashPromotionSessionList',
data() {
return {
// listnullgetList
list: null,
// listLoadingfalsetruefalse
listLoading: false,
// dialogVisible/falsetrue
dialogVisible: false,
// isEdittruefalsefalse便
isEdit: false,
// flashSessionObject.assigndefaultFlashSession API
flashSession: Object.assign({}, defaultFlashSession)
}
},
created() {
// getList
this.getList();
},
filters: {
// formatTime使
// timenull'N/A'
// timeJavaScriptDateformatDate'hh:mm:ss'::
formatTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'hh:mm:ss')
}
},
methods: {
// handleAdd
// dialogVisibletrue使/
// isEditfalse
// Object.assignflashSessiondefaultFlashSession
handleAdd() {
this.dialogVisible = true;
this.isEdit = false;
this.flashSession = Object.assign({}, defaultFlashSession);
},
// handleStatusChangeindexrow
// ?'warning'
// updateStatusrow.id{status: row.status}!
// catchgetList
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();
});
},
// handleUpdateindexrow
// dialogVisibletrue使/便
// isEdittrue API
// Object.assignrowflashSession便
// flashSessionstartTimeendTimeDate便
handleUpdate(index, row) {
this.dialogVisible = true;
this.isEdit = true;
this.flashSession = Object.assign({}, row);
this.flashSession.startTime = new Date(row.startTime);
this.flashSession.endTime = new Date(row.endTime);
},
// handleDeleteindexrow
// ?'warning'
// deleteSessionrow.id!getList
handleDelete(index, row) {
this.$confirm('是否要删除该时间段?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteSession(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
// handleDialogConfirm/
// ?'warning'
// isEdit
// isEdittrueupdateSessionflashSession.idflashSessiondialogVisiblefalsegetList使
// isEditfalsecreateSessionflashSessiondialogVisiblefalsegetList
handleDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateSession(this.flashSession.id, this.flashSession).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
this.dialogVisible = false;
this.getList();
})
} else {
createSession(this.flashSession).then(response => {
this.$message({
message: '添加成功!',
type: 'success'
});
this.dialogVisible = false;
this.getList();
})
}
})
},
// getList
// listLoadingtrue
// fetchListlistLoadingfalseresponse.datalist使
getList() {
this.listLoading = true;
fetchList({}).then(response => {
this.listLoading = false;
this.list = response.data;
});
}
}
}
</script>

@ -0,0 +1,839 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="商品名称:">
<el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input>
</el-form-item>
<el-form-item label="推荐状态:">
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="newProductTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column>
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.recommendStatus">
</el-switch>
</template>
</el-table-column>
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="batch-operate-container">
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<el-form :model="sortDialogData"
label-width="150px">
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,updateRecommendStatus,deleteHotProduct,createHotProduct,updateHotProductSort} from '@/api/hotProduct';
import {fetchList as fetchProductList} from '@/api/product';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
productName: null,
recommendStatus: null
};
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'hotProductList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
recommendOptions: Object.assign({}, defaultRecommendOptions),
list: null,
total: null,
listLoading: false,
multipleSelection: [],
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
operateType: null,
selectDialogVisible:false,
dialogData:{
list: null,
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
pageNum: 1,
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
}
},
created() {
this.getList();
},
filters:{
formatRecommendStatus(status){
if(status===1){
return '推荐中';
}else{
return '未推荐';
}
}
},
methods: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleRecommendStatusStatusChange(index,row){
this.updateRecommendStatusStatus(row.id,row.recommendStatus);
},
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
});
}
},
handleSelectProduct(){
this.selectDialogVisible=true;
this.getDialogList();
},
handleSelectSearch(){
this.getDialogList();
},
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList();
},
handleDialogSelectionChange(val){
this.dialogData.multipleSelection = val;
},
handleSelectDialogConfirm(){
if (this.dialogData.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({
type: 'success',
message: '添加成功!'
});
});
});
},
handleEditSort(index,row){
this.sortDialogVisible=true;
this.sortDialogData.sort=row.sort;
this.sortDialogData.id=row.id;
},
handleUpdateSort(){
this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateHotProductSort(this.sortDialogData).then(response=>{
this.sortDialogVisible=false;
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
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({
type: 'success',
message: '已取消操作!'
});
this.getList();
});
},
deleteProduct(ids){
this.$confirm('是否要删除该推荐?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
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>
<style></style>
#abc
<template>
<!-- 整体页面内容的外层容器用于组织和布局页面内的各个组件 -->
<div class="app-container">
<!-- 筛选搜索相关的卡片容器设置无阴影效果内部放置筛选搜索相关的元素 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 展示一个搜索图标用于直观表示此区域与搜索功能相关 -->
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<!-- 查询搜索按钮右浮动显示按钮类型为主要操作类型样式上会突出显示点击时触发 `handleSearchList` 方法用于根据设置的筛选条件发起查询搜索操作按钮尺寸为小型 -->
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<!-- 重置按钮同样右浮动且设置了右边距点击时触发 `handleResetSearch` 方法用于将筛选条件重置为默认状态按钮尺寸为小型 -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 内联表单用于收集筛选条件绑定的数据模型为 `listQuery`表单尺寸为小型标签宽度设置为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 商品名称筛选的表单项目包含一个输入框通过 `v-model` 双向绑定输入框的值到 `listQuery` 中的 `productName` 属性输入框设置了特定样式类可能用于控制宽度等样式并带有提示文本 -->
<el-form-item label="商品名称:">
<el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input>
</el-form-item>
<!-- 推荐状态筛选的表单项目包含一个下拉选择框通过 `v-model` 双向绑定选择框的值到 `listQuery` 中的 `recommendStatus` 属性可清除已选选项设置了占位文本与样式类下拉选项通过循环 `recommendOptions` 数组动态生成 -->
<el-form-item label="推荐状态:">
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 操作相关的卡片容器同样无阴影效果内部包含一些与数据列表操作相关的元素比如选择商品按钮 -->
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<!-- 选择商品按钮尺寸为迷你型点击时触发 `handleSelectProduct` 方法用于打开选择商品的对话框 -->
<el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button>
</el-card>
<!-- 表格容器用于包裹展示数据列表的表格使其在布局上与其他元素区分开来 -->
<div class="table-container">
<!-- 商品相关的数据列表表格设置了引用名称方便在JavaScript中获取实例绑定了数据来源为 `list`宽度为100%监听行选择变化事件加载状态并且显示表格边框 -->
<el-table ref="newProductTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<!-- 选择列用于在表格中显示复选框方便进行多选操作宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 编号列通过插槽获取对应行数据中的 `id` 属性值展示在单元格内宽度为120px内容居中对齐 -->
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 商品名称列通过插槽获取对应行数据中的 `productName` 属性值展示在单元格内内容居中对齐 -->
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column>
<!-- 是否推荐列包含一个开关组件用于切换商品的推荐状态绑定了状态改变事件设置了开关的开启和关闭对应的值并且双向绑定到对应行数据中的 `recommendStatus` 属性 -->
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.recommendStatus">
</el-switch>
</template>
</el-table-column>
<!-- 排序列通过插槽获取对应行数据中的 `sort` 属性值展示在单元格内宽度为160px内容居中对齐 -->
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<!-- 状态列通过插槽获取对应行数据中的 `recommendStatus` 属性值使用名为 `formatRecommendStatus` 的过滤器对其进行格式化处理后展示在单元格内宽度为160px内容居中对齐 -->
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<!-- 操作列在单元格内放置了两个文本按钮分别用于设置排序点击触发 `handleEditSort` 方法和删除商品点击触发 `handleDelete` 方法宽度为180px内容居中对齐 -->
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 批量操作相关的容器内部放置用于选择批量操作类型的下拉框以及执行操作的按钮 -->
<div class="batch-operate-container">
<!-- 批量操作类型的下拉选择框尺寸为小型双向绑定选择的值到 `operateType` 属性带有占位提示文本下拉选项通过循环 `operates` 数组生成 -->
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<!-- 执行批量操作的确定按钮设置了左边距添加了特定样式类按钮类型为主要操作类型尺寸为小型点击时触发 `handleBatchOperate` 方法 -->
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<!-- 分页容器用于放置分页组件实现数据列表的分页展示功能 -->
<div class="pagination-container">
<!-- 分页组件设置了背景色使其更突出绑定了每页显示数量改变和当前页码改变的事件处理方法配置了分页布局包含多种功能按钮绑定了每页显示数量可选择的每页显示数量数组当前页码以及总条数等相关属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
<!-- 选择商品的对话框组件设置了标题双向绑定显示状态以及宽度用于展示可选择的商品列表等相关操作 -->
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<!-- 输入框用于输入商品名称搜索关键字双向绑定输入的值到 `dialogData.listQuery.keyword` 属性设置了宽度外边距尺寸以及占位提示文本并且在输入框右侧有一个搜索图标按钮点击触发 `handleSelectSearch` 方法 -->
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<!-- 展示可选择商品数据列表的表格绑定了数据来源监听行选择变化事件并且显示表格边框 -->
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<!-- 选择列用于在表格中显示复选框方便多选操作宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 商品名称列通过插槽获取对应行数据中的 `name` 属性值展示在单元格内内容居中对齐 -->
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 货号列通过插槽获取对应行数据中的 `productSn` 属性值以特定格式添加 "NO." 前缀展示在单元格内宽度为160px内容居中对齐 -->
<el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<!-- 价格列通过插槽获取对应行数据中的 `price` 属性值以特定格式添加 "¥" 前缀展示在单元格内宽度为120px内容居中对齐 -->
<el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<!-- 对话框内的分页组件用于对可选择商品列表进行分页展示同样配置了相关的事件处理方法分页布局以及绑定了页码每页显示数量可选择的每页显示数量数组和总条数等属性 -->
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<!-- 取消按钮点击时隐藏对话框尺寸为小型 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 确定按钮点击时触发 `handleSelectDialogConfirm` 方法尺寸为小型按钮类型为主要操作类型 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<!-- 设置排序的对话框组件设置了标题双向绑定显示状态以及宽度内部包含用于输入排序值的表单 -->
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<!-- 表单用于输入排序相关的值绑定的数据模型为 `sortDialogData`标签宽度为150px -->
<el-form :model="sortDialogData"
label-width="150px">
<!-- 排序值的表单项目包含一个输入框通过 `v-model` 双向绑定输入框的值到 `sortDialogData` 中的 `sort` 属性输入框设置了宽度 -->
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<!-- 取消按钮点击时隐藏对话框尺寸为小型 -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- 确定按钮点击时触发 `handleUpdateSort` 方法尺寸为小型按钮类型为主要操作类型 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
// '@/api/hotProduct' API hotProduct
// fetchList
// updateRecommendStatus
// deleteHotProduct ID
// createHotProduct
// updateHotProductSort ID
import {fetchList, updateRecommendStatus, deleteHotProduct, createHotProduct, updateHotProductSort} from '@/api/hotProduct';
// '@/api/product' fetchList fetchProductList
import {fetchList as fetchProductList} from '@/api/product';
// defaultListQuery
// pageNum 1
// pageSize 5 5
// productName null
// recommendStatus null
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
productName: null,
recommendStatus: null
};
// defaultRecommendOptions label value
// 0 1
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'hotProductList',
data() {
return {
// listQuery Object.assign defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// recommendOptions defaultRecommendOptions
recommendOptions: Object.assign({}, defaultRecommendOptions),
// list null getList 便
list: null,
// total null便
total: null,
// listLoading false true false
listLoading: false,
// multipleSelection 便
multipleSelection: [],
// operates label value 012
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// operateType null value 便
operateType: null,
// selectDialogVisible false true使
selectDialogVisible: false,
// dialogData
dialogData: {
list: null,
total: null,
multipleSelection: [],
listQuery: {
keyword: null,
pageNum: 1,
pageSize: 5
}
},
// sortDialogVisible false true使便
sortDialogVisible: false,
// sortDialogData sort 0 id ID null
sortDialogData: {sort: 0, id: null}
}
},
created() {
// getList
this.getList();
},
filters: {
// formatRecommendStatus 使
// status 1 status 1 0
formatRecommendStatus(status) {
if (status === 1) {
return '推荐中';
} else {
return '未推荐';
}
}
},
methods: {
// handleResetSearch listQuery defaultListQuery 便
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// handleSearchList
// listQuery pageNum 1 getList
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// handleSelectionChange val multipleSelection 使 multipleSelection 便
handleSelectionChange(val) {
this.multipleSelection = val;
},
// handleSizeChange val
// listQuery pageNum 1 listQuery pageSize val getList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// handleCurrentChange val
// listQuery pageNum val getList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// handleRecommendStatusStatusChange index row updateRecommendStatusStatus IDrow.idrow.recommendStatus
handleRecommendStatusStatusChange(index, row) {
this.updateRecommendStatusStatus(row.id, row.recommendStatus);
},
// handleDelete index row deleteProduct IDrow.id
handleDelete(index, row) {
this.deleteProduct(row.id);
},
// handleBatchOperate
// multipleSelection 1 warning 1000 1
// multipleSelection multipleSelection id ids
// operateType
// operateType 0 updateRecommendStatusStatus ids ID 1
// operateType 1 updateRecommendStatusStatus ids 0
// operateType 2 deleteProduct ids
// operateType 012 warning 1000
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.updateRecommendStatusStatus(ids, 2);
} else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
// handleSelectProduct selectDialogVisible true使便 getDialogList
handleSelectProduct() {
this.selectDialogVisible = true;
this.getDialogList();
},
// handleSelectSearch getDialogList dialogData.listQuery.keyword
handleSelectSearch() {
this.getDialogList();
},
// handleDialogSizeChange val
// dialogData.listQuery pageNum 1 dialogData.listQuery pageSize val getDialogList
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
// handleDialogCurrentChange val
// dialogData.listQuery pageNum val getDialogList

@ -0,0 +1,620 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="商品名称:">
<el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input>
</el-form-item>
<el-form-item label="推荐状态:">
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="newProductTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column>
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.recommendStatus">
</el-switch>
</template>
</el-table-column>
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="batch-operate-container">
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column>
<el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<el-form :model="sortDialogData"
label-width="150px">
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,updateRecommendStatus,deleteNewProduct,createNewProduct,updateNewProductSort} from '@/api/newProduct';
import {fetchList as fetchProductList} from '@/api/product';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
productName: null,
recommendStatus: null
};
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'newProductList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
recommendOptions: Object.assign({}, defaultRecommendOptions),
list: null,
total: null,
listLoading: false,
multipleSelection: [],
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
operateType: null,
selectDialogVisible:false,
dialogData:{
list: null,
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
pageNum: 1,
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
}
},
created() {
this.getList();
},
filters:{
formatRecommendStatus(status){
if(status===1){
return '推荐中';
}else{
return '未推荐';
}
}
},
methods: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleRecommendStatusStatusChange(index,row){
this.updateRecommendStatusStatus(row.id,row.recommendStatus);
},
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
});
}
},
handleSelectProduct(){
this.selectDialogVisible=true;
this.getDialogList();
},
handleSelectSearch(){
this.getDialogList();
},
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.getDialogList();
},
handleDialogSelectionChange(val){
this.dialogData.multipleSelection = val;
},
handleSelectDialogConfirm(){
if (this.dialogData.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=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
});
});
},
handleEditSort(index,row){
this.sortDialogVisible=true;
this.sortDialogData.sort=row.sort;
this.sortDialogData.id=row.id;
},
handleUpdateSort(){
this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateNewProductSort(this.sortDialogData).then(response=>{
this.sortDialogVisible=false;
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
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({
type: 'success',
message: '已取消操作!'
});
this.getList();
});
},
deleteProduct(ids){
this.$confirm('是否要删除该推荐?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
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>
<style></style>
#abc
<script>
// '@/api/newProduct' API newProduct
// fetchList
// updateRecommendStatus
// deleteNewProduct ID
// createNewProduct
// updateNewProductSort ID
import {fetchList, updateRecommendStatus, deleteNewProduct, createNewProduct, updateNewProductSort} from '@/api/newProduct';
// '@/api/product' fetchList fetchProductList使
import {fetchList as fetchProductList} from '@/api/product';
// defaultListQuery
// pageNum 1便使
// pageSize 5 5
// productName null
// recommendStatus null
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
productName: null,
recommendStatus: null
};
// defaultRecommendOptions
// label value
// "" value 0 "" value 1便
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default
name: 'newProductList',
data() {
return {
// listQuery Object.assign defaultListQuery fetchList
listQuery: Object.assign({}, defaultListQuery),
// recommendOptions defaultRecommendOptions 便使
recommendOptions: Object.assign({}, defaultRecommendOptions),
// list null getList 便
list: null,
// total null便
total: null,
// listLoading false getList true false
listLoading: false,
// multipleSelection 便
multipleSelection: [],
// operates label value 012
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// operateType null value 便handleBatchOperate
operateType: null,
// selectDialogVisible false true使便
selectDialogVisible: false,
// dialogData list nulltotal nullmultipleSelection listQuery keywordpageNumpageSize
dialogData: {
list: null,
total: null,
multipleSelection: [],
listQuery: {
keyword: null,
pageNum: 1,
pageSize: 5
}
},
// sortDialogVisible false true使便
sortDialogVisible: false,
// sortDialogData sort 0 id ID null updateNewProductSort
sortDialogData: {sort: 0, id: null}
}
},
created() {
// getList
this.getList();
},
filters: {
// formatRecommendStatus 使
// status 1 status 1 0
formatRecommendStatus(status) {
if (status === 1) {
return '推荐中';
} else {
return '未推荐';
}
}
},
methods:
// handleResetSearch listQuery defaultListQuery 便使
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// handleSearchList
// listQuery pageNum 1 getList 便
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// handleSelectionChange val multipleSelection 使 multipleSelection 便
handleSelectionChange(val) {
this.multipleSelection = val;
},
// handleSizeChange val
// listQuery pageNum 1 listQuery pageSize val getList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// handleCurrentChange val
// listQuery pageNum val getList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// handleRecommendStatusStatusChange index row updateRecommendStatusStatus IDrow.idrow.recommendStatus使
handleRecommendStatusStatusChange(index, row) {
this.updateRecommendStatusStatus(row.id, row.recommendStatus);
},
// handleDelete index row deleteProduct IDrow.id
handleDelete(index, row) {
this.deleteProduct(row.id);
},
// handleBatchOperate
// multipleSelection 1 warning 1000 1
// multipleSelection multipleSelection id ids
// operateType
// operateType 0 updateRecommendStatusStatus ids ID 1
// operateType 1 updateRecommendStatusStatus ids 0
// operateType 2 deleteProduct ids
// operateType 012 warning 1000
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.updateRecommendStatusStatus(ids, 2);
} else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
// handleSelectProduct selectDialogVisible true使便 getDialogList
handleSelectProduct() {
this.selectDialogVisible = true;
this.getDialogList();
},
// handleSelectSearch getDialogList dialogData.listQuery.keyword 便
handleSelectSearch() {
this.getDialogList();
},

@ -0,0 +1,603 @@
<template> 
<div class="app-container">
<el-card class="filter-container" shadow="never">
<div>
<i class="el-icon-search"></i>
<span>筛选搜索</span>
<el-button
style="float:right"
type="primary"
@click="handleSearchList()"
size="small">
查询搜索
</el-button>
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
size="small">
重置
</el-button>
</div>
<div style="margin-top: 15px">
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<el-form-item label="专题名称:">
<el-input v-model="listQuery.subjectName" class="input-width" placeholder="专题名称"></el-input>
</el-form-item>
<el-form-item label="推荐状态:">
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<el-option v-for="item in recommendOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
</div>
</el-card>
<el-card class="operate-container" shadow="never">
<i class="el-icon-tickets"></i>
<span>数据列表</span>
<el-button size="mini" class="btn-add" @click="handleSelectSubject()"></el-button>
</el-card>
<div class="table-container">
<el-table ref="newSubjectTable"
:data="list"
style="width: 100%;"
@selection-change="handleSelectionChange"
v-loading="listLoading" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<el-table-column label="专题名称" align="center">
<template slot-scope="scope">{{scope.row.subjectName}}</template>
</el-table-column>
<el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope">
<el-switch
@change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
:active-value="1"
:inactive-value="0"
v-model="scope.row.recommendStatus">
</el-switch>
</template>
</el-table-column>
<el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column>
<el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<template slot-scope="scope">
<el-button size="mini"
type="text"
@click="handleEditSort(scope.$index, scope.row)">设置排序
</el-button>
<el-button size="mini"
type="text"
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="batch-operate-container">
<el-select
size="small"
v-model="operateType" placeholder="批量操作">
<el-option
v-for="item in operates"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-button
style="margin-left: 20px"
class="search-button"
@click="handleBatchOperate()"
type="primary"
size="small">
确定
</el-button>
</div>
<div class="pagination-container">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
layout="total, sizes,prev, pager, next,jumper"
:page-size="listQuery.pageSize"
:page-sizes="[5,10,15]"
:current-page.sync="listQuery.pageNum"
:total="total">
</el-pagination>
</div>
<el-dialog title="选择专题" :visible.sync="selectDialogVisible" width="50%">
<el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px"
size="small"
placeholder="专题名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input>
<el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border>
<el-table-column type="selection" width="60" align="center"></el-table-column>
<el-table-column label="专题名称" align="center">
<template slot-scope="scope">{{scope.row.title}}</template>
</el-table-column>
<el-table-column label="所属分类" width="160" align="center">
<template slot-scope="scope">{{scope.row.categoryName}}</template>
</el-table-column>
<el-table-column label="添加时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatTime}}</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
background
@size-change="handleDialogSizeChange"
@current-change="handleDialogCurrentChange"
layout="prev, pager, next"
:current-page.sync="dialogData.listQuery.pageNum"
:page-size="dialogData.listQuery.pageSize"
:page-sizes="[5,10,15]"
:total="dialogData.total">
</el-pagination>
</div>
<div style="clear: both;"></div>
<div slot="footer">
<el-button size="small" @click="selectDialogVisible = false"> </el-button>
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div>
</el-dialog>
<el-dialog title="设置排序"
:visible.sync="sortDialogVisible"
width="40%">
<el-form :model="sortDialogData"
label-width="150px">
<el-form-item label="排序:">
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="sortDialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchList,updateRecommendStatus,deleteHomeSubject,createHomeSubject,updateHomeSubjectSort} from '@/api/homeSubject';
import {fetchList as fetchSubjectList} from '@/api/subject';
import {formatDate} from '@/utils/date';
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
subjectName: null,
recommendStatus: null
};
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default {
name: 'homeSubjectList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
recommendOptions: Object.assign({}, defaultRecommendOptions),
list: null,
total: null,
listLoading: false,
multipleSelection: [],
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
operateType: null,
selectDialogVisible:false,
dialogData:{
list: null,
total: null,
multipleSelection:[],
listQuery:{
keyword: null,
pageNum: 1,
pageSize: 5
}
},
sortDialogVisible:false,
sortDialogData:{sort:0,id:null}
}
},
created() {
this.getList();
},
filters:{
formatRecommendStatus(status){
if(status===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: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSelectionChange(val){
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleRecommendStatusStatusChange(index,row){
this.updateRecommendStatusStatus(row.id,row.recommendStatus);
},
handleDelete(index,row){
this.deleteSubject(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.deleteSubject(ids);
}else {
this.$message({
message: '请选择批量操作类型',
type: 'warning',
duration: 1000
});
}
},
handleSelectSubject(){
this.selectDialogVisible=true;
this.dialogData.listQuery.keyword=null;
this.getDialogList();
},
handleSelectSearch(){
this.getDialogList();
},
handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val;
this.getDialogList();
},
handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val;
this.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=>{
this.selectDialogVisible=false;
this.dialogData.multipleSelection=[];
this.getList();
this.$message({
type: 'success',
message: '添加成功!'
});
});
});
},
handleEditSort(index,row){
this.sortDialogVisible=true;
this.sortDialogData.sort=row.sort;
this.sortDialogData.id=row.id;
},
handleUpdateSort(){
this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateHomeSubjectSort(this.sortDialogData).then(response=>{
this.sortDialogVisible=false;
this.getList();
this.$message({
type: 'success',
message: '删除成功!'
});
});
})
},
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({
type: 'success',
message: '已取消操作!'
});
this.getList();
});
},
deleteSubject(ids){
this.$confirm('是否要删除该推荐?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
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>
<style></style>
#abc
<script>
// '@/api/homeSubject' API homeSubject
// fetchList
// updateRecommendStatus
// deleteHomeSubject ID
// createHomeSubject
// updateHomeSubjectSort ID
import {fetchList, updateRecommendStatus, deleteHomeSubject, createHomeSubject, updateHomeSubjectSort} from '@/api/homeSubject';
// '@/api/subject' fetchList fetchSubjectList使
import {fetchList as fetchSubjectList} from '@/api/subject';
// '@/utils/date' formatDate 使 'yyyy-MM-dd hh:mm:ss'
import {formatDate} from '@/utils/date';
// defaultListQuery
// pageNum 1便使
// pageSize 5 5
// subjectName null
// recommendStatus null
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
subjectName: null,
recommendStatus: null
};
// defaultRecommendOptions
// label value
// "" value 0 "" value 1便
const defaultRecommendOptions = [
{
label: '未推荐',
value: 0
},
{
label: '推荐中',
value: 1
}
];
export default
name: 'homeSubjectList',
data() {
return {
// listQuery Object.assign defaultListQuery fetchList
listQuery: Object.assign({}, defaultListQuery),
// recommendOptions defaultRecommendOptions 便使
recommendOptions: Object.assign({}, defaultRecommendOptions),
// list null getList 便
list: null,
// total null便
total: null,
// listLoading false getList true false
listLoading: false,
// multipleSelection 便
multipleSelection: [],
// operates label value 012
operates: [
{
label: "设为推荐",
value: 0
},
{
label: "取消推荐",
value: 1
},
{
label: "删除",
value: 2
}
],
// operateType null value 便handleBatchOperate
operateType: null,
// selectDialogVisible false true使便
selectDialogVisible: false,
// dialogData list nulltotal nullmultipleSelection listQuery keywordpageNumpageSize
dialogData: {
list: null,
total: null,
multipleSelection: [],
listQuery: {
keyword: null,
pageNum: 1,
pageSize: 5
}
},
// sortDialogVisible false true使便
sortDialogVisible: false,
// sortDialogData sort 0 id ID null updateHomeSubjectSort
sortDialogData: {sort: 0, id: null}
}
},
created() {
// getList
this.getList();
},
filters: {
// formatRecommendStatus 使
// status 1 status 1 0
formatRecommendStatus(status) {
if (status === 1) {
return '推荐中';
} else {
return '未推荐';
}
},
// formatTime
// time null 'N/A'
// time new Date(time) formatDate 'yyyy-MM-dd hh:mm:ss' 使使
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 listQuery defaultListQuery 便使
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
// handleSearchList
// listQuery pageNum 1 getList 便
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
// handleSelectionChange val multipleSelection 使 multipleSelection 便
handleSelectionChange(val) {
this.multipleSelection = val;
},
// handleSizeChange val
// listQuery pageNum 1 listQuery pageSize val getList
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
// handleCurrentChange val
// listQuery pageNum val getList
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
// handleRecommendStatusStatusChange index row updateRecommendStatusStatus IDrow.idrow.recommendStatus使
handleRecommendStatusStatusChange(index, row) {
this.updateRecommendStatusStatus(row.id, row.recommendStatus);
},
// handleDelete index row deleteSubject IDrow.id
handleDelete(index, row) {
this.deleteSubject(row.id);
},
// handleBatchOperate
// multipleSelection 1 warning 1000 1
// multipleSelection multipleSelection id ids
// operateType
// operateType 0 updateRecommendStatusStatus ids ID 1
// operateType 1 updateRecommendStatusStatus ids 0
// operateType 2 deleteSubject ids
// operateType 012 warning 1000
Loading…
Cancel
Save