<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: 130px">
          <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.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="' '">
        <el-button type="primary" @click="getDataList">查询</el-button>
        <el-button type="primary" icon="el-icon-upload" @click="partCostUpload">导入物料成本</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :height="height"
      :data="dataList"
      ref="mainTable"
      border
      style="width: 100%;">
      <el-table-column
        v-for="(item,index) in columnList" :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-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <el-link v-if="!authUpdate" style="cursor: pointer" @click="updateModal(scope.row)">修改</el-link>
          <el-link style="cursor: pointer" @click="costHistorySearch(scope.row)">成本历史</el-link>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页栏 -->
    <el-pagination
      @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-dialog title="物料成本信息 - 修改" @close="closeDialog" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="596px">
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
        <el-form :inline="true" label-position="top" :model="modalData">
          <el-form-item label="物料编码" prop="partNo">
            <el-input v-model="modalData.partNo" disabled style="width: 128px"></el-input>
          </el-form-item>
          <el-form-item label="物料描述" prop="partDesc">
            <el-input v-model="modalData.partDesc" disabled style="width: 330px"></el-input>
          </el-form-item>
          <el-form-item label="BU">
            <el-input v-model="modalData.buDesc" disabled style="width: 80px"></el-input>
          </el-form-item>
        </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item label="物料分类编码" prop="familyID">
                <el-input v-model="modalData.familyID" disabled style="width: 128px"></el-input>
              </el-form-item>
              <el-form-item label="物料分类描述" prop="familyName">
                <el-input v-model="modalData.familyName" disabled style="width: 330px"></el-input>
              </el-form-item>
              <el-form-item label="计量单位">
                <el-input v-model="modalData.umId2" disabled style="width: 80px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item label="商品组1编码" prop="otherGroup1">
                <el-input v-model="modalData.otherGroup1" disabled style="width: 128px"></el-input>
              </el-form-item>
              <el-form-item label="商品组1描述" prop="otherGroupName1">
                <el-input v-model="modalData.otherGroupName1" disabled style="width: 330px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
              <el-form-item label="单位标准成本" prop="standardCost">
                <el-input v-model="modalData.standardCost" @change="standardCostChange()" placeholder="最多6位小数" class="inlineNumber numInput" style="width: 107px"></el-input>
              </el-form-item>
              <el-form-item label="标准成本货币" prop="standardCostCurrency" :show-message="false">
                <span slot="label">
                <a @click="getBaseList(512)">标准成本货币</a>
              </span>
                <el-input v-model="modalData.standardCostCurrency" disabled @change="standardCostCurrencyChange()" style="width: 108px"></el-input>
              </el-form-item>
              <el-form-item label="单位报价成本" prop="actualCost">
                <el-input v-model="modalData.actualCost" placeholder="最多6位小数" class="inlineNumber numInput" style="width: 107px"></el-input>
              </el-form-item>
              <el-form-item label="报价成本货币" prop="actualCostCurrency" :show-message="false">
                <span slot="label">
                <a @click="getBaseList(513)">报价成本货币</a>
              </span>
                <el-input v-model="modalData.actualCostCurrency" disabled style="width: 108px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: 0px;">
              <el-form-item label="备注" style="height: 80px">
                <el-input v-model="modalData.costRemark" style="width: 565px"></el-input>
              </el-form-item>
            </el-form>
      </el-form>
      <el-footer style="height:35px;margin-top: -25px;text-align:center">
        <el-button type="primary" @click="saveData">保存</el-button>
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 成本历史模态框 -->
    <el-dialog title="物料成本信息 - 成本历史" @close="closeCostHistoryDialog" :close-on-click-modal="false" v-drag :visible.sync="costHistoryFlag" width="680px">
      <el-table
        :height="height - 300"
        :data="costHistoryList"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in columnCostHistoryList" :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>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="closeCostHistoryDialog">关闭</el-button>
      </span>
    </el-dialog>

    <el-dialog :title="titleCon" @close="closeUploadDialog" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" label-width="80px">
        <el-button type="primary" @click="downloadFile()">下载文件模板</el-button>
        <el-row>
          <el-col :span="24">
            <el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls"
                       :before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" style="text-align: left;">
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :disabled="isLoading" @click="saveUploadFile">{{ isLoading ? '保存中...' : '保存'}}</el-button>
        <el-button type="primary" @click="closeUploadDialog">关闭</el-button>
      </span>
    </el-dialog>

    <choose-list-eam ref="baseList" @getBaseData="getBaseData"></choose-list-eam>

  </div>
