<!--app首页弹出公告-->
<template>


  <div class="app-container" style="background-color: #fff">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="118px">
      <el-form-item label="类型" prop="noticeType">
        <el-select v-model="queryParams.noticeType" placeholder="选择类型" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.sys_app_home_sub" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </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-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="118px" size="small">
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['ops:product:add']" icon="el-icon-plus" plain size="mini" type="primary"
          @click="handleAdd">新增
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="productList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column align="center" label="ID" prop="noticeId" />
      <el-table-column align="center" label="首页弹窗内容" prop="noticeContent" :show-overflow-tooltip="true" />
      <el-table-column label="图片" align="center" prop="remark">
        <template slot-scope="scope">
          <image-preview :src="scope.row.remark" :width="100" :height="100" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="类型" prop="noticeType">
        <template slot-scope="scope">
          <DictTag :options="dict.type.sys_app_home_sub" :value="scope.row.noticeType"></DictTag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="标题" prop="noticeTitle" />
      <!--      <el-table-column align="center" label="文本内容" prop="content" />-->
      <el-table-column align="center" label="新闻链接" prop="bh" />
      <el-table-column align="center" label="在线筹款额" prop="jkallAmount" />
      <el-table-column align="center" label="爱心人次" prop="jkUserNum" />
      <el-table-column align="center" label="时间" prop="sj" />
      <el-table-column align="center" label="类型" prop="lx" />
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button v-hasPermi="['ops:product:edit']" icon="el-icon-edit" size="mini" type="text"
            @click="handleUpdate(scope.row)">修改
          </el-button>
          <el-button v-hasPermi="['ops:product:remove']" icon="el-icon-delete" size="mini" type="text"
            @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
      @pagination="getList" />
    <!-- 添加或修改产品对话框 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px">
      <el-form ref="form" :model="form" :rules="rules" label-width="118px">
        <el-form-item label="标题" prop="noticeTitle" :show-overflow-tooltip='true'>
          <el-input v-model="form.noticeTitle" placeholder="请输入内容标题" />
        </el-form-item>
        <el-form-item label="文本内容" prop="content">
          <el-input v-model="form.content" placeholder="请输入文本内容" />
        </el-form-item>
        <el-form-item label="新闻链接" prop="bh">
          <el-input v-model="form.bh" placeholder="请输入新闻链接" />
        </el-form-item>
        <el-form-item label="在线筹款额" prop="jkallAmount">
          <el-input v-model="form.jkallAmount" placeholder="请输入在线筹款额" />
        </el-form-item>
        <el-form-item label="爱心人次" prop="jkUserNum">
          <el-input v-model="form.jkUserNum" placeholder="请输入爱心人次" />
        </el-form-item>
        <el-form-item label="时间" prop="form">
          <el-input v-model="form.sj" placeholder="请输入项目有效时间" />
        </el-form-item>
        <el-form-item label="类型" prop="form">
          <el-input v-model="form.lx" placeholder="请输入项目类型" />
        </el-form-item>
        <el-form-item label="类别" prop="noticeType">
          <el-radio-group v-model="form.noticeType">
            <el-radio v-for="dict in dict.type.sys_app_home_sub" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <div style="margin-bottom: 20px; display: flex">
          <el-form-item label="图片"><image-upload v-model="form.remark" /></el-form-item>
        </div>
        <p>详情内容</p>
        <Editor :value="form.noticeContent" @onChange="htmlchange" v-if="dialogFormVisible"></Editor>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定 </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getnoticelist,
  getnoticeone,
  putnotice,
  addnotice,
  delnotice,
  uploadData,
} from "@/api/ops/app/shouyegonggao.js";
import Quill from "quill";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { DomEditor } from "@wangeditor/editor";
import { getToken } from "@/utils/auth";

export default {
  name: "Product",
  dicts: ["sys_app_home_sub"],
  data() {
    return {
      //类型
      leixing: "",
      // 状态
      status: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      dialogFormVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeType: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    console.log(1234567);
    this.getList();
  },


  mounted() { },
  methods: {
    insertText() {
      const editor = this.editor; // 获取 editor 实例
      if (editor == null) return;
      // 调用 editor 属性和 API
      editor.insertText("一段文字");
      console.log(editor.children);
    },
    htmlchange(e) {
      this.form.noticeContent = e;
    },
    // / 查询产品列表 */
    getList() {
      this.loading = true;
      getnoticelist(this.queryParams).then((res) => {
        console.log(res);
        this.productList = res.rows;
        // console.log(this.productList)
        this.total = res.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pageNum: 1,
        pageSize: 10,

      };
      this.resetForm("form");
    },
    // / 搜索按钮操作 */
    handleQuery() {
      // console.log(204);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // / 重置按钮操作 */
    resetQuery() {

      this.resetForm("queryForm");
      this.queryParams.noticeType = null
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      // console.log(216);
      // this.ids = selection.map(item => item.productId)
      // this.single = selection.length!==1
      // this.multiple = !selection.length
    },
    // / 新增按钮操作 */
    handleAdd() {
      this.dialogFormVisible = true;
      this.reset();
      this.title = "添加app首页列表管理";
    },
    // / 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      getnoticeone(row.noticeId).then((res) => {
        this.form = res.data;
        this.dialogFormVisible = true;
        this.title = "修改app首页列表管理";
      });
    },
    // / 提交按钮 */
    submitForm() {
      if (this.form.noticeId != null) {
        putnotice(this.form).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.dialogFormVisible = false;
          // console.log(this.form)
          this.getList();
          // this.$refs.upload.clearFiles();
        });
      } else {
        addnotice(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.dialogFormVisible = false;
          this.getList();
          this.reset();
          // this.$refs.upload.clearFiles();
        });
      }
    },
    // / 删除按钮操作 */
    handleDelete(row) {
      const productIds = row.noticeId;
      this.$modal
        .confirm('是否确认删除产品编号为"' + productIds + '"的数据项?')
        .then(function () {
          return delnotice(productIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    // / 导出按钮操作 */
    handleExport() {
      console.log(422);
      // this.download('ops/product/export', {
      //   ...this.queryParams
      // }, product_${new Date().getTime()}.xlsx)
    },
  },
};
</script>