Files
henan-backend/ruoyi-ui/src/views/skins/ttWelfare/monthlyRecharges.vue
T

344 lines
10 KiB
Vue

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="福利名称" prop="name">
<el-input
v-model="queryParams.welfareName"
placeholder="请输入福利名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['admin:recharges:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['admin:recharges:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['admin:recharges:remove']"
>删除</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="rechargesList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="ID" align="center" prop="welfareId" />
<el-table-column label="福利名称" align="center" prop="welfareName" />
<el-table-column label="VIP等级" align="center" prop="vipLevel" />
<!--<el-table-column label="福利类型" align="center" prop="type" />-->
<el-table-column label="充值金额" align="center" prop="amount" />
<el-table-column label="宝箱ID" align="center" prop="boxId" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['admin:recharges:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['admin:recharges:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改每月充值福利对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="福利名称" prop="welfareName">
<el-input v-model="form.welfareName" placeholder="请输入福利名称" />
</el-form-item>
<el-form-item label="VIP等级" prop="vipLevel">
<el-input-number v-model="form.vipLevel" controls-position="right" :min="1" />
</el-form-item>
<el-form-item label="充值金额" prop="amount">
<el-input-number v-model="form.amount" controls-position="right" :min="0.01" :step="100" />
</el-form-item>
<el-form-item label="宝箱ID" prop="boxId">
<el-popover placement="bottom-start" width="460" trigger="hover" ref="morePop">
<el-input
slot="reference"
v-model="form.boxId"
placeholder="请选择箱子"
suffix-icon="el-icon-caret-bottom"
readonly
clearable
></el-input>
<el-form>
<el-row>
<el-form v-if="boxList">
<div class="magicbox" @scroll="scrollEventFn" v-if="boxList.length > 0">
<div class="magic"
v-for="(item, index) in boxList"
:key="index"
@click="selectBox(item)">
<div>{{item.boxName}}</div>
<div>{{item.boxId}}</div>
</div>
</div>
<div v-else>
<div style="margin: 0 auto; text-align: center">暂无箱子数据</div>
</div>
</el-form>
</el-row>
</el-form>
</el-popover>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listRecharges, getRecharges, delRecharges, addRecharges, updateRecharges } from "@/api/skins/ttWelfare/monthlyRecharges";
import { listBox } from "@/api/skins/ttBox/api";
export default {
name: "MonthlyRecharges",
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 箱子列表总条数
boxListTotal: 0,
// 每月充值福利表格数据
rechargesList: [],
// 宝箱列表数据
boxList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
welfareName: null,
boxId: null
},
// 箱子列表查询参数
boxListQueryParams: {
pageNum: 1,
pageSize: 10
},
// 表单参数
form: {},
// 表单校验
rules: {
welfareName: [
{ required: true, message: "福利名称不能为空", trigger: "blur" }
],
vipLevel: [
{ required: true, message: "VIP等级不能为空", trigger: "blur" }
],
amount: [
{ required: true, message: "充值金额不能为空", trigger: "blur" }
],
boxId: [
{ required: true, message: "宝箱不能为空", trigger: "blur" }
]
}
};
},
created() {
this.getList();
},
methods: {
/** 查询每月充值福利列表 */
getList() {
this.loading = true;
listRecharges(this.queryParams).then(response => {
this.rechargesList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 查询箱子列表 */
getBoxList() {
this.boxListQueryParams.pageNum = 1;
listBox(this.boxListQueryParams).then(response => {
this.boxList = response.rows;
this.boxListTotal = response.total;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: null,
welfareName: null,
boxId: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.welfareId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加每月充值福利";
this.getBoxList();
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.welfareId || this.ids
getRecharges(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改每月充值福利";
});
this.getBoxList();
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.welfareId != null) {
updateRecharges(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addRecharges(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.welfareId || this.ids;
this.$modal.confirm('是否确认删除每月充值福利编号为"' + ids + '"的数据项?').then(function() {
return delRecharges(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
scrollEventFn(e) {
// 判断滚动条是否到达底部
let b = e.srcElement.scrollTop + e.srcElement.clientHeight >= e.srcElement.scrollHeight;
if (b) {
// 计算总页数
let totalPage = this.boxListTotal / this.boxListQueryParams.pageSize;
this.boxListQueryParams.pageNum += 1;
if (this.boxListQueryParams.pageNum <= totalPage) {
listBox(this.boxListQueryParams).then(response => {
this.boxList.push.apply(this.boxList, response.rows);
});
} else {
this.$modal.msgWarning("没有更多箱子了");
}
}
},
selectBox(boxData) {
this.form.boxId = boxData.boxId;
this.$refs.morePop.doClose();
}
}
};
</script>
<style lang="scss" scoped>
.magicbox {
margin: 0 auto;
margin-top: 5px;
height: 300px;
overflow-y: scroll;
.magic {
height: 32px;
padding: 2px 5px;
line-height: 32px;
display: flex;
align-items: center;
justify-content: space-between;
&:hover {
background-color: #9a5c35;
transition: all ease 0.3s;
}
}
}
</style>