wr1207
2023-04-17 32e4bad2cff2793052effcd2d59cdd8923702b22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<template>
<div>
<el-card shadow="never" style="min-height:650px;">
<div v-if="search_visible" id="search" class="search">
    <el-form ref="form" size="small" :model="searchData" inline>
        <el-form-item label="可兑次数">
            <el-input id="num" v-model="searchData.num"  style="width:150px;" placeholder="请输入可兑次数"></el-input>
        </el-form-item>
        <el-form-item label="兑换人">
            <select-page :is_clear="is_clear" url="/admin/Redemption/getMember_id" :selectval.sync="searchData.member_id"></select-page>
        </el-form-item>
        <el-form-item label="状态">
            <el-select style="width:150px" v-model="searchData.status" filterable clearable placeholder="请选择">
                <el-option key="0" label="待导出" value="1"></el-option>
                <el-option key="1" label="待兑换" value="2"></el-option>
                <el-option key="2" label="已兑换" value="3"></el-option>
            </el-select>
        </el-form-item>
        <Search :search_data.sync="searchData" @refesh_list="index"></Search>
    </el-form>
</div>
<div class="btn-group" style="margin-top:10px;margin-bottom:10px;">
    <div>
        <el-button v-for="item in button_group" v-if="checkPermission(item.access)" :key="item.access"  :disabled="$data[item.disabled]" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname)">
            <span v-if="item.batch" v-text="$data['batchUpdateStatus']?'批量保存':'批量编辑'"></span>
            <span v-else v-text="item.name"></span>
        </el-button>
    </div>
    <div><TableTool :search_visible.sync="search_visible"   @refesh_list="index"></TableTool></div>
</div>
<el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="redemption_id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @sort-change='sortChange' v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">
    <el-table-column align="center" type="selection" width="42"></el-table-column>
    <el-table-column align="center" type = '' property="redemption_id"  label="编号"  width="70">
    </el-table-column>
    <el-table-column align="center"  property="code"  label="兑换码" show-overflow-tooltip width="">
    </el-table-column>
    <el-table-column align="center"  property="num"  label="可兑次数" show-overflow-tooltip width="">
    </el-table-column>
    <el-table-column align="center"  property="member.nick_name"  label="兑换人" show-overflow-tooltip width="">
    </el-table-column>
    <el-table-column align="center"  property="recieve_time"  label="兑换时间" show-overflow-tooltip width="">
        <template slot-scope="scope">
            {{parseTime(scope.row.recieve_time)}}
        </template>
    </el-table-column>
    <el-table-column align="center"  property="status"  label="状态" show-overflow-tooltip width="">
        <template slot-scope="scope">
            <el-tag type="primary" v-if="scope.row.status == '1'" size="mini" effect="dark">待导出</el-tag>
            <el-tag type="warning" v-if="scope.row.status == '2'" size="mini" effect="dark">待兑换</el-tag>
            <el-tag type="success" v-if="scope.row.status == '3'" size="mini" effect="dark">已兑换</el-tag>
        </template>
    </el-table-column>
</el-table>
<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
</el-card>
 
<!--添加-->
<Add :show.sync="dialog.addDialogStatus" size="small" @refesh_list="index"></Add>
<!--批量添加-->
<Adds :show.sync="dialog.addsDialogStatus" size="small" @refesh_list="index"></Adds>
<!--导出弹窗-->
<el-dialog title="导出进度条" :visible="dumpshow" :before-close="closedialog" width="500px">
    <el-progress :percentage="percentage"></el-progress>
</el-dialog>
 
</div>
</template>
 
