<template>
  <div>
    <div  class="my-tabs" style="padding:0 16px;margin-top:16px">
      <el-tabs v-model="editableTabsValue" type="card" @tab-click="onChange">
        <el-tab-pane
            v-for="(item, index) in editableTabs"
            :key="item.name"
            :label="item.title"
            :name="item.name"
        >
        </el-tab-pane>
      </el-tabs>
    </div>
    <basicLayout 
      style="padding-top:0 !important"
      ref="basicLayout" 
      formPath="projectChange" 
      tableName="projectTable" 
      idName="sa_projectid" 
      :apiId="{query:20221020143502,del:20221020144302}" 
      :options="options">
      <div slot="custom">
        <time-select @clearSelect="clearTime" @timeChange="timeChange"></time-select>
      </div>
      <template v-slot:tbList="scope">
        <div 
          v-if="scope.data.column.columnname == 'grade'"
        >{{projectLead&&projectLead.find(item => item.rowindex==scope.data.column.data[scope.data.column.columnname]).value}}</div>
        <div v-else-if="scope.data.column.data[scope.data.column.columnname] && scope.data.column.columnname != 'operation'">{{scope.data.column.data[[scope.data.column.columnname]]}}</div>
        <div v-else>
          --
        </div>
      </template>
      <template v-slot:tbOpreation="scope">
        <el-button 
          size="mini" 
          type="text" 
          class="inline-16" 
          @click="$router.push({path:'/projectChangeDetail',query:{id:scope.data.data.sa_projectid,rowindex:scope.data.data.rowindex}})">详 情
        </el-button>
        <Del 
          :id="scope.data.data.sa_projectid" 
          :nameId="20221020144302" 
          nameKey="sa_projectids" 
          @deleteSuccess="$refs.basicLayout.listData()"
          class="inline-16"
          v-if="tool.checkAuth($route.name,'delete')"
        />
      </template>
    </basicLayout>
  </div>
</template>

<script>
import Del from './components/del'
import TimeSelect from '@/SManagement/submitedit_one/components/TimeSelect'
export default {
  components:{Del,TimeSelect},
  name: "index",
  provide () {
    return {
      enterpriseList:() => this.enterpriseList,
      projectType:() => this.projectType,
      projectLead:() => this.projectLead,
      projectPanl:() => this.projectPanl
    }
  },
  data() {
    return {
      editableTabsValue:'0',
      /* 企业列表 */
      enterpriseList:'',
      /* 企业列表 */
      projectType:'',
      projectLead:'',
      projectPanl:'',
      options:[],
      editableTabs: [{
        title: '全部',
        name: "0",
      }, {
        title: '我负责的',
        name: "1",
      }, {
        title: '我参与的',
        name: "2",
      }, {
        title: '我下属负责的',
        name: "3",
      }, {
        title: '我下属参与的',
        name: "4",
      }],
    }
  },
  created () {
    this.getProjectPanl()
    this.getEnterprise()
    this.getSysetms()
  },
  methods: {
    /* 获取联系人:负责人列表 */
    async getAccount () {
      let res = await this.$api.requested({
        "id": "20221018150602",
        "content": {
            "sys_enterpriseid": 1,
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": ""
            }
        }
      })
    },
    async getSysetms () {
      /* 获取项目类型 */
      let res = await this.$store.dispatch('optiontypeselect','projecttype')
      this.projectType = res.data
      /* 获取项目等级 */
      let res2 = await this.$store.dispatch('optiontypeselect','projectgrade')
      this.projectLead = res2.data
      console.log(this.projectLead);
      
    },
    /** 获取公司数据 */
    async getEnterprise () {
      let res = await this.$api.requested({
        "id": 20221021095802,
        "content": {
            "pageNumber": 1,
            "pageSize": 99999,
            "where": {
                "condition": ""
            }
        },
      })
      this.enterpriseList = res.data
    },
    /* 获取项目模板 */
    async getProjectPanl () {
      let res = await this.$api.requested({
        "id": "20221019085604",
        "content": {
            "pageNumber": 1,
            "pageSize": 99999999,
            "where":{
                "condition":""
            }
        }
      })
      this.projectPanl = res.data
    },
    queryData(id){
      console.log("执行")
      this.$refs['basicLayout'].param.content.type = id
      this.$refs['basicLayout'].param.content.isExport = false
      this.$refs['basicLayout'].listData()
    },
    onChange (val) {
      console.log(val)
      this.$refs['basicLayout'].param.content.type = val.name
      this.$refs['basicLayout'].param.content.isExport = 0
      this.$refs['basicLayout'].listData()
    },
    clearTime () {
      this.$refs['basicLayout'].param.content.where.startdate = ''
      this.$refs['basicLayout'].param.content.where.enddate = ''
      this.$refs['basicLayout'].listData()
    },
    timeChange (time) {
      this.$refs['basicLayout'].param.content.where.startdate = time[0]
      this.$refs['basicLayout'].param.content.where.enddate = time[1]
      this.$refs['basicLayout'].listData()
    }
  },
  mounted () {
    this.queryData(1)
  }
}
</script>

<style scoped>

</style>