index.vue 9.8 KB
Newer Older
sunhongwei's avatar
sunhongwei committed
1 2 3
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
4 5
      <el-form-item :label="$t('公告标题')" prop="title">
        <el-input v-model="queryParams.title" :placeholder="$t('请输入公告标题')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
6
      </el-form-item>
7 8
      <el-form-item :label="$t('操作人员')" prop="createBy">
        <el-input v-model="queryParams.createBy" :placeholder="$t('请输入操作人员')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
9
      </el-form-item>
10 11
      <el-form-item :label="$t('类型')" prop="type">
        <el-select v-model="queryParams.type" :placeholder="$t('公告类型')" clearable>
chenjiuping's avatar
chenjiuping committed
12
          <el-option v-for="dict in noticeTypeDictDatas" :key="parseInt(dict.value)" :label="$l(dict, 'label')" :value="parseInt(dict.value)"/>
sunhongwei's avatar
sunhongwei committed
13 14 15
        </el-select>
      </el-form-item>
      <el-form-item>
16 17
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{$t('搜索')}}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{$t('重置')}}</el-button>
sunhongwei's avatar
sunhongwei committed
18 19 20 21 22 23
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
24
                   v-hasPermi="['system:notice:create']"s>{{$t('新增')}}</el-button>
sunhongwei's avatar
sunhongwei committed
25 26 27 28 29
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="noticeList">
30 31 32
      <el-table-column :label="$t('序号')" align="center" prop="id" width="100" />
      <el-table-column :label="$t('公告标题')" align="center" prop="title" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('公告类型')" align="center" prop="type" width="100">
sunhongwei's avatar
sunhongwei committed
33 34 35 36
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="scope.row.type"/>
        </template>
      </el-table-column>
37
      <el-table-column :label="$t('状态')" align="center" prop="status" width="100">
sunhongwei's avatar
sunhongwei committed
38 39 40 41
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
        </template>
      </el-table-column>
42
      <el-table-column :label="$t('有效日期')" align="center" prop="validateDate" width="150" >
sunhongwei's avatar
sunhongwei committed
43
        <template slot-scope="scope">
chenjiuping's avatar
chenjiuping committed
44
          <span>{{ parseTime(scope.row.validateDate, '{y}-{m}-{d}') }}</span>
sunhongwei's avatar
sunhongwei committed
45 46
        </template>
      </el-table-column>
47 48
<!--      <el-table-column :label="$t('创建者')" align="center" prop="createBy"  width="150"/>-->
      <el-table-column :label="$t('创建时间')" align="center" prop="createTime"  width="150">
sunhongwei's avatar
sunhongwei committed
49
        <template slot-scope="scope">
chenjiuping's avatar
chenjiuping committed
50 51 52
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
53
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
chenjiuping's avatar
chenjiuping committed
54
        <template slot-scope="scope" >
sunhongwei's avatar
sunhongwei committed
55
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
56
                     v-hasPermi="['system:notice:update']">{{$t('修改')}}</el-button>
sunhongwei's avatar
sunhongwei committed
57
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
58
                     v-hasPermi="['system:notice:delete']">{{$t('删除')}}</el-button>
sunhongwei's avatar
sunhongwei committed
59 60 61 62 63 64 65 66 67 68 69 70
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
71 72
            <el-form-item :label="$t('公告标题')" prop="title">
              <el-input v-model="form.title" :placeholder="$t('请输入公告标题')" />
sunhongwei's avatar
sunhongwei committed
73 74
            </el-form-item>
          </el-col>
chenjiuping's avatar
chenjiuping committed
75
          <el-col :span="12">
76 77
            <el-form-item :label="$t('标题英文')" prop="title">
              <el-input v-model="form.titleEn" :placeholder="$t('请输入标题英文')" />
chenjiuping's avatar
chenjiuping committed
78 79
            </el-form-item>
          </el-col>
sunhongwei's avatar
sunhongwei committed
80
          <el-col :span="12">
81 82
            <el-form-item :label="$t('公告类型')" prop="type">
              <el-select v-model="form.type" :placeholder="$t('请选择')">
sunhongwei's avatar
sunhongwei committed
83 84 85 86 87 88 89 90 91
                <el-option
                    v-for="dict in noticeTypeDictDatas"
                    :key="parseInt(dict.value)"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
