zhangyanpeng
2020-01-23 7f2bc78a5101017c4470577003e4cf99c0ca7648
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<template>
    <div>
        <el-row >
          <el-col :span="18">
                <el-form label-width="80px" :inline="true" :label-position="labelPosition" :model="formInline" class="form-inline">
                    <el-form-item label="标题">
                        <el-input v-model="formInline.title" placeholder="标题"></el-input>
                    </el-form-item>
                    
                    <el-form-item label="描述">
                        <el-input v-model="formInline.desp" placeholder="描述"></el-input>
                    </el-form-item>
                    
                    <el-form-item >
                        <el-button type="primary" @click="query_">查询</el-button>
                        <el-button type="info" @click="empty_">重置</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
          <el-col :span="4" ><el-button type="primary" @click="createNew">创建</el-button></el-col>
        </el-row>
        
 
    <div class="infinite-list-wrapper" style="overflow:auto; height: 70vh; border-top: 1px solid #c3c5c7;">
        
        <div class="list" v-infinite-scroll="load" infinite-scroll-disabled="disabled">
            <div v-for="one in dataList" :key="one.id" class="list-item" @click="showItem(one)">
                <el-row >
                  <el-col :span="20"><div class="grid-content z_grid-content1 grid-content_text">{{one.title}}</div></el-col>
                  <el-col :span="4"><div class="grid-content z_grid-content1 grid-content_time">{{one.time}}</div></el-col>
                </el-row>
                
                <el-row>
                  <el-col :span="20"><div class="grid-content z_grid-content2">{{one.desp}}</div></el-col>
                </el-row>
            </div>
        </div>
        <p v-if="loading">加载中...</p>
        <p v-if="noMore">没有更多了</p>
    </div>
    <el-dialog
      title="详情"
      :visible.sync="dialogVisible"
      width="40%"
      height="40%"
      custom-class="handleClose">
      <span>{{selectOne.title}}</span>
      <el-divider></el-divider>
     <div style="content">
        <span>{{selectOne.desp}}</span>
     </div>
     
      <span slot="footer" class="dialog-footer">
        <el-button v-if="selectOne.attachment && selectOne.attachment != ''" type="primary" @click="download">下 载</el-button>
      </span>
    </el-dialog>
    
    <el-dialog title="创建话题" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="话题名称" :label-width="formLabelWidth">
          <el-input v-model="form.title" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="话题内容" :label-width="formLabelWidth">
            <el-input type="textarea"  v-model="form.desp" autocomplete="off"></el-input>
        </el-form-item>
        <el-upload
          class="upload-demo"
          :action="uploadUrl"
          :on-preview="handlePreview"
          :data="form"
          :limit="3"
          :auto-upload='false'
          ref="upload"
            :on-change="onChange"
          :on-exceed="handleExceed"
            >
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">不超过50M</div>
        </el-upload>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="createTopic">确 定</el-button>
      </div>
    </el-dialog>
    
        </div>
</template>
 
<script>
    export default {
        data() {
            return {
                uploadUrl:"/api/api/file/topicUpload",
                form:{},
                pageno:1,
                total:0,
                maxPage:0,
                fileList: [],
                dialogVisible: false,
                dialogFormVisible: false,
                labelPosition: "right",
                formInline:{},
                selectOne:{
                    title:"biaoti",
                    desp:"miaoshu",
                    attachment:"222"
                },
                dataList: [
                //     {id:1,attachment:"222",title:"标题", desp:"描述时发生纠纷司符合双方酒叟发动机时代峰峻配电间 刀片机水电费搜豆腐皮搜的看法我都叫打破是觉得批发商附加费第三季度破发接收到发地方就搜到到四点分发偶读囧", time:"12分钟前"},
                //     {id:1,attachment:"222",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                //     {id:1,attachment:"",title:"11", desp:"111", time:"11111"},
                 ],
                loading: false,
                
            }
        },
        computed: {
            noMore() {
                return this.maxPage == this.pageno 
            },
            disabled() {
                return this.loading || this.noMore
            }
        },
        mounted() {
            this.getData();
        },
        methods: {
            onChange(file, fileList) {
                this.fileList = [];
                this.fileList = fileList;
            },
            createTopic() {
                let me = this;
                var userId = localStorage.getItem('userId');
                if(!userId) {
                    this.$router.push('/login');
                }
                this.form.userId = userId;
                let params = this.form;
                
                if(this.fileList.length == 0) {
                    //不带附件
                    let url = "/api/topic/add";
                    this.$axios.get(url, {
                            params
                        })
                        .then(data_ => {
                            if(data_.data.success) {
                                this.$message('创建成功');
                                me.dialogFormVisible = false;
                            }else {
                                this.$message({message:'话题创建失败', type: 'warning'});
                            }
                        }).catch(error => {
                            console.log(error);
                        })
                }else {
                    this.$refs.upload.submit();
                }
            },
             handleRemove(file, fileList) {
                    console.log(file, fileList);
                  },
                  handlePreview(file) {
                    console.log(file);
                  },
                  handleExceed(files, fileList) {
                    this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
                  },
                  beforeRemove(file, fileList) {
                    return this.$confirm(`确定移除 ${ file.name }?`);
                  },
            load() {
                
                if(me.pageno < me.maxPage) {
                    me.pageno++;
                }
                query_();
                
            
            },
            showItem(one) {
                this.dialogVisible = true;
                this.selectOne = one;
            },
            createNew() {
                this.dialogFormVisible = true;
            },
            empty_() {
                this.formInline = {};
                this.query_();
            },
            query_() {
                this.getData(this.formInline);
            },
            getData(query) {
                let me = this;
                this.loading = true
                this.loading_table = true;
                let pageno = this.pagenum;
                let url = "/api/topic/page/" + this.pageno;
                let params =  {};
                if(query){
                    params.title = query.title;
                    params.desp = query.desp;
                }
                this.$axios.get(url, {
                        params
                    })
                    .then(data_ => {
                        console.log(data_);
                        if(data_.data.success) {
                            me.dataList.push.apply(me.dataList, data_.data.data.records)
                            me.total = data_.data.data.total;
                            me.pageno = data_.data.data.pageno;
                            me.maxPage = data_.data.data.maxPage;
                            
                            
                        }
                            me.loading = false
                    }).catch(error => {
                        console.log(error);
                            me.loading = false
                    })
            },
        }
    }
</script>
 
<style>
    .grid-content{
        text-align: left;
        padding: 5px;
    }
    
    .grid-content_text {
        font-weight: bold;
        font-style: italic;
        color: #000;
    }
    .grid-content_time {
        font-weight: bold;
        font-style: italic;
        color: #909399;
    }
    .z_grid-content1{
      display:table-cell;
      vertical-align:bottom;
        height: 50px;
    }
    .z_grid-content2{
      color: #83878a;
        padding: 0px;
      height: 40px;
        line-height: 40px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .content{
        
    }
    
    .form-inline {
        text-align: left;
    }
    
    .list {
        
    }
    .list-item {
        margin-top: 20px;
        padding-bottom: 5px;
        border-bottom: 1px solid #c3c5c7;
    }
    
    .handleClose {
        margin: 10px;
        text-align: left;
    }
    .handleClose .el-dialog__body {
        padding: 10px 20px;
    }
    .handleClose .el-divider--horizontal{
        margin: 5px;
    }
</style>