</template>
<script>
import {partInformationSearch,partCostInformationEdit,savePartCostComponentByExcel} from "@/api/part/partInformation";
import Chooselist from "../common/Chooselist.vue";
import {getSiteAndBuByUserName, queryFileId} from "../../../api/qc/qc";
import ChooseListEam from "../common/Chooselist_eam.vue";
import {costHistorySearch, verifyData} from "../../../api/part/partInformation";
import {getTableDefaultListLanguage, getTableUserListLanguage} from "../../../api/table";
import {downLoadObjectFile} from "../../../api/eam/eam_object_list";

export default {
  components: {
    ChooseListEam,
    Chooselist
  },
  data() {
    return {
      // ======== 行高 ========
      height: 200,
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      userBuList: [],
      // 导入
      titleCon: '文件导入',
      visible: false,
      isLoading: false,
      fileList: [],
      // 条件查询
      searchData: {
        site: '',
        userName: this.$store.state.user.name,
        bu: '',
        buNo: '',
        partNo: '',
        partDesc: '',
        page: 1,
        limit: 10
      },
      modalData: {
        id: null,
        partId: null,
        bu: '',
        site: '',
        buNo: '',
        sourceBu: '',
        partNo: '',
        partDesc: '',
        umId2: '',
        umName: '',
        familyId: '',
        familyName: '',
        otherGroup1: '',
        otherGroupName1: '',
        standardCost: '',
        standardCostCurrency: '',
        actualCost: '',
        actualCostCurrency: '',
        costRemark: '',
        createBy: '',
        createDate: '',
        updateBy: '',
        updateDate: ''
      },
      originalData: {},
      // ======== 数据列表 ========
      dataList: [],
      costHistoryList: [],
      // 展示列集
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1BuDesc',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'buDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1PartNo',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'partNo',
          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: 6010011,
          serialNumber: '6010011Table1PartDesc',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '物料描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1UmId2',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'umId2',
          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: 6010011,
          serialNumber: '6010011Table1UmName',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'umName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '计量单位名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1PartType2Desc',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'partType2Desc',
          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: 6010011,
          serialNumber: '6010011Table1FamilyId',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'familyId',
          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: 6010011,
          serialNumber: '6010011Table1FamilyName',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'familyName',
          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: 6010011,
          serialNumber: '6010011Table1ProductGroupId1',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'productGroupId1',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组1编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1ProductGroupName1',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'productGroupName1',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '商品组1名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1StandardCost',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'standardCost',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '单位标准成本',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1StandardCostCurrency',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'standardCostCurrency',
          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: 6010011,
          serialNumber: '6010011Table1ActualCost',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'actualCost',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '单位报价成本',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1ActualCostCurrency',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'actualCostCurrency',
          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: 6010011,
          serialNumber: '6010011Table1CostRemark',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'costRemark',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table1CreateDate',
          tableId: '6010011Table1',
          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: 6010011,
          serialNumber: '6010011Table1CreateBy',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'createBy',
          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: 6010011,
          serialNumber: '6010011Table1UpdateDate',
          tableId: '6010011Table1',
          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: 6010011,
          serialNumber: '6010011Table1UpdateBy',
          tableId: '6010011Table1',
          tableName: '物料成本表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        }
      ],
      columnCostHistoryList: [
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table2FieldCaption',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'fieldcaption',
          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: 6010011,
          serialNumber: '6010011Table2FieldName',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'fieldname',
          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: 6010011,
          serialNumber: '6010011Table2OldValue',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'oldvalue',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'Old Value',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table2NewValue',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'newvalue',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'New Value',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010011,
          serialNumber: '6010011Table2Recordtype',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'recordtype',
          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: 6010011,
          serialNumber: '6010011Table2UserId',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'userid',
          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: 6010011,
          serialNumber: '6010011Table2CreateDate',
          tableId: '6010011Table2',
          tableName: '物料成本表',
          columnProp: 'createdate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        }
      ],
      // ======== 模态框开关控制 ========
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      modalFlag: false,
      modalDisableFlag: false,
      costHistoryFlag: false,
      menuId: this.$route.meta.menuId,
      tagNo:undefined,
    }
  },

  mounted () {
    this.$nextTick(() => {
      this.height = window.innerHeight - 180
    })
  },

  created () {
    // 按钮控制
    this.getButtonAuthData()
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
    if (!this.authSearch) {
      // 获取数据列表
      this.getDataList()
    }
  },

  methods: {
    getBaseList(val){
      this.tagNo = val
      this.$nextTick(()=>{
        let strVal = ''
        let conSql = ''
          if (val === 512) {
            strVal = this.modalData.standardCostCurrency ? this.modalData.standardCostCurrency : ''
          }
          if (val === 513) {
            strVal = this.modalData.actualCostCurrency ? this.modalData.actualCostCurrency : ''
          }
        if (this.modalData.bu === null || this.modalData.bu === '') {
          this.$message.warning("请选择BU!")
          return
        } else {
          conSql = " and site = '" + this.modalData.bu.split('-')[0] + "'"
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    getBaseData(val){
        if (this.tagNo === 512){
          this.modalData.standardCostCurrency = val.Currency
          if (this.modalData.actualCostCurrency === '' || this.modalData.actualCostCurrency == null){
            this.modalData.actualCostCurrency = val.Currency
          }
        }
        if (this.tagNo === 513){
          this.modalData.actualCostCurrency = val.Currency
        }
    },

    // 获取用户的bu
    getSiteAndBuByUserName () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(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()
    },

    //获取按钮的权限数据
    getButtonAuthData () {
      let searchFlag = this.isAuth(this.menuId+":search")
      let saveFlag = this.isAuth(this.menuId+":save")
      let updateFlag = this.isAuth(this.menuId+":update")
      let deleteFlag = this.isAuth(this.menuId+":delete")
      //处理页面的权限数据
      this.authSearch = !searchFlag
      this.authSave = !saveFlag
      this.authUpdate = !updateFlag
      this.authDelete = !deleteFlag
    },

    // ======== 列表数据刷新方法 ========
    /**
     * 获取数据列表
     */
    getDataList () {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      this.searchData.buNo = this.searchData.bu.split('_')[1]
      partInformationSearch(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])
          }
        }
      })
    },

    updateModal (row) {
      this.modalData = {
        id: row.id,
        partId: row.partId,
        bu: row.site + '-' + row.sourceBu,
        site: row.site,
        buNo: row.sourceBu,
        buDesc: row.buDesc,
        partNo: row.partNo,
        partDesc: row.partDesc,
        umId2: row.umId2,
        umName: row.umName,
        familyId: row.familyId,
        familyName: row.familyName,
        otherGroup1: row.otherGroup1,
        otherGroupName1: row.otherGroupName1,
        standardCost: row.standardCost,
        standardCostCurrency: row.standardCostCurrency,
        actualCost: row.actualCost,
        actualCostCurrency: row.actualCostCurrency,
        costRemark: row.costRemark,
        createBy: row.createBy,
        createDate: row.createDate,
      }
      if (this.modalData.standardCost === null || this.modalData.standardCost === ''){
        this.modalData.standardCost = 0
      }
      if (this.modalData.standardCostCurrency === null || this.modalData.standardCostCurrency === ''){
        this.modalData.standardCostCurrency = 'CNY'
      }
      if (this.modalData.actualCost === null || this.modalData.actualCost === ''){
        this.modalData.actualCost = 0
      }
      if (this.modalData.actualCostCurrency === null || this.modalData.actualCostCurrency === ''){
        this.modalData.actualCostCurrency = 'CNY'
      }
      this.originalData = JSON.parse(JSON.stringify(this.modalData))
      this.modalFlag = true
    },

    saveData () {
      if (JSON.stringify(this.modalData) === JSON.stringify(this.originalData)) {
        this.closeDialog()
        return
      }
      // 单位标准成本 和单位报价成本只能为正整数的数字，提示2500ms
      let reg = /^[0-9]+.?[0-9]*/
      if (!reg.test(this.modalData.standardCost) || !reg.test(this.modalData.actualCost)) {
        this.$alert('单位标准成本和单位报价成本只能为正整数的数字！', '提示', {
          confirmButtonText: '确定',
          callback: action => {
          }
        })
        return
      }
      let inData = {
        id: this.modalData.id,
        partId: this.modalData.partId,
        bu: this.modalData.bu,
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        standardCost: this.modalData.standardCost,
        standardCostCurrency: this.modalData.standardCostCurrency,
        actualCost: this.modalData.actualCost,
        actualCostCurrency: this.modalData.actualCostCurrency,
        costRemark: this.modalData.costRemark,
        updateBy: this.$store.state.user.name,
        updateDate:''
      }
      this.$confirm('确定保存吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        partCostInformationEdit(inData).then(({data}) => {
          if (data.code === 0) {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            this.getDataList()
            this.closeDialog()
          } else {
            this.$message.error(data.msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消保存'
        })
      })
    },

    closeDialog () {
      this.modalData = {
        flag: '',
        title: '',
        bu: '',
        site: this.$store.state.user.site,
        buNo: '',
        partNo: '',
        partDesc: '',
        umId2: '',
        umName: '',
        familyId: '',
        familyName: '',
        otherGroup1: '',
        otherGroupName1: '',
        standardCost: '',
        standardCostCurrency: '',
        actualCost: '',
        actualCostCurrency: '',
        costRemark: '',
      }
      this.modalFlag = false
    },

    standardCostChange(){
      if (this.modalData.actualCost === '' || this.modalData.actualCost === null){
        this.modalData.actualCost = this.modalData.standardCost
      }
    },

    costHistorySearch(row) {
      let inData = {
        site: row.site,
        partno: row.partNo
      }
      costHistorySearch(inData).then(({data}) => {
        if (data.code === 0) {
          this.costHistoryList = data.rows
          this.costHistoryFlag = true
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    closeCostHistoryDialog () {
      this.costHistoryFlag = false
      this.costHistoryList = []
    },

    // 动态列开始 获取 用户保存的 格式列
    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.columnList = 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.columnList = data.rows
              break;
          }
        }
      })
    },

    partCostUpload () {
      this.visible = true
    },

    // 关闭modal
    closeUploadDialog () {
      this.fileList = []
      // 清空文件上传记录
      this.$refs.uploadFile.clearFiles()
      // 关闭当前的页面
      this.visible = false
    },

    // 保修当前的数据
    saveUploadFile () {
      this.isLoading = true
      // 判断文件是否上传
      if (null == this.fileList || 0 === this.fileList.length) {
        this.$message.error("请先上传文件!")
        return false
      }
      const formData = new FormData()
      formData.append("file", this.fileList[0].raw)
      formData.append("updateBy", this.$store.state.user.name)
      formData.append("site", this.$store.state.user.site.toString())
      savePartCostComponentByExcel(formData).then(({data}) => {
        if (data.code === 0) {
          this.$message.success(data.msg)
          this.getDataList()
          // 关闭窗口并刷新页面
          this.closeUploadDialog()
          this.isLoading = false
        } else {
          this.$message.warning(data.msg)
          this.isLoading = false
        }
      })
    },

    // 上传之前
    beforeUploadHandle (file) {
      let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase()
      if (!(extName === '.xlsx' || extName === '.xls')) {
        this.$message.error('数据导入失败，请选择正确的xlsx模板文件')
        return false
      }
    },

    // 选择上传文件时
    onChange (file) {
      this.fileList.push(file)
    },

    // 下载
    async downloadFile () {
      let file = {
        id: 0,
        fileName: ''
      }
      let tempData = {
        orderRef1: 'partCost',
        orderRef2: 'partCostFormat'
      }
      await queryFileId(tempData).then(({data}) => {
        if (data && data.code === 0) {
          file.id = data.data.id
          file.fileName = data.data.fileName
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
      await downLoadObjectFile(file).then(({data}) => {
        // 不限制文件下载类型
        const blob = new Blob([data], {type: "application/octet-stream"})
        // 下载文件名称
        const fileName = file.fileName
        // a标签下载
        const linkNode = document.createElement('a')
        // a标签的download属性规定下载文件的名称
        linkNode.download = fileName
        linkNode.style.display = 'none'
        // 生成一个Blob URL
        linkNode.href = URL.createObjectURL(blob)
        document.body.appendChild(linkNode)
        // 模拟在按钮上的一次鼠标单击
        linkNode.click()
        // 释放URL 对象
        URL.revokeObjectURL(linkNode.href)
        document.body.removeChild(linkNode)
      })
    },
  }
}
</script>
<style scoped>
.numInput /deep/ .el-input__inner{
  text-align: right;
}
/deep/  .inlineNumber input::-webkit-outer-spin-button,
/deep/  .inlineNumber input::-webkit-inner-spin-button {
  -webkit-appearance: none;

}
/deep/  .inlineNumber input[type="number"]{
  -moz-appearance: textfield;
  padding-right: 5px !important;
}
</style>
```
