<template>
  <div class="business-situation">
    <cy-info-title type="center">企业经营情况</cy-info-title>
    <el-form
      :model="ruleForm"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item label="上游采购单据（请提供2家合作企业）" style="width: 100%;">
        <div class="table-box">
          <el-table
            :data="upstreamTableData"
            style="width: 100%"
          >
            <el-table-column prop="date" label="合作企业名称">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.name"
                  disabled
                />
              </template>
              <!-- <template slot-scope="scope">
                <cy-custom-select
                  :key="key"
                  :value.sync="scope.row.name"
                >
                  <el-option
                    v-for="item in listData"
                    :key="item.corporateName"
                    :label="item.corporateName"
                    :value="item.corporateName"
                  />
                </cy-custom-select>
              </template> -->
            </el-table-column>
            <el-table-column prop="name" label="上游采购单据（请上传验收单、结算单或对账单、发票、近期回款凭证）">
              <template slot-scope="scope">
                <cy-upload
                  :ref="`upfileStorage${scope.$index}`"
                  :upload-params="{
                    fileType: 'enterprise_upstream_documents'
                  }"
                  :file-data="scope.row.fileStorages"
                  default-desc="请上传验收单、结算单或对账单、发票、近期回款凭证"
                  disabled
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form-item>
      <el-form-item label="下游采购单据（请提供2家合作企业）" style="width: 100%;">
        <div class="table-box">
          <el-table
            :data="downstreamTableData"
            style="width: 100%"
          >
            <el-table-column prop="date" label="国央企名称">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.name"
                  disabled
                />
              </template>
              <!-- <template slot-scope="scope">
                <cy-custom-select
                  :key="key"
                  :value.sync="scope.row.name"
                >
                  <el-option
                    v-for="item in listData"
                    :key="item.corporateName"
                    :label="item.corporateName"
                    :value="item.corporateName"
                  />
                </cy-custom-select>
              </template> -->
            </el-table-column>
            <el-table-column prop="name" label="下游采购单据（请上传验收单、结算单或对账单、发票、近期回款凭证）">
              <template slot-scope="scope">
                <cy-upload
                  :ref="`downfileStorage${scope.$index}`"
                  :upload-params="{
                    fileType: 'enterprise_sales_documents'
                  }"
                  :file-data="scope.row.fileStorages"
                  default-desc="请上传验收单、结算单或对账单、发票、近期回款凭证"
                  disabled
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// import { getEnterpriseInspectionInfo } from '@/api/myBusiness/supplierEnterprise'
export default {
  props: {
    businessInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {},
      listData: [],
      key: 0,
      upstreamTableData: [
        // {
        //   name: '',
        //   fileStorages: []
        // },
        // {
        //   name: '',
        //   fileStorages: []
        // }
      ],
      downstreamTableData: [
        // {
        //   name: '',
        //   fileStorages: []
        // },
        // {
        //   name: '',
        //   fileStorages: []
        // }
      ]
    }
  },
  watch: {
    businessInfo: {
      handler(newV) {
        if (newV && Object.keys(newV).length) {
          const { upstreamProcurementDocuments, salesDocumentsInfos } = newV
          this.upstreamTableData = upstreamProcurementDocuments.length ? upstreamProcurementDocuments.filter(item => item.name) : this.upstreamTableData
          this.downstreamTableData = salesDocumentsInfos.length ? salesDocumentsInfos.filter(item => item.name) : this.downstreamTableData
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    // searchClick(val) {
    //   getEnterpriseInspectionInfo({ keyword: val }).then(({ data }) => {
    //     this.listData = data
    //   })
    // },
    // handlerOperate(optionType, { $index }, name) {
    //   if (optionType === 'add') {
    //     this[name].push({
    //       name: '',
    //       fileStorages: []
    //     })
    //   } else {
    //     this[name].splice($index, 1)
    //     this.key += 1
    //   }
    // },
    getParams() {
      const upstreamProcurementDocuments = this.upstreamTableData.map((item, index) => {
        return {
          name: item.name,
          files: this.$refs[`upfileStorage${index}`].getFileLists.map(item => item.id)
        }
      })
      const salesDocumentsInfos = this.downstreamTableData.map((item, index) => {
        return {
          name: item.name,
          files: this.$refs[`downfileStorage${index}`].getFileLists.map(item => item.id)
        }
      })
      return {
        upstreamProcurementDocuments,
        salesDocumentsInfos
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.business-situation {

}
</style>

<style lang="scss">
.business-situation {
  .iconfont {
    font-size: 26px;
  }
}
</style>
