ADD file via upload

main
pjhmizn49 1 year ago
parent 35f02b2e7d
commit 48031c4675

@ -0,0 +1,545 @@
<template>
<div>
<div class="tableTop">
<div>
<el-input @input="handleSearch" suffix-icon="el-icon-search" style="width: 300px" placeholder="请输入搜索关键字" v-model="input" clearable></el-input>
</div>
<div>
<el-button @click="handleAdd" type="primary">添加套餐</el-button>
<el-button @click="handleDeleteMul" type="danger">批量删除</el-button>
</div>
<!-- 表单 -->
<el-dialog title="套餐信息" :visible.sync="dialogVisible" :before-close="handleClose">
<el-form align="left" ref="dialogForm" :rules="rules" :model="dialogForm" label-width="130px" style="margin-right: 150px">
<el-form-item label="优惠套餐名" prop="discount_name">
<el-input v-model="dialogForm.discount_name" placeholder="请输入优惠套餐名"></el-input>
</el-form-item>
<el-form-item label="优惠折扣(%)" prop="discount_num">
<el-input-number v-model="dialogForm.discount_num" :step="5" :min="10"></el-input-number>
</el-form-item>
<el-form-item label="优惠商品" required>
<el-cascader
v-model="cascadeBackResult"
placeholder="试试搜索:玫瑰"
:options="options"
@change="handleCascade"
filterable>
</el-cascader>
</el-form-item>
<el-form-item label="套餐起止日期" required>
<el-date-picker
v-model="dialogForm.dateRange"
type="daterange"
value-format="yyyy-MM-dd"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose"> </el-button>
<el-button type="primary" @click="submitForm"> </el-button>
</div>
</el-dialog>
</div>
<el-table
ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="60"></el-table-column>
<el-table-column prop="discount_id" label="id" width="100"></el-table-column>
<el-table-column prop="discount_name" label="优惠套餐名" width="300"></el-table-column>
<el-table-column prop="discount_num" label="优惠折扣(%)" width="120"></el-table-column>
<el-table-column label="优惠商品" width="180"
:filters="[{ text: '全部商品', value: 0 },{text: '按商品', value: -1 },{text: '按种类', value: -2 }]"
:filter-method="filterClass">
<template slot-scope="scope">
<el-tag
class="tag"
:type="scope.row.discount_f_id===0 && scope.row.discount_c_id===0 ? 'success' : 'primary'"
disable-transitions
style="height: auto;white-space: normal;">
<span v-show="scope.row.discount_f_id===0 && scope.row.discount_c_id===0"></span>
<span v-show="scope.row.discount_f_id!==0">{{ scope.row.discount_f_id }}</span>
<span v-show="scope.row.discount_c_id!==0">{{ scope.row.discount_c_id }}</span>
</el-tag>
</template>
</el-table-column>
<el-table-column prop="discount_start_time" sortable label="优惠开始时间" width="160"></el-table-column>
<el-table-column prop="discount_end_time" sortable label="优惠结束时间" width="160"></el-table-column>
<el-table-column label="操作" >
<template slot-scope="scope">
<el-button @click="handleModify(scope.row)" type="primary" size="small" plain>修改</el-button>
<el-button @click="handleDelete(scope.row)" type="danger" size="small" plain>删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
background
:current-page="currentPage"
:page-size="pageSize"
layout="total, prev, pager, next, jumper"
:total="total"
:page-count="page_number"
style="margin-top: 30px"
@current-change="handleCurrentChange">
</el-pagination>
</div>
</template>
<script>
import Cookie from "js-cookie";
export default {
data() {
return {
//
tableData: [{
discount_id: 1,
discount_name: '',
discount_num: 1,
discount_f_id: '',
discount_c_id:'',
discount_start_time:'',
discount_end_time:''
}],
dialogForm:[{
discount_id: 1,
discount_name: '',
discount_num: 1,
discount_f_id: '',
discount_c_id:'',
// discount_start_time:'',
// discount_end_time:''
dateRange:['']//
}],
//
options:[],
//
cascadeBackResult:[],
//
rules:{
discount_name:[
{ required:true, trigger:'blur', message:'请输入套餐名'}
],
discount_num:[
{ required:true, trigger:'blur', message:'请输入折扣'}
],
dateRange:[
{ required:true, trigger:'blur', message:'请选择日期'}
]
},
//
multipleSelection: [],
input: '',//
dialogVisible:false,//
modelType:0, //01
//
currentPage:1,
pageSize:10,
page_number:1,//
total:10,//
}
},
created() {
this.currentPage=1;
this.fetchData();
},
methods: {
fetchData(){
//
const _this=this;
try {
axios({
method: 'post',
url: 'http://localhost:8181/discount/list',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
page:_this.currentPage,
page_size:_this.pageSize
}
}).then(function (response){
if (response.data.code===200){
//
_this.tableData=response.data.data.discounts;
_this.page_number=response.data.data.page_number;
_this.total=response.data.data.total;
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}catch (error){
this.$message.warning('页面加载出错,请重试!')
}
},
//
handleSearch(){
const _this = this
try {
axios({
method: 'post',
url: 'http://localhost:8181/discount/query',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
page:_this.currentPage,
page_size:_this.pageSize,
discount_name:_this.input
}
}).then(function (response){
if (response.data.code===200){
//
_this.tableData=response.data.data.discounts;
_this.page_number=response.data.data.page_number;
_this.total=response.data.data.total;
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}catch (error){
this.$message.warning('页面加载出错,请重试!')
}
},
//
handleCurrentChange(page) {
this.currentPage = page;
this.fetchData();
},
//
handleSelectionChange(val) {
this.multipleSelection = val;
},
//
filterClass(value, row) {
if(value===0) //
return row.discount_c_id===0 && row.discount_f_id===0;
if(value===-1) //
return row.discount_c_id===0 && row.discount_f_id!==0;
if(value===-2) //
return row.discount_c_id!==0 && row.discount_f_id===0;
},
//
//
getCascade(){
const _this=this;
axios({
method: 'post',
url: 'http://localhost:8181/discount/cascade',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
}
}).then(function (response){
if (response.data.code===200){
//
_this.options=response.data.cascade;
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
},
//
handleCascade(value){
if(value[0]===0){ //
this.dialogForm.discount_f_id=0;
this.dialogForm.discount_c_id=0;
}
else if(value[0]===-1){ //
this.dialogForm.discount_f_id=value[1];
this.dialogForm.discount_c_id=0;
}
else if(value[0]===-2){ //
this.dialogForm.discount_f_id=0;
this.dialogForm.discount_c_id=value[1];
}
},
//
cascadeBack(value1,value2){
if(value1===0) //
this.cascadeBackResult=[0]
else if (value1===-1 || value1===-2)
this.cascadeBackResult=[value1,value2]
},
//
handleAdd(){
this.modelType = 0
this.dialogVisible = true
this.getCascade()
},
//
handleModify(row){
const _this = this
this.modelType = 1
this.getCascade()
axios({
method: 'post',
url: 'http://localhost:8181/discount/info',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
discount_id: row.discount_id
}
}).then(function (response){
if (response.data.code===200) {
//
_this.dialogForm = response.data.data
//
if(response.data.data.discount_f_id===0 && response.data.data.discount_c_id===0)
_this.cascadeBack(0,0)
else if(response.data.data.discount_f_id!==0)
_this.cascadeBack(-1,response.data.data.discount_f_id) //
else if(response.data.data.discount_c_id!==0)
_this.cascadeBack(-2,response.data.data.discount_c_id) //
//elementUIDatePickerVue$set
_this.$set(_this.dialogForm,'dateRange',[response.data.data.discount_start_time,response.data.data.discount_end_time])
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
_this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
this.dialogVisible = true
},
//
submitForm(){ //
const _this=this;
this.$refs.dialogForm.validate((valid) =>{
if(valid){
//
if(_this.dialogForm.discount_f_id===undefined || _this.dialogForm.discount_f_id===''){
_this.$message.warning('请选择优惠商品')
return
}
if(_this.dialogForm.dateRange===undefined || _this.dialogForm.dateRange.length===0){
_this.$message.warning('请选择日期')
return
}
if(_this.modelType===0){
//
axios({
method: 'post',
url: 'http://localhost:8181/discount/add',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
discount_name:_this.dialogForm.discount_name,
discount_num:_this.dialogForm.discount_num,
discount_f_id:_this.dialogForm.discount_f_id,
discount_c_id:_this.dialogForm.discount_c_id,
discount_start_time:_this.dialogForm.dateRange[0],
discount_end_time:_this.dialogForm.dateRange[1]
}
}).then(function (response){
if (response.data.code===200) {
//
_this.$message.success('添加成功!')
//
_this.fetchData()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}
else if(_this.modelType===1){
//
axios({
method: 'post',
url: 'http://localhost:8181/discount/modify',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
discount_id:_this.dialogForm.discount_id,
discount_name:_this.dialogForm.discount_name,
discount_num:_this.dialogForm.discount_num,
discount_f_id:_this.dialogForm.discount_f_id,
discount_c_id:_this.dialogForm.discount_c_id,
discount_start_time:_this.dialogForm.dateRange[0],
discount_end_time:_this.dialogForm.dateRange[1]
}
}).then(function (response){
if (response.data.code===200) {
//
_this.$message.success('修改成功!')
//
_this.handleSearch()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}
//
this.handleClose();
}
})
},
//
handleDelete(row){
const _this = this;
this.$confirm('此操作将永久删除该套餐, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//
axios({
method: 'post',
url: 'http://localhost:8181/discount/deletePer',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
discount_id:row.discount_id
}
}).then(function (response){
if (response.data.code===200) {
//
_this.handleSearch()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
this.$message({type: 'success', message: '删除成功!'});
}).catch(() => {
this.$message({type: 'info', message: '已取消删除'});
});
},
handleDeleteMul(){
const _this = this
if(_this.multipleSelection.length===0)
this.$message({type: 'warning', message: '请选择套餐'});
else{
let ids = []
for (let i=0; i<_this.multipleSelection.length; i++){
ids[i] = _this.multipleSelection[i].discount_id
}
this.$confirm('此操作将永久删除套餐信息, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//
axios({
method: 'post',
url: 'http://localhost:8181/discount/deleteMul',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
discount_ids:ids
}
}).then(function (response){
if (response.data.code===200) {
//
_this.handleSearch()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
this.$message({type: 'success', message: '批量删除成功!'});
}).catch(() => {
this.$message({type: 'info', message: '已取消删除'});
});
}
},
//dialog
handleClose(){
this.$refs.dialogForm.resetFields()
//
this.dialogForm.discount_id = 1;
this.dialogForm.discount_name='';
this.dialogForm.discount_num=1;
this.dialogForm.discount_f_id='';
this.dialogForm.discount_c_id='';
this.cascadeBackResult=[];
this.dialogForm.discount_start_time='';
this.dialogForm.discount_end_time='';
this.dialogForm.dateRange=[];
this.dialogVisible = false;
}
}
}
</script>
<style>
.tableTop{
width: 1200px;
display: flex;
justify-content: space-between;
align-items: center;
margin: 10px 0 20px 50px;
}
</style>
Loading…
Cancel
Save