<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.buDesc" 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.operationNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'工序名称'">
        <el-input v-model="searchData.operationName" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" @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"
      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="160"
        label="操作">
        <template slot-scope="scope">
          <el-link v-if="!authUpdate" style="cursor: pointer" @click="updateModal(scope.row)">修改</el-link>
          <el-link v-if="!authDelete" style="cursor: pointer" @click="delModal(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="modalData.title" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="577px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="工序号" prop="operationNo" :rules="rules.operationNo">
          <el-input v-model="modalData.operationNo" :disabled="modalDisableFlag" style="width: 140px"></el-input>
        </el-form-item>
        <el-form-item label="工序名称" prop="operationName" :rules="rules.operationName">
          <el-input v-model="modalData.operationName" style="width: 302px"></el-input>
        </el-form-item>
        <el-form-item label="BU" prop="bu" :rules="rules.bu">
          <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag" style="width: 70px">
            <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>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="workCenterNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(216)"><a herf="#">加工中心编码</a></span>
          <el-input v-model="modalData.workCenterNo" @blur="workCenterBlur(216)" style="width: 140px"></el-input>
        </el-form-item>
        <el-form-item :label="'加工中心名称'" prop="workCenterDesc" :rules="rules.workCenterDesc">
          <el-input v-model="modalData.workCenterDesc" disabled style="width: 302px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="laborClassNo" :rules="rules.laborClassNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(217, 1)"><a herf="#">人员等级编码</a></span>
          <el-input v-model="modalData.laborClassNo" @blur="laborClassBlur(217)" style="width: 140px"></el-input>
        </el-form-item>
        <el-form-item :label="'人员等级描述'" prop="laborClassDesc" :rules="rules.laborClassDesc">
          <el-input v-model="modalData.laborClassDesc" disabled style="width: 302px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="setupLaborClassNo" :rules="rules.setupLaborClassNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(217, 2)"><a herf="#">调机时人员等级编码</a></span>
          <el-input v-model="modalData.setupLaborClassNo" @blur="setupLaborClassBlur(217)" style="width: 140px"></el-input>
        </el-form-item>
        <el-form-item :label="'调机时人员等级描述'" prop="setupLaborClassDesc" :rules="rules.setupLaborClassDesc">
          <el-input v-model="modalData.setupLaborClassDesc" disabled style="width: 302px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:30px;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>

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


<script>
import {
  searchStandardRoutingOperationList, // 分类信息列表查询
  saveStandardRoutingOperation, // 分类信息新增
  updateStandardRoutingOperation, // 分类信息编辑
  deleteStandardRoutingOperation // 分类信息删除
} from '@/api/part/standardRoutingOperation.js'
import {getSiteAndBuByUserName} from "@/api/eam/eam.js"
import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
import {verifyData} from "../../../api/part/partInformation";

import ChooseList from '@/views/modules/common/Chooselist_eam'

