123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <template>
- <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.productName" class="input-width" placeholder="商品名称"></el-input>
- </el-form-item>
- <el-form-item label="推荐状态:">
- <el-select v-model="listQuery.recommendStatus" placeholder="全部" clearable class="input-width">
- <el-option v-for="item in recommendOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- </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="handleSelectProduct()">选择商品</el-button>
- </el-card>
- <div class="table-container">
- <el-table ref="newProductTable"
- :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.productName}}</template>
- </el-table-column>
- <el-table-column label="是否推荐" width="200" align="center">
- <template slot-scope="scope">
- <el-switch
- @change="handleRecommendStatusStatusChange(scope.$index, scope.row)"
- :active-value="1"
- :inactive-value="0"
- v-model="scope.row.recommendStatus">
- </el-switch>
- </template>
- </el-table-column>
- <el-table-column label="排序" width="160" align="center">
- <template slot-scope="scope">{{scope.row.sort}}</template>
- </el-table-column>
- <el-table-column label="状态" width="160" align="center">
- <template slot-scope="scope">{{scope.row.recommendStatus | formatRecommendStatus}}</template>
- </el-table-column>
- <el-table-column label="操作" width="180" align="center">
- <template slot-scope="scope">
- <el-button size="mini"
- type="text"
- @click="handleEditSort(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>
- <el-dialog title="选择商品" :visible.sync="selectDialogVisible" width="50%">
- <el-input v-model="dialogData.listQuery.keyword"
- style="width: 250px;margin-bottom: 20px"
- size="small"
- placeholder="商品名称搜索">
- <el-button slot="append" icon="el-icon-search" @click="handleSelectSearch()"></el-button>
- </el-input>
- <el-table :data="dialogData.list"
- @selection-change="handleDialogSelectionChange" border>
- <el-table-column type="selection" width="60" align="center"></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="160" align="center">
- <template slot-scope="scope">NO.{{scope.row.productSn}}</template>
- </el-table-column>
- <el-table-column label="价格" width="120" align="center">
- <template slot-scope="scope">¥{{scope.row.price}}</template>
- </el-table-column>
- </el-table>
- <div class="pagination-container">
- <el-pagination
- background
- @size-change="handleDialogSizeChange"
- @current-change="handleDialogCurrentChange"
- layout="prev, pager, next"
- :current-page.sync="dialogData.listQuery.pageNum"
- :page-size="dialogData.listQuery.pageSize"
- :page-sizes="[5,10,15]"
- :total="dialogData.total">
- </el-pagination>
- </div>
- <div style="clear: both;"></div>
- <div slot="footer">
- <el-button size="small" @click="selectDialogVisible = false">取 消</el-button>
- <el-button size="small" type="primary" @click="handleSelectDialogConfirm()">确 定</el-button>
- </div>
- </el-dialog>
- <el-dialog title="设置排序"
- :visible.sync="sortDialogVisible"
- width="40%">
- <el-form :model="sortDialogData"
- label-width="150px">
- <el-form-item label="排序:">
- <el-input v-model="sortDialogData.sort" style="width: 200px"></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer">
- <el-button @click="sortDialogVisible = false" size="small">取 消</el-button>
- <el-button type="primary" @click="handleUpdateSort" size="small">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import {fetchList,updateRecommendStatus,deleteNewProduct,createNewProduct,updateNewProductSort} from '@/api/newProduct';
- import {fetchList as fetchProductList} from '@/api/product';
- const defaultListQuery = {
- pageNum: 1,
- pageSize: 5,
- productName: null,
- recommendStatus: null
- };
- const defaultRecommendOptions = [
- {
- label: '未推荐',
- value: 0
- },
- {
- label: '推荐中',
- value: 1
- }
- ];
- export default {
- name: 'newProductList',
- data() {
- return {
- listQuery: Object.assign({}, defaultListQuery),
- recommendOptions: Object.assign({}, defaultRecommendOptions),
- list: null,
- total: null,
- listLoading: false,
- multipleSelection: [],
- operates: [
- {
- label: "设为推荐",
- value: 0
- },
- {
- label: "取消推荐",
- value: 1
- },
- {
- label: "删除",
- value: 2
- }
- ],
- operateType: null,
- selectDialogVisible:false,
- dialogData:{
- list: null,
- total: null,
- multipleSelection:[],
- listQuery:{
- keyword: null,
- pageNum: 1,
- pageSize: 5
- }
- },
- sortDialogVisible:false,
- sortDialogData:{sort:0,id:null}
- }
- },
- created() {
- this.getList();
- },
- filters:{
- formatRecommendStatus(status){
- if(status===1){
- return '推荐中';
- }else{
- return '未推荐';
- }
- }
- },
- 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();
- },
- handleRecommendStatusStatusChange(index,row){
- this.updateRecommendStatusStatus(row.id,row.recommendStatus);
- },
- handleDelete(index,row){
- this.deleteProduct(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.updateRecommendStatusStatus(ids,1);
- } else if (this.operateType === 1) {
- //取消推荐
- this.updateRecommendStatusStatus(ids,0);
- } else if(this.operateType===2){
- //删除
- this.deleteProduct(ids);
- }else {
- this.$message({
- message: '请选择批量操作类型',
- type: 'warning',
- duration: 1000
- });
- }
- },
- handleSelectProduct(){
- this.selectDialogVisible=true;
- this.getDialogList();
- },
- handleSelectSearch(){
- this.getDialogList();
- },
- handleDialogSizeChange(val) {
- this.dialogData.listQuery.pageNum = 1;
- this.dialogData.listQuery.pageSize = val;
- this.getDialogList();
- },
- handleDialogCurrentChange(val) {
- this.dialogData.listQuery.pageNum = val;
- this.getDialogList();
- },
- handleDialogSelectionChange(val){
- this.dialogData.multipleSelection = val;
- },
- handleSelectDialogConfirm(){
- if (this.dialogData.multipleSelection < 1) {
- this.$message({
- message: '请选择一条记录',
- type: 'warning',
- duration: 1000
- });
- return;
- }
- let selectProducts = [];
- for (let i = 0; i < this.dialogData.multipleSelection.length; i++) {
- selectProducts.push({
- productId:this.dialogData.multipleSelection[i].id,
- productName:this.dialogData.multipleSelection[i].name
- });
- }
- this.$confirm('使用要进行添加操作?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- createNewProduct(selectProducts).then(response=>{
- this.selectDialogVisible=false;
- this.dialogData.multipleSelection=[];
- this.getList();
- this.$message({
- type: 'success',
- message: '添加成功!'
- });
- });
- });
- },
- handleEditSort(index,row){
- this.sortDialogVisible=true;
- this.sortDialogData.sort=row.sort;
- this.sortDialogData.id=row.id;
- },
- handleUpdateSort(){
- this.$confirm('是否要修改排序?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- updateNewProductSort(this.sortDialogData).then(response=>{
- this.sortDialogVisible=false;
- this.getList();
- this.$message({
- type: 'success',
- message: '删除成功!'
- });
- });
- })
- },
- getList() {
- this.listLoading = true;
- fetchList(this.listQuery).then(response => {
- this.listLoading = false;
- this.list = response.data.list;
- this.total = response.data.total;
- })
- },
- updateRecommendStatusStatus(ids,status){
- this.$confirm('是否要修改推荐状态?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- let params=new URLSearchParams();
- params.append("ids",ids);
- params.append("recommendStatus",status);
- updateRecommendStatus(params).then(response=>{
- this.getList();
- this.$message({
- type: 'success',
- message: '修改成功!'
- });
- });
- }).catch(() => {
- this.$message({
- type: 'success',
- message: '已取消操作!'
- });
- this.getList();
- });
- },
- deleteProduct(ids){
- this.$confirm('是否要删除该推荐?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- let params=new URLSearchParams();
- params.append("ids",ids);
- deleteNewProduct(params).then(response=>{
- this.getList();
- this.$message({
- type: 'success',
- message: '删除成功!'
- });
- });
- })
- },
- getDialogList(){
- fetchProductList(this.dialogData.listQuery).then(response=>{
- this.dialogData.list=response.data.list;
- this.dialogData.total=response.data.total;
- })
- }
- }
- }
- </script>
- <style></style>
|