<template>
  <div>
    <!-- :oldFormPath="{edit:'HManagement/salesForecastTemplate/modules'}" -->
    <basicDetails
        ref="details"
        :titleText="`提报单号:${mainData.billnum}`"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20220908134403"
        idname="sa_salesforecastbillid"
        :tabs="['项目产品清单']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <!-- <el-button 
          size="mini" 
          class="inline-16"
          @click="addBuill(mainData)"
          v-if="tool.checkAuth($route.name,'create_sales')" 
          :disabled="mainData.status == '结束' || new Date().valueOf() > new Date(mainData.enddate).valueOf()"
        >提交</el-button> -->

      </div>
      <div slot="slot0">
        <el-row :gutter="20">
          <el-col :span="24">
            <project :mainData="mainData" @queryProduct="queryProduct" ref="project"></project>
          </el-col>
          <el-col :span="24">
            <div style="border-bottom:1px solid #f1f2f3;margin-bottom:16px"></div>
          </el-col>
          <el-col :span="24">
            <product  :mainData="mainData" ref="prod" @onSuccess='queryMainData' @discountrateSet="discountrateSet"></product>
          </el-col>
        </el-row>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo'
import project from './project'
import product from './product'

export default {
  name: "detail",
  data() {
    return {
      drawer:false,
      mainData:{},
      mainAreaData:{},
      detailInfo:{},
      sa_salesforecastprojectid:'',
      sa_projectid:""
    }
  },
  components:{
    BaseInfo,
    project,
    product
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20220914104603,
        "content": {
          "sa_salesforecastbillid":this.$route.query.id
        }
      })
      this.mainData = res.data[0]
      this.changeDataStructure()
      this.$refs['project'].listData(id)
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
        {label:'提报要求',value:this.mainData.remarks},
        {label:'提报类型',value:this.mainData.isrepeat === 1 ?'月度提报':'单次提报'},
        {label:'提报开始时间',value:this.mainData.periodstart.split(' ')[0]},
        {label:'提报截止时间',value:this.mainData.periodend.split(' ')[0]},
        {label:'预测金额(元)',value:this.mainData.sumamount},
        {label:'提报人',value:this.mainData.createby},
        {
          label:'状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '待提报':
                style = {color:'#3874f6'}
                break;
              case '提报中':
                style = {color:'#52c41a'}
                break;
              case '已提报':
                style = {color:'#333333'}
                break;
              default:
                break;
            }
            return style
          }
        },
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      console.log(id,"翻页获取的id")
      this.$router.replace({path:'/product_detail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    queryProduct (id,discountrate,sa_salesforecastprojectid) {
      discountrate = Math.round((discountrate * 100)*100) /100
      this.$refs['prod'].listData(id,discountrate)
      this.sa_salesforecastprojectid = sa_salesforecastprojectid
      this.sa_projectid = id
      console.log(sa_salesforecastprojectid,'sa_salesforecastprojectid')
    },
    async discountrateSet(val){
      console.log(val,"新的折扣")
      val = val / 100
      const res = await this.$api.requested({
        "id": 20220913154403,
        "content": {
          "sa_salesforecastmodelid":this.mainData.sa_salesforecastmodelid,
          "sa_salesforecastbillid":this.mainData.sa_salesforecastbillid,
          "sa_projectids": [{
            "sa_salesforecastprojectid":this.sa_salesforecastprojectid,
            "sa_projectid":this.sa_projectid,
            "discountrate":val
          }]
        }
      })
      this.tool.showMessage(res,()=>{
        this.queryMainData()
      })
    }
  },
  mounted () {
    this.queryMainData()
  },
  created() {
  }
}
</script>

<style scoped>

</style>