<template>
  <div class="orderclue">
    <list ref="list" :teamList="teamList">
      <template v-slot:detail="scope">
          <p @click="detail(scope.data)" v-if="tool.checkAuth($route.name,'read')">详情</p>
      </template>
      <template v-slot:edit="scope">
          <edit :detailInfo="scope.data" 
                @updataList="updataList"
                :arealist="arealist" 
                v-if="userInfo.name == scope.data.data.leadername && userInfo.name == scope.data.data.leadername ? scope.data.data.status == '待跟进' || scope.data.data.status == '跟进中' : ''"></edit>
      </template>
      <template v-slot:goUp="scope">
        <follow :detailInfo="scope.data" 
                @updataList="updataList" 
                v-if="userInfo.name == scope.data.data.leadername && userInfo.name == scope.data.data.leadername ? scope.data.data.status == '待跟进' || scope.data.data.status == '跟进中' : ''"></follow>
      </template>
      <template v-slot:move="scope">
        <move :data="[scope.data.data.sat_orderclueid]" 
              @updataList="updataList" 
              :teamList="teamList"  
              v-if="userInfo.isAuth == 1 && userInfo.isAuth == 1 ? scope.data.data.status == '待跟进' || scope.data.data.status == '跟进中' : ''"></move>
      </template>
    </list>
  </div>
</template>

<script>
import Header from '@/SManagement/archives_upload/components/Header'
import list from '@/SManagement/orderclue/components/list'
import add from '@/SManagement/orderclue/components/add'
import edit from '@/SManagement/orderclue/components/edit'
import follow from '@/SManagement/orderclue/components/follow'
import move from '@/SManagement/orderclue/components/move'
import exportBtn from '@/SManagement/orderclue/components/export'

export default {
  name: 'index',
  data() {
    return {
      teamList:[],
      arealist:[],
      userInfo: ''
    };
  },
  provide() {
    return {
      arealist:() => this.arealist
    }
  },
  components:{ Header , list , add , exportBtn , edit , follow , move , add },
  computed:{
  },
  watch:{
  },
  created() {
    this.getTeamList()
    this.query_arealist()
    this.queryUserInfo()
  },
  methods: {
    detail(data) {
      this.$router.push({
        path:'/orderclue_detail',
        query: {
          id:data.data.sat_orderclueid
        }
      })
    },
    updataList() {
      this.$refs.list.param.content.pageNumber = 1
      this.$refs.list.getList()
    },
    async getTeamList () {
      let res = await this.$api.requested({
        "classname": "sale.team.team",
        "method": "query_teamList",
        "content": {
          "pageNumber": 1,
          "pageSize": 99999,
          "where": {
              "condition": ""
          }
        }
      })
      this.teamList = res.data
    },
    async query_arealist() {
      const res = await this.$api.requested({
        "classname": "system.tools",
        "method": "query_arealist",
        "content": {
        }
      })
      console.log(res.data);
      
      this.arealist = this.tool.createMenu(res.data)
    },
    async queryUserInfo() {
      let res = await this.$api.requested({
        "classname": "common.usercenter.usercenter",
        "method": "queryUserMsg",
        "content": {
        }
      })
      this.userInfo = {
        isAuth : res.data.agenthr.isleader,
        name: res.data.name
      }
      window.sessionStorage.setItem('userInfo',JSON.stringify(this.userInfo))
    }
  },
};
</script>

<style scoped>
  .orderclue {
    height: 100%;
  }
</style>
