branch_lyj
Liuyujie 7 months ago
parent 7d848d789f
commit d4508b8dae

@ -1,9 +1,14 @@
<template>  <template>
<!-- 整个应用的容器 -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索的卡片容器设置了阴影效果为无 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 显示筛选搜索文字 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 查询搜索按钮设置了样式为右浮动类型为主要按钮点击时触发handleSearchList方法按钮大小为小 -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 重置按钮设置了样式为右浮动右外边距为15px点击时触发handleResetSearch方法按钮大小为小 -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,12 +25,18 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 内联表单绑定了listQuery数据模型表单大小为小标签宽度为140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单项目标签为商品名称 -->
<el-form-item label="商品名称:"> <el-form-item label="商品名称:">
<!-- 输入框双向绑定listQuery.productName数据设置了类名和占位提示文字 -->
<el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input> <el-input v-model="listQuery.productName" class="input-width" placeholder="商品名称"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为推荐状态 -->
<el-form-item label="推荐状态:"> <el-form-item label="推荐状态:">
<!-- 下拉选择框双向绑定listQuery.recommendStatus数据设置了占位提示文字和可清除添加了类名 -->
<el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
<!-- 循环生成下拉选项根据recommendOptions数据中的每个item来生成对应的选项 -->
<el-option v-for="item in recommendOptions" <el-option v-for="item in recommendOptions"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
@ -35,24 +47,34 @@
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作相关的卡片容器设置了阴影效果为无 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- 图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<span>数据列表</span> <!-- 显示数据列表文字 -->
<i>数据列表</i>
<!-- 选择商品按钮设置了按钮大小为迷你点击时触发handleSelectProduct方法 -->
<el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button> <el-button size="mini" class="btn-add" @click="handleSelectProduct()"></el-button>
</el-card> </el-card>
<!-- 表格容器 -->
<div class="table-container"> <div class="table-container">
<!-- el-table组件绑定了list数据作为表格数据源设置了宽度为100%选择变化时触发handleSelectionChange方法加载状态绑定listLoading显示边框 -->
<el-table ref="newProductTable" <el-table ref="newProductTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 表格列类型为选择列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 表格列标签为编号宽度为120px内容居中对齐通过插槽作用域显示对应行的id数据 -->
<el-table-column label="编号" width="120" align="center"> <el-table-column label="编号" width="120" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为商品名称内容居中对齐通过插槽作用域显示对应行的productName数据 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.productName}}</template> <template slot-scope="scope">{{scope.row.productName}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为是否推荐宽度为200px内容居中对齐包含一个开关组件开关状态改变时触发handleRecommendStatusStatusChange方法设置了开关的激活值未激活值以及双向绑定对应行的recommendStatus数据 -->
<el-table-column label="是否推荐" width="200" align="center"> <el-table-column label="是否推荐" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@ -63,12 +85,15 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 表格列标签为排序宽度为160px内容居中对齐通过插槽作用域显示对应行的sort数据 -->
<el-table-column label="排序" width="160" align="center"> <el-table-column label="排序" width="160" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为状态宽度为160px内容居中对齐通过管道formatRecommendStatus对对应行的recommendStatus数据进行格式化后显示 -->
<el-table-column label="状态" width="160" align="center"> <el-table-column label="状态" width="160" align="center">
<template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template> <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为操作宽度为180px内容居中对齐包含两个按钮分别点击时触发handleEditSort和handleDelete方法 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -83,10 +108,13 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 批量操作的容器 -->
<div class="batch-operate-container"> <div class="batch-operate-container">
<!-- 下拉选择框设置了大小为小双向绑定operateType数据设置了占位提示文字 -->
<el-select <el-select
size="small" size="small"
v-model="operateType" placeholder="批量操作"> v-model="operateType" placeholder="批量操作">
<!-- 循环生成下拉选项根据operates数据中的每个item来生成对应的选项 -->
<el-option <el-option
v-for="item in operates" v-for="item in operates"
:key="item.value" :key="item.value"
@ -94,6 +122,7 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<!-- 确定按钮设置了左外边距为20px样式类点击时触发handleBatchOperate方法类型为主要按钮大小为小 -->
<el-button <el-button
style="margin-left: 20px" style="margin-left: 20px"
class="search-button" class="search-button"
@ -103,7 +132,9 @@
确定 确定
</el-button> </el-button>
</div> </div>
<!-- 分页容器 -->
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置了背景色页面尺寸改变时触发handleSizeChange方法当前页改变时触发handleCurrentChange方法布局样式绑定了当前页每页显示数量可选的每页显示数量列表以及总记录数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -115,27 +146,35 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 选择商品的对话框绑定了显示状态设置了标题和宽度 -->
<el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%"> <el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
<!-- 输入框双向绑定dialogData.listQuery.keyword数据设置了宽度下外边距大小和占位提示文字包含一个搜索按钮点击时触发handleSelectSearch方法 -->
<el-input v-model="dialogData.listQuery.keyword" <el-input v-model="dialogData.listQuery.keyword"
style="width: 250px;margin-bottom: 20px" style="width: 250px;margin-bottom: 20px"
size="small" size="small"
placeholder="商品名称搜索"> placeholder="商品名称搜索">
<el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button> <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
</el-input> </el-input>
<!-- 表格绑定了dialogData.list数据作为数据源选择变化时触发handleDialogSelectionChange方法显示边框 -->
<el-table :data="dialogData.list" <el-table :data="dialogData.list"
@selection-change="handleDialogSelectionChange" border> @selection-change="handleDialogSelectionChange" border>
<!-- 表格列类型为选择列宽度为60px内容居中对齐 -->
<el-table-column type="selection" width="60" align="center"></el-table-column> <el-table-column type="selection" width="60" align="center"></el-table-column>
<!-- 表格列标签为商品名称内容居中对齐通过插槽作用域显示对应行的name数据 -->
<el-table-column label="商品名称" align="center"> <el-table-column label="商品名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为货号宽度为160px内容居中对齐通过插槽作用域显示对应行的productSn数据格式化为NO. + 货号 -->
<el-table-column label="货号" width="160" align="center"> <el-table-column label="货号" width="160" align="center">
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> <template slot-scope="scope">NO.{{scope.row.productSn}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为价格宽度为120px内容居中对齐通过插槽作用域显示对应行的price数据格式化为 + 价格 -->
<el-table-column label="价格" width="120" align="center"> <el-table-column label="价格" width="120" align="center">
<template slot-scope="scope">{{scope.row.price}}</template> <template slot-scope="scope">{{scope.row.price}}</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination分页组件设置了背景色页面尺寸改变时触发handleDialogSizeChange方法当前页改变时触发handleDialogCurrentChange方法布局样式绑定了当前页每页显示数量可选的每页显示数量列表以及总记录数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleDialogSizeChange" @size-change="handleDialogSizeChange"
@ -149,36 +188,48 @@
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div slot="footer"> <div slot="footer">
<!-- 取消按钮设置了大小为小点击时隐藏对话框 -->
<el-button size="small" @click="selectDialogVisible = false"> </el-button> <el-button size="small" @click="selectDialogVisible = false"> </el-button>
<!-- 确定按钮设置了大小为小类型为主要按钮点击时触发handleSelectDialogConfirm方法 -->
<el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button> <el-button size="small" type="primary" @click="handleSelectDialogConfirm()"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<!-- 设置排序的对话框绑定了显示状态设置了标题和宽度 -->
<el-dialog title="设置排序" <el-dialog title="设置排序"
:visible.sync="sortDialogVisible" :visible.sync="sortDialogVisible"
width="40%"> width="40%">
<!-- 表单绑定了sortDialogData数据模型设置了标签宽度 -->
<el-form :model="sortDialogData" <el-form :model="sortDialogData"
label-width="150px"> label-width="150px">
<!-- 表单项目标签为排序 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<!-- 输入框双向绑定sortDialogData.sort数据设置了宽度 -->
<el-input v-model="sortDialogData.sort" style="width: 200px"></el-input> <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer"> <span slot="footer">
<!-- 取消按钮点击时隐藏对话框设置了大小为小 -->
<el-button @click="sortDialogVisible = false" size="small"> </el-button> <el-button @click="sortDialogVisible = false" size="small"> </el-button>
<!-- 确定按钮点击时触发handleUpdateSort方法设置了大小为小类型为主要按钮 -->
<el-button type="primary" @click="handleUpdateSort" size="small"> </el-button> <el-button type="primary" @click="handleUpdateSort" size="small"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
// '@/api/hotProduct'
import {fetchList, updateRecommendStatus, deleteHotProduct, createHotProduct, updateHotProductSort} from '@/api/hotProduct'; import {fetchList, updateRecommendStatus, deleteHotProduct, createHotProduct, updateHotProductSort} from '@/api/hotProduct';
// '@/api/product'fetchListfetchProductList
import {fetchList as fetchProductList} from '@/api/product'; import {fetchList as fetchProductList} from '@/api/product';
//
const defaultListQuery = { const defaultListQuery = {
pageNum: 1, pageNum: 1,
pageSize: 5, pageSize: 5,
productName: null, productName: null,
recommendStatus: null recommendStatus: null
}; };
//
const defaultRecommendOptions = [ const defaultRecommendOptions = [
{ {
label: '未推荐', label: '未推荐',
@ -189,16 +240,26 @@
value: 1 value: 1
} }
]; ];
// Vue
export default { export default {
//
name: 'hotProductList', name: 'hotProductList',
data() { data() {
return { return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery), listQuery: Object.assign({}, defaultListQuery),
// defaultRecommendOptions
recommendOptions: Object.assign({}, defaultRecommendOptions), recommendOptions: Object.assign({}, defaultRecommendOptions),
// null
list: null, list: null,
// null
total: null, total: null,
// truefalse
listLoading: false, listLoading: false,
//
multipleSelection: [], multipleSelection: [],
//
operates: [ operates: [
{ {
label: "设为推荐", label: "设为推荐",
@ -213,8 +274,11 @@
value: 2 value: 2
} }
], ],
// null
operateType: null, operateType: null,
// falsetrue
selectDialogVisible: false, selectDialogVisible: false,
//
dialogData: { dialogData: {
list: null, list: null,
total: null, total: null,
@ -225,13 +289,17 @@
pageSize: 5 pageSize: 5
} }
}, },
//
sortDialogVisible: false, sortDialogVisible: false,
// id
sortDialogData: {sort: 0, id: null} sortDialogData: {sort: 0, id: null}
} }
}, },
//
created() { created() {
this.getList(); this.getList();
}, },
// 1
filters: { filters: {
formatRecommendStatus(status) { formatRecommendStatus(status) {
if (status === 1) { if (status === 1) {
@ -242,31 +310,39 @@
} }
}, },
methods: { methods: {
//
handleResetSearch() { handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery = Object.assign({}, defaultListQuery);
}, },
// 1
handleSearchList() { handleSearchList() {
this.listQuery.pageNum = 1; this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
//
handleSelectionChange(val) { handleSelectionChange(val) {
this.multipleSelection = val; this.multipleSelection = val;
}, },
// 1
handleSizeChange(val) { handleSizeChange(val) {
this.listQuery.pageNum = 1; this.listQuery.pageNum = 1;
this.listQuery.pageSize = val; this.listQuery.pageSize = val;
this.getList(); this.getList();
}, },
//
handleCurrentChange(val) { handleCurrentChange(val) {
this.listQuery.pageNum = val; this.listQuery.pageNum = val;
this.getList(); this.getList();
}, },
// id
handleRecommendStatusStatusChange(index, row) { handleRecommendStatusStatusChange(index, row) {
this.updateRecommendStatusStatus(row.id, row.recommendStatus); this.updateRecommendStatusStatus(row.id, row.recommendStatus);
}, },
// id
handleDelete(index, row) { handleDelete(index, row) {
this.deleteProduct(row.id); this.deleteProduct(row.id);
}, },
//
handleBatchOperate() { handleBatchOperate() {
if (this.multipleSelection < 1) { if (this.multipleSelection < 1) {
this.$message({ this.$message({
@ -276,7 +352,7 @@
}); });
return; return;
} }
let ids = []; let ids = []; //
for (let i = 0; i < this.multipleSelection.length; i++) { for (let i = 0; i < this.multipleSelection.length; i++) {
ids.push(this.multipleSelection[i].id); ids.push(this.multipleSelection[i].id);
} }
@ -290,32 +366,38 @@
// //
this.deleteProduct(ids); this.deleteProduct(ids);
} else { } else {
this.$message({ this.$message({ //
message: '请选择批量操作类型', message: '请选择批量操作类型',
type: 'warning', type: 'warning',
duration: 1000 duration: 1000
}); });
} }
}, },
//
handleSelectProduct() { handleSelectProduct() {
this.selectDialogVisible = true; this.selectDialogVisible = true;
this.getDialogList(); this.getDialogList();
}, },
//
handleSelectSearch() { handleSelectSearch() {
this.getDialogList(); this.getDialogList();
}, },
// 1
handleDialogSizeChange(val) { handleDialogSizeChange(val) {
this.dialogData.listQuery.pageNum = 1; this.dialogData.listQuery.pageNum = 1;
this.dialogData.listQuery.pageSize = val; this.dialogData.listQuery.pageSize = val;
this.getDialogList(); this.getDialogList();
}, },
//
handleDialogCurrentChange(val) { handleDialogCurrentChange(val) {
this.dialogData.listQuery.pageNum = val; this.dialogData.listQuery.pageNum = val;
this.getDialogList(); this.getDialogList();
}, },
//
handleDialogSelectionChange(val) { handleDialogSelectionChange(val) {
this.dialogData.multipleSelection = val; this.dialogData.multipleSelection = val;
}, },
//
handleSelectDialogConfirm() { handleSelectDialogConfirm() {
if (this.dialogData.multipleSelection < 1) { if (this.dialogData.multipleSelection < 1) {
this.$message({ this.$message({
@ -336,7 +418,7 @@
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => { //
createHotProduct(selectProducts).then(response => { createHotProduct(selectProducts).then(response => {
this.selectDialogVisible = false; this.selectDialogVisible = false;
this.dialogData.multipleSelection = []; this.dialogData.multipleSelection = [];
@ -348,17 +430,19 @@
}); });
}); });
}, },
//
handleEditSort(index, row) { handleEditSort(index, row) {
this.sortDialogVisible = true; this.sortDialogVisible = true;
this.sortDialogData.sort=row.sort; this.sortDialogData.sort = row.sort; //id
this.sortDialogData.id = row.id; this.sortDialogData.id = row.id;
}, },
handleUpdateSort(){ //
handleUpdateSort() { //
this.$confirm('是否要修改排序?', '提示', { this.$confirm('是否要修改排序?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => { //
updateHotProductSort(this.sortDialogData).then(response => { updateHotProductSort(this.sortDialogData).then(response => {
this.sortDialogVisible = false; this.sortDialogVisible = false;
this.getList(); this.getList();
@ -369,58 +453,62 @@
}); });
}) })
}, },
//
getList() { getList() {
this.listLoading = true; this.listLoading = true;
fetchList(this.listQuery).then(response => { fetchList(this.listQuery).then(response => { //fetchList
this.listLoading = false; this.listLoading = false;
this.list = response.data.list; this.list = response.data.list; //
this.total = response.data.total; this.total = response.data.total;
}) })
}, },
//
updateRecommendStatusStatus(ids, status) { updateRecommendStatusStatus(ids, status) {
this.$confirm('是否要修改推荐状态?', '提示', { this.$confirm('是否要修改推荐状态?', '提示', { //
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
let params=new URLSearchParams(); let params = new URLSearchParams(); //idURLSearchParams
params.append("ids", ids); params.append("ids", ids);
params.append("recommendStatus", status); params.append("recommendStatus", status);
updateRecommendStatus(params).then(response=>{ updateRecommendStatus(params).then(response => { //updateRecommendStatus
this.getList(); this.getList();
this.$message({ this.$message({
type: 'success', type: 'success',
message: '修改成功!' message: '修改成功!' //
}); });
}); });
}).catch(() => { }).catch(() => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '已取消操作!' message: '已取消操作!' //
}); });
this.getList(); this.getList();
}); });
}, },
//
deleteProduct(ids) { deleteProduct(ids) {
this.$confirm('是否要删除该推荐?', '提示', { this.$confirm('是否要删除该推荐?', '提示', { //
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
let params=new URLSearchParams(); let params = new URLSearchParams(); //idURLSearchParams
params.append("ids", ids); params.append("ids", ids);
deleteHotProduct(params).then(response=>{ deleteHotProduct(params).then(response => { //deleteHotProduct
this.getList(); this.getList();
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!' //
}); });
}); });
}) })
}, },
//
getDialogList() { getDialogList() {
fetchProductList(this.dialogData.listQuery).then(response=>{ fetchProductList(this.dialogData.listQuery).then(response => { //fetchProductList
this.dialogData.list=response.data.list; this.dialogData.list = response.data.list; //
this.dialogData.total = response.data.total; this.dialogData.total = response.data.total;
}) })
} }

Loading…
Cancel
Save