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
<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-select style="width:150px" v-model="searchData.type" 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-option key="3" label="公告" value="4"></el-option>
                <el-option key="4" label="富文本" value="5"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="标题">
            <el-input id="title" v-model="searchData.title"  style="width:150px;" placeholder="请输入标题"></el-input>
        </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="0"></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="content_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="content_id"  label="编号"  width="70">
    </el-table-column>
    <el-table-column align="center"  property="type"  label="类型" show-overflow-tooltip width="">
        <template slot-scope="scope">
            <span v-if="scope.row.type == '1'" >用户协议</span>
            <span v-if="scope.row.type == '2'" >隐私政策</span>
            <span v-if="scope.row.type == '3'" >使用指南</span>
            <span v-if="scope.row.type == '4'" >公告</span>
            <span v-if="scope.row.type == '5'" >富文本</span>
        </template>
    </el-table-column>
    <el-table-column align="center"  property="title"  label="标题" show-overflow-tooltip width="">
    </el-table-column>
    <el-table-column align="center"  property="content"  label="内容" show-overflow-tooltip width="">
    </el-table-column>
    <el-table-column align="center"  property="create_time"  label="创建时间" show-overflow-tooltip width="">
        <template slot-scope="scope">
            {{parseTime(scope.row.create_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="danger" v-if="scope.row.status == '0'" size="mini" effect="dark">禁用</el-tag>
        </template>
    </el-table-column>
    <el-table-column :fixed="$store.getters.device == 'mobile'?false:'right'" label="操作" align="center" width="190">
        <template slot-scope="scope">
            <div v-if="scope.row.content_id">
                <el-button  size="mini" v-if="checkPermission('/admin/Content/update')" icon="el-icon-edit" type="primary" @click="update(scope.row)" >修改</el-button>
                <el-button  size="mini" v-if="checkPermission('/admin/Content/delete')" icon="el-icon-delete" type="danger" @click="del(scope.row)" >删除</el-button>
            </div>
        </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>
<!--修改-->
<Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index"></Update>
<!--查看详情-->
<Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refesh_list="index"></Detail>
 
</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 Add from '@/views/admin/content/add.vue'
import Update from '@/views/admin/content/update.vue'
import Detail from '@/views/admin/content/detail.vue'
export default {
    components: {
        Search,
        Page,
        TableTool,
        Add,
        Update,
        Detail,
    },
    data: function() {
        return {
            dialog: {
                addDialogStatus : false,
                updateDialogStatus : false,
                detailDialogStatus : false,
            },
            searchData:{},
            button_group:[
                {name:'添加',color:'success',access:'/admin/Content/add',icon:'el-icon-plus',disabled:'',clickname:'add'},
                {name:'修改',color:'primary',access:'/admin/Content/update',icon:'el-icon-edit',disabled:'single',clickname:'update'},
                {name:'删除',color:'danger',access:'/admin/Content/delete',icon:'el-icon-delete',disabled:'multiple',clickname:'del'},
                {name:'查看详情',color:'info',access:'/admin/Content/detail',icon:'el-icon-view',disabled:'single',clickname:'detail'},
            ],
            loading: false,
            page_data: {
                limit: 20,
                page: 1,
                total:20,
            },
            order:'',
            sort:'',
            ids: [],
            single:true,
            multiple:true,
            search_visible:true,
            list: [],
            updateInfo:{},
            detailInfo:{},
        }
    },
    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/Content/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);
                }
            })
        },
        updateExt(row,field){
            if(row.content_id){
                this.$axios.post('/admin/Content/updateExt',{content_id:row.content_id,[field]:row[field]}).then(res => {
                    if(res.data.status == 200){
                        this.$message({message: res.data.msg, type: 'success'})
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            }
        },
        add(){
            this.dialog.addDialogStatus = true
        },
        update(row){
            let id = row.content_id ? row.content_id : this.ids.join(',')
            this.$axios.post('/admin/Content/getUpdateInfo',{content_id:id}).then(res => {
                if(res.data.status == 200){
                    this.dialog.updateDialogStatus = true
                    this.updateInfo = res.data.data
                }else{
                    this.$message.error(res.data.msg)
                }
            })
        },
        del(row){
            this.$confirm('确定操作吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let ids = row.content_id ? row.content_id : this.ids.join(',')
                this.$axios.post('/admin/Content/delete',{content_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(() => {})
        },
        detail(row){
            this.dialog.detailDialogStatus = true
            this.detailInfo = {content_id:row.content_id ? row.content_id : this.ids.join(',')}
        },
        selection(selection) {
            this.ids = selection.map(item => item.content_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.content_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>