<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" :model="queryForm">
      <el-form-item label="BU">
        <el-select v-model="queryForm.buNo" placeholder="请选择" clearable style="width: 80px">
          <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="queryForm.partNo" clearable style="width: 100px"></el-input>
      </el-form-item>
      <el-form-item label="配件名称">
        <el-input v-model="queryForm.partDescription" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="序列号">
        <el-input v-model="queryForm.serialNumber" clearable style="width: 100px"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryForm.status"  style="width: 80px">
          <el-option value="启用" label="启用"></el-option>
          <el-option value="禁用" label="禁用"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="addModal()">新增</el-button>
      </el-form-item>
    </el-form>

<!--    <el-table-->
<!--      v-if="queryForm.groupType === '0'"-->
<!--      :data="dataList"-->
<!--      border-->
<!--      :height="height + 70"-->
<!--      v-loading="dataListLoading"-->
<!--      @selection-change="handleSelectionChange"-->
<!--      :row-style="controlRowStyle"-->
<!--      style="width: 100%;">-->
<!--      <el-table-column-->
<!--        v-for="(item,index) in arrayColumns0" :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">-->
<!--          <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>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->
<!--    <el-table-->
<!--      v-if="queryForm.groupType === '1'"-->
<!--      :data="dataList"-->
<!--      border-->
<!--      :height="height + 70"-->
<!--      v-loading="dataListLoading"-->
<!--      @selection-change="handleSelectionChange"-->
<!--      :row-style="controlRowStyle"-->
<!--      style="width: 100%;">-->
<!--      <el-table-column-->
<!--        v-for="(item,index) in arrayColumns1" :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">-->
<!--          <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>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->
    <el-table
      :data="headDataList"
      border
      :height="350"
      v-loading="dataListLoading"
      highlight-current-row
      @row-click="handleRowClick"
      style="width: 100%;">
      <el-table-column
        v-for="(item,index) in headColumns" :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">
      </el-table-column>
      <el-table-column label="操作" fixed="right" style="width: 120px">
        <template slot-scope="scope">
          <el-link style="cursor: pointer"  @click="updateModal(scope.row)">编辑</el-link>
          <el-link style="cursor: pointer"  @click="deleteData(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <el-table
      :data="dataList"
      border
      :height="380"
      v-loading="dataListLoading2"
      :span-method="objectSpanMethod"
      style="width: 100%;">
      <el-table-column
        v-for="(item,index) in arrayColumns2" :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">
      </el-table-column>
    </el-table>

    <el-form :inline="true" label-position="top" :model="queryForm">
      <el-form-item label="未上机">
        <el-input v-model="locationId"  style="width: 150px" readonly></el-input>
      </el-form-item>
      <el-form-item label="到厂时间">
        <el-input v-model="arrivalTime"  style="width: 170px" readonly></el-input>
      </el-form-item>
    </el-form>

    <!-- 新增和修改 -->
    <el-dialog title="核心备件" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="290px">
      <el-form :inline="true" label-position="top" :model="modalData"  style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="BU" prop="bu">
          <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag"  style="width: 240px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.sitename"
              :value = "i.buNo">
              <span style="float: left;width: 100px">{{ i.sitename }}</span>
              <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
                {{ i.buDesc }}
              </span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData"  style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="配件编码:">
          <span style="cursor: pointer" slot="label" @click="getBaseList(1200)"><a herf="#">配件编码</a></span>
          <el-input v-model="modalData.partNo" style="width: 114px" disabled></el-input>
        </el-form-item>
        <el-form-item label="配件名称:">
          <el-input v-model="modalData.partDesc" style="width: 114px" disabled></el-input>
        </el-form-item>
        <el-form-item label="序列号:">
          <el-input v-model="modalData.serialNumber" style="width: 114px" :disabled="modalDisableFlag"></el-input>
        </el-form-item>
        <el-form-item label="是否启用:">
          <el-select v-model="modalData.status" style="width: 114px">
            <el-option label="启用" value="启用"></el-option>
            <el-option label="禁用" value="禁用"></el-option>
          </el-select>
        </el-form-item>
          <el-form-item label="到厂时间">
            <el-date-picker
              style="width: 240px"
              v-model="modalData.arrivalTime"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'备注:'">
          <el-input type="textarea" :rows="2" v-model="modalData.remark" style="width: 240px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 30px;text-align:center">
        <el-button type="primary" @click="saveData()">保存</el-button>
        <el-button type="primary" @click="modalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

<!--    <el-pagination-->
<!--      @size-change="sizeChangeHandle"-->
<!--      @current-change="currentChangeHandle"-->
<!--      :current-page="pageIndex"-->
<!--      :page-sizes="[20, 100, 500, 1000]"-->
<!--      :page-size="pageSize"-->
<!--      :total="totalPage"-->
<!--      layout="total, sizes, prev, pager, next, jumper">-->
<!--    </el-pagination>-->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

  </div>
