<template>
  <el-tabs type="border-card" style="min-height: 600px;" v-model="activeName">
    <el-tab-pane name="audit">
      <span slot="label"><i class="el-icon-date"></i> 待审核</span>
      <el-table v-loading="loading" :data="this.tasks" style="height: 100%">
        <el-table-column label="项目名称" align="center" key="projectName" prop="projectName"
                         :show-overflow-tooltip="true"/>
        <el-table-column label="测试类型" align="center" key="testType" width="100" prop="testType"
                         :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ findLabelValueByProp(tasktypelist, scope.row.testType, 'dictValue', 'dictLabel')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" key="contactName" prop="contactName"
                         :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column label="工期" align="center" key="period" prop="period"
                         :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{scope.row.period}}天</span>
          </template>
        </el-table-column>
        <el-table-column label="金额" align="center" key="price" prop="price"  :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{scope.row.price  | currency('￥')}}</span>
          </template>
        </el-table-column>
        <!--          <el-table-column label="任务状态" align="center" key="status" prop="status" width="100"-->
        <!--                           :show-overflow-tooltip="true">-->
        <!--            <template slot-scope="scope">-->
        <!--           <audit-status :status="scope.row.status"></audit-status>-->
        <!--            </template>-->
        <!--          </el-table-column>-->
        <el-table-column label="创建时间" align="center" key="createTime" prop="createTime" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" key="applyId" prop="applyId" >
          <template slot-scope="scope">
              <span><el-button  size="mini"  type="text"
                                icon="el-icon-edit" @click="auditTask(scope.row.applyId)">审核</el-button></span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <crowdsource-audit ref="crowdsourceAudit"  @closeDialog="closeDialog" :list="tasktypelist" ></crowdsource-audit>
    </el-tab-pane>
    <el-tab-pane name="tobeExpired" label="即将到期">
      <span slot="label"><i class="el-icon-date"></i>即将到期的任务</span>
      <crowdsource-list :list1="tasktypelist" type="tobeExpired" v-if="activeName=='tobeExpired'" ref="tobeExpired"></crowdsource-list>
    </el-tab-pane>
    <el-tab-pane name="allTask">
      <span slot="label"><i class="el-icon-date"></i>所有任务</span>
      <crowdsource-list :list1="tasktypelist" type="allTask" v-if="activeName=='allTask'" ref="allTask"></crowdsource-list>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
  import {listApply} from "@/api/crowdsource/crowdsource";
  import CrowdsourceAudit from "@/views/components/CrowdsourceAudit";
  import AuditStatus from "@/views/components/enum/AuditStatus";
  import TestType from "@/views/components/enum/TestType";
  import CrowdsourceList from "@/views/components/CrowdsourceList";
  import store from "@/store";
  import mixin from '@/mixin/index.js'
  export default {
    name: "CrowdsourceManage",
    components: {TestType, CrowdsourceAudit, AuditStatus, CrowdsourceList},
    mixins: [mixin],
    data() {
      return {
        open:false,
        // 遮罩层
        loading: true,
        applyId:0,
        activeName: 'audit',
        tasks: [],
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          testType: undefined,
          feeType: undefined
        },
      }
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        this.list();
      },
      list() {
        listApply(this.queryParams).then(response => {
            this.tasks = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        )
      },
      auditTask(applyId) {
        this.$refs.crowdsourceAudit.openDialog(applyId);
      },
      closeDialog(){
        this.loading = true;
        this.list();
      }
    },
    watch: {
      activeName(newVal, oldVal) {
        store.commit('SET_ACTIVENAMEMANAGER', newVal);
      }
    },
    computed: {},
    created() {
      this.list();
      if (store.getters.activeNameManager == 'audit' || store.getters.activeNameManager == 'tobeExpired' || store.getters.activeNameManager == 'allTask')
         this.activeName = store.getters.activeNameManager;
    }
  }
</script>

<style scoped>
  .type {
    color: #1890FF;
    font-weight: bold;
    font-size: 14px;
    margin-right: 10px;
  }

  .tip {
    font-size: 13px;
    color: gray;
  }

  .el-link {
    margin-right: 10px;
    font-size: 13px;
  }

  .active {
    color: #1890FF;
  }

  .el-row {
    margin-bottom: 5px;
    display: flex;
    flex-wrap: wrap
  }

  .el-card {
    min-width: 100%;
    height: 100%;
    margin-right: 20px;
    transition: all .5s;
  }
</style>
