<!-- 运营管理 协议管理 -->
<template>
  <div class="app-container">
    <el-button
      type="primary"
      icon="el-icon-plus"
      size="mini"
      @click="getDetail()"
      v-hasPermi="['operation:agreement:add']"
      >新增</el-button
    >

    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="协议名称" align="center" prop="name" />
      <el-table-column
        label="协议类型"
        align="center"
        prop="type"
        :formatter="typeFormatter"
      />
      <el-table-column label="更新时间" align="center" prop="updateTime" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="getDetail(scope.row.id, true)"
            >查看</el-button
          >
          <el-button
            type="text"
            @click="getDetail(scope.row.id)"
            v-hasPermi="['operation:agreement:edit']"
            >编辑</el-button
          >
          <el-button
            type="delete"
            @click="getDelete(scope.row)"
            v-hasPermi="['operation:agreement:delete']"
            >删除</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 { list, remove } from "@/api/operation/agreement";
import { dialogCallBack } from "@/utils/DialogUtil";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10,
      },
      // 列表
      tableData: [],
      // 总数据
      total: 0,
      // 协议类型
      typeOptions: [
        {
          value: 0,
          label: "用户协议",
        },
        {
          value: 1,
          label: "隐私协议",
        },
        {
          value: 2,
          label: "音乐服务许可协议",
        },
        {
          value: 3,
          label: "儿童隐私保护指南",
        },
        {
          value: 4,
          label: "VIP音乐服务协议",
        },
        {
          value: 5,
          label: "爱听付费协议",
        },
        {
          value: 6,
          label: "关于我们",
        },
        {
          value: 7,
          label: "第三方信息共享清单",
        },
        {
          value: 8,
          label: "已收集个人信息清单",
        },
        {
          value: 9,
          label: "连接设备提示",
        },
        {
          value: 10,
          label: "联通认证服务协议",
        },
        {
          value: 11,
          label: "电信认证服务协议",
        },
        {
          value: 12,
          label: "移动认证服务协议",
        },
      ],
    };
  },
  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;
        }
      });
    },

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

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

    // 字典翻译
    typeFormatter(row) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
  },
};
</script>