lanan-system-vue/src/views/member/active/ChooseCouponDraw.vue

259 lines
8.0 KiB
Vue
Raw Normal View History

2024-09-19 22:54:02 +08:00
<template>
<!-- 对话框(添加 / 修改) -->
<el-drawer
title="选择卡券"
size="60%"
:visible.sync="drawVisible"
@close="cancelForm"
>
<div style="padding: 0 10px;margin-bottom: 70px">
<!-- 搜索工作栏 -->
<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.name" placeholder="请输入卡券名称" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="卡券类型" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择卡券类型" @keyup.enter.native="handleQuery">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.MEMBER_COUPON_TYPE)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<el-form-item label="核销规则" prop="outRule">
<el-select v-model="queryParams.type" placeholder="请选择核销规则" @keyup.enter.native="handleQuery">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.MEMBER_COUPON_OUT_RULE)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 操作工具栏 -->
<el-row>
<el-col :span="3">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
v-hasPermi="['member:coupon:create']">新增
</el-button>
</el-col>
</el-row>
<el-table
ref="multipleTable"
height="460"
v-loading="formLoading"
:data="list"
:stripe="true"
@select="selectRow"
@select-all="handleSelectAll"
:show-overflow-tooltip="true">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column label="卡券名称" width="250" align="left" prop="name"/>
<el-table-column label="卡券类型" width="80" align="left" prop="type">
<template v-slot="scope">
<dict-tag :type="DICT_TYPE.MEMBER_COUPON_TYPE" :value="scope.row.type"/>
</template>
</el-table-column>
<el-table-column label="适用车型" width="130" align="center" prop="carModel">
<template v-slot="scope">
<dict-tag :type="DICT_TYPE.MEMBER_CAR" :value="scope.row.carModel"/>
</template>
</el-table-column>
<el-table-column label="开始有效期" align="center" prop="beginTime" width="150">
<template v-slot="scope">
<span>{{ parseTime(scope.row.beginTime) }}</span>
</template>
</el-table-column>
<el-table-column label="结束有效期" align="center" prop="endTime" width="150">
<template v-slot="scope">
<span>{{ parseTime(scope.row.endTime) }}</span>
</template>
</el-table-column>
<el-table-column label="面额" width="100" align="right" prop="amount"/>
<el-table-column label="备注" show-overflow-tooltip align="left" prop="remark"/>
</el-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
</div>
<div
style="position: absolute;bottom: 0;width: 100%;right: 0;padding: 5px 20px 0;z-index: 999;background: white;text-align: right">
<div class="demo-drawer__footer">
<el-button @click="cancelForm"> </el-button>
<el-button type="primary" @click="submitForm"> </el-button>
</div>
</div>
<!-- 对话框(添加 / 修改) -->
<CouponForm ref="formRef" @success="getList"/>
</el-drawer>
<!-- 对话框(添加 / 修改) -->
</template>
<script>
import * as CouponApi from '@/api/member/coupon';
import CouponForm from '@/views/member/coupon/CouponForm.vue';
export default {
name: "ChooseCouponDraw",
components: {CouponForm},
data() {
return {
// 弹出层标题
// 是否显示弹出层
drawVisible: false,
// 表单的加载中1修改时的数据加载2提交的按钮禁用
formLoading: false,
// 导出遮罩层
exportLoading: false,
// 显示搜索条件
showSearch: true,
//回参
formData: {},
// 总条数
total: 0,
// 卡券列表
list: [],
multipleSelection: [],
// 查询参数
queryParams: {
pageNo: 1,
pageSize: 10,
name: null,
type: null,
carModel: null,
outRule: null,
},
};
},
methods: {
/** 打开弹窗 */
async open(multipleSelection) {
this.drawVisible = true;
this.formLoading = true;
this.reset();
try {
const res = await CouponApi.getCouponPage(this.queryParams);
this.list = res.data.records;
this.total = res.data.total;
this.multipleSelection = JSON.parse(JSON.stringify(multipleSelection))
this.defaultChecked(multipleSelection)
} finally {
this.formLoading = false;
}
},
/**选中*/
selectRow(val, row) {
//当前点击是否勾选
let selectBool = val.length && val.indexOf(row) !== -1
if (!selectBool) {
//取消勾选
this.multipleSelection.forEach((item, i) => {
if (item.id == row.id) {
this.multipleSelection.splice(i, 1)
}
})
} else {
//选中
this.multipleSelection.push(row)
}
},
/**全选*/
handleSelectAll(val) {
if (val.length == this.list.length) { //全选
this.multipleSelection = this.multipleSelection.concat(val)
//去重
let obj = {}
let result = []
this.multipleSelection.forEach(item => {
if (!obj[item.id]) {
result.push(item)
obj[item.id] = true
}
})
this.multipleSelection = result
} else { //取消全选
this.list.forEach(item => {
this.multipleSelection.forEach((multItem, i) => {
if (item.id == multItem.id) {
this.multipleSelection.splice(i, 1)
}
})
})
}
},
/**设置默认选中*/
defaultChecked(multipleSelection) {
const that = this;
this.$nextTick(() => {
that.list.forEach((v, i) => {
multipleSelection.map(item => {
if (item.id === v.id) {
that.$refs.multipleTable.toggleRowSelection(v, true);
}
})
});
});
},
cancelForm() {
this.drawVisible = false
},
/** 添加/修改操作 */
openForm(id) {
this.$refs["formRef"].open(id);
},
/** 查询列表 */
async getList() {
try {
this.formLoading = true
const res = await CouponApi.getCouponPage(this.queryParams);
this.list = res.data.records;
this.total = res.data.total;
this.defaultChecked(this.multipleSelection)
} finally {
this.formLoading = false
}
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNo = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/**重置参数*/
reset() {
this.queryParams = {
pageNo: 1,
pageSize: 10,
name: null,
type: null,
carModel: null,
outRule: null,
}
},
/** 提交按钮 */
submitForm() {
this.drawVisible = false
this.$emit('success', this.multipleSelection)
},
}
};
</script>