<template>
  <div class="app-container">
    <el-card>
      <el-row :gutter="6">
        <el-col :xs="24" :md="4">
          <el-select v-model="listQuery.qtask" placeholder="所属任务" @change="handleFilter" clearable style="width: 100%;">
            <el-option
              v-for="item in taskOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-col>
        <el-col :xs="24" :md="6">
          <el-input
            v-model="listQuery.search"
            placeholder="资质/服务"
            style="width: 100%;"
            class="filter-item"
            @keyup.enter.native="handleFilter"
          />
        </el-col>
        <el-col :xs="24" :md="6">
          <el-button
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >搜索
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            icon="el-icon-refresh-left"
            @click="resetFilter"
          >重置
          </el-button>
        </el-col>
      </el-row>
    </el-card>
    <el-card style="margin-top: 10px">
      <el-table
        v-loading="listLoading"
        :data="list.results"
        style="width: 100%;"
        border
        fit
        stripe
        highlight-current-row
        max-height="700"
        ref="filterTable"
      >
        <el-table-column type="index" width="50"/>
        <el-table-column label="资质名称" prop="quali_name">

        </el-table-column>
        <el-table-column label="能力文件" prop="afield_name">
          <template slot-scope="scope">
            <el-link :href="scope.row.file" target="_blank" type="primary">{{scope.row.afield_name }}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="能力类型" prop="atype_name">
        </el-table-column>
        <el-table-column label="操作类型" prop="action">
        </el-table-column>
        <el-table-column label="所属单位" prop="belong_dept"></el-table-column>
        <el-table-column label="创建日期">
          <template slot-scope="scope">{{scope.row.create_time.substring(0, 10)}}</template>
        </el-table-column>
        <el-table-column label="变更日期">
          <template slot-scope="scope">{{scope.row.update_time.substring(0, 10)}}</template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-link
              v-if="checkPermission(['qaction_confirm'])"
              type="warning"
              size="small"
              icon="el-icon-s-promotion"
              @click="handleDelete(scope)"
            >删除
            </el-link>
            <el-link
              v-if="checkPermission(['qaction_confirm'])"
              type="primary"
              size="small"
              icon="el-icon-s-promotion"
              @click="handleCheck(scope)"
            >审核
            </el-link>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="list.count > 0"
        :total="list.count"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.page_size"
        @pagination="getList"
      />
    </el-card>
    <el-drawer
      title="我是标题"
      :visible.sync="drawer"
      :direction="rtl"
    >
      <span>我来啦!</span>
    </el-drawer>
  </div>

</template>

<script>
  import {getOrgList} from "@/api/org";
  import {getCMAGroup} from "@/api/cma";
  import { qactionMy,getQtask,qactionDelete,qactionConfirm,qactionItem } from "@/api/ability";
  import checkPermission from "@/utils/permission";
  import Pagination from "@/components/Pagination";

  export default {
    components: {Pagination},
    name: "qactionMy",
    data() {
      return {
        list: {count: 0},
        listQuery: {
          page: 1,
          page_size: 20,
          qtask: '',
          search: ''
        },
        org: [],
        drawer:false,
        taskOptions: [],
        listLoading: false,
        dialogVisible: false,
        dialogType: "new",
        typeOptions: {
          'CMA': '',
          'CNAS': '',
          'OTHER': ''
        },
      };
    },
    mounted() {
      this.getList();
      // this.getGroup();
      this.getQtaskList();
    },
    methods: {
      checkPermission,
      getList() {
        this.listLoading = true;
        qactionMy(this.listQuery).then((response) => {
          if (response.data) {
            this.list = response.data;
          }
          this.listLoading = false;
        });
      },
      getQtaskList() {
        getQtask().then((response) => {
          if (response.data) {
            this.taskOptions = response.data.results;
          }
        })
      },
      getGroup() {
        getOrgList({ can_supervision: true }).then((res) => {
          this.org = res.data;
        });
      },
      handleFilter() {
        this.getList();
      },
      resetFilter() {
        this.listQuery.qtask = '';
        this.listQuery.search = '';
      },
      handleDelete(scope) {
        this.$confirm("确认删除?", "警告", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "error",
        })
          .then(async () => {
            await qactionDelete(scope.row.id);
            this.getList();
            this.$message({
              type: "success",
              message: "成功删除!",
            });
          })
          .catch((err) => {
          });
      },
      handleCheck(scope){
        this.$confirm("确认审核通过?", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(async () => {
            await qactionConfirm(scope.row.id);
            this.getList();
            this.$message({
              type: "success",
              message: "操作成功!",
            });
          })
          .catch((err) => {
          });
      },
    },
  }
</script>

<style scoped>

</style>

