广告编辑功能完善

This commit is contained in:
zhh 2018-11-13 17:09:47 +08:00
parent 784e2ad4a5
commit 4ecd009ffd
9 changed files with 587 additions and 4 deletions

43
src/api/homeAdvertise.js Normal file
View File

@ -0,0 +1,43 @@
import request from '@/utils/request'
export function fetchList(params) {
return request({
url:'/home/advertise/list',
method:'get',
params:params
})
}
export function updateStatus(id,params) {
return request({
url:'/home/advertise/update/status/'+id,
method:'post',
params:params
})
}
export function deleteHomeAdvertise(data) {
return request({
url:'/home/advertise/delete',
method:'post',
data:data
})
}
export function createHomeAdvertise(data) {
return request({
url:'/home/advertise/create',
method:'post',
data:data
})
}
export function getHomeAdvertise(id) {
return request({
url:'/home/advertise/'+id,
method:'get',
})
}
export function updateHomeAdvertise(id,data) {
return request({
url:'/home/advertise/update/'+id,
method:'post',
data:data
})
}

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1542099977341" class="icon" style="" viewBox="0 0 1040 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1384" xmlns:xlink="http://www.w3.org/1999/xlink" width="54.84375" height="54"><defs><style type="text/css"></style></defs><path d="M984.104361 326.757019C933.414889 208.820979 838.555427 114.26851 720.236672 63.756069c31.996738-25.119097 72.263837-40.220027 116.151393-40.220027 103.862509 0 188.064236 83.923388 188.064236 187.452299C1024.453325 254.725472 1009.297137 294.866704 984.104361 326.757019zM976.434681 534.080901c0 122.913401-48.40443 234.320747-126.857223 317.182966l64.928778 64.711837c8.587586 8.563026 13.906731 20.391423 13.906731 33.464159 0 26.137287-21.258163 47.327912-47.487547 47.327912-13.106506 0-24.977881-5.300726-33.564443-13.863752l-69.749574-69.51319c-75.249845 52.398394-166.623925 83.376942-265.383206 83.376942-98.56997 0-189.785437-30.846542-264.950348-83.051531l-69.257364 69.029166c-8.696056 8.67252-20.700461 14.022365-33.957393 14.022365-26.520003 0-48.02069-21.431102-48.02069-47.868217 0-13.214976 5.376451-25.178449 14.06432-33.841759l64.402799-64.184835c-78.218456-82.829474-126.489856-194.070021-126.489856-316.792063 0-255.531837 207.833489-462.687898 464.207507-462.687898C768.608356 71.393004 976.434681 278.549064 976.434681 534.080901zM512.228197 167.119205c-203.332988 0-368.164081 164.305113-368.164081 366.961696 0 202.663746 164.832116 366.961696 368.164081 366.961696 203.323778 0 368.163057-164.298973 368.163057-366.961696C880.391255 331.423295 715.551976 167.119205 512.228197 167.119205zM704.314027 581.944002 512.228197 581.944002c-26.520003 0-48.021713-21.425985-48.021713-47.862078L464.206484 278.808984c0-26.435069 21.502733-47.863101 48.021713-47.863101 26.50977 0 48.019667 21.428032 48.019667 47.863101l0 207.40984L704.314027 486.218824c26.510794 0 48.02069 21.424962 48.02069 47.862078C752.334717 560.518017 730.824821 581.944002 704.314027 581.944002zM41.209564 333.240687c-25.736151-32.570813-41.210587-73.572646-41.210587-118.251218C0 109.25124 85.995583 23.536043 192.084807 23.536043c44.819788 0 85.962837 15.425318 118.635981 41.078581C189.876512 116.213815 92.974531 212.787314 41.209564 333.240687z" p-id="1385"></path></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -201,6 +201,12 @@ export const constantRouterMap = [
name: 'sms',
meta: {title: '营销', icon: 'sms'},
children: [
{
path: 'flash',
name: 'flash',
component: () => import('@/views/sms/flash/index'),
meta: {title: '秒杀活动列表', icon: 'sms-flash'}
},
{
path: 'coupon',
name: 'coupon',
@ -257,6 +263,20 @@ export const constantRouterMap = [
name: 'homeAdvertise',
component: () => import('@/views/sms/advertise/index'),
meta: {title: '广告列表', icon: 'sms-ad'}
},
{
path: 'addAdvertise',
name: 'addHomeAdvertise',
component: () => import('@/views/sms/advertise/add'),
meta: {title: '添加广告'},
hidden:true
},
{
path: 'updateAdvertise',
name: 'updateHomeAdvertise',
component: () => import('@/views/sms/advertise/update'),
meta: {title: '编辑广告'},
hidden:true
}
]
},

View File

@ -454,7 +454,7 @@
}
}
</script>
<style scroped>
<style scoped>
.input-width {
width: 203px;
}

View File

@ -0,0 +1,13 @@
<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>

View File

@ -0,0 +1,185 @@
<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>

View File

@ -1,13 +1,307 @@
<template> 
<div> {{msg}}</div>
<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 {msg: '首页广告列表'}
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></style>
<style scoped>
.input-width {
width: 203px;
}
</style>

View File

@ -0,0 +1,13 @@
<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>

View File

@ -0,0 +1,14 @@
<template> 
<div> {{msg}}</div>
</template>
<script>
export default {
name:'flashPromotionList',
data() {
return {msg: '秒杀活动列表'}
}
}
</script>
<style></style>