<!-- 内容管理 文章管理 -->
<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-form inline size="mini">
      <el-form-item label="文章标题：">
        <el-input v-model="form.title" placeholder="请输入文章标题" clearable />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="form.listDate"
          type="datetimerange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getSearch"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          @click="getDetail()"
          v-hasPermi="['content:article:add']"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column
        label="文章ID"
        prop="id"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="文章标题"
        prop="title"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="分享标题"
        prop="shareTitle"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column label="分享图片" align="center" width="100px">
        <template slot-scope="scope">
          <el-image :src="scope.row.shareIcon" />
        </template>
      </el-table-column>
      <el-table-column label="浏览数" prop="viewCount" align="center" />
      <el-table-column
        label="创建时间"
        prop="createTime"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="更新时间"
        prop="updateTime"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-popover trigger="click">
            <vue-qr :text="getUrl(scope.row)" :ref="`qrcode` + scope.row.id" />
            <el-button type="text" slot="reference" style="margin-right: 10px"
              >预览</el-button
            >
          </el-popover>
          <el-button type="text" @click="getDetail(scope.row.id, true)"
            >查看</el-button
          >
          <el-button
            type="text"
            @click="getDetail(scope.row.id)"
            v-hasPermi="['content:article:edit']"
            >编辑</el-button
          >
          <el-button
            type="delete"
            @click="getDelete(scope.row)"
            v-hasPermi="['content:article:delete']"
            >删除</el-button
          >
          <el-button
            type="text"
            v-clipboard:copy="getUrl(scope.row)"
            v-clipboard:success="copySuccess"
            >复制</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { change, list } from "@/api/content/article";
import { dialogCallBack } from "@/utils/DialogUtil";
import VueQr from "vue-qr";
export default {
  components: {
    VueQr,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10,
      },
      // 列表
      tableData: [],
      // 总数据
      total: 0,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 列表
    getList() {
      this.loading = true;
      list(this.form).then((res) => {
        if (res.code === 0) {
          this.tableData = res.data.records;
          this.total = res.data.total;
          this.loading = false;
        }
      });
    },

    // 搜索
    getSearch() {
      this.form.pageNum = 1;
      this.getList();
    },

    // 重置
    getRefresh() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
      };
      this.getList();
    },

    // 详情
    getDetail(id, boolean) {
      this.$router.push({
        path: `/content/articleList/detail`,
        query: {
          id: id,
          boolean: boolean,
        },
      });
    },

    // 删除
    getDelete(row) {
      var that = this;
      dialogCallBack(that, function () {
        that
          .$confirm(`是否删除${row.title}？`, "提示：", {
            type: "warning",
          })
          .then(() => {
            change(row.id, 2).then((res) => {
              if (res.code === 0) {
                that.$message.success("删除成功！");
                that.getList();
              }
            });
          })
          .catch(() => {});
      });
    },

    // 复制地址
    getUrl(e) {
      return `${e.copyUrl}pages/content/index?articleId=${e.id}`;
    },

    copySuccess() {
      this.$message.success("复制成功！");
    },
  },
};
</script>