</template>

<script>
import {
  getWareHouseList,
} from '@/api/partspare/wareHouseEntity.js'
import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
import {getAllBuList}from  '@/api/factory/site.js'
import {getTableDefaultListLanguage, getTableUserListLanguage} from "../../../api/table";
import Chooselist from "../common/Chooselist.vue";
import {
  deleteCoreSparePart,
  getCoreSparePartList,
  getEamWorkOrderCoreComponentsList,
  saveCoreSparePart
} from "../../../api/partspare/coreSparePart";
export default {
  components: {
    Chooselist
  },
  data() {
    return {
      userBuList: [],
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: "库存信息" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["库存信息"],
      exportFooter: [],
      exportList:[],
      // 导出 end
      queryForm: {
        site: '',
        limit: 1,
        page: '',
        partNo: '',
        partDescription: '',
        status: '启用',
        active: 'Y',
        safetyStock: '',
        buNo: '2_03-RFID'
      },
      locationId: '',
      arrivalTime: '',
      tagNo: 0,
      modalFlag: false,
      modalDisableFlag: false,
      modalData: {
        flag: '',
        site: '',
        bu: '',
        buNo: '',
        partNo: '',
        partDesc: '',
        createBy: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
        arrivalTime: '',
        remark: ''
      },
      headDataList: [],
      dataList: [],
      wareHouseList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      height: 200,
      dataListLoading: false,
      dataListLoading2: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      // 展示列集
      columnList: [],
      // 汇总方式=‘未上机备件’
      // arrayColumns1: [
      //   // {
      //   //   userId: this.$store.state.user.name,
      //   //   functionId: 200101103,
      //   //   serialNumber: '200101103Table1BuDesc',
      //   //   tableId: '200101103Table1',
      //   //   tableName: '库存信息汇总表',
      //   //   columnProp: 'buDesc',
      //   //   headerAlign: "center",
      //   //   align: "left",
      //   //   columnLabel: 'BU',
      //   //   columnHidden: false,
      //   //   columnImage: false,
      //   //   columnSortable: true,
      //   //   sortLv: 0,
      //   //   status: true,
      //   //   fixed: '',
      //   //   columnWidth: 80,
      //   // },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1PartNo',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'partNo',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '配件编号',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: true,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1PartDescription',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'partDescription',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '名称',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1WarehouseId',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'oldSerialNo',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '序列号',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1LocationId',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'locationId',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '库位编码',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1InQty',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'createdDate',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '到厂时间',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1OutQty',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'estUseQty',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '存放寿命',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1QtyOnHand',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'lifespan',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '是否已到寿命',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table1MaxStock',
      //     tableId: '200101103Table1',
      //     tableName: '库存信息汇总表',
      //     columnProp: 'supplierName',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '供应商',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }
      // ],
      // 汇总方式=‘当前核心备件’
      // arrayColumns0: [
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2PartNo',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'partNo',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '配件编码',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: true,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2PartDescription',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'partDescription',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '名称',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2BatchNo',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'newSerialNo',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '序列号',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2WarehouseId',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'resourceId',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '机台编号',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2LocationId',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'createdDate',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '上机时间',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2Umid',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'workTime',
      //     headerAlign: "center",
      //     align: "left",
      //     columnLabel: '使用时长(时)',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 100,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2AveragePrice',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'estUseQty',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '推荐寿命',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   },
      //   {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2InQty',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'lifespan',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '是否到寿命',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }, {
      //     userId: this.$store.state.user.name,
      //     functionId: 200101103,
      //     serialNumber: '200101103Table2OutQty',
      //     tableId: '200101103Table2',
      //     tableName: '库存信息序号表',
      //     columnProp: 'createdBy',
      //     headerAlign: "center",
      //     align: "right",
      //     columnLabel: '上机人员',
      //     columnHidden: false,
      //     columnImage: false,
      //     columnSortable: false,
      //     sortLv: 0,
      //     status: true,
      //     fixed: '',
      //     columnWidth: 140,
      //   }],
      // 汇总方式=‘备件上下机记录’
      arrayColumns2: [
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1PartNo',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'partNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '配件编号',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1PartDescription',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'partDescription',
          headerAlign: "center",
          align: "left",
          columnLabel: '名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1SerialNo',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'serialNo',
          headerAlign: "center",
          align: "left",
          columnLabel: '序列号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1OnOffStatus',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'onOffStatus',
          headerAlign: "center",
          align: "left",
          columnLabel: '上下机状况',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1CreatedDate',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'createdDate',
          headerAlign: "center",
          align: "left",
          columnLabel: '更换时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1TimeDiffMonths',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'timeDiffMonths',
          headerAlign: "center",
          align: "left",
          columnLabel: '上机时长(天)',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1EstUseQty',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'estUseQty',
          headerAlign: "center",
          align: "center",
          columnLabel: '推荐寿命',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1FeedBackDesc',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'feedBackDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '故障原因',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1FeedBackDesc',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: '111',
          headerAlign: "center",
          align: "center",
          columnLabel: '是否人为原因损伤',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1CreatedBy',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'createdBy',
          headerAlign: "center",
          align: "left",
          columnLabel: '上机人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1OrderNo',
          tableId: '200101103Table1',
          tableName: '库存信息汇总表',
          columnProp: 'orderNo',
          headerAlign: "center",
          align: "left",
          columnLabel: '工单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        }
      ],
      headColumns: [
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1Bu',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'bu',
          headerAlign: "center",
          align: "center",
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1PartNo',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'partNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '配件编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1PartDesc',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'partDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '配件名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1SerialNumber',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'serialNumber',
          headerAlign: "center",
          align: "left",
          columnLabel: '序列号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        // {
        //   userId: this.$store.state.user.name,
        //   functionId: 200101103,
        //   serialNumber: '200101103Table1ArrivalTime',
        //   tableId: '200101103Table1',
        //   tableName: '核心备件表',
        //   columnProp: 'arrivalTime',
        //   headerAlign: "center",
        //   align: "left",
        //   columnLabel: '到厂时间',
        //   columnHidden: false,
        //   columnImage: false,
        //   columnSortable: false,
        //   sortLv: 0,
        //   status: true,
        //   fixed: '',
        //   columnWidth: 160,
        // },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1Status',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'status',
          headerAlign: "center",
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1Remark',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'remark',
          headerAlign: "center",
          align: "left",
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1CreateBy',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'createBy',
          headerAlign: "center",
          align: "center",
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1CreateTime',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'createTime',
          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: 200101103,
          serialNumber: '200101103Table1UpdateBy',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'updateBy',
          headerAlign: "center",
          align: "center",
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 200101103,
          serialNumber: '200101103Table1UpdateTime',
          tableId: '200101103Table1',
          tableName: '核心备件表',
          columnProp: 'updateTime',
          headerAlign: "center",
          align: "center",
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160,
        }
      ]
    }
  },
  // watch: {
  //   'queryForm.groupType': {
  //     handler(newVal, oldVal) {
  //       if (this.queryForm.groupType === '0'){
  //         this.columnList = this.arrayColumns
  //       }else {
  //         this.columnList = this.arrayPart
  //       }
  //     },
  //     deep: true,
  //     immediate: true
  //   }
  // },
  activated() {
    // this.getDataList()
    // this.getWareHouseList()
  },
  created() {
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
    this.getTableUserColumn(this.$route.meta.menuId+'table2',2)
    this.getDataList()
    this.getWareHouseList()
  },
  mounted() {
    this.favoriteIsOk()
    this. getBu ()
    this.$nextTick(() => {
      this.height = window.innerHeight - 210
    })
  },
  methods: {

    // 获取bu列表
    getBu () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getAllBuList(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },

    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },

    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2) {
        if (rowIndex % 2 === 0) {
          return {
            rowspan: 2,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },

    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.queryForm.page = this.pageIndex
      this.queryForm.limit = this.pageSize
      getCoreSparePartList(this.queryForm).then(({data}) => {
        if (data && data.code === 0) {
          this.headDataList = data.list
          // this.pageIndex = data.page.currPage
          // this.pageSize = data.page.pageSize
          // this.totalPage = data.page.totalCount
        }
        this.dataListLoading = false
      })
      // 清空下方数据
      this.dataList = []
      this.locationId = ''
      this.arrivalTime = ''
    },
    handleRowClick(row){
      this.locationId = row.locationId
      this.arrivalTime = row.arrivalTime
      this.dataListLoading2 = true
      let params = {
        site: row.site,
        buNo: row.buNo,
        partNo: row.partNo,
        serialNo: row.serialNumber
      }
      getEamWorkOrderCoreComponentsList(params).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.list
        }
        this.dataListLoading2 = false // 移到这里
      }).catch(() => {
        this.dataListLoading2 = false // 异常也关闭 loading
      })
    },
    // 新增按钮
    addModal () {
      this.modalData = {
        flag: '1',
        site: '',
        buNo: '',
        bu: '2_03-RFID',
        partNo: '',
        partDesc: '',
        serialNumber: '',
        status: '启用',
        createBy: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
        arrivalTime: new Date(),
        remark: ''
      }
      this.modalDisableFlag = false
      this.modalFlag = true
    },
    updateModal(row){
      this.modalData = {
        flag: '2',
        site: row.site,
        buNo: row.buNo,
        bu: row.site + '_' + row.buNo,
        partNo: row.partNo,
        partDesc: row.partDesc,
        serialNumber: row.serialNumber,
        status: row.status,
        updateBy: this.$store.state.user.name,
        arrivalTime: row.arrivalTime,
        remark: row.remark
      }
      this.modalDisableFlag = true
      this.modalFlag = true
    },
    // 保存数据
    saveData(){
      this.modalData.serialNumber = (this.modalData.serialNumber || '').trim()
      if (this.modalData.bu === '' || this.modalData.bu == null) {
        this.$message.warning('请选择BU！')
        return
      }
      if (this.modalData.partNo === '' || this.modalData.partNo == null) {
        this.$message.warning('请填写配件编码！')
        return
      }
      if (this.modalData.serialNumber === '' || this.modalData.serialNumber == null) {
        this.$message.warning('请填写序列号！')
        return
      }
      if (this.modalData.status === '' || this.modalData.status == null) {
        this.$message.warning('请填写启用状态！')
        return
      }
      if (this.modalData.arrivalTime === '' || this.modalData.arrivalTime == null) {
        this.$message.warning('请选择到厂时间！')
        return
      }
      saveCoreSparePart(this.modalData).then(({data})=>{
        if (data && data.code === 0) {
          this.$message.success(data.msg)
          this.modalFlag = false
          this.getDataList()
        } else {
          this.$alert(data.msg || '保存失败', '错误', {
            confirmButtonText: '确定'
          })
        }
      }).catch(() => {
        this.$message.error('保存异常')
      })
    },
    deleteData(row){
      this.$confirm(`是否删除该 条记录?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteCoreSparePart(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {})
    },
    getBaseList (val,type) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = ''
        let conSql = " and site = '" + this.modalData.bu.split('_')[0] + "' and bu_no = '" + this.modalData.bu.split('_')[1] + "'"
        if (val === 1200) {
          this.$refs.baseList.init(val, strVal, conSql)
        }
      })
    },
    // 回调方法
    getBaseData (val) {
      if (this.tagNo === 1200) {
        this.modalData.partNo = val.part_no
        this.modalData.partDesc = val.partDesc
      }
    },

    // 获取仓库列表
    getWareHouseList () {
      let wareHouse = {
        username: this.$store.state.user.name,
        warehousetype: "备品备件仓",
      }
      getWareHouseList(wareHouse).then(({data}) =>{
        if (data && data.code === 0) {
          this.wareHouseList = data.data
        }
      })
    },


    // 控制单行的背景颜色
    controlRowStyle ({row, rowIndex}) {
      if (this.queryForm.groupType === '1' && row.lifespan ==  '是') {
        return { 'background-color': '#FFD3D3', cursor: 'pointer' }
      }
    },

    startDownload () {},

    finishDownload () {},

    fields () {
      if (this.queryForm.groupType === '0'){
        this.columnList = this.arrayColumns
      }else {
        this.columnList = this.arrayPart
      }
      let json = "{"
      this.columnList.forEach((item, index) => {
        if (index == this.columnList.length - 1) {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
        } else {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
        }
      })
      json += "}"
      let s = eval("(" + json + ")")

      return s
    },

    // 校验用户是否收藏
    favoriteIsOk () {
      let userFavorite = {
        userId: this.$store.state.user.id,
        languageCode: this.$i18n.locale
      }
      userFavoriteList(userFavorite).then(({data}) => {
        for (let i = 0; i < data.list.length; i++) {
          if(this.$route.meta.menuId === data.list[i].menuId){
            this.favorite = true
          }
        }
      })
    },

    // 收藏 OR 取消收藏
    favoriteFunction () {
      let userFavorite = {
        userId: this.$store.state.user.id,
        functionId: this.$route.meta.menuId,
      }
      if (this.favorite) {
        // 取消收藏
        this.$confirm(`确定取消收藏`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        })
      } else {
        // 收藏
        saveUserFavorite(userFavorite).then(({data}) => {
          this.$message.success(data.msg)
          this.favorite = true
        })
      }
    },

    // 动态列开始 获取 用户保存的 格式列
    async getTableUserColumn (tableId, columnId) {
      let queryTableUser = {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        status: true,
        languageCode: this.$i18n.locale
      }
      await getTableUserListLanguage(queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          switch (columnId) {
            case 1:
              this.arrayColumns = data.rows
              break;
            case 2:
              this.arrayPart = data.rows
              break;
          }
        } else {
          this.getColumnList(tableId, columnId)
        }
      })
    },

    // 获取 tableDefault 列
    async getColumnList (tableId, columnId) {
      let queryTable= {
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        languageCode: this.$i18n.locale
      }
      await getTableDefaultListLanguage(queryTable).then(({data}) => {
        if (!data.rows.length === 0) {
          switch (columnId) {
            case 1:
                this.arrayColumns = data.rows
                break;
            case 2:
              this.arrayPart = data.rows
              break;
          }
        }
      })
    },

  }
}
</script>
