<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="70%"
    @close="cancel"
  >
    <div class="switch">
      <div class="switch_left">
        <ul>
          <li
            v-for="item in tabOptions"
            :key="item.key"
            :class="{ active: activeComp == item.key }"
            @click="activeComp = item.key"
          >
            {{ item.name }}
          </li>
        </ul>
      </div>
    </div>
    <div v-if="activeComp == 'main'">
      <el-form ref="form" :model="form" label-width="120px" class="el-form-box">
        <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="8">
            <el-form-item label="采购计划单名称：" class="form_item_label" prop="planName">
              <el-input v-model="form.planName" disabled>
                <template slot="append" v-if="form.planName">
                  <el-button type="primary" @click="openPlanDetail(form)" title="查看详情" icon="el-icon-view"></el-button>
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="询价单名称：" prop="inquiryName">
              <el-input v-model="form.inquiryName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="acceptUnpack" label="是否接受拆单:">
              <el-select v-model="form.acceptUnpack" placeholder="请选择" disabled style="width: 100%">
                <el-option label="接受" :value="1"></el-option>
                <el-option label="不接受" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="remark" label="备注：">
              <el-input type="textarea" v-model="form.remark" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <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-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"
      >
        <template v-slot:files="{ row }">
          <div v-if="row.files && row.files?.length">
            <el-link
              v-for="link in row.files"
              :key="link.id"
              type="primary"
              :underline="false"
              @click="downloadFile(link)"
            >
              {{ link.name }}</el-link
            >
          </div>
        </template>
      </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>
    <bpmDetail
      v-if="activeComp === 'bpm' && form.processInstanceId"
      :id="form.processInstanceId"
    ></bpmDetail>
    <div slot="footer" class="footer">
      <el-button @click="cancel">返回</el-button>
    </div>
    <planDetaillog ref="planDetaillogRef" :isModal="false"></planDetaillog>
  </ele-modal>
</template>

<script>
  import { getpurchaseinquiry } from '@/api/purchasingManage/inquiryManage';
  import { getFile } from '@/api/system/file';
  import dictMixins from '@/mixins/dictMixins';
  import { copyObj } from '@/utils/util';
  import inquiryTable from './inquiryTable.vue';
  import planDetaillog from '../../../purchasingManage/purchasePlanManage/components/detailDialog.vue';
  import bpmDetail from '@/views/bpm/processInstance/detail.vue';

  export default {
    mixins: [dictMixins],
    components: {
      inquiryTable,
      planDetaillog,bpmDetail
    },
    props: {
      isModal: {
        default: true
      }
    },
    data() {
      return {
        activeComp: 'main',
        tabOptions: [
          { key: 'main', name: '核价单详情' },
          { key: 'bpm', name: '流程详情' }
        ],
        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',
            align: 'center',
          },
          {
            width: 140,
            prop: 'productCode',
            label: '编码',
            slot: 'productCode',
            align: 'center',
          },
          {
            width: 240,
            prop: 'productName',
            label: '名称',
            slot: 'productName',
            align: 'center',
          },

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

          {
            width: 120,
            prop: 'specification',
            label: '规格',
            slot: 'specification',
            align: 'center',
          },
          // {
          //   width: 130,
          //   prop: 'modelType',
          //   label: '品牌',
          //   slot: 'modelType'
          // },
          {
            width: 170,
            prop: 'expectReceiveDate',
            label: '到货日期',
            slot: 'expectReceiveDate',
            align: 'center',
          },
          {
            width: 140,
            prop: 'files',
            label: '附件',
            slot: 'files',
            align: 'center',
          },
          {
            width: 220,
            prop: 'remark',
            label: '备注',
            slot: 'remark',
            align: 'center',
          }
        ]
      };
    },
    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);
      },
      //查看详情
      openPlanDetail(row) {
        this.$refs.planDetaillogRef.open(row);
      }
      // //获取需求详情
      // async getDetailData(id) {
      //   this.loading = true;
      //   let data = await getDetail(id);
      //   this.loading = false;
      //   if (data) {
      //     this.$nextTick(() => {
      //       this.inventoryList = copyObj(data.detailList);
      //     });
      //   }
      // }
    }
  };
</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>
