<template>
  <div class="app-container">
    
    <el-card>
      <el-input v-model="memberName" style="width: 380px" placeholder="请输入内容"></el-input>
     <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      <el-button type="primary" icon="el-icon-search" @click="reset">重置</el-button>
      <el-table
        v-loading="listLoading"
        :data="subinspecttasklist"
       
        border
        fit
        stripe
        highlight-current-row
        max-height="600"
      >
        <el-table-column type="index" width="50" />
         <el-table-column align="center" label="批级任务">
          <template slot-scope="scope">{{ scope.row.inspecttask_.name }}</template>
        </el-table-column>
         <el-table-column align="center" label="开始巡查时间">
          <template slot-scope="scope">{{ scope.row.inspecttask_.start_date }}</template>
        </el-table-column>

        <el-table-column align="center" label="结束巡查时间">
          <template slot-scope="scope">{{ scope.row.inspecttask_.end_date }}</template>
        </el-table-column>
         <el-table-column align="center" label="任务名称">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
         <el-table-column align="center" label="任务状态">
          <template slot-scope="scope">
            {{ scope.row.state }}</template>
        </el-table-column>
         <el-table-column align="center" label="巡查公司数">
          <template slot-scope="scope">{{ scope.row.depts_count }}</template>
        </el-table-column >
           <el-table-column align="center" 
     label="组长">
          <template slot-scope="scope" >
           <span v-for="item in scope.row.members" v-bind:key="item.member">
           
            <el-tag v-if="item.type=='组长'" effect="plain">{{
                item.member__name
              }}</el-tag>
            </span>
            </template>
        </el-table-column>
        
       
      

        <el-table-column
          align="center"
         label="操作"
          width="200px"
          fixed="right"
        >
       
          <template slot-scope="scope">
            <el-link @click="handleClick(scope)"   type="primary">执行</el-link>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    
  </div>
</template>
<script>
import { getsubinspecttaskselflist} from "@/api/subinspecttask";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { getDictList, getDictTypeList } from "@/api/dict";
const defaultinspectTable = {
  name: "",
  require: "",
  type: null,
  sortnum: null,
};
export default {
  components: { Pagination, Treeselect },
  data() {
    return {
     subinspecttasklist:[],
      listLoading: true,
      dialogVisible: false,
      memberName:"",
      memberlist:[],
     
    };
  },
  computed: {},
  watch: {
    filterOrgText(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getList();
  },
  methods: {
    checkPermission,

    

    getList() {
      this.listLoading = true;
      getsubinspecttaskselflist().then((response) => {
        if (response.data) {
          this.subinspecttasklist = response.data;
         
         
        }
        this.listLoading = false;
      });
       
    },
    
   handleClick(scope){
       this.$router.push({name: "myTaskdos", params: { id: scope.row.id,leaders:scope.row.members }, })
      
   },

    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    
      search() {
        for(var i=0;i<this.subinspecttasklist.length;i++ )
          {
             for(var j=0;j<this.subinspecttasklist[i].members.length;j++ )
          {
            
             if(this.subinspecttasklist[i].members[j].member__name==this.memberName && this.subinspecttasklist[i].members[j].type=="组长")
             {
               console.log(this.memberName)
              
               this.memberlist.push(this.subinspecttasklist[i],)
                console.log( this.memberlist)
             }

          }
          
          }
          this.subinspecttasklist=this.memberlist;
          this.memberlist=[];
      },
      reset(){

        this.getList();
      }

   
  },
};
</script>
