<template>
  <div>
    <headerTitle title="基本信息"></headerTitle>
    <el-form
      label-width="120px"
      ref="form"
      :model="form"
      :rules="rules"
      style="margin-top: 30px"
    >
      <el-row>
        <el-col :span="8">
          <el-form-item label="客户名称：" prop="contactName">
            {{ detailData.contactName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="	商机名称：" prop="name">
            {{ detailData.name }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="负责人名称：" prop="responsibleName">
            {{ detailData.responsibleName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="商机来源：" prop="sourceCode">
            {{ detailData.sourceName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
            <el-form-item label="赢单率：" prop="winRate">
              {{detailData.winRate? detailData.winRate + '%' : '' }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预算：" prop="budget">
              {{ detailData.budget? detailData.budget + '万元':'' }}
            </el-form-item>
          </el-col>
        <el-col :span="8">
          <el-form-item label="预计结单日期：" prop="expectedClosingDate">
            {{ detailData.expectedClosingDate }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="商机阶段：" prop="stageCode">
            {{ detailData.stageName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="附件：" prop="files">
            <div v-if="detailData.files && detailData.files?.length">
              <el-link
                v-for="link in detailData.files"
                :key="link.id"
                type="primary"
                :underline="false"
                @click="downloadFile(link)"
              >
                {{ link.name }}</el-link
              >
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="备注：" prop="remark">
            {{ detailData.remark }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <headerTitle title="产品清单"></headerTitle>

    <inventoryTable
    pageName="businessOpportunity"
      v-if="['productionSupervisorApprove1','technicianApprove','techLeaderApprove','productionSupervisorApprove2','salesManagerApprove'].includes(taskDefinitionKey)"
      ref="inventoryTable"
      :taskDefinitionKey=taskDefinitionKey
      :isDeliveryDeadline="false"
      :isGuaranteePeriod="false"
      :isCustomerMark="false"
    ></inventoryTable>

    <inventoryTabledetail
     v-if="!['productionSupervisorApprove1','technicianApprove','techLeaderApprove','productionSupervisorApprove2','salesManagerApprove'].includes(taskDefinitionKey)"
      ref="inventoryTabledetailRef"
      :isDeliveryDeadline="false"
      :isGuaranteePeriod="false"
      :isCustomerMark="false"
    ></inventoryTabledetail>
    <!-- <el-card
      shadow="never"
      header="竞品对手"
      body-style="padding: 22px 20px 0 20px;"
    >
      <ele-pro-table
        ref="table"
        :needPage="false"
        :columns="competAnalysisListcolumns1"
        :datasource="detailData.competAnalysisList"
        row-key="id"
      >
      </ele-pro-table>
    </el-card>
    <el-card
      shadow="never"
      header="关键人信息"
      body-style="padding: 22px 20px 0 20px;"
    >
      <ele-pro-table
        ref="table"
        :needPage="false"
        :columns="partyListcolumns"
        :datasource="detailData.partyList"
        row-key="id"
      >
      </ele-pro-table>
    </el-card> -->
  </div>
</template>

<script>
  import { getDetail } from '@/api/bpm/components/saleManage/businessOpportunity';
  import { getFile } from '@/api/system/file';
  import dictMixins from '@/mixins/dictMixins';
  import inventoryTable from '@/views/bpm/handleTask/components/contractBook/inventoryTable.vue';
  import inventoryTabledetail from '@/views/bpm/handleTask/components/contractBook/inventoryTabledetail.vue';

  export default {
    mixins: [dictMixins],
    components: {
      inventoryTable,
      inventoryTabledetail
    },
    props: {
      businessId: {
        default: ''
      },
      taskDefinitionKey: {
        default: ''
      }
    },
    data() {
      return {
        visible: false,
        title: '详情',
        row: {},
        activeName: 'base',
        form: {},
        rules: {},
        detailData: {},
        competAnalysisListcolumns1: [
          {
            prop: 'name',
            label: '竞争对手名称',
            // sortable: 'custom',
            showOverflowTooltip: true,
            align: 'center',
            width: 300
          },
          {
            prop: 'analysis',
            label: '竞品分析',
            showOverflowTooltip: true,
            align: 'center'
          }
        ],
        partyListcolumns: [
          {
            prop: 'linkName',
            label: '关键人名称',
            // sortable: 'custom',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          },
          {
            prop: 'linkMobilePhone',
            label: '联系方式',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          },
          {
            prop: 'linkPost',
            label: '职位',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          },
          {
            prop: 'attitudeName',
            label: '态度',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          },
          {
            prop: 'influenceName',
            label: '影响力',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          },
          {
            prop: 'goal',
            label: '项目目标/期望',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          }
        ],
        competAnalysisListcolumns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            width: 200,
            prop: 'productName',
            label: '名称',
            slot: 'productName'
          },
          {
            width: 120,
            prop: 'productCode',
            label: '编码',
            slot: 'productCode'
          },
          {
            width: 200,
            prop: 'productCategoryName',
            label: '类型',
            slot: 'productCategoryName'
          },
          {
            width: 160,
            prop: 'productBrand',
            label: '牌号',
            slot: 'productBrand'
          },
          {
            width: 120,
            prop: 'modelType',
            label: '型号',
            slot: 'modelType'
          },
          {
            width: 120,
            prop: 'specification',
            label: '规格',
            slot: 'specification'
          },

          {
            width: 160,
            prop: 'singlePrice',
            label: '单价',
            slot: 'singlePrice'
          },
          {
            width: 120,
            prop: 'totalCount',
            label: '数量',
            slot: 'totalCount'
          },
          {
            width: 120,
            prop: 'totalPrice',
            label: '销售总金额',
            slot: 'totalPrice',
            formatter: (_row, _column, cellValue) => {
              return _row.totalPrice? _row.totalPrice + '元':'';
            }
          },
          {
            width: 120,
            prop: 'measuringUnit',
            label: '计量单位',
            slot: 'measuringUnit'
          },
          {
            width: 120,
            prop: 'deliveryDays',
            label: '交期(天)',
            slot: 'deliveryDays'
          },
          {
            width: 200,
            prop: 'guaranteePeriod',
            label: '质保期',
            slot: 'guaranteePeriod',
            formatter: (_row, _column, cellValue) => {
              return (_row.guaranteePeriod||'') + _row.guaranteePeriodUnitName;
            }
          },
          // {
          //   width: 120,
          //   prop: 'guaranteePeriodUnitCode',
          //   label: '',
          //   slot: 'guaranteePeriodUnitCode'
          // },
          {
            width: 240,
            prop: 'customerReqFiles',
            label: '客户需求',
            slot: 'customerReqFiles'
          },
          {
            width: 120,
            prop: 'technicalAnswerName',
            label: '技术答疑人',
            slot: 'technicalAnswerName'
          },
          {
            width: 220,
            prop: 'technicalParams',
            label: '技术参数',
            slot: 'technicalParams'
          },
          {
            width: 240,
            prop: 'technicalDrawings',
            label: '技术图纸',
            slot: 'technicalDrawings',
            formatter: (_row, _column, cellValue) => {
              return (_row.guaranteePeriod||'') + _row.guaranteePeriodUnitName;
            }
          },
          {
            width: 220,
            prop: 'remark',
            label: '备注',
            slot: 'remark'
          }
        ]
      };
    },
    created() {
      this.getDetailData(this.businessId);
      console.log(this.taskDefinitionKey,'11111111111111111');
    },
    methods: {
      downloadFile(file) {
        getFile({ objectName: file.storePath }, file.name);
      },
      async getDetailData(id) {
        this.loading = true;
        const data = await getDetail(id);

        this.loading = false;
        if (data) {
          this.detailData = data;
          this.$refs.inventoryTable &&
            this.$refs.inventoryTable.putTableValue(data);
          this.$refs.inventoryTabledetailRef &&
            this.$refs.inventoryTabledetailRef.putTableValue(data);
        }
      },
      getTableValue() {
        return this.$refs.inventoryTable.getTableValue();
      }
    }
  };
</script>

<style scoped lang="scss">
  .ele-dialog-form {
    .el-form-item {
      margin-bottom: 10px;
    }
  }
</style>
