<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.billno"
        formPath="QuotedPrice"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221020165103"
        delApiId="20221020165503"
        idname="sa_quotedpriceid"
        ownertable="sa_quotedprice"
        :statusCheck="[{key:'status',value:'审核'},{key:'status',value:'提交'}]"
        :tags="[]"
        :tabs="['产品清单','详细信息','历史报价']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
        <!-- 使用此插槽可不传[tags] -->
        <!-- :tabs="['经销商团队','代理区域','营销类别','账户余额']" -->
      </div>
      <div slot="customOperation">
        <!-- 此区域提供了自定义操作按钮 -->
        <submit_to class="inline-16" v-if="tool.checkAuth($route.name,'submit') && mainData.status === '新建'" :disabled="disabled" :sa_quotedpriceid="mainData.sa_quotedpriceid" @onSubmit="onSuccess"></submit_to>
        <toVoid class="inline-16" v-if="tool.checkAuth($route.name,'toVoid') && mainData.status === '新建'" :disabled="disabled" :data="mainData.sa_quotedpriceid" ></toVoid>
        <examine_to class="inline-16" v-if="tool.checkAuth($route.name,'toExamine') && mainData.status === '提交'" :disabled="disabled" :sa_quotedpriceid="mainData.sa_quotedpriceid" @onExamine="onSuccess"></examine_to>
        <deApprove class="inline-16" v-if="tool.checkAuth($route.name,'deApprove') && mainData.status !== '新建'" :disabled="disabled" :data="mainData" @onDeApprove="onSuccess"></deApprove>
        <copyTo class="inline-16" v-if="tool.checkAuth($route.name,'copyTo') " :data="mainData.sa_quotedpriceid" :disabled="disabled"></copyTo>
      </div>
      <div slot="slot1" class=" normal-panel">
        <detailed :data="mainData"  v-if="flag"></detailed>
      </div>
      <div slot="slot0" class=" normal-panel">
        <productInventory ref="productList" :data="mainData" v-if="flag"></productInventory>
      </div>
      <div slot="slot2" class=" normal-panel">
        <historicalQuotation :data="mainData" v-if="flag"></historicalQuotation>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailed from './modules/detailed/index'
import contacts from './modules/contacts/list'
import address_manage from './modules/addressManage/list'
import submit_to from './components/submitTo'
import examine_to from './components/examineTo'
import project_change from './modules/projectChange/index'
import customer_assocalated from './modules/customerAssociated/index'
import productInventory from './modules/productInventory/index'
import toVoid from './components/toVoid'
import historicalQuotation from './modules/historicalQuotation/index'
import copyTo from "@/SDrpManagement/QuotedPrice/detail/components/copyTo";
import deApprove from './components/deApprove'
export default {
  name: "index",
  data(){
    return {
      mainData:[],
      mainAreaData:[],
      disabled:false,
      flag:false,
      totalPrice:0,
      userInfo:JSON.parse(window.sessionStorage.getItem('userInfo'))
    }
  },
  components:{
    detailed,
    contacts,
    address_manage,
    submit_to,
    examine_to,
    project_change,
    customer_assocalated,
    productInventory,
    toVoid,
    historicalQuotation,
    copyTo,
    deApprove
  },
  watch:{
    mainData(val) {
      if (this.mainData.leader.length !== 0){
        if (JSON.parse(window.sessionStorage.getItem('userInfo')).userid === this.mainData.leader[0].userid){
          this.disabled = false
        }else {
          this.disabled = true
        }
      }
      console.log("权限结果",this.disabled)
    }
  },
  methods:{
    async queryMainData(id){
      const res = await this.$api.requested({
        "id": 20221020165203,
        "version":1,
        "content": {
          nocache:true,
          "sa_quotedpriceid":id
        }
      })
      this.mainData = res.data
      /*this.$refs.productList.productData()*/
      this.$nextTick(()=>{
        this.$refs.productList.productData()
      })
      this.productList()

     /* this.changeDataStructure()*/
     /* this.$refs.detailed.detailedList(this.mainData)*/
      this.flag = true
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.flag = false
      this.$router.replace({path:'/quotedPriceDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    changeDataStructure(){
      let that = this
      this.mainAreaData = [
        {
          label:'客户名称',
          value:this.mainData.enterprisename
        },
        {
          label:'项目编号',
          value:this.mainData.projectnum
        },
        {
          label:'项目名称',
          value:this.mainData.projectname
        },
        {
          label:'报价日期',
          value:this.mainData.billdate
        },
        {
          label:'有效期',
          value:this.mainData.begdate?this.mainData.begdate + '至' + this.mainData.enddate:"--"
        },
        {
          label:'总金额(元)',
          value:this.totalPrice.toFixed(2)
        },
        {
          label:'联系人',
          value:this.mainData.contactsname
        },
        {
          label:'手机号',
          value:this.mainData.contactsphonenumber
        },
        {
          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
            
          }
        },
        /*{
          label:'邮箱',
          value:this.mainData.email
        }*/
      ]
    },
    /*产品配置信息*/
    async productList(){
      const res = await this.$api.requested({
        "id": 20221021095503,
        "version":1,
        "content": {
          "sa_quotedpriceid":this.$route.query.id     //sat_notice_classid<=0时 为新增
        }
      })
      this.totalPrice = 0
      res.data.forEach((item)=> {
        this.totalPrice = this.totalPrice + item.price * item.qty
      })
      /*this.queryMainData(this.$route.query.id)*/
      this.changeDataStructure()
    },
    onSuccess(){
      this.queryMainData(this.$route.query.id)

    }
  },
  mounted() {
    this.queryMainData(this.$route.query.id)
  }
}
</script>

<style scoped>

</style>