export default {
  // 组件
  components: {
    ChooseList
  },
  watch: {
    'modalData.workCenterNo': function (val) {
      this.modalData.workCenterNo = val.toUpperCase()
    },
    'modalData.setupLaborClassNo': function (val) {
      this.modalData.setupLaborClassNo = val.toUpperCase()
    },
    'modalData.laborClassNo': function (val) {
      this.modalData.laborClassNo = val.toUpperCase()
    },
  },
  data () {
    return {
      // 导出
      exportData: [],
      exportName: '物料分类' + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ['物料分类'],
      exportFooter: [],
      resultList: [],
      userBuList: [],
      // ======== 行高 ========
      height: 200,
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      // 条件查询
      searchData: {
        site: '',
        userName: this.$store.state.user.name,
        buNo: '',
        operationNo: '',
        operationName: '',
        page: 1,
        limit: 10
      },
      modalData: {
        flag: '',
        title: '',
        bu: '',
        site: this.$store.state.user.site,
        buNo: '',
        operationNo: '',
        operationName: '',
        workCenterNo: '',
        workCenterDesc: '',
        laborClassNo: '',
        laborClassDesc: '',
        setupLaborClassNo: '',
        setupLaborClassDesc: '',
      },
      // ======== 数据列表 ========
      dataList: [],
      // 展示列集
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 6010012,
          serialNumber: '6010012Table1BuDesc',
          tableId: "6010012Table1",
          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: 6010012,
          serialNumber: '6010012Table1OperationNo',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'operationNo',
          headerAlign: "center",
          align: "left",
          columnLabel: '工序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010012,
          serialNumber: '6010012Table1OperationName',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'operationName',
          headerAlign: "center",
          align: "left",
          columnLabel: '工序名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          functionId: 6010012,
          serialNumber: '6010012Table1WorkCenterNo',
          tableId: '6010012Table1',
          tableName: '标准工序表',
          columnProp: 'workCenterNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '加工中心编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          functionId: 6010012,
          serialNumber: '6010012Table1WorkCenterDesc',
          tableId: '6010012Table1',
          tableName: '标准工序表',
          columnProp: 'workCenterDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '加工中心名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010012,
          serialNumber: '6010012Table1LaborClassNo',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'laborClassNo',
          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: 6010012,
          serialNumber: '6010012Table1LaborClassDesc',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'laborClassDesc',
          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: 6010012,
          serialNumber: '6010012Table1SetupLaborClassNo',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'setupLaborClassNo',
          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: 6010012,
          serialNumber: '6010012Table1SetupLaborClassDesc',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'setupLaborClassDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '调机时人员等级描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 118
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010012,
          serialNumber: '6010012Table1CreateDate',
          tableId: '6010012Table1',
          tableName: '标准工序表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 170
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010012,
          serialNumber: '6010012Table1CreateBy',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'createBy',
          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: 6010012,
          serialNumber: '6010012Table1UpdateDate',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'updateDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 170
        },
        {
          userId: this.$store.state.user.name,
          functionId: 6010012,
          serialNumber: '6010012Table1UpdateBy',
          tableId: "6010012Table1",
          tableName: "标准工序表",
          columnProp: 'updateBy',
          headerAlign: "center",
          align: "center",
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
      ],
      rules: {
        bu: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        operationNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        operationName: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        workCenterNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        workCenterDesc: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        laborClassNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        laborClassDesc: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        setupLaborClassNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        setupLaborClassDesc: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
      },
      // ======== 模态框开关控制 ========
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      modalFlag: false,
      modalDisableFlag: false,
      menuId: this.$route.meta.menuId,
    }
  },

  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: {
    // 获取用户的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()
    },

    //导出excel
    async createExportData() {
      this.searchData.limit = -1
      this.searchData.page = 1
      await searchStandardRoutingOperationList(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
    },

    // ======== chooseList相关方法 ========
    /**
     * 获取基础数据列表S
     * @param val
     * @param type
     */
    getBaseList (val, type) {
      this.tagNo = val
      this.tagNo1 = type
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        if (val === 217) {
          if(type === 1) {
            strVal = this.modalData.laborClassNo?this.modalData.laborClassNo:''
          } else if (type === 2) {
            strVal = this.modalData.setupLaborClassNo?this.modalData.setupLaborClassNo:''
          }
        }
        if (val === 216) {
          strVal = this.modalData.workCenterNo?this.modalData.workCenterNo:''
        }
        if (this.modalData.bu === null || this.modalData.bu === '') {
          this.$message.warning("请选择BU!")
          return
        } else {
          conSql = " and site = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no = '" + this.modalData.bu.split('_')[1] + "'"
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    /**
     * 列表方法的回调
     * @param val
     */
    getBaseData (val) {
      if (this.tagNo === 217) {
        if (this.tagNo1 === 1) {
          this.modalData.laborClassNo = val.class_no
          this.modalData.laborClassDesc = val.class_desc
        } else if (this.tagNo1 === 2) {
          this.modalData.setupLaborClassNo = val.class_no
          this.modalData.setupLaborClassDesc = val.class_desc
        }
      }
      if (this.tagNo === 216) {
        this.modalData.workCenterNo = val.work_center_no
        this.modalData.workCenterDesc = val.work_center_desc
      }
    },

    // 获取数据列表
    getDataList () {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      searchStandardRoutingOperationList(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
        }
      })
    },

    addModal () {
      this.modalData = {
        flag: '1',
        title: '标准工序新增',
        bu: this.userBuList[0].buNo,
        buNo: '',
        site: '',
        operationNo: '',
        operationName: '',
        workCenterNo: '',
        workCenterDesc: '',
        laborClassNo: '',
        laborClassDesc: '',
        setupLaborClassNo: '',
        setupLaborClassDesc: '',
        createBy: this.$store.state.user.name,
      }
      this.modalDisableFlag = false
      this.modalFlag = true
      console.log(this.modalData)
    },

    /**
     * 分类信息编辑模态框
     * @param row
     */
    updateModal (row) {
      this.modalData = {
        flag: '2',
        title: '标准工序编辑',
        site: row.site,
        bu: row.site + '_' + row.buNo,
        buNo: row.buNo,
        id: row.id,
        operationNo: row.operationNo,
        operationName: row.operationName,
        workCenterNo: row.workCenterNo,
        workCenterDesc: row.workCenterDesc,
        laborClassNo: row.laborClassNo,
        laborClassDesc: row.laborClassDesc,
        setupLaborClassNo: row.setupLaborClassNo,
        setupLaborClassDesc: row.setupLaborClassDesc,
        updateBy: this.$store.state.user.name,
      }
      this.modalDisableFlag = true
      this.modalFlag = true
    },

    // ======== 新增/编辑/删除方法 ========
    /**
     * 分类信息新增/编辑
     */
    saveData () {
      if (this.modalData.bu === '' || this.modalData.bu == null) {
        this.$message.warning('请选择BU！')
        return
      }
      if (this.modalData.operationNo === '' || this.modalData.operationNo == null) {
        this.$message.warning('请填写工序号！')
        return
      }
      if (this.modalData.operationName === '' || this.modalData.operationName == null) {
        this.$message.warning('请填写工序名称！')
        return
      }
      if (this.modalData.workCenterNo === '' || this.modalData.workCenterNo == null) {
        this.$message.warning('请填写加工中心编码！')
        return
      }
      if (this.modalData.workCenterDesc === '' || this.modalData.workCenterDesc == null) {
        this.$message.warning('请填写加工中心名称！')
        return
      }
      if (this.modalData.laborClassNo === '' || this.modalData.laborClassNo == null) {
        this.$message.warning('请填写人员等级编码！')
        return
      }
      if (this.modalData.laborClassDesc === '' || this.modalData.laborClassDesc == null) {
        this.$message.warning('请填写人员等级！')
        return
      }
      if (this.modalData.setupLaborClassNo === '' || this.modalData.setupLaborClassNo == null) {
        this.$message.warning('请填写调机时人员等级编码！')
        return
      }
      if (this.modalData.setupLaborClassDesc === '' || this.modalData.setupLaborClassDesc == null) {
        this.$message.warning('请填写调机时人员等级！')
        return
      }
      if (this.modalData.flag === '1') {
        saveStandardRoutingOperation(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 {
        updateStandardRoutingOperation(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: '确定'
            })
          }
        })
      }
    },

    /**
     * 分类信息删除
     */
    delModal (row) {
      this.$confirm(`是否删除这条分类信息?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteStandardRoutingOperation(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.partSelections = []
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },

    // 加工中心输入校验
    workCenterBlur (tagNo) {
      if (this.modalData.workCenterNo != null && this.modalData.workCenterNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and work_center_no = '" + this.modalData.workCenterNo + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.workCenterDesc = data.baseListData[0].work_center_desc
            } else {
              this.$alert('该加工中心不存在,请重新输入加工中心编码！', '提示', {
                confirmButtonText: '确定'
              })
              this.modalData.workCenterNo = ''
              this.modalData.workCenterDesc = ''
            }
          } else {
            this.$message.warning(data.msg)
            this.modalData.workCenterNo = ''
            this.modalData.workCenterDesc = ''
          }
        })
      }
    },

    // 人员等级描述
    setupLaborClassBlur (tagNo) {
      if (this.modalData.setupLaborClassNo != null && this.modalData.setupLaborClassNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and class_no = '" + this.modalData.setupLaborClassNo + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.setupLaborClassDesc = data.baseListData[0].class_desc
            } else {
              this.$alert('该调机时人员等级不存在,请重新输入调机时人员等级编码！', '提示', {
                confirmButtonText: '确定'
              })
              this.modalData.setupLaborClassNo = ''
              this.modalData.setupLaborClassDesc = ''
            }
          } else {
            this.$message.warning(data.msg)
            this.modalData.setupLaborClassNo = ''
            this.modalData.setupLaborClassDesc = ''
          }
        })
      }
    },

    // 人员等级描述
    laborClassBlur (tagNo) {
      if (this.modalData.laborClassNo != null && this.modalData.laborClassNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and class_no = '" + this.modalData.laborClassNo + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.laborClassDesc = data.baseListData[0].class_desc
            } else {
              this.$alert('该人员等级不存在,请重新输入人员等级编码！', '提示', {
                confirmButtonText: '确定'
              })
              this.modalData.laborClassNo = ''
              this.modalData.laborClassDesc = ''
            }
          } else {
            this.$message.warning(data.msg)
            this.modalData.laborClassNo = ''
            this.modalData.laborClassDesc = ''
          }
        })
      }
    },

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

    //获取按钮的权限数据
    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 lang="scss">
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
  height: 459px;
}
</style>
