<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="`${mainData.title}`"
        :oldFormPath="{edit:'HManagement/salesForecastTemplate/modules'}"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20220906150203"
        delApiId="20220906150603"
        idname="sa_salesforecastmodelid"
        tags=""
        :tabs="['预测提报记录']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <release v-if="tool.checkAuth($route.name,'release')" :data="mainData" @onSuccess="onSuccess"></release>
        <finish v-if="tool.checkAuth($route.name,'cancel')" :data="mainData" @onSuccess="onSuccess"></finish>
      </div>
      <div slot="slot0" >
        <el-row :gutter="10"> 
          <el-col :span="24">
            <forecastList ref="forecast" @tableRowClick="onTableClick"></forecastList>
          </el-col>
          <el-col :span="24">
            <submitDetail ref="project"></submitDetail>
          </el-col>
        </el-row>
        <!-- <submitDetail ref="submitDetail"></submitDetail> -->
      </div>
      
    </basicDetails>
  </div>
</template>

<script>
import forecastList from './forecastList.vue'
import submitDetail from './project.vue'
import release from './release.vue'
import finish from './finish.vue'

export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{}
    }
  },
  components:{
    forecastList,
    submitDetail,
    finish,
    release
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20220906150303,
        "content": {
          "sa_salesforecastmodelid":this.$route.query.id
        }
      })
      this.mainData = res.data
      // this.$refs['forecast'].listData(this.$route.query.id,1)
      this.changeDataStructure()
    },
    changeDataStructure() {
      this.mainAreaData = [
       {label:'提报要求',value:this.mainData.remarks},
        {label:'提报类型',value:this.mainData.isrepeat == 1 ?'月度提报':'单次提报'},
        {label:'预测金额',value:this.mainData.outamountsum},
        {label:'负责人',value:this.mainData.createby},
        {label:'状态',value:this.mainData.status},
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/salesForecastDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    onTableClick (row) {
      this.$refs['project'].listData(row.sa_salesforecastbillid)
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>