<template>
  <div class="mod-config">
    <!-- 条件查询 -->
    <div style="width: 1000px">
      <el-form label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
        <el-row :gutter="10">
          <el-col :span="3">
            <el-form-item label="BU">
              <bu-select v-model="searchData.buId">
                <el-option label="全部" value=""></el-option>
              </bu-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="加工中心编码">
              <el-input v-model="searchData.workCenterNo" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="加工中心名称">
              <el-input v-model="searchData.workCenterDesc" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="状态">
              <el-select v-model="searchData.active" style="width: 100%;" placeholder="请选择">
                <el-option label="全部" value=""></el-option>
                <el-option label="启用" value="Y"></el-option>
                <el-option label="停用" value="N"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label=" ">
              <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <!-- 展示列表 -->
    <el-table
      height="42vh"
      :data="dataList"
      @row-click="changeData"
      :row-style="rowStyle"
      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">
          <template v-if="item.columnProp==='active'">
            <span> {{ scope.row[item.columnProp] === 'Y' ? '启用' : '停用' }}</span>
          </template>
          <template v-else>
            <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>
        </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-tabs style="height: auto;min-height: 40vh" class="customer-tab" v-model="activeName" type="border-card" @tab-click="tabClick">
      <el-tab-pane label="详情" name="detail">
        <el-form label-position="top" :model="currentRow">
          <el-row :gutter="10">
            <el-col :span="3">
              <el-form-item label="工厂编码">
                <el-input v-model="currentRow.site" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="BU">
                <el-input v-model="currentRow.buDesc" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="加工中心编码">
                <el-input v-model="currentRow.workshopId" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="加工中心名称">
                <el-input v-model="currentRow.workCenterDesc" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="加工中心类型">
                <el-input v-model="currentRow.workCenterType" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="加工中心组编码">
                <el-input v-model="currentRow.prolineNo" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="3">
              <el-form-item label="机台数量">
                <el-input v-model="currentRow.resourceCount" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="人均日产量">
                <el-input v-model="currentRow.refDailyProduction" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="速度">
                <el-input v-model="currentRow.refSpeed" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="时间">
                <el-input v-model="currentRow.refTime" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="效率">
                <el-input v-model="currentRow.refEfficiency" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="3">
              <el-form-item label="录入时间">
                <el-input v-model="currentRow.createdDate" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="录入人">
                <el-input v-model="currentRow.createdBy" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="最近修改时间">
                <el-input v-model="currentRow.updatedDate" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="最近修改人">
                <el-input v-model="currentRow.updateBy" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="15">
              <el-form-item :label="'备注'" class="auto">
                <el-input v-model="currentRow.remark" readonly resize='none' :rows="3" type="textarea"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>

      <el-tab-pane label="成本" name="cost">
        <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
        <el-table
          :data="dataList2"
          height="33vh"
          border
          style="width: 100%; ">
          <el-table-column
            v-for="(item,index) in columnList2" :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="160"
            label="操作">
            <template slot-scope="scope">
              <a type="text" size="small" @click="updateModal(scope.row)">修改</a>
              <a type="text" size="small" @click="deleteModal(scope.row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>

      <el-tab-pane label="机台" name="resource">
        <el-table
          :data="dataList3"
          height="35vh"
          border
          style="width: 100%; ">
          <el-table-column
            v-for="(item,index) in columnList3" :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-tab-pane>
    </el-tabs>


    <!-- 新增和修改 -->
    <el-dialog title="成本" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="500px">
      <el-form label-position="top" :model="modalData1" :rules="rules">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="加工中心编码" prop="workCenterNo">
              <el-input v-model="modalData1.workCenterNo" :disabled="!isNew"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="单位成本" prop="unitCost">
              <el-input-number v-model="modalData1.unitCost" style="width: 100%" :controls="false"
                               :step="0"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位制造费用成本" prop="overheadCost">
              <el-input-number v-model="modalData1.overheadCost" style="width: 100%" :controls="false"
                               :step="0"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位人工成本" prop="laborCost">
              <el-input-number v-model="modalData1.laborCost" style="width: 100%" :controls="false"
                               :step="0"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'启用日期'">
              <el-date-picker
                style="width: 100%"
                v-model="modalData1.beginDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'结束日期'">
              <el-date-picker
                style="width: 100%"
                v-model="modalData1.endDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" class="auto">
              <el-input v-model="modalData.remark" :rows="3" type="textarea"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:30px;line-height: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-dialog title="加工中心" :close-on-click-modal="false" v-drag :visible.sync="modalFlag1" width="500px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules"
               style="margin-left: 7px;margin-top: -5px;">

        <el-form-item label="加工中心编码:" prop="workCenterNo">
          <el-input v-model="modalData.workCenterNo" style="width: 221px"></el-input>
        </el-form-item>

        <el-form-item label="加工中心名称:" prop="workCenterDesc">
          <el-input v-model="modalData.workCenterDesc" style="width: 221px;text-align:end"></el-input>
        </el-form-item>

        <el-form-item label="加工中心类型:" prop="workCenterType">
          <el-input v-model="modalData.workCenterType" style="width: 221px"></el-input>
        </el-form-item>

        <el-form-item label="加工中心组编码:" prop="prolineNo">
          <el-input v-model="modalData.prolineNo" style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="状态:" prop="active">
          <el-input v-model="modalData.active" style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveData1()">保存</el-button>
        <el-button type="primary" @click="modalFlag1 = false">关闭</el-button>
      </el-footer>
    </el-dialog>


  </div>