chenjiuping's avatar
chenjiuping committed
92
          <el-col :span="12">
93
            <el-form-item :label="$t('状态')">
sunhongwei's avatar
sunhongwei committed
94 95 96 97 98 99 100 101 102
              <el-radio-group v-model="form.status">
                <el-radio
                    v-for="dict in statusDictDatas"
                    :key="parseInt(dict.value)"
                    :label="parseInt(dict.value)"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
chenjiuping's avatar
chenjiuping committed
103
          <el-col :span="12">
104
            <el-form-item :label="$t('有效日期')">
chenjiuping's avatar
chenjiuping committed
105 106 107 108 109
              <el-date-picker type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd" :editable="false"
                              v-model="form.validateDate"
                              style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
sunhongwei's avatar
sunhongwei committed
110
          <el-col :span="24">
111
            <el-form-item :label="$t('内容')">
sunhongwei's avatar
sunhongwei committed
112 113 114
              <editor v-model="form.content" :min-height="192"/>
            </el-form-item>
          </el-col>
chenjiuping's avatar
chenjiuping committed
115
          <el-col :span="24">
116
            <el-form-item :label="$t('内容英文')">
chenjiuping's avatar
chenjiuping committed
117 118 119
              <editor v-model="form.contentEn" :min-height="192"/>
            </el-form-item>
          </el-col>
sunhongwei's avatar
sunhongwei committed
120 121 122
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
123 124
        <el-button type="primary" @click="submitForm">{{$t('确 定')}}</el-button>
        <el-button @click="cancel">{{$t('取 消')}}</el-button>
sunhongwei's avatar
sunhongwei committed
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
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";
import Editor from '@/components/Editor';

import {CommonStatusEnum} from '@/utils/constants'
import { getDictDatas, DICT_TYPE } from '@/utils/dict'

export default {
  name: "Notice",
  components: {
    Editor
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        title: undefined,
        createBy: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        title: [
169
          { required: true, message: this.$t("公告标题不能为空"), trigger: "blur" }
sunhongwei's avatar
sunhongwei committed
170 171
        ],
        type: [
172
          { required: true, message: this.$t("公告类型不能为空"), trigger: "change" }
sunhongwei's avatar
sunhongwei committed
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
        ]
      },

      // 枚举
      CommonStatusEnum: CommonStatusEnum,
      // 数据字典
      noticeTypeDictDatas: getDictDatas(DICT_TYPE.SYSTEM_NOTICE_TYPE),
      statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS)
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listNotice(this.queryParams).then(response => {
        this.noticeList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        title: undefined,
chenjiuping's avatar
chenjiuping committed
206
        titleEn: undefined,
sunhongwei's avatar
sunhongwei committed
207 208
        type: undefined,
        content: undefined,
chenjiuping's avatar
chenjiuping committed
209
        contentEn: undefined,
sunhongwei's avatar
sunhongwei committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
        status: CommonStatusEnum.ENABLE
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
228
      this.title = this.$t("添加公告");
sunhongwei's avatar
sunhongwei committed
229 230 231 232 233 234 235 236
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNotice(id).then(response => {
        this.form = response.data;
        this.open = true;
237
        this.title = this.$t("修改公告");
sunhongwei's avatar
sunhongwei committed
238 239 240 241 242 243 244 245
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id !== undefined) {
            updateNotice(this.form).then(response => {
246
              this.$modal.msgSuccess(this.$t("修改成功"));
sunhongwei's avatar
sunhongwei committed
247 248 249 250 251
              this.open = false;
              this.getList();
            });
          } else {
            addNotice(this.form).then(response => {
252
              this.$modal.msgSuccess(this.$t("新增成功"));
sunhongwei's avatar
sunhongwei committed
253 254 255 256 257 258 259 260 261 262
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
263
      this.$modal.confirm(this.$t('是否确认删除公告编号为"') + ids + this.$t('"的数据项?')).then(function() {
sunhongwei's avatar
sunhongwei committed
264 265 266
          return delNotice(ids);
        }).then(() => {
          this.getList();
267
          this.$modal.msgSuccess(this.$t("删除成功"));
sunhongwei's avatar
sunhongwei committed
268 269 270 271 272
      }).catch(() => {});
    }
  }
};
</script>