<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="公告跳转类型" prop="noticeId">
        <el-input
          v-model="queryParams.noticeId"
          placeholder="请输入公告跳转类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="appid" prop="appId">
        <el-input
          v-model="queryParams.appId"
          placeholder="请输入appid"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入公告标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="数据创建时间" prop="createAt">
        <el-date-picker clearable size="small"
          v-model="queryParams.createAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择数据创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="数据更新时间" prop="updateAt">
        <el-date-picker clearable size="small"
          v-model="queryParams.updateAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择数据更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否删除" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入是否删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跳转连接" prop="linkUrl">
        <el-input
          v-model="queryParams.linkUrl"
          placeholder="请输入跳转连接"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公告跳转类型" prop="noticeSkipType">
        <el-select v-model="queryParams.noticeSkipType" placeholder="请选择公告跳转类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="公告跳转类型" prop="noticeTypeId">
        <el-input
          v-model="queryParams.noticeTypeId"
          placeholder="请输入公告跳转类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </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"
          v-hasPermi="['system:LzydNotice:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:LzydNotice:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:LzydNotice:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:LzydNotice:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="LzydNoticeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="公告id" align="center" prop="noticeId" />
      <el-table-column label="appid" align="center" prop="appId" />
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="内容" align="center" prop="content" width="400" />
      <el-table-column label="公告跳转类型" align="center" prop="noticeSkipType" />
      <el-table-column label="公告类型" align="center" prop="noticeTypeId" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否删除" align="center" prop="isDelete" />
      <el-table-column label="跳转连接" align="center" prop="linkUrl" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:LzydNotice:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:LzydNotice:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改荔枝app-公告记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公告id" prop="noticeId">
          <el-input v-model="form.noticeId" placeholder="请输入公告id" />
        </el-form-item>
        <el-form-item label="商户id" prop="appId">
          <el-input v-model="form.appId" placeholder="请输入商户id" />
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="内容">
          <!-- <editor v-model="form.content" :min-height="192"/> -->
          <textarea v-model="form.content" placeholder="请输入内容"/>
        </el-form-item>
        <!-- <el-form-item label="数据创建时间" prop="createAt">
          <el-date-picker clearable size="small"
            v-model="form.createAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择数据创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数据更新时间" prop="updateAt">
          <el-date-picker clearable size="small"
            v-model="form.updateAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择数据更新时间">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="是否删除" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入是否删除" />
        </el-form-item> -->
        <el-form-item label="跳转链接" prop="linkUrl">
          <el-input v-model="form.linkUrl" placeholder="请输入跳转链接" />
        </el-form-item>
        <el-form-item label="公告跳转类型" prop="noticeSkipType">
          <el-select v-model="form.noticeSkipType" placeholder="请选择公告跳转类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="公告类型" prop="noticeTypeId">
          <el-input v-model="form.noticeTypeId" placeholder="请输入公告跳转类型" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLzydNotice, getLzydNotice, delLzydNotice, addLzydNotice, updateLzydNotice, exportLzydNotice } from "@/api/system/LzydNotice";
import Editor from '@/components/Editor';

export default {
  name: "LzydNotice",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 荔枝app-公告记录表格数据
      LzydNoticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeId: null,
        appId: null,
        title: null,
        content: null,
        createAt: null,
        updateAt: null,
        isDelete: null,
        linkUrl: null,
        noticeSkipType: null,
        noticeTypeId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeId: [
          { required: true, message: "公告跳转类型不能为空", trigger: "blur" }
        ],
        appId: [
          { required: true, message: "商户id不能为空", trigger: "blur" }
        ],
        title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        content: [
          { required: true, message: "内容不能为空", trigger: "blur" }
        ],
        linkUrl: [
          { required: false, message: "跳转连接不能为空", trigger: "blur" }
        ],
        noticeSkipType: [
          { required: false, message: "公告跳转类型不能为空", trigger: "change" }
        ],
        noticeTypeId: [
          { required: false, message: "公告跳转类型不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询荔枝app-公告记录列表 */
    getList() {
      this.loading = true;
      listLzydNotice(this.queryParams).then(response => {
        this.LzydNoticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        noticeId: null,
        appId: null,
        title: null,
        content: null,
        createAt: null,
        updateAt: null,
        isDelete: null,
        linkUrl: null,
        noticeSkipType: null,
        noticeTypeId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加荔枝app-公告记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLzydNotice(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改荔枝app-公告记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLzydNotice(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLzydNotice(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除荔枝app-公告记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLzydNotice(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有荔枝app-公告记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportLzydNotice(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
