<template>
  <div class="mod-config">
    <!-- 查询条件 -->
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.bu" placeholder="请选择" clearable style="width: 120px">
          <el-option
            v-for = "i in userBuList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buNo">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="询价单号">
        <el-input v-model="searchData.rfqNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="客户编码">
        <span style="cursor: pointer" slot="label" @click="getBaseList(509,2)"><a herf="#">客户编码</a></span>
        <el-input v-model="searchData.customerNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'客户名称'">
        <el-input v-model="searchData.customerDesc" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'询价日期'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.requestStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label=" ">
        <div style="text-align: center;"><i class="el-icon-right"></i></div>
      </el-form-item>
      <el-form-item :label="' '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.requestEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'优先等级'">
        <dict-data-select v-model="searchData.priorityLevel" clearable style="width: 120px" :use-default-value="false"
                          dict-type="priority_Level"/>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item label="产品编码">
        <span style="cursor: pointer" slot="label" @click="getBaseList(2005)"><a herf="#">产品编码</a></span>
        <el-input v-model="searchData.partNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'产品名称'">
        <el-input v-model="searchData.partDesc" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'PjM'">
        <span style="cursor: pointer" slot="label" @click="getBaseList(2004,1)"><a herf="#">PjM</a></span>
        <el-input v-model="searchData.requesterName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'报价专员'">
        <span style="cursor: pointer" slot="label" @click="getBaseList(2002,1)"><a herf="#">报价专员</a></span>
        <el-input v-model="searchData.quoterName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'要求报价日期'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.requiredCompletionStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label=" ">
        <div style="text-align: center;"><i class="el-icon-right"></i></div>
      </el-form-item>
      <el-form-item :label="' '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.requiredCompletionEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.status" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="草稿" value="C"></el-option>
          <el-option label="已下达" value="B"></el-option>
          <el-option label="已报价" value="A"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="getDataList()">查询</el-button>