<script>
import Search from '@/components/common/Search.vue'
import Page from '@/components/common/Page.vue'
import TableTool from '@/components/common/TableTool.vue'
import SelectPage from '@/components/common/SelectPage.vue'
import XLSX from "xlsx"
import Add from '@/views/admin/redemption/add.vue'
import Adds from '@/views/admin/redemption/adds.vue'
export default {
    components: {
        Search,
        Page,
        TableTool,
        SelectPage,
        Add,
        Adds,
    },
    data: function() {
        return {
            dialog: {
                addDialogStatus : false,
                addsDialogStatus : false,
            },
            searchData:{},
            button_group:[
                {name:'添加',color:'success',access:'/admin/Redemption/add',icon:'el-icon-plus',disabled:'',clickname:'add'},
                {name:'批量添加',color:'warning',access:'/admin/Redemption/adds',icon:'el-icon-plus',disabled:'',clickname:'adds'},
                {name:'导出',color:'warning',access:'/admin/Redemption/dumpdata',icon:'el-icon-download',disabled:'',clickname:'dumpdata'},
                {name:'设为已导出',color:'primary',access:'/admin/Redemption/changeStatus',icon:'el-icon-edit-outline',disabled:'multiple',clickname:'changeStatus'},
            ],
            loading: false,
            page_data: {
                limit: 20,
                page: 1,
                total:20,
            },
            order:'',
            sort:'',
            ids: [],
            single:true,
            multiple:true,
            search_visible:true,
            list: [],
            exceldata:[],
            dumppage:1,
            ws:{},
            dumpshow:false,
            percentage:0,
            filename:'',
            is_clear:false,
        }
    },
    methods:{
        index(){
            let param = {limit:this.page_data.limit,page:this.page_data.page,order:this.order,sort:this.sort}
            Object.assign(param, this.searchData,this.$route.query)
            this.loading = true
            this.$axios.post('/admin/Redemption/index',param).then(res => {
                if(res.data.status == 200){
                    this.list = res.data.data.data
                    this.page_data.total = res.data.data.total
                    this.loading = false
                }else{
                    this.$message.error(res.data.msg);
                }
            })
        },
        add(){
            this.dialog.addDialogStatus = true
        },
        adds(){
            this.dialog.addsDialogStatus = true
        },
        dumpdata(){
            this.$confirm('确定操作吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.dumpshow = true
                this.confirmdumpdata()
            }).catch(() => {})
        },
        confirmdumpdata(){
            let query = {page:this.dumppage,order:this.order,sort:this.sort}
            Object.assign(query, this.searchData,{redemption_id:this.ids.join(',')},this.urlobj)
            this.$axios.post('/admin/Redemption/dumpdata',query).then(res => {
                if(res.data.data && res.data.data.length > 0){
                    if(this.dumppage == 1){
                        this.exceldata.push(res.data.header)
                    }
                    res.data.data.forEach((item) => {
                        this.exceldata.push(Object.values(item))
                    })
                    this.percentage = res.data.percentage
                    this.filename = res.data.filename
                    this.ws = XLSX.utils.aoa_to_sheet(this.exceldata)
                    this.dumppage = this.dumppage + 1
                    this.confirmdumpdata()
                }else{
                    let wb = XLSX.utils.book_new()
                    XLSX.utils.book_append_sheet(wb, this.ws)
                    XLSX.writeFile(wb, this.filename)
                    this.exceldata = []
                    this.dumpshow = false
                    this.dumppage = 1
                    this.percentage = 0
                }
            })
        },
        closedialog(){
            this.dumpshow = false
        },
        changeStatus(row){
            this.$confirm('确定操作吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let ids = row.redemption_id ? row.redemption_id : this.ids.join(',')
                this.$axios.post('/admin/Redemption/changeStatus',{redemption_id:ids}).then(res => {
                    if(res.data.status == 200){
                        this.$message({message: res.data.msg, type: 'success'})
                        this.index()
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            }).catch(() => {})
        },
        selection(selection) {
            this.ids = selection.map(item => item.redemption_id)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        handleRowClick(row, rowIndex,event){
            if(event.target.className !== 'el-input__inner'){
                this.$refs.multipleTable.toggleRowSelection(row)
            }
        },
        rowClass ({ row, rowIndex }) {
            for(let i=0;i<this.ids.length;i++) {
                if (row.redemption_id === this.ids[i]) {
                    return 'rowLight'
                }
            }
        },
        sortChange(val){
            if(val.order == 'descending'){
                this.order= 'desc'
            }
            if(val.order == 'ascending'){
                this.order= 'asc'
            }
            this.sort = val.prop
            this.index()
        },
        fn(method){
            this[method](this.ids)
        },
    },
    mounted(){
        this.index()
    },
}
</script>
 
<style  lang="scss">
@import '@/assets/scss/common.scss'
</style>