<template>
  <div class="mod-config">
    <div>
        <span @click="favoriteFunction()">
         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
        </span>
    </div>

    <!-- 条件查询 -->
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buNo" placeholder="请选择" clearable style="width: 100px">
          <el-option
            v-for = "i in buList"
            :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.classNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'人工等级名称'">
        <el-input v-model="searchData.classDesc" clearable style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item label="是否在用">
        <el-select v-model="searchData.active" clearable placeholder="请选择" style="width: 100px">
          <el-option label="是" value="Y"></el-option>
          <el-option label="否" value="N"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
        <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>


    </el-form>

    <!-- 展示列表 -->
    <el-table
      :height="height"
      :data="dataList"
      ref="laborClassTable"
      @row-click="laborClassClickRow"
      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">
          <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-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-on-click-modal="false" v-drag :visible.sync="modalFlag" width="450px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
        <el-form-item label="BU" prop="bu" :rules="rules.bu">
          <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag" style="width: 75px">
            <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="是否在用" prop="active">
          <el-select v-model="modalData.active" placeholder="请选择" style="width: 70px">
            <el-option label="是" value="Y"></el-option>
            <el-option label="否" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules">
        <el-form-item label="人工等级编码" prop="classNo">
          <el-input v-model="modalData.classNo" :disabled="modalDisableFlag" style="width: 158px"></el-input>
        </el-form-item>
        <el-form-item label="人工等级名称" prop="classDesc">
          <el-input  v-model="modalData.classDesc" style="width: 246px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
        <el-form-item label="备注" style="height: 80px">
          <el-input type="textarea" v-model="modalData.remark" :rows="3" resize='none' show-word-limit style="width: 418px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;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-tabs v-model="activeName" style="width: 100%" :style="{height: secondHeight + 'px'}" type="border-card" @tab-click="tabClick" class="customer-tab">
      <el-tab-pane label="详情" name="detail">
        <el-form label-position="top" :model="dataList1" style="margin-left: 10px;margin-top: 5px;margin-right: 10px">
          <el-row :gutter="10">
            <el-col :span="4">
              <div class="grid-content bg-purple">
                <el-form-item :label="'人工等级编码'">
                  <el-input v-model="dataList1.classNo" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="10">
              <div class="grid-content bg-purple">
                <el-form-item :label="'人工等级名称'">
                  <el-input v-model="dataList1.classDesc" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="2">
              <div class="grid-content bg-purple">
                <el-form-item :label="'是否在用'">
                  <el-input v-model="dataList1.activeDesc" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="4">
              <div class="grid-content bg-purple">
                <el-form-item :label="'创建人'">
                  <el-input v-model="dataList1.createdBy" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="grid-content bg-purple">
                <el-form-item :label="'创建时间'">
                  <el-input v-model="dataList1.createdDate" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="grid-content bg-purple">
                <el-form-item :label="'修改人'">
                  <el-input v-model="dataList1.updatedBy" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="grid-content bg-purple">
                <el-form-item :label="'修改时间'">
                  <el-input v-model="dataList1.updatedDate" readonly></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="16">
              <div class="grid-content bg-purple">
                <el-form-item label="备注" style="height: 80px">
                  <el-input type="textarea" v-model="dataList1.remark" readonly :rows="3" resize='none' show-word-limit></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>

      <el-tab-pane label="成本" name="cost">
        <div style="margin-left: 5px;margin-top: 5px">
          <el-button v-if="!authSave" type="primary" @click="addModal1()">新增</el-button>
        </div>
        <el-table
          :data="dataList2"
          :height="secondHeight - 54"
          border
          style="width: 100%;margin-top: 5px">
          <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
            header-align="center"
            align="center"
            width="100"
            label="操作">
            <template slot-scope="scope">
              <a type="text" size="small" @click="updateModal1(scope.row)">修改</a>
              <a type="text" size="small" @click="deleteModal1(scope.row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <!-- 成本新增和修改  -->
    <el-dialog title="成本" :close-on-click-modal="false" v-drag :visible.sync="modalFlag1" width="500px">
      <el-form :inline="true" label-position="top" :model="modalData1" :rules="rules1" style="margin-top: -5px;">
        <el-form-item label="单位制造费用成本:" prop="overheadCost">
          <el-input-number :controls="false" :step="0" min="0" v-model="modalData1.overheadCost" style="width: 225px"></el-input-number>
        </el-form-item>
        <el-form-item label="单位人工成本:" prop="unitCost">
          <el-input-number :controls="false" :step="0" min="0" v-model="modalData1.unitCost" style="width: 225px"></el-input-number>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData1" :rules="rules1">
        <el-form-item :label="'启用日期'" prop="beginDate">
          <el-date-picker
            style="width: 225px"
            v-model="modalData1.beginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="'结束日期'" >
          <el-date-picker
            style="width: 225px"
            v-model="modalData1.endDate"
            type="date"
            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-top: -5px;">
        <el-form-item label="备注" style="height: 80px">
          <el-input type="textarea" v-model="modalData1.remark" :rows="3" resize='none' show-word-limit style="width: 467px"></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, //查询人工等级
  insertByLabor,//新增人工等级
  updateLabor,//修改人工等级
  deleteLabor,//删除人工等级
  findByLabor,//查询(获取单个详情数据)
  appendByLaborClass,//成本新增
  queryByLaborClass, //成本查询
  amendByLaborClass,//成本修改
  deleteByLaborClass,//删除成本
} from "@/api/fanucGroup/labor.js"
import {getSiteAndBuByUserName, getSiteAndBuByUserName2} from "@/api/qc/qc.js"
import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
export default {
  data () {
    return {
      activeName:'detail',
      currentRow:'',
      currentRow2:'',
      headerData2:'',
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: "检验方法" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["检验方法"],
      exportFooter: [],
      exportList: [],
      buList: [],
      // 导出 end
      searchData: {
        site: '',
        buNo: '',
        userName: this.$store.state.user.name,
        classNo: '',
        classDesc: '',
        active: '',
        page: 1,
        limit: 10,
      },
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      height: 200,
      secondHeight: 200,
      dataList: [],
      dataList1: {
        site: '',
        buNo: '',
        classNo: '',
        classDesc: '',
        active: '',
        createdDate: '',
        createdBy: '',
        updatedDate: '',
        updatedBy: '',
        remark: '',
      },
      dataList2:[],
      dataListLoading: false,
      modalFlag: false,
      modalFlag1: false,
      modalDisableFlag: false,
      modalDisableFlag1: false,
      modalData: {
        site: '',
        id: '',
        bu: '',
        buNo: '',
        classNo: '',
        classDesc: '',
        active: '',
        createdDate: '',
        createdBy: '',
        updatedDate: '',
        updatedBy: '',
        remark: '',
      },
      modalData1:{
        site: '',
        classNo: '',
        itemNo: '',
        unitCost: '',
        overheadCost: '',
        umId: '',
        beginDate: '',
        endDate: '',
        remark: '',
        laborClassId: '',
      },
      // 标头展示
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableBuNo',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 100,
          columnProp: 'buDesc',
          headerAlign: 'center',
          align: "center",
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableClassNo',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 120,
          columnProp: 'classNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '人工等级编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableClassDesc',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 200,
          columnProp: 'classDesc',
          headerAlign: 'center',
          align: "left",
          columnLabel: '人工等级名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableActive',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 100,
          columnProp: 'activeDesc',
          headerAlign: 'center',
          align: "center",
          columnLabel: '是否在用',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableRemark',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 200,
          columnProp: 'remark',
          headerAlign: 'center',
          align: "left",
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableCreatedDate',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 160,
          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: 501003,
          serialNumber: '501003TableCreatedBy',
          tableId: "501003Table",
          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: 501003,
          serialNumber: '501003TableUpdatedDate',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 160,
          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: 501003,
          serialNumber: '501003TableUpdatedBy',
          tableId: "501003Table",
          tableName: "人工等级",
          columnWidth: 100,
          columnProp: 'updatedBy',
          headerAlign: 'center',
          align: "left",
          columnLabel: '修改人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnList2: [
        {
          userId: this.$store.state.user.name,
          functionId: 501003,
          serialNumber: '501003TableItemNo',
          tableId: "501003Table",
          tableName: "成本",
          columnWidth: 100,
          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: 501003,
          serialNumber: '501003TableUnitCost',
          tableId: "501003Table",
          tableName: "成本",
          columnWidth: 100,
          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: 501003,
          serialNumber: '501003TableOverheadCost',
          tableId: "501003Table",
          tableName: "成本",
          columnWidth: 100,
          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: 501003,
          serialNumber: '501003TableBeginDate',
          tableId: "501003Table",
          tableName: "成本",
          columnWidth: 150,
          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: 501003,
          serialNumber: '501003TableEndDate',
          tableId: "501003Table",
          tableName: "成本",
          columnWidth: 150,
          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: 501003,
          serialNumber: '501003TableRemark',
          tableId: "501003Table",
          tableName: "成本",
          columnWidth: 200,
          columnProp: 'remark',
          headerAlign: 'center',
          align: "left",
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      rules: {
        classNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        bu: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
      },
      rules1: {
        overheadCost: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        unitCost: [
          {
            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 / 2 - 30
      /*第二个表格高度的动态调整*/
      this.secondHeight = window.innerHeight - this.height - 175
    })
  },

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

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

  methods: {
    // 获取用户的bu
    getSiteAndBuByUserName2 () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName2(tempData).then(({data}) => {
        if (data.code === 0) {
          this.buList = data.rows
        }
      })
    },

    // 获取用户的bu
    getSiteAndBuByUserName () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    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, '');
    },

    // 查询获取数据列表
    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.$refs.laborClassTable.setCurrentRow(this.dataList[0])
            this.laborClassClickRow(this.dataList[0])
          } else {
            this.currentRow = {}
          }
        }
      })
    },

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

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

    //页签二插查询
    tabClick (tab, event) {
      // 刷新列表数据
      if (this.activeName === 'cost') {
        this.refreshCurrentTabTable2()
      }
    },

    laborClassClickRow (row) {
      this.currentRow = JSON.parse(JSON.stringify(row))
      this.dataList1 = this.currentRow
      this.refreshCurrentTabTable2()
    },

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

    refreshCurrentTabTable2(){
      queryByLaborClass(this.currentRow).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code === 0) {
          this.dataList2 = data.rows
        } else {
          this.dataList2 = []
        }
      });
    },
    //人工等级
    // 新增按钮
    addModal () {
      this.modalData = {
        flag: '1',
        site: '',
        buNo: '',
        bu: this.userBuList[0].buNo,
        classNo: '',
        classDesc: '',
        active: 'Y',
        createdDate: '',
        createdBy: this.$store.state.user.name,
        updatedDate: '',
        updatedBy: '',
        remark: '',
      }
      this.modalDisableFlag = false
      this.modalFlag = true
    },

    // 修改按钮
    updateModal (row) {
      this.modalData = {
        flag: '2',
        id: row.id,
        bu: row.site + '_' + row.buNo,
        site: row.site,
        buNo: row.buNo,
        classNo: row.classNo,
        classDesc: row.classDesc,
        active: row.active,
        createdDate: row.createdDate,
        createdBy: row.createdBy,
        updatedDate: '',
        updatedBy: this.$store.state.user.name,
        remark: row.remark,
      }
      this.modalDisableFlag = true
      this.modalFlag = true
    },

    saveData () {
      if (this.modalData.bu === '' || this.modalData.bu == null) {
        this.$message.warning('请选择BU！')
        return
      }
      if (this.modalData.classNo === '' || this.modalData.classNo == null) {
        this.$message.warning('请填写人工等级编码！')
        return
      }
      if (this.modalData.classDesc === '' || this.modalData.classDesc == null) {
        this.$message.warning('请填写人工等级名称！')
        return
      }
      if (this.modalData.flag === '1') { // 新增
        insertByLabor(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      } else { // 修改
        updateLabor(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },

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

    //成本
    // 新增按钮
    addModal1 () {
      this.modalData1 = {
        flag1: '1',
        site: this.currentRow.site,
        buNo: this.currentRow.buNo,
        classNo: this.currentRow.classNo,
        itemNo: '',
        unitCost: '',
        overheadCost: '',
        umId: '',
        beginDate: this.formatDate(new Date()),
        endDate: '',
        remark: '',
      }
      this.modalDisableFlag1 = false
      this.modalFlag1 = true
    },

    // 修改按钮
    updateModal1 (row) {
      this.modalData1 = {
        flag1: '2',
        site: this.currentRow.site,
        buNo: this.currentRow.buNo,
        classNo: this.currentRow.classNo,
        itemNo: row.itemNo,
        unitCost: row.unitCost,
        overheadCost: row.overheadCost,
        umId: row.umid,
        beginDate: row.beginDate,
        endDate: row.endDate,
        remark: row.remark,
      }
      this.modalDisableFlag1 = true
      this.modalFlag1 = true
    },

    // 新增/修改方法
    saveData1 () {
      if (this.modalData1.beginDate === '' || this.modalData1.beginDate == null) {
        this.$message.warning('请选择启动日期！')
        return
      }
      if (this.modalData1.flag1 === '1') { // 新增
        appendByLaborClass(this.modalData1).then(({data}) => {
          if (data && data.code === 0) {
            this.refreshCurrentTabTable2()
            this.modalFlag1 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      } else { // 修改
        amendByLaborClass(this.modalData1).then(({data}) => {
          if (data && data.code === 0) {
            this.refreshCurrentTabTable2()
            this.modalFlag1 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },

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

    // 校验用户是否收藏
    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.page.list
      })
      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) {
          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;
          }
        } 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>
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
  height: 459px;
}
.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>