<!--        <el-button type="primary" icon="el-icon-upload" @click="handleImportQuotation()">导入</el-button>-->
<!--        <download-excel-->
<!--          :fields="fields()"-->
<!--          :data="exportData"-->
<!--          type="xls"-->
<!--          :name="exportName"-->
<!--          :header="exportHeader"-->
<!--          :footer="exportFooter"-->
<!--          :fetch="createExportData"-->
<!--          :before-generate="startDownload"-->
<!--          :before-finish="finishDownload"-->
<!--          worksheet="导出信息"-->
<!--          class="el-button el-button&#45;&#45;primary el-button&#45;&#45;medium">-->
<!--          {{ "导出" }}-->
<!--        </download-excel>-->
      </el-form-item>
    </el-form>

    <!-- 询价产品列表 -->
    <el-table
      height="37vh"
      :data="dataList"
      border
      :row-style="rowStyle"
      ref="mainTable"
      @row-click="inquiryPartClickRow"
      @current-change="changeCurrentRow"
      style="width: 100%;margin-top: 5px">
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :align="item.align"
        :fixed="item.fixed === ''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <div v-if="item.columnProp !== 'status' && item.columnProp !== 'priorityLevel'">
            <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </div>
          <div v-else-if="item.columnProp === 'status'">
            <span v-if="!item.columnHidden">
              <span v-if="scope.row.status === 'C'">草稿</span>
              <span v-if="scope.row.status === 'B'">已下达</span>
              <span v-if="scope.row.status === 'A'">已报价</span>
            </span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </div>
          <div v-else-if="item.columnProp === 'priorityLevel'">
            <span v-if="!item.columnHidden">
              <span v-if="scope.row.priorityLevel === 'A'">普通</span>
              <span v-if="scope.row.priorityLevel === ' B'">重要</span>
              <span v-if="scope.row.priorityLevel === ' C'">紧急</span>
            </span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页插件 -->
    <el-pagination style="margin-top: 0px"
                   @size-change="sizeChangeHandle"
                   @current-change="currentChangeHandle"
                   :current-page="pageIndex"
                   :page-sizes="[20, 50, 100, 200, 500]"
                   :page-size="pageSize"
                   :total="totalPage"
                   layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 页签 -->
    <el-tabs style="margin-top: 0px; width: 100%; height: 100%;" v-model="activeTable" class="customer-tab" type="border-card" @tab-click="tabClick">
      <!-- 询价明细 属性页签 -->
      <el-tab-pane label="属性" name="inquiryPartItem">
        <el-table
          :height="height - 300"
          :data="inquiryPartItemDataList"
          border
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnItemList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <div v-if="item.columnProp !== 'textValue' && item.columnProp !== 'numValue'">
                <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
              </div>
              <div v-else>
                {{ scope.row.textValue ? scope.row.textValue : scope.row.numValue }}
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <!-- 询价明细 详情页签 -->
      <el-tab-pane label="详情" name="inquiryPartDetail">
        <div style="margin-left: 10px;height: 225px">
          <el-form :inline="true" label-position="top" :model="inquiryPartCurrentRow">
            <el-form-item :label="'BU'">
              <el-input v-model="inquiryPartCurrentRow.buDesc" readonly style="width: 70px"></el-input>
            </el-form-item>
            <el-form-item :label="'客户编码'">
              <el-input v-model="inquiryPartCurrentRow.customerNo" readonly style="width: 160px"></el-input>
            </el-form-item>
            <el-form-item :label="'客户名称'">
              <el-input v-model="inquiryPartCurrentRow.customerDesc" readonly style="width: 340px"></el-input>
            </el-form-item>
            <el-form-item :label="'询价单号'">
              <el-input v-model="inquiryPartCurrentRow.rfqNo" readonly style="width: 160px"></el-input>
            </el-form-item>
            <el-form-item :label="'询价日期'">
              <el-input v-model="inquiryPartCurrentRow.requestDate" readonly style="width: 100px"></el-input>
            </el-form-item>
            <el-form-item :label="'询价数量'">
              <el-input-number :controls="false" :step="0" v-model="inquiryPartCurrentRow.inquiryQty" readonly style="width: 70px"></el-input-number>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="inquiryPartCurrentRow">
            <el-form-item :label="'状态'">
              <el-input v-model="statusDisplay" readonly style="width: 70px"></el-input>
            </el-form-item>
            <el-form-item :label="'产品编码'">
              <el-input v-model="inquiryPartCurrentRow.partNo" readonly style="width: 160px"></el-input>
            </el-form-item>
            <el-form-item :label="'产品描述'">
              <el-input v-model="inquiryPartCurrentRow.partDesc" readonly style="width: 340px"></el-input>
            </el-form-item>
            <el-form-item :label="'客户询价单号'">
              <el-input v-model="inquiryPartCurrentRow.customerInquiryNo" readonly style="width: 160px"></el-input>
            </el-form-item>
            <el-form-item :label="'要求报价日期'">
              <el-input v-model="inquiryPartCurrentRow.requiredCompletionDate" readonly style="width: 100px"></el-input>
            </el-form-item>
            <el-form-item :label="'计量单位'">
              <el-input v-model="inquiryPartCurrentRow.umName" readonly style="width: 70px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="inquiryPartCurrentRow">
            <el-form-item :label="'属性模版'">
              <el-input v-model="inquiryPartCurrentRow.codeNo" readonly style="width: 244px"></el-input>
            </el-form-item>
            <el-form-item :label="'PjM'">
              <el-input v-model="inquiryPartCurrentRow.requesterName" readonly style="width: 163px"></el-input>
            </el-form-item>
            <el-form-item :label="'报价专员'">
              <el-input v-model="inquiryPartCurrentRow.quoterName" readonly style="width: 163px"></el-input>
            </el-form-item>
            <el-form-item :label="'优先等级'">
              <el-input v-model="priorityLevelDisplay" readonly style="width: 274px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="inquiryPartCurrentRow">
            <el-form-item :label="'备注'">
              <el-input v-model="inquiryPartCurrentRow.remark" readonly style="width: 885px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" :model="inquiryPartCurrentRow">
            <el-form-item :label="'创建人'">
              <el-input v-model="inquiryPartCurrentRow.createBy" readonly style="width: 146px"></el-input>
            </el-form-item>
            <el-form-item :label="'创建时间'">
              <el-input v-model="inquiryPartCurrentRow.createDate" readonly style="width: 263px"></el-input>
            </el-form-item>
            <el-form-item :label="'更新人'">
              <el-input v-model="inquiryPartCurrentRow.updateBy" readonly style="width: 161px"></el-input>
            </el-form-item>
            <el-form-item :label="'更新时间'">
              <el-input v-model="inquiryPartCurrentRow.updateDate" readonly style="width: 276px"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </el-tab-pane>
      <!-- 询价明细 相关文档 -->
      <el-tab-pane label="相关文档" name="inquiryPartDocument">
      </el-tab-pane>
      <!-- 询价明细 报价记录页签 -->
      <el-tab-pane label="报价记录" name="inquiryPartQuotation">
      </el-tab-pane>
    </el-tabs>

    <!-- chooseList模态框 -->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
