<template>
  <ele-modal
    custom-class="ele-dialog-form long-dialog-form"
    :centered="true"
    v-if="visible"
    :visible.sync="visible"
    :title="title"
    :close-on-click-modal="false"
    :model="isModal"
    width="60%"
    @close="cancel"
  >
    <el-form ref="form" :model="form" label-width="120px">
      <headerTitle title="基本信息">
        <!-- <el-button
                  size="small"
                  type="primary"
                  icon="el-icon-s-grid"
                  class="ele-btn-icon"
                  @click="exportTable"
                >
                 导出
                </el-button> -->
      </headerTitle>
      <el-row>
        <el-col :span="12" style="height: 46px;">
          <el-form-item label="采购计划单名称：" prop="planName">
            <el-link
              type="primary"
              :underline="false"
              @click="openPlanDetail(form)"
            >
              {{ form.planName }}
              </el-link
            >
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item prop="askFile" label="附件：">
            <el-link
              v-if="form.files && form.files !== ''"
              type="primary"
              :underline="false"
              @click="downloadFile(form.files)"
            >
              {{ form.files.name }}</el-link
            >
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="remark" label="备注：">
            {{ form.remark }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <headerTitle title="产品清单" style="margin-top: 15px"></headerTitle>
    <ele-pro-table
      ref="table"
      :needPage="false"
      :columns="columns"
      :toolkit="[]"
      :datasource="form.detailList"
      row-key="id"
    >
    </ele-pro-table>
    <headerTitle title="报价清单" style="margin-top: 15px"></headerTitle>
    <inquiryTable
      :radio="form.winnerId"
      v-for="item in form.supplierList"
      :key="item.supplierId"
      style="margin-top: 15px;"
      status="Detail"
      :obj="item"

    ></inquiryTable>

    <div slot="footer" class="footer">
      <el-button @click="cancel">返回</el-button>
    </div>


  </ele-modal>

</template>

<script>
  import { getplanDetail } from '@/api/bpm/components/purchasingManage/purchasePlanManage';
  import { getFile } from '@/api/system/file';
  import dictMixins from '@/mixins/dictMixins';
  import { copyObj } from '@/utils/util';
  import inquiryTable from './inquiryTable.vue';


  export default {
    mixins: [dictMixins],
    components: {
      inquiryTable
    },
    props: {
      isModal: {
        default: true
      }
    },
    data() {
      return {
        visible: false,
        title: '详情',
        row: {},
        form: {},
        detailData: {},
        inventoryList: [],
        columns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            width: 150,
            prop: 'productCategoryName',
            label: '分类',
            slot: 'productCategoryName'
          },
          {
            width: 140,
            prop: 'productCode',
            label: '编码',
            slot: 'productCode'
          },
          {
            width: 240,
            prop: 'productName',
            label: '名称',
            slot: 'productName'
          },

          {
            width: 150,
            prop: 'productBrand',
            label: '牌号',
            slot: 'productBrand'
          },
          {
            width: 80,
            prop: 'totalCount',
            label: '数量',
            slot: 'totalCount'
          },
          {
            width: 100,
            prop: 'measuringUnit',
            label: '单位',
            slot: 'measuringUnit'
          },
          {
            width: 130,
            prop: 'modelType',
            label: '型号',
            slot: 'modelType'
          },

          {
            width: 120,
            prop: 'specification',
            label: '规格',
            slot: 'specification'
          },
          // {
          //   width: 130,
          //   prop: 'modelType',
          //   label: '品牌',
          //   slot: 'modelType'
          // },
          {
            width: 170,
            prop: 'expectReceiveDate',
            label: '到货日期',
            slot: 'expectReceiveDate'
          },
          {
            width: 140,
            prop: 'files',
            label: '附件',
            slot: 'files'
          },
          {
            width: 220,
            prop: 'remark',
            label: '备注',
            slot: 'remark'
          }
        ]
      };
    },
    methods: {
      // //导出
      // async exportTable() {
      //   this.loading = true;
      //   const response = await getExport(this.detailId);
      // },
      async open(row) {
        this.visible = true;
        this.getInquiryData(row.id);
        this.detailId = row.id;
      },

      cancel() {
        this.$nextTick(() => {
          // 关闭后，销毁所有的表单数据
          (this.form = {}),
            (this.otherForm = copyObj(this.otherFormDef)),
            (this.tableBankData = []);
          this.tableLinkData = [];
          this.visible = false;
        });
      },
      downloadFile(file) {
        getFile({ objectName: file.storePath }, file.name);
      },
      async getInquiryData(id) {
        this.loading = true;

        const data = await getpurchaseinquiry(id);
        this.loading = false;
        if (data) {
          this.form = data;
          if (data.files && data.files.length > 0) {
            this.form.files = data.files[0];
          } else {
            this.form.files = null;
          }
        }
        // await this.getDetailData(data.requirementId);
      },

    }
  };
</script>

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

  .headbox {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .amount {
      font-size: 14px;
      font-weight: bold;
    }
  }
</style>
