<template>
  <div class="app-container part-container">
    <template v-if="isInfo">
      <!-- 企业信息 -->
      <div class="view-content">
        <Info :companyInfo="companyInfo" />
      </div>
      <!-- 基本信息 -->
      <div class="view-content">
        <BasicIinformation
          :infos="infos"
          :companyType="companyType"
          :nowedit="nowedit"
          :noweditis="1"
          @focus-nowedit="focusNowedits"/>
      </div>
      <!-- 发包属性 -->
      <div class="view-content">
        <ElCardinput
          :infos="infos"
          title="发包属性"
          field="companyAttribute"
          :projectDetails="infos.companyAttribute"
          :nowedit="nowedit"
          :noweditis="2"
          @focus-nowedit="focusNowedits" />
      </div>
      <!-- 主营业务 -->
      <div class="view-content">
        <ElCardinput
          :infos="infos"
          title="主营业务"
          field="mainBusiness"
          :projectDetails="infos.mainBusiness"
          :nowedit="nowedit"
          :noweditis="3"
          @focus-nowedit="focusNowedits" />
      </div>
      <!-- 经营范围 -->
      <div class="view-content">
        <ElCardinput
          :infos="infos"
          title="经营范围"
          field="businessScope"
          :projectDetails="infos.businessScope"
          :nowedit="nowedit"
          :noweditis="4"
          @focus-nowedit="focusNowedits" />
      </div>
    </template>
  </div>
</template>

<script>
import { getDictType } from '@/api/main'
import { customerInfo } from '@/api/detail/party-a/cooperate'
import Info from "./component/info"
import BasicIinformation from "./component/basicIinformation"
import ElCardinput from "./component/elCardinput"
export default {
  name: 'Business',
  props: ['customerIds', 'companyInfo', 'customerInfo'],
  components: {
    Info,
    BasicIinformation,
    ElCardinput
  },
  data() {
    return {
      isInfo:false,
      infos:{},
      projectDetails:'',
      nowedit: -1,
      companyType: {
        companyNaturelist: [],//企业性质
        companyLevellist: [],//企业级别
        isOnlistlist:[
          {
            dictValue: 0,
            dictLabel:'否',
          },
          {
            dictValue: 1,
            dictLabel:'是',
          }
        ],//上市公司
        isMajorlist:[
          {
            dictValue: 0,
            dictLabel:'否',
          },
          {
            dictValue: 1,
            dictLabel:'是',
          }
        ],//局级大客户
        creditLevellist: [],//资信等级
      },
      iscompanyInfo:{}
    }
  },
  watch: {
    "customerIds"(newVal, oldVal) {
      if(newVal){
        this.customerInfos()
      }
    }
  },
  created() {
    this.infos = this.customerInfo
    this.iscompanyInfo = this.companyInfo ? this.companyInfo : {}
  },
  mounted(){
    this.customerInfos()
  },
  methods: {
    async handleQuery() {
      let [type1,type2,type3] = await Promise.all([
        getDictType('company_nature_type'),
        getDictType('company_level_type'),
        getDictType('credit_level_type')
      ])
      if(type1.code==200){
        type1.data.forEach(item => {
          this.companyType.companyNaturelist.push({dictLabel:item.dictLabel,dictValue:item.dictLabel})
        })
      }
      if(type2.code==200){
        type2.data.forEach(item => {
          this.companyType.companyLevellist.push({dictLabel:item.dictLabel,dictValue:item.dictLabel})
        })
      }
      if(type3.code==200){
        type3.data.forEach(item => {
          this.companyType.creditLevellist.push({dictLabel:item.dictLabel,dictValue:item.dictLabel})
        })
      }
      this.isInfo = true
    },

    customerInfos(){
      this.isInfo = false
      customerInfo(this.customerIds).then(res=>{
        this.$nextTick(()=>{
          this.infos = res.data
          this.handleQuery()
        })
      })
    },
    focusNowedits(e){
      this.nowedit = e
    }
  }
}
</script>

<style lang="scss" scoped>
.part-container{
  margin: 0;
  padding: 0;
  .view-content{
    margin-top: 16px;
  }
}
</style>