import Chooselist from '@/views/modules/common/Chooselist_eam'
import {getSiteAndBuByUserName} from "../../../api/qc/qc";
import {searchInquiryApplicationInfo,addInquiryApplicationInfo,updateInquiryApplicationInfo,deleteInquiryApplicationInfo} from "@/api/inquiry/inquiryApplication";
import {searchInquiryDetailInfo,addInquiryDetailInfo,updateInquiryDetailInfo,deleteInquiryDetailInfo} from "@/api/inquiry/inquiryDetail";
import {getItemListByInquiryPartAndCodeNo,updateInquiryPartItemList,searchInquiryDetailHeaderInfo} from "@/api/inquiry/inquiryDetail";
import DictDataSelect from "../sys/dict-data-select.vue";
import {queryCustomerList} from "@/api/customer/customer";
import {verifyData} from "@/api/part/partInformation";
import {EventBus} from "../../../main";

export default {
  components: {
    DictDataSelect,
    Chooselist
  },
  computed: {
    statusDisplay() {
      return this.inquiryPartCurrentRow.status === 'C' ? '草稿' : (this.inquiryPartCurrentRow.status === 'B' ? '已下达' : '已报价')
    },
    priorityLevelDisplay() {
      return this.inquiryPartCurrentRow.priorityLevel === 'A' ? '普通' : (this.inquiryPartCurrentRow.priorityLevel === ' B' ? '重要' : '紧急')
    }
  },
  data() {
    return {
      userBuList: [],
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      height: 200,
      // 条件查询
      searchData: {
        site: this.$store.state.user.site,
        customerNo: '',
        customerDesc: '',
        id: '',
        rfqNo: '',
        bu: '',
        requestStartDate: '',
        requestEndDate: '',
        requiredCompletionStartDate: '',
        requiredCompletionEndDate: '',
        status: '',
        quoterName: '',
        requesterName: '',
        priorityLevel: '',
        partNo: '',
        partDesc: '',
        page: 1,
        limit: 10,
        menuId: this.$route.meta.menuId,
      },
      // 初始页签
      activeTable: 'inquiryPartItem',
      // ======== 数据列表 ========
      dataList: [],
      inquiryPartItemDataList: [],
      // ======== 列表表头 ========
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1BuDesc',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'buDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1rfqNo',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'rfqNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '询价单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1CustomerNo',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'customerNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '客户编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1CustomerDesc',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'customerDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '客户名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1RequestDate',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'requestDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '询价日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1RequesterName',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'requesterName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: 'PjM',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1QuoterName',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'quoterName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '报价专员',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1RequiredCompletionDate',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'requiredCompletionDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '要求报价日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1CustomerInquiryNo',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'customerInquiryNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '客户询价单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2PartNo',
          tableId: '102001Table2',
          tableName: '询价产品表',
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '产品编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2PartDesc',
          tableId: '102001Table2',
          tableName: '询价产品表',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '产品描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1Status',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'status',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2InquiryQty',
          tableId: '102001Table2',
          tableName: '询价产品表',
          columnProp: 'inquiryQty',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '询价数量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Unit',
          tableId: '102001Table2',
          tableName: '询价产品表',
          columnProp: 'umName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '计量单位',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2CodeNo',
          tableId: '102001Table2',
          tableName: '询价产品表',
          columnProp: 'codeNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '属性模版',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1PriorityLevel',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'priorityLevel',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '优先等级',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Remark',
          tableId: '102001Table2',
          tableName: '询价产品表',
          columnProp: 'remark',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1CreateDate',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1CreateBy',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1UpdateDate',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table1UpdateBy',
          tableId: '102001Table1',
          tableName: '询价信息表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        }
      ],
      columnItemList:  [
        {
          userId: this.$store.state.user.name,
          functionId: 601006,
          serialNumber: '601006Table3ItemID',
          tableId: "601006Table3",
          tableName: "物料属性表",
          columnProp: 'itemNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601006,
          serialNumber: '601006Table3PropertiesItemDesc',
          tableId: "601006Table3",
          tableName: "物料属性表",
          columnProp: 'itemDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '属性名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601006,
          serialNumber: '601006Table3ValueType',
          tableId: "601006Table3",
          tableName: "物料属性表",
          columnProp: 'valueType',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601006,
          serialNumber: '601006Table3ValueChooseFlag',
          tableId: "601006Table3",
          tableName: "物料属性表",
          columnProp: 'textValue',
          headerAlign: "center",
          align: "left",
          columnLabel: '属性值',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        // {
        //   userId: this.$store.state.user.name,
        //   functionId: 601006,
        //   serialNumber: '601006Table3ValueChooseFlag',
        //   tableId: "601006Table3",
        //   tableName: "物料属性表",
        //   columnProp: 'numValue',
        //   headerAlign: "center",
        //   align: "center",
        //   columnLabel: '数字值',
        //   columnHidden: false,
        //   columnImage: false,
        //   status: true,
        //   fixed: '',
        //   columnWidth: 70,
        // },
      ],
      // ======== 选中的当前行数据 ========
      inquiryPartCurrentRow: {},
    }
  },

  mounted() {
    this.$nextTick(() => {
      /*第二个表格高度的动态调整*/
      this.height = window.innerHeight - 210;
    })
    EventBus.$on('updateInquiryPartInfo', () => {
      this.getDataList();
    });
  },

  created() {
    this.getSiteAndBuByUserName()
    this.getDataList()
  },

  activated() {
    console.log(this.$route.query.id)
    if (this.$route.query.id) {
      this.getDataList(this.$route.query.id);
      this.activeTable = 'inquiryPartDetail';
    }
  },

  methods: {
    // 获取用户的bu
    getSiteAndBuByUserName() {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },
    // ======== 分页相关方法 ========
    /**
     * 每页数
     * @param val
     */
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    /**
     * 当前页
     * @param val
     */
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },


    // ======== 页签切换相关方法 ========
    /**
     * 列表表格选择替换
     * @param tab
     * @param event
     */
    tabClick(tab, event) {
      // 刷新列表数据
      this.refreshCurrentTabTable()
    },

    // ======== 列表操作方法 ========
    /**
     * 单机选中询价信息
     * @param row
     */
    inquiryPartClickRow(row) {
      this.inquiryPartCurrentRow = JSON.parse(JSON.stringify(row))
    },
    /**
     * 当前值发生变化的时候修改
     * @param row
     * @param oldRow
     */
    changeCurrentRow(row, oldRow) {
      // 判断是否是获取焦点的事件
      if (row) {
        this.inquiryPartCurrentRow = JSON.parse(JSON.stringify(row))
        //刷新当前页表
        this.refreshCurrentTabTable()
      }
    },
    /**
     * 刷新页签的table数据
     */
    refreshCurrentTabTable() {
      if (this.activeTable === 'inquiryPartItem') {
        this.getItemListByInquiryPartAndCodeNo()
      }
    },

    // ======== chooseList相关方法 ========
    /**
     * 获取基础数据列表S
     * @param val
     * @param type
     */
    getBaseList(val, type) {
      this.tagNo = val
      this.tagNo1 = type
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        if (val === 220) {
          strVal = this.inquiryPartModalData.codeNo ? this.inquiryPartModalData.codeNo : ''
          conSql = " and function_type = 'PRICECHECK'" + " and site = '" + this.inquiryPartModalData.bu.split('_')[0] + "'" +
            " and bu_no = '" + this.inquiryPartModalData.bu.split('_')[1] + "'"
        }
        if (val === 509) {
          if (type === 1) {
            strVal = this.modalData.customerNo ? this.modalData.customerNo : ''
          }
          if (type === 2) {
            strVal = this.searchData.customerNo ? this.searchData.customerNo : ''
          }
        }
        if (val === 510) {
          strVal = this.inquiryPartModalData.umId ? this.inquiryPartModalData.umId : ''
          conSql = " and site = '" + this.inquiryPartModalData.bu.split('_')[0] + "'"
        }
        if (val === 2002) {
          if (type === 1) {
            strVal = this.searchData.quoterName ? this.searchData.quoterName : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
          if (type === 2) {
            strVal = this.modalData.quoterName ? this.modalData.quoterName : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
        }
        if (val === 2004) {
          if (type === 1) {
            strVal = this.searchData.requesterName ? this.searchData.requesterName : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
          if (type === 2) {
            strVal = this.modalData.requesterName ? this.modalData.requesterName : ''
            conSql = " and b.site = '" + this.$store.state.user.site + "'"
          }
        }
        if (val === 2005) {
          strVal = this.searchData.partNo ? this.searchData.partNo : ''
          conSql = " and b.site = '" + this.$store.state.user.site + "'"
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    /**
     * 列表方法的回调
     * @param val
     */
    getBaseData(val) {
      console.log(val)
      if (this.tagNo === 220) {
        this.inquiryPartModalData.codeNo = val.code_no
        this.inquiryPartModalData.codeDesc = val.code_desc
      }
      if (this.tagNo === 509) {
        if (this.tagNo1 === 1) {
          if (val.customer_no === this.modalData.customerNo) {
            return
          }
          this.modalData.customerNo = val.customer_no
          this.modalData.customerDesc = val.customer_desc
        }
        if (this.tagNo1 === 2) {
          if (val.customer_no === this.searchData.customerNo) {
            return
          }
          this.searchData.customerNo = val.customer_no
        }
      }
      if (this.tagNo === 510) {
        this.inquiryPartModalData.umId = val.UMID
        this.inquiryPartModalData.umName = val.UMName
      }
      if (this.tagNo === 2002) {
        if (this.tagNo1 === 1) {
          this.searchData.quoter = val.username
          this.searchData.quoterName = val.user_display
        }
        if (this.tagNo1 === 2) {
          this.modalData.quoter = val.username
          this.modalData.quoterName = val.user_display
        }
      }
      if (this.tagNo === 2004) {
        if (this.tagNo1 === 1) {
          this.searchData.requester = val.username
          this.searchData.requesterName = val.user_display
        }
        if (this.tagNo1 === 2) {
          this.modalData.requester = val.username
          this.modalData.requesterName = val.user_display
        }
      }
      if (this.tagNo === 2005) {
        this.searchData.partNo = val.part_no
      }
    },

    // ======== 列表数据刷新方法 ========
    /**
     * 获取数据列表
     */
    getDataList(id) {
      if (id) {
        this.searchData.id = id
      } else {
        this.searchData.id = ''
      }
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      searchInquiryDetailHeaderInfo(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.dataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          //判断是否全部存在数据
          if (this.totalPage > 0) {
            //设置选中行
            this.$refs.mainTable.setCurrentRow(this.dataList[0])
            this.inquiryPartClickRow(this.dataList[0])
            this.refreshCurrentTabTable() //加载当前的页签的table
          }
        }
      })
    },

    async getItemListByInquiryPartAndCodeNo() {
      let inData = this.inquiryPartCurrentRow
      inData.inquiryPartId = inData.id
      inData.recordType = 'PRICECHECK'
      return getItemListByInquiryPartAndCodeNo(inData).then(({data}) => {
        if (data && data.code === 0) {
          this.inquiryPartItemDataList = data.rows;
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },

    rowStyle({row}) {
      if (this.inquiryPartCurrentRow.id === row.id) {
        return {'background-color': '#E8F7F6', cursor: 'pointer'};
      }
    },
  }
}


</script>

<style scoped lang="scss">
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
}
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
.el-input-number /deep/ .el-input__inner {
  text-align: right;
  padding-right: 5px !important;
}
</style>
