<template>
  <div class="app-container">
    <el-form
      v-if="is_super"
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="85px"
      @submit.prevent
    >
      <el-form-item label="所属站点" prop="tenant_id">
        <SiteOptions v-model="queryParams" />
      </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-tabs
      type="card"
      v-model="queryParams.activeName"
      @tab-click="handleClick"
    >
      <el-tab-pane label="待审核" name="1"></el-tab-pane>
      <el-tab-pane label="已驳回" name="3"></el-tab-pane>
      <el-tab-pane label="已通过" name="2"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="dataList" ref="tableRef">
      <el-table-column label="数据编号" align="center" prop="id" />
      <el-table-column label="成果名称" align="center" prop="name" />
      <el-table-column label="成果领域" align="center" prop="research_name" />
      <el-table-column label="所属专家" align="center" prop="laboratory_name" />
      <el-table-column label="研究机构" align="center" prop="area" />
      <el-table-column
        v-if="queryParams.activeName == 2"
        label="浏览量"
        align="center"
        prop="area"
      />
      <el-table-column
        v-if="queryParams.activeName == 2"
        label="收藏量"
        align="center"
        prop="area"
      />
      <el-table-column label="站点" align="center" prop="address" />
      <el-table-column label="申请时间" align="center" prop="address" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleExamine(scope.row.id)"
            v-if="queryParams.activeName == 1"
          >
            审核
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleExamine(scope.row.id)"
            v-if="queryParams.activeName == 3"
          >
            查看
          </el-button>
          <!-- <el-button
            size="mini"
            type="text"
            @click="handleClaim(scope.row.id)"
            v-if="queryParams.activeName == 2"
          >
            下架
          </el-button> -->
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row.id)"
            v-if="queryParams.activeName != 1"
          >
            删除
          </el-button>
          <div v-if="queryParams.activeName == 2">
            <el-button size="mini" type="text" @click="handleAdd(scope.row.id)">
              上传视频
            </el-button>
            <el-button size="mini" type="text" @click=""> 删除视频 </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page_num"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
    <!-- 上传视频对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="520px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="视频类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择">
            <el-option label="静态视频" value="1"> </el-option>
            <el-option label="视频地址" value="2"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="视频地址:" prop="file">
          <FileUpload
            v-model="form.file"
            :limit="1"
            :fileType="['mp4']"
            v-if="form.type == 1"
          />
          <el-input v-model="form.file" placeholder="请输入视频地址" v-else />
        </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>
export default {
  data() {
    return {
      is_super: this.$store.getters.is_super,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 实验室表格数据
      dataList: null,
      // 查询参数
      queryParams: {
        page_num: 1,
        page_size: 10,
        activeName: "1",
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      rules: {
        file: [
          {
            required: true,
            message: "视频地址不能为空",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  methods: {
    /** 查询机构列表 */
    getList() {
      this.loading = true;
      this.dataList = [1];
      this.total = 15;
      this.loading = false;
      // expertList(this.queryParams).then((response) => {
      //   this.dataList = response.data.data;
      //   this.total = response.data.count;
      //   this.loading = false;
      // });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page_num = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleClick() {
      this.$nextTick(() => {
        this.$refs["tableRef"].doLayout();
      });
    },
    handleExamine(id) {
      this.$router.push({
        path: "/dataAudit/achievementExamine",
        query: { id },
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 新增视频按钮操作 */
    handleAdd(row) {
      this.reset();
      this.open = true;
      this.title = "添加视频";
    },
    // 表单重置
    reset() {
      this.form = {
        type: "1",
        file: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // aboutAdd(this.form).then((response) => {
          //   this.$modal.msgSuccess("新增成功");
          //   this.open = false;
          //   this.getList();
          // });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(id) {
      this.$modal
        .confirm('是否确认删除成果编号为"' + id + '"的数据项？')
        .then(function () {
          return tenantDelete({ id });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
  created() {
    this.getList();
  },
};
</script>