<template>
  <div class="contract-base-info">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
      :style="formStyle"
    >
      <el-form-item label="项目名称" prop="projectInformationId">
        <el-select
          v-model="ruleForm.projectInformationId"
          placeholder="请选择项目名称"
          clearable
          @change="projectChange"
        >
          <el-option
            v-for="item in entryNameList"
            :key="item.projectInformationId"
            :label="item.projectName"
            :value="item.projectInformationId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="核心企业名称">
        <el-input
          v-model="ruleForm.enterprise"
          placeholder="请输入核心企业名称"
          disabled
        />
      </el-form-item>
      <el-form-item label="供应商（主体）名称">
        <el-input
          v-model="ruleForm.mainEnterprise"
          placeholder="请输入供应商（主体）名称"
          disabled
        />
      </el-form-item>
      <el-form-item label="贸易平台">
        <el-input
          v-model="ruleForm.platformName"
          placeholder="请输入贸易平台"
          disabled
        />
      </el-form-item>
      <el-form-item label="业务编号">
        <el-input
          v-model="ruleForm.businessNumber"
          placeholder="请输入业务编号"
          disabled
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { salesContractManagementGetCompletedSales } from '@/api/myTrade/purchaseContractManagement/purchaseContractManagement'
export default {
  components: {

  },
  props: {
    'formStyle': {
      type: Object,
      default: () => {}
    },
    info: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        enterprise: '',
        mainEnterprise: '',
        platformName: '',
        businessNumber: '',
        projectInformationId: '',
        supplierId: '',
        id: '',
        platformId: '',
        projectName: ''
      },
      rules: {
        projectInformationId: [{ required: true, message: '请选择项目名称', trigger: 'change' }]
      },
      entryNameList: []
    }
  },
  watch: {
    'info.mathId': {
      handler(newV) {
        if (newV) {
          Object.keys(this.ruleForm).forEach(key => {
            this.ruleForm[key] = this.info.basicInfo[key]
          })
          window.$bus.$emit('detailChange', { mainEnterprise: this.ruleForm.mainEnterprise, platformName: this.ruleForm.platformName, businessNumber: this.ruleForm.businessNumber })
        }
      },
      immediate: true
    }
  },
  created() {
    this.salesContractManagementGetCompletedSales()
  },
  methods: {
    salesContractManagementGetCompletedSales() {
      salesContractManagementGetCompletedSales().then(response => {
        this.entryNameList = response.data
      })
    },
    projectChange() {
      this.invoiceInformation = this.entryNameList.filter(item => item.projectInformationId === this.ruleForm.projectInformationId)[0] || {}
      this.ruleForm.enterprise = this.invoiceInformation.enterprise
      this.ruleForm.mainEnterprise = this.invoiceInformation.mainEnterprise
      this.ruleForm.businessNumber = this.invoiceInformation.businessNumber
      this.ruleForm.platformName = this.invoiceInformation.platformName
      this.ruleForm.supplierId = this.invoiceInformation.supplierId
      this.ruleForm.platformId = this.invoiceInformation.platformId
      this.ruleForm.projectName = this.invoiceInformation.projectName
      window.$bus.$emit('change', { mainEnterprise: this.ruleForm.mainEnterprise, platformName: this.ruleForm.platformName, businessNumber: this.ruleForm.businessNumber })
    },
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleFormRef.validate(valid => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        })
      })
    }
  }
}
</script>

  <style lang="scss" scoped>
  .contract-base-info {
  }
  </style>
