<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="文件名称" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          clearable
        />
      </el-form-item>
      <el-form-item label="分享状态" prop="fileName">
        <el-select
          v-model="queryParams.shareStatus"
          placeholder="请选择分享状态"
          clearable
        >
          <el-option
            v-for="item in dict.type.share_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </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-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="shareList">
      <el-table-column
        label="文件名称"
        align="center"
        prop="fileName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="分享截止时间"
        align="center"
        prop="endTime"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="分享类型"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.share_type"
            :value="scope.row.shareType"
          />
        </template>
      </el-table-column>
      <el-table-column label="分享状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag :type="getShareStatusTagType(scope.row.shareStatus)"
            ><dict-tag
              :options="dict.type.share_status"
              :value="scope.row.shareStatus"
          /></el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        :show-overflow-tooltip="true"
      />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-link type="primary" style="margin-right: 16px">
            <svg-icon icon-class="revoke"> </svg-icon>撤销分享
          </el-link>
          <el-link type="primary" icon="el-icon-view"> 预览 </el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.currentPage"
      :limit.sync="queryParams.pageCount"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getAdminShareList } from "@/api/user/share";
import { shareStatusConstant } from "./constant";

export default {
  name: "myShare",
  dicts: ["share_type", "share_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      shareList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        currentPage: 1,
        pageCount: 10,
        fileName: "", //文件名称
        shareStatus: "", //分享状态
      },
      // 分享状态常量
      shareStatusConstant,
    };
  },
  computed: {
    getShareStatusTagType(shareStatus) {
      return (shareStatus) => {
        switch (shareStatus) {
          case shareStatusConstant.SHARED: //已分享
            return "success";
          case shareStatusConstant.EXPIRED: //已失效
            return "info";
          case shareStatusConstant.REVOKED: //已撤销
            return "warning";
        }
      };
    },
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      getAdminShareList(this.queryParams).then((res) => {
        this.total = res.data.total;
        this.loading = false;
        this.shareList = res.data.records;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("queryForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.currentPage = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 取消分享
    handleCancelShare(row) {
      console.log(row);
    },
  },
};
</script>
