<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"
    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-show="activeComp === 'main'">
      <el-form ref="form" :model="form" :rules="rules" 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 gutter="12">
          <el-col :span="12">
            <el-form-item
              label="关联商机名称"
              prop="opportunityName">
              <el-input v-model="detailData.opportunityName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="询价方名称"
              prop="contactName">
              <el-input v-model="form.contactName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="询价方联系人"
              prop="contactLinkName">
              <el-input v-model="form.contactLinkName" disabled></el-input>
            </el-form-item>

            <el-form-item
              label="询价方电话"
              prop="contactTel">
              <el-input v-model="form.contactTel" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="询价方传真"
              prop="contactFax">
              <el-input v-model="form.contactFax" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="询价方Email"
              prop="contactEmail">
              <el-input v-model="form.contactEmail" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="询价方地址"
              prop="contactAddress">
              <el-input v-model="form.contactAddress" disabled></el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item
              label="报价方名称"
              prop="quoteName">
              <el-input v-model="form.quoteName" disabled></el-input>
            </el-form-item>

            <el-form-item
              label="报价方联系人"
              prop="quoteLinkName">
              <el-input v-model="form.quoteLinkName" disabled></el-input>
            </el-form-item>
            <el-form-item prop="quoteTel" label="报价方联系电话">
              <el-input v-model="form.quoteTel" disabled></el-input>
            </el-form-item>
            <el-form-item prop="quoteFax" label="报价方传真">
              <el-input v-model="form.quoteFax" disabled></el-input>
            </el-form-item>

            <el-form-item
              label="报价方Email"
              prop="quoteEmail">
              <el-input v-model="form.quoteEmail" disabled></el-input>
            </el-form-item>

            <el-form-item
              label="报价方地址"
              prop="quoteAddress">
              <el-input v-model="form.quoteAddress" disabled></el-input>
            </el-form-item>
            <el-form-item prop="askFile" label="附件">
              <el-link
                v-if="form.askFile && form.askFile !== ''"
                type="primary"
                :underline="false"
                @click="downloadFile(form.askFile)"
              >
                {{ form.askFile.name }}</el-link
              >
            </el-form-item>
          </el-col>
        </el-row>
        <headerTitle title="报价单产品清单"></headerTitle>
        <inventoryTabledetail
          :isCustomerMark="false"
          ref="inventoryTabledetailRef"
        ></inventoryTabledetail>
        <el-row style="margin-top: 20px">
          <el-col :span="6">
            <el-form-item prop="taxRate" label="税率">
              <el-input v-model="form.taxRate" disabled>
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="deliveryDate" label="交货日期">
              <el-input v-model="form.deliveryDate" disabled>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item
              label="结算方式"
              prop="payWay">
              <el-input v-model="form.settlementModeName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item
              label="是否接受拆单"
              prop="acceptUnpack"
            >
              <el-select v-model="form.acceptUnpack" placeholder="请选择" style="width: 100%;" disabled>
                <el-option
                  v-for="item in acceptUnpackoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>


    </div>

    <bpmDetail
      v-if="activeComp === 'bpm' && form.processInstanceId"
      :id="form.processInstanceId"
    ></bpmDetail>

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

<script>
  import { getDetail, getExport } from '@/api/saleManage/quotation';
  import { getFile } from '@/api/system/file';
  import dictMixins from '@/mixins/dictMixins';
  import { copyObj } from '@/utils/util';
  import bpmDetail from '@/views/bpm/processInstance/detail.vue';
  import inventoryTabledetail from '@/views/contractManage/contractBook/components/inventoryTabledetail.vue';
  import {acceptUnpackoptions} from '@/enum/dict';
  export default {
    mixins: [dictMixins],
    components: {
      bpmDetail,
      inventoryTabledetail
    },
    data() {
      return {
        activeComp: 'main',
        tabOptions: [
          { key: 'main', name: '报价详情' },
          { key: 'bpm', name: '流程详情' }
        ],
        visible: false,
        detailId: '',
        title: '详情',
        row: {},
        activeName: 'base',
        form: {},
        rules: {},
        detailData: {},
        acceptUnpackoptions,
        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 + '元';
            }
          },
          {
            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'
          }
        ]
      };
    },
    methods: {
      //导出
      async exportTable() {
        this.loading = true;
        const response = await getExport(this.detailId);
      },
      async open(row) {
        this.form = row;
        this.visible = true;
        this.getDetailData(row.id);
        this.detailId = row.id;
      },

      cancel() {
        this.$nextTick(() => {
          // 关闭后，销毁所有的表单数据
          (this.form = copyObj(this.formDef)),
            (this.otherForm = copyObj(this.otherFormDef)),
            (this.tableBankData = []);
          this.tableLinkData = [];
          this.visible = false;
        });
      },
      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.$nextTick(() => {
            this.$refs.inventoryTabledetailRef &&
              this.$refs.inventoryTabledetailRef.putTableValue(data);
          });
        }
      }
    }
  };
</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>