</template>

<script>
import {
  findAll, // 检验方法查询
  updateFanuc, // 检验方法修改
  findFanuc,//查询(传的list)
  appendByCost,//成本新增
  queryByCost, //成本查询
  amendByCost,//成本修改
  deleteByCost,//删除成本
  queryResourceInfo,//机台查询
} from "@/api/fanucGroup/fanuc.js"
import {getSiteAndBuByUserName} from "@/api/eam/eam.js"
import BuSelect from "../../../components/selector/select/BuSelect.vue";

export default {
  components: {BuSelect},
  data() {
    return {
      activeName: 'detail',
      currentRow: {},
      headerData: '',
      currentRow2: '',
      isNew: false,
      headerData2: '',
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: "检验方法" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["检验方法"],
      exportFooter: [],
      exportList: [],
      // 导出 end
      searchData: {
        site: '',
        buNo: '',
        buId: '',
        workshopId: '',
        workCenterNo: '',
        workCenterDesc: '',
        workCenterTypeDb: '',
        workCenterType: '',
        updateBy: this.$store.state.user.name,
        updateDate: '',
        averageCapacity: '',
        efficiency: '',
        utilization: '',
        capacityTypeDb: '',
        capacityType: '',
        umid: '',
        active: '',
        prolineNo: '',
        needSetupFlag: '',
        createdBy: this.$store.state.user.name,
        createdDate: '',
        remark: '',
        delflag: '',
        version: '',
        page: 1,
        limit: 10,
      },
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      height: 200,
      dataList: [],
      dataList1: [],
      dataList2: [],
      dataList3: [],
      dataListLoading: false,
      modalFlag: false,
      modalDisableFlag: false,
      modalFlag1: false,
      modalDisableFlag1: false,
      modalData: {
        site: this.$store.state.user.site,
        bu: '',
        buNo: '',
        workshopId: '',
        workCenterNo: '',
        workCenterDesc: '',
        workCenterTypeDb: '',
        workCenterType: '',
        updateBy: this.$store.state.user.name,
        updateDate: '',
        averageCapacity: '',
        efficiency: '',
        utilization: '',
        capacityTypeDb: '',
        capacityType: '',
        umid: '',
        active: '',
        prolineNo: '',
        needSetupFlag: '',
        createdBy: this.$store.state.user.name,
        createdDate: '',
        remark: '',
        delflag: '',
        version: ''
      },
      modalData1: {
        site: this.$store.state.user.site,
        workCenterNo: '',
        itemNo: '',
        unitCost: '',
        overheadCost: '',
        laborCost: '',
        umId: '',
        beginDate: this.formatDate(new Date()),
        endDate: '',
        remark: '',
        serialNo: '',
      },
      // 标头展示
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableSite',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 60,
          columnProp: 'site',
          headerAlign: 'center',
          align: "center",
          columnLabel: '工厂编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableBuDesc',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'buDesc',
          headerAlign: 'center',
          align: "left",
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableWorkCenterNo',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 120,
          columnProp: 'workCenterNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '加工中心编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableWorkCenterDesc',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 150,
          columnProp: 'workCenterDesc',
          headerAlign: 'center',
          align: "left",
          columnLabel: '加工中心名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableWorkCenterType',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'workCenterType',
          headerAlign: 'center',
          align: "center",
          columnLabel: '加工中心类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableProlineNo',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 120,
          columnProp: 'prolineNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '加工中心组编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableResourceCount',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 80,
          columnProp: 'resourceCount',
          headerAlign: 'center',
          align: "right",
          columnLabel: '机台数',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableRefDailyProduction',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'refDailyProduction',
          headerAlign: 'center',
          align: "right",
          columnLabel: '人均日产量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableRefSpeed',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'refSpeed',
          headerAlign: 'center',
          align: "right",
          columnLabel: '速度',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableRefTime',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'refTime',
          headerAlign: 'center',
          align: "right",
          columnLabel: '时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableRefEfficiency',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'refEfficiency',
          headerAlign: 'center',
          align: "right",
          columnLabel: '效率',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableActive',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 80,
          columnProp: 'active',
          headerAlign: 'center',
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableCreatedDate',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 130,
          columnProp: 'createdDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '录入时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableCreatedBy',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: "left",
          columnLabel: '录入人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableUpdateDate',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 130,
          columnProp: 'updatedDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '最近修改时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableUpdateBy',
          tableId: "501002Table",
          tableName: "加工中心",
          columnWidth: 100,
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: "left",
          columnLabel: '最近修改人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnList1: [
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableSite',
          tableId: "501002Table",
          tableName: "工厂编码",
          columnWidth: 130,
          columnProp: 'site',
          headerAlign: 'center',
          align: "center",
          columnLabel: '工厂编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableBuNo',
          tableId: "501002Table",
          tableName: "BU",
          columnWidth: 130,
          columnProp: 'buNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: 'Bu',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableWorkCenterNo',
          tableId: "501002Table",
          tableName: "加工中心编码",
          columnWidth: 130,
          columnProp: 'workCenterNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '加工中心编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableWorkCenterDesc',
          tableId: "501002Table",
          tableName: "加工中心名称",
          columnWidth: 130,
          columnProp: 'workCenterDesc',
          headerAlign: 'center',
          align: "left",
          columnLabel: '加工中心名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableWorkCenterType',
          tableId: "501002Table",
          tableName: "加工中心类型",
          columnWidth: 130,
          columnProp: 'workCenterType',
          headerAlign: 'center',
          align: "center",
          columnLabel: '加工中心类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableProlineNo',
          tableId: "501002Table",
          tableName: "加工中心组编码",
          columnWidth: 130,
          columnProp: 'prolineNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '加工中心组编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableActive',
          tableId: "501002Table",
          tableName: "状态",
          columnWidth: 130,
          columnProp: 'active',
          headerAlign: 'center',
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableCreatedDate',
          tableId: "501002Table",
          tableName: "创建时间",
          columnWidth: 130,
          columnProp: 'createdDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableCreatedBy',
          tableId: "501002Table",
          tableName: "创建人",
          columnWidth: 130,
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: "left",
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableUpdateDate',
          tableId: "501002Table",
          tableName: "修改时间",
          columnWidth: 130,
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: "left",
          columnLabel: '修改时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableUpdateBy',
          tableId: "501002Table",
          tableName: "修改时间",
          columnWidth: 130,
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: "left",
          columnLabel: '修改时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableRemark',
          tableId: "501002Table",
          tableName: "备注",
          columnWidth: 130,
          columnProp: 'remark',
          headerAlign: 'center',
          align: "left",
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnList2: [
        // {
        //   userId: this.$store.state.user.name,
        //   functionId: 501002,
        //   serialNumber: '501002TableSite',
        //   tableId: "501002Table",
        //   tableName: "工厂编码",
        //   columnWidth: 130,
        //   columnProp: 'site',
        //   headerAlign: 'center',
        //   align: "center",
        //   columnLabel: '工厂编码',
        //   columnHidden: false,
        //   columnImage: false,
        //   columnSortable: false,
        //   sortLv: 0,
        //   status: true,
        //   fixed: '',
        // },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableItemNo',
          tableId: "501002Table",
          tableName: "序号",
          columnWidth: 130,
          columnProp: 'itemNo',
          headerAlign: 'center',
          align: "right",
          columnLabel: '序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableUnitCost',
          tableId: "501002Table",
          tableName: "单位成本",
          columnWidth: 130,
          columnProp: 'unitCost',
          headerAlign: 'center',
          align: "right",
          columnLabel: '单位成本',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableOverheadCost',
          tableId: "501002Table",
          tableName: "单位制造费用成本",
          columnWidth: 130,
          columnProp: 'overheadCost',
          headerAlign: 'center',
          align: "right",
          columnLabel: '单位制造费用成本',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableLaborCost',
          tableId: "501002Table",
          tableName: "单位人工成本",
          columnWidth: 130,
          columnProp: 'laborCost',
          headerAlign: 'center',
          align: "right",
          columnLabel: '单位人工成本',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableBeginDate',
          tableId: "501002Table",
          tableName: "启用日期",
          columnWidth: 130,
          columnProp: 'beginDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '启用日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableEndDate',
          tableId: "501002Table",
          tableName: "结束日期",
          columnWidth: 130,
          columnProp: 'endDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '结束日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableRemark',
          tableId: "501002Table",
          tableName: "备注",
          columnWidth: 130,
          columnProp: 'remark',
          headerAlign: 'center',
          align: "left",
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnList3: [
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableResourceId',
          tableId: "501002Table",
          tableName: "机台编码",
          columnWidth: 130,
          columnProp: 'resourceId',
          headerAlign: 'center',
          align: "left",
          columnLabel: '机台编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableResourceDesc',
          tableId: "501002Table",
          tableName: "机台名称",
          columnWidth: 130,
          columnProp: 'resourceDesc',
          headerAlign: 'center',
          align: "left",
          columnLabel: '机台名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableCreationDate',
          tableId: "501002Table",
          tableName: "创建时间",
          columnWidth: 130,
          columnProp: 'creationDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501002,
          serialNumber: '501002TableCreatedBy',
          tableId: "501002Table",
          tableName: "创建人",
          columnWidth: 130,
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: "left",
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      rules: {
        prodLineNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        site: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        bu: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        unitCost: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        overheadCost: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        laborCost: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        beginDate: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ]
      },
      options: [],
      userBuList: [],
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      menuId: this.$route.meta.menuId,
    }
  },

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

  //编码自动转化成大写
  watch: {
    modalData: {
      deep: true,
      handler: function (newV, oldV) {
        this.modalData.prodLineNo = this.modalData.prodLineNo.toUpperCase()
      }
    }
  },

  created() {
    //页面在加载的时候就调用查询方法
    this.getDataList()
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
  },

  methods: {
    formatDate(date) {
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      // const hours = date.getHours().toString().padStart(2, '0');
      // const minutes = date.getMinutes().toString().padStart(2, '0');
      // const seconds = date.getSeconds().toString().padStart(2, '0');
      // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      return `${year}-${month}-${day}`;
    },


    validateInput() {
      // 只保留数字
      this.inputValue = this.inputValue.replace(/\D/g, '');
    },
    // 获取用户的bu
    getSiteAndBuByUserName() {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    // 查询获取数据列表
    getDataList() {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      findAll(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.dataList.length > 0) {
          this.currentRow = this.dataList[0]
          this.refreshCurrentTabTable()
        }
      })
    },

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

    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
//页签二插查询

    tabClick(tab, event) {
      // 刷新列表数据
      if (this.activeName == 'detail') {
        this.refreshCurrentTabTable()
      } else if (this.activeName == 'cost') {
        this.refreshCurrentTabTable2()
      } else if (this.activeName == 'resource') {
        this.refreshCurrentTabTable3()
      }
    },

    changeData(row) {
      this.currentRow = JSON.parse(JSON.stringify(row));
      // this.headerData = row;

      if (this.activeName === 'detail') {
        // this.refreshCurrentTabTable()
      } else if (this.activeName === 'cost') {
        this.refreshCurrentTabTable2()
      } else if (this.activeName === 'resource') {
        this.refreshCurrentTabTable3()
      }
    },

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

    refreshCurrentTabTable() {

      findFanuc(this.currentRow).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code === 0) {
          this.dataList1 = data.rows[0]
        } else {
          this.dataList1 = [];
        }
      });
    },

    refreshCurrentTabTable2() {

      queryByCost(this.currentRow).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code == 0) {
          this.dataList2 = data.rows
        } else {
          this.dataList2 = [];
        }
      });
    },

    refreshCurrentTabTable3() {
      queryResourceInfo(this.currentRow).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code == 0) {
          this.dataList3 = data.rows
        } else {
          this.dataList3 = [];
        }
      });
    },

    // 新增按钮
    addModal() {
      this.modalData1 = {
        flag: '1',
        site: this.$store.state.user.site,
        workCenterNo: this.currentRow.workCenterNo,
        itemNo: '',
        unitCost: '',
        overheadCost: '',
        laborCost: '',
        umId: '',
        beginDate: this.formatDate(new Date()),
        endDate: '',
        remark: '',

      }
      this.modalDisableFlag = false
      this.modalFlag = true
    },

    // 修改按钮
    updateModal(row) {
      this.modalData1 = {
        flag: '2',
        site: this.$store.state.user.site,
        workCenterNo: this.currentRow.workCenterNo,
        id: row.id,
        itemNo: row.itemNo,
        unitCost: row.unitCost,
        overheadCost: row.overheadCost,
        laborCost: row.laborCost,
        umId: row.umid,
        beginDate: row.beginDate,
        endDate: row.endDate,
        remark: row.remark,
      }
      this.modalDisableFlag = true
      this.modalFlag = true
    },

    // 删除方法
    deleteModal(row) {
      this.$confirm(`是否删除此数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteByCost(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable2()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },

    // 新增/修改方法
    saveData() {
      if (this.modalData1.flag === '1') { // 新增
        if (this.modalData1.workCenterNo == null || this.modalData1.workCenterNo === '') {
          this.$message.warning('请选择一条加工中心数据！')
          return
        }
        if (this.modalData1.beginDate == null || this.modalData1.beginDate === '') {
          this.$message.warning('请选择启用日期！')
          return
        }
        if (this.modalData1.unitCost == null || this.modalData1.unitCost < 0) {
          this.$message.warning('单位成本不能小于0！')
          return
        }
        appendByCost(this.modalData1).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable2()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      } else { // 修改
        amendByCost(this.modalData1).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable2()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {

              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },
    //加工中心
    updateModal1(row) {
      this.modalData = {
        flag: '2',
        site: this.$store.state.user.site,
        id: row.id,
        bu: row.bu,
        buNo: row.buNo,
        workshopId: row.buNo,
        workCenterNo: row.workCenterNo,
        workCenterDesc: row.workCenterDesc,
        workCenterTypeDb: row.workCenterTypeDb,
        workCenterType: row.workCenterType,
        updateBy: this.$store.state.user.name,
        updateDate: row.updateDate,
        averageCapacity: row.averageCapacity,
        efficiency: row.efficiency,
        utilization: row.utilization,
        capacityTypeDb: row.capacityTypeDb,
        capacityType: row.capacityType,
        umid: row.umid,
        active: row.active,
        prolineNo: row.prolineNo,
        needSetupFlag: row.needSetupFlag,
        createdBy: this.$store.state.user.name,
        createdDate: row.createDate,
        remark: row.remark,
        delflag: row.delflag,
        version: row.version
      }
      this.modalDisableFlag1 = true
      this.modalFlag1 = true
    },
    saveData1() {
      if (this.modalData.flag === '2') { // 修改
        updateFanuc(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable2()
            this.modalFlag1 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {

              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },


    // 查询检验类型
    inspectionTypeSearch() {
      let tempData = {
        site: this.$store.state.user.site
      }
      inspectionTypeSearch(tempData).then(({data}) => {
        if (data.code === 0) {
          this.options = data.rows
        }
      })
    },

    // 校验用户是否收藏
    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) {
        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
        })
      }
    },

    //导出excel
    async createExportData() {
      this.searchData.limit = -1
      this.searchData.page = 1
      await findAll(this.searchData).then(({data}) => {
        this.exportList = data.rows
      })
      return this.exportList
    },

    startDownload() {
    },

    finishDownload() {
    },

    fields() {
      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
    },

    // 动态列开始 获取 用户保存的 格式列
    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) {
          //this.columnList1 = []
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
            // case 2:
            //   this.columnDetailList = data.rows
            //   break;
            // case 3:
            //   this.columnList2 = data.rows
            //   break;
            // case 4:
            //   this.columnList3 = 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;
            // case 2:
            //   this.columnDetailList = data.rows
            //   break;
            // case 3:
            //   this.columnList2 = data.rows
            //   break;
            // case 4:
            //   this.columnList3 = data.rows
            //   break;
          }
        } else {
          // this.showDefault = true.
        }
      })
    },

    //获取按钮的权限数据
    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
    },
  }
}
</script>

<style scoped>
.numInput /deep/ .el-input__inner {
  text-align: right;
  padding-right: 5px !important;
}
.auto /deep/ .el-form-item__content {
  height: auto;
  line-height: 1.5;
}
</style>
