张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<template>
  <div class="main">
    <div class="main_header">
      <div class="header_item">
        <span class="header_label">公告名称:</span>
        <el-input v-model="noticeName" clearable placeholder="请输入公告名称"></el-input>
      </div>
      <div class="header_item">
        <span class="header_label">发布时间:</span>
        <el-date-picker 
          v-model="timeDate" 
          type="daterange" 
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <div class="header_item">
        <el-button v-if="showButton('search')" icon="el-icon-search" @click="searchSafetyAfficheList(true)">查询</el-button>
        <el-button class="search_btn" v-if="showButton('insert')" icon="el-icon-plus" @click="propInsert()">新增</el-button>
      </div>
    </div>
    <div class="main_content">
      <el-table
        ref="table"
        v-loading="loading"
        :data="afficheList"
        height="100%">
        <el-table-column label="序号" width="60" align="center">
          <template #default="scope">
            <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="noticeName" label="公告名称" width="180" align="center"></el-table-column>
        <el-table-column prop="noticeTypeName" label="公告分类" align="center"></el-table-column>
        <el-table-column label="公告内容" show-overflow-tooltip align="center">
          <template #default="{ row }">
            <div class="notice_content" v-html="row.noticeContent"></div>
          </template>
        </el-table-column>
        <el-table-column prop="publishTime" label="发布时间" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template #default="{ row }">
            <el-button class="table_btn" size="mini" v-if="showButton('update')" @click="propUpdate(row)">修改</el-button>
            <el-button class="delete_btn" size="mini" v-if="showButton('delete')" @click="deleteInfo(row)">删除</el-button>
            <el-button class="table_btn" size="mini" v-if="showButton('delete') && row.status === 2" @click="changeStatus(row, 1)">发布</el-button>
            <el-button class="table_btn" size="mini" v-if="showButton('delete') && row.status === 1" @click="changeStatus(row, 2)">下架</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="main_footer">
      <el-pagination
        background
        @current-change="changePageNum"
        @size-change="changePageSize"
        :current-page="pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 新增公告 修改公告信息 -->
    <el-dialog
      class="prop_dialog"
      :title="asyncTitle ? '新增公告' : '修改公告信息'"
      :visible.sync="asyncAffiche"
      width="45%">
      <el-form ref="form" :model="formAffiche" :rules="rulesAffiche" label-width="auto" class="rule_form">
        <el-form-item label="公告名称:" prop="noticeName">
          <el-input v-model="formAffiche.noticeName" clearable placeholder="请输入公告名称"></el-input>
        </el-form-item>
        <el-form-item label="公告分类:" prop="noticeType">
          <el-select v-model="formAffiche.noticeType" clearable placeholder="请选择公告分类">
            <el-option
              v-for="item in afficheType"
              :key="item.dictId"
              :label="item.dictName"
              :value="item.dictId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公告内容:" prop="noticeContent">
          <edit-forms v-if="asyncAffiche" :editor-show.sync="formAffiche.noticeContent" @editorCreate="editorCreate" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="asyncAffiche = false">取 消</el-button>
        <el-button class="submit_btn" @click="asyncTitle ? submitInsertForm() : submitUpdateForm()">提 交</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { buttonPinia } from '../../pinia';
import EditForms from '@/components/EditForms.vue'
import { throttle } from '../../plugins/public';
  export default {
    components: {
      EditForms
    },
    data() {
      var validatePass = (rule, value, callback) => {
        if (this.editInstance.getText().length > 5000) {
          callback(new Error('公告文字数量应在5000字以内'));
        } else {
          callback();
        }
      };
      return {
        noticeName: '',
        timeDate: '',
        pageNum: 1,
        pageSize: 10,
        total: 0,
        loading: false,
        afficheList: [],
        asyncTitle: true, // true 新增 false  修改
        asyncAffiche: false, // 弹窗
        formAffiche: {}, // 表单信息
        rulesAffiche: {
          noticeName: [{
            required: true,
            message: '请输入公告名称',
            tirgger: 'blur'
          }],
          noticeType: [{
            required: true,
            message: '请选择公告分类',
            tirgger: ['blur', 'change']
          }],
          noticeContent: [{
            required: true,
            message: '请输入公告内容',
            tirgger: 'blur'
          }, {
            validator: validatePass,
            trigger: 'blur'
          }]
        }, // 表单校验规则
        afficheType: [], // 分类信息
        editInstance: '', // 富文本实例
      }
    },
    mounted() {
      this.searchSafetyAfficheList(true);
    },
    methods: {
      // 获取公告类型
      async getAfficheTypeData() {
        const { data } = await this.$api.Dictionary.searchDictionary({
          dictType: 'su_notice_type',
          pageNum: 1,
          pageSize: 100000
        });
        this.afficheType = data.list;
      },
      // 查询安全公告信息
      searchSafetyAfficheList(bol) {
        if(bol) {
          this.pageNum = 1;
        }
        this.loading = true;
        this.afficheList = [];
        this.$api.Safety.searchSafetyAfficheList({
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          noticeName: this.noticeName,
          startTime: this.timeDate ? `${this.timeDate[0]} 00:00:00` : '',
          endTime: this.timeDate ? `${this.timeDate[1]} 23:23:59` : ''
        }).then((res) => {
          if(res.success) {
            this.total = res.data.total;
            this.afficheList = res.data.list;
          }
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        })
      },
      // 打开添加信息
      propInsert() {
        this.asyncTitle = true;
        this.asyncAffiche = true;
      },
      // 打开修改信息
      propUpdate(row) {
        this.asyncTitle = false;
        this.asyncAffiche = true;
        this.$nextTick(() => {
          this.$set(this.formAffiche, 'id', row.id);
          this.$set(this.formAffiche, 'noticeName', row.noticeName);
          this.$set(this.formAffiche, 'noticeType', row.noticeType);
          this.$set(this.formAffiche, 'noticeContent', row.noticeContent);
        })
      },
      // 删除公告信息
      deleteInfo(row) {
        this.$confirm("该操作将删除该公告信息,是否继续删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
       })
       .then(() => {
         this.$api.Safety.deleteSafetyAfficheInfo({
          id: row.id
        }).then(res => {
          if(res.success) {
            this.searchSafetyAfficheList(true);
            this.$message.success("删除成功!");
          } else {
            this.$message.warning(res.statusMsg);
          }
        })
       })
       .catch(() => {
         this.$message.warning("您已取消");
       })
      },
      // 修改发布状态
      changeStatus(row, status) {
        this.$api.Safety.upAndDownSafetyAfficheInfo({
          id: row.id,
          status: status
        }).then((res) => {
          if(res.success) {
            this.$message.success(status === 1 ? '发布成功!': '下架成功!');
            this.searchSafetyAfficheList();
          } else {
            this.$message.warning(res.statusMsg);
          }
        })
      },
      // 提交添加信息
      submitInsertForm: throttle(function() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const params = Object.assign({}, this.formAffiche);
            this.$api.Safety.insertSafetyAfficheInfo(params).then((res) => {
              if(res.success) {
                this.asyncAffiche = false;
                this.$message.success('添加成功!');
                this.searchSafetyAfficheList(true);
              } else {
                this.$message.warning(res.statusMsg);
              }
            })
          }
        })
      }, 3000),
      // 提交修改信息
      submitUpdateForm: throttle(function() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const params = Object.assign({}, this.formAffiche);
            this.$api.Safety.insertSafetyAfficheInfo(params).then((res) => {
              if(res.success) {
                this.asyncAffiche = false;
                this.$message.success('修改成功!');
                this.searchSafetyAfficheList(true);
              } else {
                this.$message.warning(res.statusMsg);
              }
            })
          }
        })
      }, 3000),
      //富文本返回结果
      editorCreate(editors){
        this.editInstance = editors;
      },
      // 切换页码
      changePageNum(page) {
        this.pageNum = page;
        this.searchSafetyAfficheList();
      },
      // 切换每页条数
      changePageSize(size) {
        this.pageSize = size;
        this.searchSafetyAfficheList();
      },
      // 判断按钮权限信息
      showButton(str) {
        const pinia = buttonPinia();
        return pinia.$state.buttonInfo.includes(str);
      }
    },
    watch: {
      asyncAffiche(bol) {
        if(!bol) {
          this.formAffiche = {};
          this.$refs.form.resetFields();
        } else {
          this.getAfficheTypeData();
        }
      }
    },
  }
</script>
 
<style lang="scss" scoped>
@import '@/style/layout-main.scss';
 
.notice_content {
  white-space: nowrap;
  overflow: hidden;
  max-height: 48px;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1; // 超出多少行
  -webkit-box-orient: vertical;
}
 
::v-deep .w-e-scroll {
  color: #fff;
  background: #061C48;
}
 
::v-deep .editor_index {
  margin-top: 0 !important;
}
</style>