<template>
  <div>
    <fieldset class="customer-field" style="width: 100%; padding: 0.35em 0.75em 0.425em;">
      <el-row>
        <el-col :span="24">
          <el-button @click="initToolHeaderModel('Y')" :disabled = "authAdd" type="primary">{{ buttons.new }}</el-button>
          <el-button @click="initToolHeaderModel('N')" :disabled = "authEdit" type="primary">{{ buttons.edit }}</el-button>
          <el-button @click="deleteToolHeader()" :disabled = "authDelete" type="primary">{{ buttons.delete }}</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form :inline="true" label-position="top" label-width="100px">
            <el-form-item>
              <el-link slot="label" @click="getBaseList(70)"> {{labels.headerInputLabel1}}</el-link>
              <el-input style="width: 100px;"
                        @keyup.enter.native="getHeaderData"
                        v-model="headerData.toolId"></el-input> <!---->
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel2">
              <el-input style="width: 100px;" readonly v-model="headerData.toolDescription"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel3">
              <el-input style="width: 100px;" readonly v-model="headerData.spec"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel4">
              <el-input style="width: 100px;" readonly v-model="headerData.site"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel5">
              <el-input style="width: 100px;" readonly v-model="headerData.familyId"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel6">
              <el-input style="width: 100px;" readonly v-model="headerData.familyName"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel7">
              <el-input style="width: 100px;" readonly v-model="headerData.umid"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel8">
              <el-input style="width: 100px;" readonly v-model="headerData.strActive"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form :inline="true" label-position="top" label-width="100px">
            <el-form-item :label="labels.headerInputLabel9">
              <el-input style="width: 100px;" readonly v-model="headerData.codeNo"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel10">
              <el-input style="width: 100px;" readonly v-model="headerData.defaultLocationId"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel11">
              <el-input style="width: 100px;" readonly v-model="headerData.strPartCreated"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel12">
              <el-input style="width: 100px;" readonly v-model="headerData.partNo"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel14">
              <el-input style="width: 100px;" readonly v-model="headerData.strCreateDate"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel15">
              <el-input style="width: 100px;" readonly v-model="headerData.createdBy"></el-input>
            </el-form-item>
            <el-form-item :label="labels.headerInputLabel13">
              <el-input style="width: 215px;" readonly v-model="headerData.remark"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </fieldset>

    <el-tabs @tab-click="selectTabs" style="font-size: 12px" class="customer-tab" v-model="activeName"
             type="border-card">
      <el-tab-pane :label="labels.tool" name="toolInfo">
        <el-row>
          <el-col :span="7">
            <fieldset class="customer-field" style="width: 98%;">
              <legend>{{labels.dataInfo}}</legend>
              <el-form :inline="true" label-position="top" label-width="95px" style="padding: 5px;">
                <el-form-item>
                  <el-button @click="initToolModel('Y')" :disabled = "authAdd" type="primary">{{ buttons.new2 }}</el-button>
                  <el-button @click="initToolModel('N')" :disabled = "authEdit" type="primary">{{ buttons.edit }}</el-button>
                  <el-button @click="printMethod('Y')" type="primary">{{ buttons.toolPrint }}</el-button>
                  <el-button @click="printMethod('N')" type="primary">{{ buttons.toolPrint2 }}</el-button>
                </el-form-item>
              </el-form>
              <el-form :inline="true" label-position="top" label-width="95px">
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel1">
                      <el-select @change="toolInstanceIdChange(currentDetailData.toolInstanceId)"
                                 v-model="currentDetailData.toolInstanceId" :placeholder="labels.placeholder" style="width: 150px;">
                        <el-option
                          v-for="item in selectList.select4"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel2">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.status"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel3">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.supplierId"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel4">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.supplierName"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel5">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.strPurchaseDate"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel6">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.steelSeal"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel7">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.strPhaseInDate"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel8">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.strPhaseOutDate"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel9">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.estUseQty"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel10">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.actualUseQty"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel11">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.strCreateDate"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel12">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.createdBy"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item :label="labels.leftInputLabel13">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.orderNo"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item :label="labels.locationId">
                      <el-input style="width: 150px;" readonly v-model="currentDetailData.locationId"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item :label="labels.leftInputLabel14">
                      <el-input style="width: 300px;" readonly v-model="currentDetailData.remark"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </fieldset>
          </el-col>
          <el-col :span="17">
            <fieldset class="customer-field" style="width: 100%;  ">
              <legend>{{labels.rightInputLabel1}}</legend>
              <el-table
                width="100%"
                :height="height/2"
                :data="sfdcToolingHistList"
                border
                v-loading="dataListLoading"
                @selection-change="selectionChangeHandle"
                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"
                  :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>
            </fieldset>
            <fieldset class="customer-field" style="width: 100%;  ">
              <legend>{{labels.rightInputLabel2}}</legend>
              <el-table
                width="100%"
                :height="height/2"
                :data="toolInstanceIdUseHist"
                border
                v-loading="dataListLoading"
                @selection-change="selectionChangeHandle"
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnList1" :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"
                  :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>
            </fieldset>
          </el-col>
        </el-row>
      </el-tab-pane>
      <el-tab-pane :label="labels.productlist" name="tool">
        <el-table
          width="100%"
          :height="height+50"
          :data="toolRouteDataList"
          border
          v-loading="dataListLoading"
          @selection-change="selectionChangeHandle"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in routeToolList" :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>

    <column v-if="visible" ref="column" @refreshData="getTableUserColumn"></column>
    <!--新增或编辑 工具信息-->
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag
               :title="labels.toolInfo" :visible.sync="toolHeaderShow" width="473px">
      <el-form :inline="true" label-position="top" label-width="100px">
        <el-form-item :label="labels.headerInputLabel1">
          <el-input style="width: 100px;" :readonly="!this.toolDetailAddOrEdit"
                    v-model="editHeaderData.toolId"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel2">
          <el-input style="width: 100px;" v-model="editHeaderData.toolDescription"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel3">
          <el-input style="width: 100px;" v-model="editHeaderData.spec"></el-input>
        </el-form-item>
        <el-form-item>
          <el-link slot="label" @click="getBaseList(23)"> {{labels.headerInputLabel5}}</el-link>
          <el-input style="width: 100px;" v-model="editHeaderData.familyId"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel6">
          <el-input style="width: 100px;" class="customer-input-color-red" readonly
                    v-model="editHeaderData.familyName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-link slot="label" @click="getBaseList(7)"> {{labels.headerInputLabel7}}</el-link>
          <el-input style="width: 100px;" readonly v-model="editHeaderData.umid"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel9">
          <el-input style="width: 100px;" v-model="editHeaderData.codeNo"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel8">
          <el-checkbox style="width: 100px;" v-model="editHeaderData.active"></el-checkbox>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel10">
          <el-input style="width: 100px;" v-model="editHeaderData.defaultLocationId"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel13">
          <el-input style="width: 215px;" v-model="editHeaderData.remark"></el-input>
        </el-form-item>
        <el-form-item :label="labels.headerInputLabel11">
          <el-checkbox style="width: 100px;" v-model="editHeaderData.strPartCreated"></el-checkbox>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveAndUpdateToolHeader()">{{buttons.true}}</el-button>
        <el-button type="primary" @click="toolHeaderShow = false">{{buttons.cancel}}</el-button>
    </span>
    </el-dialog>
    <!--新增或编辑实例-->
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag
               :title="labels.leftInputLabel15" :visible.sync="setUp.toolEditFlag" width="736px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="labels.leftInputLabel1">
          <el-input style="width: 130px;" :readonly="toolDetailAddOrEdit" v-model="editData.toolInstanceId"></el-input>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel2">
          <el-select style="width: 130px;" v-model="editData.status">
            <el-option :label="labels.tip1" value="未投用"></el-option>
            <el-option :label="labels.tip2" value="已投用"></el-option>
            <el-option :label="labels.tip3" value="停用"></el-option>
          </el-select>
          <!--          <el-input style="width: 130px;" :readonly="toolDetailAddOrEdit" v-model="editData.status"></el-input>-->
        </el-form-item>
        <el-form-item>
          <span slot="label" @click="getBaseList(3)"><el-link>{{labels.supplierId}}</el-link> </span>
          <el-input style="width: 130px;" v-model="editData.supplierId"></el-input>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel4">
          <el-input style="width: 274px;" class="customer-input-color-red" readonly
                    v-model="editData.supplierName"></el-input>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel5" style="height: 28px;">
          <el-date-picker
            v-model="editData.strPurchaseDate"
            value-format='yyyy-MM-dd'
            format='yyyy-MM-dd'
            :placeholder="labels.placeholder"
            style="width: 130px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel6">
          <el-input style="width: 130px;" v-model="editData.steelSeal"></el-input>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel7">
          <el-date-picker
            v-model="editData.strPhaseInDate"
            value-format='yyyy-MM-dd '
            format='yyyy-MM-dd'
            :placeholder="labels.placeholder"
            style="width: 130px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel8">
          <el-date-picker
            v-model="editData.strPhaseOutDate"
            :placeholder="labels.placeholder"
            value-format='yyyy-MM-dd'
            format='yyyy-MM-dd'
            style="width: 130px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel9">
          <el-input oninput="value=value.replace(/[^0-9]/g,'')" style="width: 130px;"
                    v-model="editData.estUseQty"></el-input>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel10">
          <el-input oninput="value=value.replace(/[^0-9]/g,'')" style="width: 130px;"
                    v-model="editData.actualUseQty"></el-input>
        </el-form-item>
        <el-form-item :label="labels.locationId">
          <el-input style="width: 130px;" v-model="editData.locationId"></el-input>
        </el-form-item>
        <el-form-item :label="labels.leftInputLabel14">
          <el-input style="width: 418px;" v-model="editData.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary"  @click="saveAndUpdateToolDetail()">{{buttons.true}}</el-button>
        <el-button type="primary" @click="setUp.toolEditFlag = false">{{buttons.cancel}}</el-button>
    </span>
    </el-dialog>

    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

  </div>


</template>

<script>

import Chooselist from '@/views/modules/common/Chooselist'

import column from "../common/column";
import {
  searchSysLanguagePackList,
  searchSysLanguageParam,
  searchFunctionButtonList,
  saveButtonList,
  searchSysLanguage,
  searchLanguageListByLanguageCode,
  saveSysLanguageOne
} from "@/api/sysLanguage.js"
import getLodop from '@/utils/LodopFuncs.js'
import {
  saveTableDefaultList,
  saveTableUser,
  getTableDefaultListLanguage,
  getTableUserListLanguage,
  removerDefault,
  removerUser
} from "@/api/table.js"
import {
  userFavoriteList,
  saveUserFavorite,
  removeUserFavorite,
} from '@/api/userFavorite.js'
import {
  getToolHeaderData,
  getToolDetailList,
  getToolInstanceIdUseHist,
  getSfdcToolingHistList,
  getToolHeaderList,
  updateToolDetail,
  saveToolInfoDetail,
  editToolHeader,
  saveToolHeader,
  deleteToolHeader
} from '@/api/knifemold/tool-info.js'
import {
  printToolData
} from "@/api/knifemold/receive.js"

import {
  searchProcessRouteTool,
} from "@/api/base/productProcessRoute.js"
var functionId='106001003';
export default {
  components: {
    column,
    Chooselist
  },
  data() {
    return {
      authEdit: false,
      authAdd: false,
      authDelete: false,
      jumpFlag:true,
      menuId: this.$route.meta.menuId,
      labels: {
        tip1: '未投用',
        tip2: '已投用',
        tip3: '停用',
        headerInputLabel1: '工具编码',
        headerInputLabel2: '工具名称',
        headerInputLabel3: '规格型号',
        headerInputLabel4: '工厂编号',
        headerInputLabel5: '工具分类',
        headerInputLabel6: '工具分类名称',
        headerInputLabel7: '计量单位',
        headerInputLabel8: '在用',
        headerInputLabel9: '属性模块',
        headerInputLabel10: '默认库位',
        headerInputLabel11: '创建物料编码',
        headerInputLabel12: '物料编码',
        headerInputLabel13: '说明',
        headerInputLabel14: '新增日期',
        headerInputLabel15: '录入人',
        leftInputLabel1: '实例编码',
        leftInputLabel2: '状态',
        leftInputLabel3: '供应商编码',
        leftInputLabel4: '供应商名称',
        leftInputLabel5: '采购日期',
        leftInputLabel6: '钢印编码',
        leftInputLabel7: '入库日期',
        leftInputLabel8: '终止日期',
        leftInputLabel9: '预计刀模寿命',
        leftInputLabel10: '使用寿命',
        leftInputLabel11: '录入日期',
        leftInputLabel12: '录入人',
        leftInputLabel13: '采购订单号',
        leftInputLabel14: '备注',
        leftInputLabel15: '工具实例信息',
        rightInputLabel1: '工具使用记录:',
        rightInputLabel2: '工具维修记录:',
        tool:'工具实例',
        dataInfo:'数据明细/编辑',
        placeholder:'请选择',
        locationId:'库位编码',
        productlist:'使用该工具的产品清单',
        toolInfo:'工具信息',
        supplierId:'供应商编码',
        placeholder2:'选择日期',
        point:'提示',
        true:'确定',
        cancel:'取消',
        deleteAsk:'确定进行删除操作?',
        toolInstanceIdIn:'请选择工具信息！',
        warning1:'预计使用寿命必须大于0',
        toolIdIn:'工具编号不能为空，请选择',
        familyIdIn:'工具分类不能为空，请选择',
        umidIn:'计量单位不能为空，请选择',
        cancelAsk:'是否取消收藏？',
      },
      buttons: {
        add: '添加',
        edit: '编辑',
        delete: '删除',
        deleteList: '批量删除',
        cz: '操作',
        search: '查询',
        download: '导出',
        new:'新增',
        new2:'新建',
        toolPrint:'工具标签',
        toolPrint2:'网版',
        true:'确定',
        cancel:'取消',
      },
      queryButton: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'button'
      },
      queryLabel: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'label'
      },
      activeName: 'toolInfo',
      toolHeaderShow: false,
      toolHeaderAddOrEdit: false,
      toolDetailAddOrEdit: false,
      toolHeaderList: [],
      queryHeaderData: {
        site: this.$store.state.user.site,
        toolId: '',
        toolDescription: ''
      },
      editData: {
        actualUseQty: 0,
        createDate: "",
        createdBy: this.$store.state.user.name,
        description: null,
        estUseQty: 0,
        inspectDuration: null,
        lastUpdateBy: null,
        latestInspectDate: null,
        latestUseDate: null,
        locationId: null,
        phaseInDate: "",
        phaseOutDate: "",
        purchaseDate: "",
        remark: "",
        site: this.$store.state.user.site,
        status: "",
        statusRef: null,
        steelSeal: null,
        strCreateDate: "",
        strLatestInspectDate: null,
        strLatestUseDate: null,
        strPhaseInDate: "",
        strPhaseOutDate: "",
        strPurchaseDate: "",
        supplierId: "",
        supplierName: "",
        toolDescription: null,
        toolId: "",
        toolIndex: null,
        toolInstanceId: "",
        torNumacc: null,
        torNumdown: null,
        workCenterNo: null,

      },
      setUp: {
        toolEditFlag: false,
        saveToolFlag: false,
        toolHeaderFlag: false,
      },
      toolInstanceIdUseHist: [],
      sfdcToolingHistList: [],
      selectList: {
        select1: [{
          value: 'Y',
          label: '启用'
        }, {
          value: 'N',
          label: '禁用'
        }],
        select2: [{
          value: 'Y',
          label: '是'
        }, {
          value: 'N',
          label: '否'
        }],
        select3: [{
          value: 'P',
          label: '个人'
        }, {
          value: 'G',
          label: '组'
        }],
        select4: [],
        select5: [],
      },
      currentDetailData: {
        actualUseQty: '',
        createDate: '',
        createdBy: '',
        description: '',
        estUseQty: '',
        inspectDuration: '',
        lastUpdateBy: '',
        latestInspectDate: '',
        latestUseDate: '',
        locationId: '',
        phaseInDate: '',
        phaseOutDate: '',
        purchaseDate: '',
        remark: '',
        site: '',
        status: '',
        statusRef: '',
        supplierId: '',
        supplierName: '',
        toolDescription: '',
        toolId: '',
        toolIndex: '',
        toolInstanceId: '',
        torNumacc: '',
        torNumdown: '',
        workCenterNo: '',
        steelSeal: '',
        strCreateDate: '',
        strLatestInspectDate: '',
        strLatestUseDate: '',
        strPhaseInDate: '',
        strPhaseOutDate: '',
        strPurchaseDate: '',
      },
      detailList: [],
      headerData: {
        active: "",
        codeNo: null,
        createDate: "",
        createdBy: "",
        defaultLocationId: null,
        defaultWarehouseId: null,
        familyId: null,
        familyName: null,
        lastUpdateBy: null,
        partCreatedFlag: null,
        partNo: null,
        remark: null,
        site: this.$store.state.user.site,
        spec: null,
        standardCost: null,
        strActive: "",
        strCreateDate: "",
        strPartCreated: "",
        toolDescription: "",
        toolId: "",
        umid: null
      },
      editHeaderData: {
        active: "",
        codeNo: null,
        createDate: "",
        createdBy: "",
        defaultLocationId: null,
        defaultWarehouseId: null,
        familyId: null,
        familyName: null,
        lastUpdateBy: null,
        partCreatedFlag: null,
        partNo: null,
        remark: null,
        site: this.$store.state.user.site,
        spec: null,
        standardCost: null,
        strActive: "",
        strCreateDate: "",
        strPartCreated: "",
        toolDescription: "",
        toolId: "",
        umid: null
      },
      site: this.$store.state.user.site,
      // table高度
      height: 450,
      // 是否收藏
      favorite: false,
      addLanguage: false,
      functionId: 106001003,
      tableId: "toolInfo106001003",
      value1: true,
      visible: false,
      showDefault: false,
      // 默认table 查询参数
      queryTable: {
        functionId: 106001003,
        tableId: "toolInfo106001003",
        languageCode: this.$i18n.locale
      },
      // 用户table 查询参数
      queryTableUser: {
        userId: this.$store.state.user.name,
        functionId: 106001003,
        tableId: "toolInfo106001003",
        status: true,
        languageCode: this.$i18n.locale
      },
      // 语言词典查询参数
      querySysLanguageParam: {
        languageCode: this.$i18n.locale
      },
      // 语言词典集合
      sysLanguageParams: [],
      // 用户table 配置集合
      userColumnList: [],
      // 展示列集
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          serialNumber: 'toolUseHist106001003OrderNo',
          tableId: "toolUseHist106001003",
          tableName: "工具使用记录",
          columnProp: "orderNo",
          headerAlign: "center",
          align: "center",
          columnLabel: "生产订单号",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          serialNumber: 'toolUseHist106001003FinishQty',
          tableId: "toolUseHist106001003",
          tableName: "工具使用记录",
          columnProp: "finishQty",
          headerAlign: "center",
          align: "center",
          columnLabel: "使用寿命",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          serialNumber: 'toolUseHist106001003OStrReportDate',
          tableId: "toolUseHist106001003",
          tableName: "工具使用记录",
          columnProp: "strReportDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "录入日期",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          serialNumber: 'toolUseHist106001003Reportedby',
          tableId: "toolUseHist106001003",
          tableName: "工具使用记录",
          columnProp: "reportedby",
          headerAlign: "center",
          align: "center",
          columnLabel: "录入人",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
        }
      ],
      // 展示列集
      columnList1: [
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          tableId: "service106001003",
          serialNumber:  '106001003Table2strDeliveryDate',
          tableName: "工具维修记录",
          columnProp: "strDeliveryDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "送修日期",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          tableId: "service106001003",
          serialNumber:  '106001003Table2supplierName',
          tableName: "工具维修记录",
          columnProp: "supplierName",
          headerAlign: "center",
          align: "center",
          columnLabel: "供应商",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          tableId: "service106001003",
          serialNumber:  '106001003Table2strReturnDate',
          tableName: "工具维修记录",
          columnProp: "strReturnDate",
          headerAlign: "center",
          align: "center",
          columnLabel: "返回日期",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106001003,
          tableId: "service106001003",
          serialNumber:  '106001003Table2createdBy',
          tableName: "工具维修记录",
          columnProp: "createdBy",
          headerAlign: "center",
          align: "center",
          columnLabel: "接收人",
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        // {
        //   userId: this.$store.state.user.name,
        //   functionId: 106001003,
        //   tableId: "common1002",
        //   tableName: "commonLanguage",
        //   columnProp: "languageCode",
        //   headerAlign: "center",
        //   align: "center",
        //   columnLabel: "语言编码",
        //   columnHidden: false,
        //   columnImage: false,
        //   columnSortable: true,
        //   sortLv: 0,
        //   status: true,
        //   fixed: '',
        // }
      ],
      // 工具显示列表
      toolRouteDataList: [],
      // 工具使用清单
      routeToolList: [
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3PartNo',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "partNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "产品编码",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3PartDescription',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "partDescription",
          headerAlign: "center",
          align: "left",
          columnLabel: "产品名称",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3Spec',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "spec",
          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:  106001003,
          serialNumber:  '106001003Table3RevNo',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "revNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "工艺路线版本",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3ItemNo',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "itemNo",
          headerAlign: "center",
          align: "left",
          columnLabel: "工序号",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3active',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "active",
          headerAlign: "center",
          align: "left",
          columnLabel: "产品是否在用",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },

        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3toolqty',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "toolqty",
          headerAlign: "center",
          align: "right",
          columnLabel: "工具数量",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3remark',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "remark",
          headerAlign: "center",
          align: "left",
          columnLabel: "备注",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId:  106001003,
          serialNumber:  '106001003Table3createdate',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "createdate",
          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:  106001003,
          serialNumber:  '106001003Table3createby',
          tableId: "106001003Table3",
          tableName: "工具使用清单",
          columnProp: "createby",
          headerAlign: "center",
          align: "left",
          columnLabel: "录入人",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        }
      ],
      // 数据集
      dataList: [],

      // 导出 start
      exportData: [],
      exportName: "页面功能语言",
      exportHeader: ["页面功能语言"],
      exportFooter: [],
      exportDefaultValue: "这一行这一列没有数据",
      // 导出 end
      buttonList: [
        // {
        //   functionId: "106001003",
        //   languageValue: '添加',
        //   objectId: 'add',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '编辑',
        //   objectId: 'edit',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '删除',
        //   objectId: 'delete',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '批量删除',
        //   objectId: 'deleteList',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '操作',
        //   objectId: 'cz',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '查询',
        //   objectId: 'search',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '导出',
        //   objectId: 'download',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '设置列表',
        //   objectId: 'settingTable',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // },
        // {
        //   functionId: "106001003",
        //   languageValue: '设置默认配置',
        //   objectId: 'defaultTable',
        //   objectType: "button",
        //   tableId: "toolInfo106001003"
        // }
      ],
      languageList: [],
      languageColumnList: [],
      languageDataList: [],
      queryLanguage: {},
      // 数据集条件
      querySysLanguagePack: {
        page: 1,
        limit: 1,
        languageValue: '',
        objectType: '',
        objectId: ''
      },
      // 分页
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  watch: {
    editData: {
      deep: true,
      handler: function (newV, oldV) {
        if (this.editData.locationId) {
          this.editData.locationId = this.editData.locationId.toUpperCase()
        }
      }
    },
    editHeaderData: {
      deep: true,
      handler: function (newV, oldV) {
        if (this.editHeaderData.toolId) {
          this.editHeaderData.toolId = this.editHeaderData.toolId.toUpperCase()
        }
      }
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.height = window.innerHeight - 310;
    })
  },
  activated() {
    this.getHeaderData()
    // this.getDataList()
    this.getLanguageList()
  },
  methods: {
    // 删除 工具主表信息
    deleteToolHeader() {
      this.$confirm(this.labels.deleteAsk, this.labels.point, {
        confirmButtonText: this.labels.true,
        cancelButtonText:this.labels.cancel,
        type: 'warning'
      }).then(() => {
        let dto = {
          site: this.site,
          toolId: this.headerData.toolId
        }
        // 删除工具主记录
        deleteToolHeader(dto).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
          } else {
            this.$message.warning(data.msg)
          }
        })
      })

    },
    // 选在 tab 时触发
    selectTabs() {
      if (this.activeName == 'tool') {
        this.getToolRouteList()
      }
    },
    // 获取工具对应的使用工序信息
    getToolRouteList() {
      let query = {
        site: this.site,
        toolID: this.headerData.toolId,
        user: this.$store.state.user.name
      }
      searchProcessRouteTool(query).then(({data}) => {
        this.toolRouteDataList = data.rows
      })
    },
    printMethod(val) {
      if (!this.currentDetailData.toolInstanceId) {
        this.$alert(this.labels.toolInstanceIdIn, this.labels.point, {
          confirmButtonText: this.labels.true,
          callback: action => {
            this.bannersBut = false
          }
        });
        return
      }
      let dto = {
        site: this.currentDetailData.site,
        toolInstanceId: this.currentDetailData.toolInstanceId
      }
      printToolData(dto).then(({data}) => {
        if (data.code == 0) {
          let printDataList = []
          let printData = {
            SupplierName: data.data.SupplierName,
            createDate: data.data.createDate,
            createdBy: data.data.createdBy,
            estUseQty: data.data.estUseQty,
            locationId: data.data.locationId,
            phaseInDate: data.data.phaseInDate,
            site: data.data.site,
            spec: data.data.spec,
            status: data.data.status,
            supplierId: data.data.supplierId,
            toolDescription: data.data.toolDescription,
            toolId: data.data.toolId,
            toolInstanceId: this.currentDetailData.toolInstanceId
          }
          printDataList.push(printData)
          if (val == 'Y') {
            this.labelPrintGJ(printDataList)
          } else {
            this.labelPrintWB(printDataList)
          }
        }
      })

    },
    labelPrintWB(printDataList) {
      const LODOP = getLodop()
      if (LODOP) {
        //LODOP.SET_LICENSES("","7B5624CC84EF99D6B17F27DF4AF4310C","","");
        //LODOP.SET_LICENSES("", "7B5624CC84E599D6B17F27DF40F4310C", "", "");
        //循环调用打印机
        for (let i = 0; i < printDataList.length; i++) {
          let printData = printDataList[i]
          LODOP.NewPage();
          LODOP.SET_PRINT_PAGESIZE(0, 700, 180, "");
          LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE", 1);
          LODOP.ADD_PRINT_RECT(2, 5, 250, 67, 0, 1);
          LODOP.ADD_PRINT_LINE(19, 5, 18, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(36, 5, 35, 205, 0, 1);
          LODOP.ADD_PRINT_LINE(54, 5, 53, 205, 0, 1);
          LODOP.ADD_PRINT_LINE(2, 65, 69, 66, 0, 1);
          LODOP.ADD_PRINT_LINE(68, 205, 18, 206, 0, 1);
          LODOP.ADD_PRINT_BARCODE(21, 208, 90, 60, "QRCode", printData.toolInstanceId);
          LODOP.ADD_PRINT_TEXT(5, 9, 60, 14, "工具名称");
          LODOP.ADD_PRINT_TEXT(21, 9, 60, 15, "工具编号");
          LODOP.ADD_PRINT_TEXT(38, 9, 60, 15, "实例编号");
          LODOP.ADD_PRINT_TEXT(55, 9, 60, 15, "经办人");
          LODOP.ADD_PRINT_TEXT(4, 70, 180, 14, printData.toolDescription);
          LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
          LODOP.ADD_PRINT_TEXT(21, 71, 133, 14, printData.toolId);
          LODOP.ADD_PRINT_TEXT(39, 71, 133, 14, printData.toolInstanceId);
          LODOP.ADD_PRINT_TEXT(55, 71, 133, 14, printData.createdBy);
        }
        //LODOP.PRINT_DESIGN();
        LODOP.PREVIEW();
        // LODOP.PRINT();

      }
    },
    labelPrintGJ(printDataList) {
      const LODOP = getLodop()
      if (LODOP) {
        //LODOP.SET_LICENSES("","7B5624CC84EF99D6B17F27DF4AF4310C","","");
        //LODOP.SET_LICENSES("", "7B5624CC84E599D6B17F27DF40F4310C", "", "");
        //循环调用打印机
        for (let i = 0; i < printDataList.length; i++) {
          let printData = printDataList[i]
          LODOP.NewPage();
          LODOP.SET_PRINT_PAGESIZE(0, 700, 540, "");
          LODOP.ADD_PRINT_RECT(6, 5, 250, 190, 0, 1);
          LODOP.ADD_PRINT_LINE(24, 5, 23, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(41, 5, 40, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(58, 5, 57, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(75, 5, 74, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(92, 5, 91, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(109, 5, 108, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(126, 5, 125, 178, 0, 1);
          LODOP.ADD_PRINT_LINE(144, 5, 143, 178, 0, 1);
          LODOP.ADD_PRINT_LINE(162, 5, 161, 178, 0, 1);
          LODOP.ADD_PRINT_LINE(179, 5, 178, 255, 0, 1);
          LODOP.ADD_PRINT_LINE(23, 65, 195, 66, 0, 1);
          LODOP.ADD_PRINT_LINE(178, 177, 108, 178, 0, 1);
          LODOP.ADD_PRINT_BARCODE(110, 183, 110, 85, "QRCode", printData.toolInstanceId);
          LODOP.ADD_PRINT_TEXT(9, 94, 100, 14, "工具标签");
          LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          LODOP.ADD_PRINT_TEXT(26, 9, 60, 14, "工具名称");
          LODOP.ADD_PRINT_TEXT(43, 9, 60, 15, "规格型号");
          LODOP.ADD_PRINT_TEXT(60, 9, 60, 15, "工具编号");
          LODOP.ADD_PRINT_TEXT(77, 9, 60, 15, "实例编号");
          LODOP.ADD_PRINT_TEXT(94, 9, 60, 15, "厂商");
          LODOP.ADD_PRINT_TEXT(111, 9, 60, 15, "入库日期");
          LODOP.ADD_PRINT_TEXT(129, 9, 60, 15, "库位");
          LODOP.ADD_PRINT_TEXT(147, 9, 60, 15, "经办人");
          LODOP.ADD_PRINT_TEXT(181, 9, 60, 15, "检验签章");
          LODOP.ADD_PRINT_TEXT(25, 72, 180, 14, printData.toolDescription);
          LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
          LODOP.ADD_PRINT_TEXT(42, 72, 180, 14, printData.spec); // 规格
          LODOP.ADD_PRINT_TEXT(60, 72, 180, 14, printData.toolId);
          LODOP.ADD_PRINT_TEXT(78, 71, 180, 14, printData.toolInstanceId);
          LODOP.ADD_PRINT_TEXT(94, 71, 180, 14, printData.SupplierName);
          LODOP.ADD_PRINT_TEXT(111, 71, 95, 14, this.dayjs(printData.createDate).format("YYYY-MM-DD"));
          LODOP.ADD_PRINT_TEXT(130, 71, 95, 14, printData.locationId);
          LODOP.ADD_PRINT_TEXT(148, 71, 95, 14, printData.createdBy);


        }
        //LODOP.PRINT_DESIGN();
        LODOP.PREVIEW();
        //LODOP.PRINT();
      }
    },
    getBaseData(val) {
      if (this.tagNo === 70) {
        this.headerData.toolId = val.ToolID
        // this.headerData.toolDescription = val.ToolDescription
        this.getHeaderData()
      }
      if (this.tagNo === 3) {
        this.editData.supplierId = val.SupplierID
        this.editData.supplierName = val.SupplierName
      }
      if (this.tagNo === 23) {
        this.editHeaderData.familyId = val.FamilyID
        this.editHeaderData.familyName = val.FamilyName
      }
      if (this.tagNo === 7) {
        this.editHeaderData.umid = val.UMID
      }
    },
    // 获取基础数据列表
    getBaseList(val, number) {
      this.number = number
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = "";
        if (val === 3) {
          strVal = this.editData.supplierId
        }
        if (val === 70) {
          strVal = this.headerData.toolId
        }
        if (val === 23) {
          strVal = this.editHeaderData.familyId
        }
        if (val === 7) {
          strVal = this.editHeaderData.umid
        }
        this.$refs.baseList.init(val, strVal)
      })
    },
    getTime(date) {
      var json_date = new Date(date).toJSON();
      return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
    },
    // toolDetail
    initToolModel(val) {
      this.setUp.toolEditFlag = true
      this.setUp.saveToolFlag = false
      if (val != 'Y') {
        this.toolDetailAddOrEdit = true
        this.editData = JSON.parse(JSON.stringify(this.currentDetailData))
      } else {
        Object.assign(this.$data.editData, this.$options.data.call(this).editData);
        this.toolDetailAddOrEdit = false
        this.editData.toolInstanceId = this.headerData.toolId
        this.editData.locationId = this.headerData.defaultLocationId
        this.editData.toolId = this.headerData.toolId
        this.editData.status = '未投用'
      }
    },
    async saveAndUpdateToolDetail() {
      this.setUp.saveToolFlag = true
      this.editData.purchaseDate = this.editData.strPurchaseDate
      this.editData.phaseInDate = this.editData.strPhaseInDate
      this.editData.phaseOutDate = this.editData.strPhaseOutDate
      if (!this.editData.estUseQty || this.editData.estUseQty == 0) {
        this.$message.warning(this.labels.warning1)
        return
      }
      if (this.toolDetailAddOrEdit) {
        await updateToolDetail(this.editData).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.setUp.toolEditFlag = false
          } else {
            this.$message.error(data.msg)
          }
          this.setUp.saveToolFlag = false
        })

      } else {
        await saveToolInfoDetail(this.editData).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.setUp.toolEditFlag = false
          } else {
            this.$message.error(data.msg)
          }
          this.setUp.saveToolFlag = false
        })
      }
      await this.getDetailList()
      this.currentDetailData.toolInstanceId = this.editData.toolInstanceId
      this.toolInstanceIdChange()
    },
    // toolHeader
    initToolHeaderModel(val) {
      this.toolHeaderShow = true
      if (val == 'Y') {
        this.toolDetailAddOrEdit = true
        Object.assign(this.$data.editHeaderData, this.$options.data.call(this).editHeaderData);
      } else {
        this.toolDetailAddOrEdit = false
        this.editHeaderData = JSON.parse(JSON.stringify(this.headerData))
        this.editHeaderData.active = this.headerData.active == 'Y' ? true : false
      }
    },
    saveAndUpdateToolHeader() {
      if (!this.editHeaderData.toolId) {
        this.$message.warning(this.labels.toolIdIn)
        return
      }
      if (!this.editHeaderData.familyId) {
        this.$message.warning(this.labels.familyIdIn)
        return
      }
      if (!this.editHeaderData.umid) {
        this.$message.warning(this.labels.umidIn)
        return
      }
      this.editHeaderData.active = this.editHeaderData.active ? 'Y' : 'N'
      if (this.toolDetailAddOrEdit) {
        this.editHeaderData.createdBy = this.$store.state.user.name
        saveToolHeader(this.editHeaderData).then(({data}) => {
          if (data.code == 0) {
            this.toolHeaderShow = false
            this.headerData.toolId = this.editHeaderData.toolId
            this.getHeaderData()
            this.$message.success(data.msg)
          } else {
            this.$message.warning(data.msg)
          }
        })
      } else {
        editToolHeader(this.editHeaderData).then(({data}) => {
          if (data.code == 0) {
            this.$message.success(data.msg)
            this.toolHeaderShow = false
            this.headerData.toolId = this.editHeaderData.toolId
            this.getHeaderData()
          } else {
            this.$message.warning(data.msg)
          }
        })
      }


    },
    getToolHeaderList() {
      getToolHeaderList(this.queryHeaderData).then(({data}) => {
        this.toolHeaderList = data.rows
      })
    },
    //获取工具使用记录
    getSfdcToolingHistList() {
      let queryData = {
        site: this.site,
        toolInstanceId: this.currentDetailData.toolInstanceId
      }
      getSfdcToolingHistList(queryData).then(({data}) => {
        this.sfdcToolingHistList = data.rows
      })
    },
    //获取工具使用记录
    getToolInstanceIdUseHist() {
      let queryData = {
        site: this.site,
        toolInstanceId: this.currentDetailData.toolInstanceId
      }
      getToolInstanceIdUseHist(queryData).then(({data}) => {
        this.toolInstanceIdUseHist = data.rows
      })
    },
    toolInstanceIdChange() {
      this.sfdcToolingHistList = []
      this.toolInstanceIdUseHist = []
      let queryData = {
        site: this.site,
        toolInstanceId: this.currentDetailData.toolInstanceId,
      }
      getToolDetailList(queryData).then(({data}) => {
        let list = data.rows
        if (list.length > 0) {
          this.currentDetailData = list[0]
          this.getToolInstanceIdUseHist()
          this.getSfdcToolingHistList()
        }
      })
    },
    async getDetailList() {
      this.currentDetailData = {}
      this.selectList.select4 = []
      this.sfdcToolingHistList = []
      this.toolInstanceIdUseHist = []
      let queryData = {
        site: this.site,
        toolId: this.headerData.toolId,
        toolDescription: this.headerData.toolDescription,
      }
      await getToolDetailList(queryData).then(({data}) => {
        let list = data.rows
        for (let i = 0; i < list.length; i++) {
          let selectData = {
            value: list[i].toolInstanceId,
            label: list[i].toolInstanceId,
          }
          this.selectList.select4.push(selectData);
        }
        if (list.length > 0) {
          this.currentDetailData = list[0]
          this.toolInstanceIdChange()
        }
      })
    },
    //获取主记录信息
    getHeaderData() {
      let queryData = {
        site: this.site,
        toolId: this.headerData.toolId,
        // toolDescription: this.headerData.toolDescription,
      }
      getToolHeaderData(queryData).then(({data}) => {
        if (data.code == 0) {
          this.headerData = data.row ? data.row : this.headerData
          this.getDetailList()
        }

      })
    },
    // 打印方式
    printReport() {
      alert(this.$store.state.user.site)
      //
      // const LODOP = getLodop()
      // if (LODOP) {
      //   var strBodyStyle = '<style>'
      //   strBodyStyle += 'table { border-top: 1 solid #000000; border-left: 1 solid #000000;  border-collapse:collapse;  border-spacing:0;}'
      //   strBodyStyle += 'caption {  line-height:2em; }'
      //   strBodyStyle += 'td { border-right: 1 solid #000000; border-bottom: 1 solid #000000; text-align:center; padding:2px 3px; font-size:11px;}'
      //   strBodyStyle += '</style>' //设置打印样式
      //   var strFormHtml = strBodyStyle + '<body>' + document.getElementById('commmon').innerHTML + '</body>'   //获取打印内容
      //
      //   LODOP.PRINT_INIT('')  //初始化
      //   LODOP.PRINT_DESIGN();
      //   //LODOP.PREVIEW();
      //   //LODOP.PRINT();
      //
      //   LODOP.SET_PRINT_PAGESIZE(2, 0, 0, 'A4')  //设置横向
      //   LODOP.ADD_PRINT_HTM('1%', '1%', '98%', '98%', strFormHtml)    //设置打印内容
      //   LODOP.SET_PREVIEW_WINDOW(2, 0, 0, 800, 600, '')  //设置预览窗口模式和大小
      //   LODOP.PREVIEW()
      // }
    },
    // 校验用户是否收藏
    favoriteIsOk() {
      let userFavorite = {
        userId: this.$store.state.user.id,
        languageCode: this.$i18n.locale
      }
      userFavoriteList(userFavorite).then(({data}) => {
        let size = data.list.filter(item => item.menuId == this.$route.meta.menuId).length;
        if (size > 0) {
          this.favorite = true
        } else {
          this.favorite = false
        }
      })
    },
    // 收藏 OR 取消收藏
    favoriteFunction() {
      let userFavorite = {
        userId: this.$store.state.user.id,
        functionId:  106001003,
      }
      if (this.favorite) {
        // 取消收藏
        this.$confirm(this.labels.cancelAsk, this.labels.point, {
          confirmButtonText: this.labels.true,
          cancelButtonText: this.labels.cancel,
          type: 'warning'
        }).then(() => {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        })
      } else {
        // 收藏
        saveUserFavorite(userFavorite).then(({data}) => {
          this.$message.success(data.msg)
          this.favorite = true
        })
      }

    },
    // 保存语言编辑
    saveLanguageList(val) {
      saveSysLanguageOne(val).then(({data}) => {
        if (data.code == 0) {
          this.$message.success(data.msg)
        } else {
          this.$message.error(data.msg)
        }
      })
    },
    // 编辑语言
    addLanguageFun() {
      if (this.querySysLanguagePack.languageCode) {
        this.addLanguage = true
        this.languageColumnList = []
        let query = {
          functionId: 106001003,
          tableId: "common1002",
          languageCode: this.$i18n.locale
        }
        getTableDefaultListLanguage(query).then(({data}) => {
          if (data.rows.length > 0) {
            this.languageColumnList = data.rows
          }
        })
        this.languageColumnList = this.columnList
        searchLanguageListByLanguageCode(this.querySysLanguagePack).then(({data}) => {
          this.languageDataList = data.rows
        })
      } else {
        this.$message("请选中一种语言")
      }
    },
    // 获取多语言列表
    getLanguageList() {
      searchSysLanguage(this.queryLanguage).then(({data}) => {
        this.languageList = data.rows
      })
    },
    // 获取button的词典
    getFunctionButtonList() {
      //首先查询当前按钮的多语言
      searchFunctionButtonList(this.queryButton).then(({data}) => {
        if (JSON.stringify(data.data) != '{}') {
          this.buttons = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
      //其次查询当前标签的多语言
      searchFunctionButtonList(this.queryLabel).then(({data}) => {
        if (JSON.stringify(data.data) != '{}') {
          this.labels = data.data
        } else {
          // saveButtonList(this.buttonList).then(({data}) => {
          // })
        }
      });
    },
    // 获取语言词典
    getSysLanguageParamList() {
      searchSysLanguageParam(this.querySysLanguageParam).then(({data}) => {
        this.sysLanguageParams = data.rows
      })
    },
    // 打开页面设置
    userSetting() {
      this.visible = true;
      let queryTable = {
        userId: this.$store.state.user.name,
        functionId: 106001003,
        tableId: "toolInfo106001003",
        languageCode: this.$i18n.locale
      }
      this.$nextTick(() => {
        this.$refs.column.init(queryTable);
      });
    },
    // 获取 用户保存的 格式列
    getTableUserColumn() {
      getTableUserListLanguage(this.queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          //this.columnList = []
          this.columnList = data.rows
        } else {
          this.getColumnList()
        }

      })
    },
    // 保存 默认配置 列
    async saveColumnList() {
      // 删除所有的该页面下保存的数据
      if (this.userColumnList) {
        //删除 user自定义的数据
        await removerUser(this.queryTable)
      }
      // 删除默认配置
      await removerDefault(this.queryTable)
      // 保存页面 table属性
      let sumColumnList = this.columnList.concat(this.columnList1);
      sumColumnList = sumColumnList.map(item => {
        return item = {
          tableId: item.tableId,
          tableName: item.tableName,
          columnProp: item.columnProp,
          columnLabel: item.columnLabel,
          columnHidden: false,
          columnImage: false,
          columnSortable: item.columnSortable,
          columnWidth: item.columnWidth,
          format: item.format,
          functionId:  106001003,
          sortLv: item.sortLv,
          status: true,
          fixed: item.fixed,
          serialNumber: item.serialNumber,
          columnType: item.columnType,
          align: item.align
        }
      })

      await saveTableDefaultList(sumColumnList)
      // 保存页面 button label title 属性
      let buttons = this.buttonList.map(item => {
        return item = {
          functionId:  106001003,
          languageValue: item.languageValue,
          objectId: item.objectId,
          objectType: item.objectType,
          tableId: item.tableId
        }
      })
      await saveButtonList(buttons)
      this.getFunctionButtonList()
      this.getColumnList()
    },
    // 获取 tableDefault 列
    getColumnList() {
      getTableDefaultListLanguage(this.queryTable).then(({data}) => {
        if (!data.rows.length == 0) {
          // this.showDefault = false
          this.columnList = data.rows
        } else {
          // this.showDefault = true
        }
      })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      searchSysLanguagePackList(this.querySysLanguagePack).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    // 删除
    deleteHandle(id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('//prd/delete'),
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message.success('操作成功')
            this.getDataList()
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    },
    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
    },
    createExportData() {
      // 点击导出按钮之后,开始导出数据之前的执行函数,返回值为需要下载的数据
      // TODO:构造需要下载的数据返回
      if (this.dataListSelections.length > 0) {
        return this.dataListSelections;
      }
      return this.dataList;
    },
    startDownload() {
      //  this.exportData = this.dataList

    },
    finishDownload() {
    },
    //获取按钮的权限数据
    getButtonAuthData(){
      let updateFlag = this.isAuth(this.menuId+":revise");
      let fullControFlag = this.isAuth(this.menuId+":fullContro");
      let deleteFlag = this.isAuth(this.menuId+":remove");
      //处理页面的权限数据
      this.authEdit = !updateFlag ||!fullControFlag;
      this.authAdd = !fullControFlag;
      this.authDelete = !deleteFlag;

    },
    // 获取 用户保存的 格式列
    async getTableUserColumn2(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.columnList = []
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
            case 2:
              this.columnList1 = data.rows
              break;
            case 3:
              this.routeToolList = data.rows
              break;

          }

        } else {
          this.getColumnList2(tableId, columnId)
        }
      })

    },
    // 获取 tableDefault 列
    async getColumnList2(tableId, columnId) {
      this.queryTable.tableId = tableId
      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.columnList1 = data.rows
              break;
            case 3:
              this.routeToolList = data.rows
              break;

          }
        } else {
          // this.showDefault = true
        }
      })

    },


  },
  created() {
    this.getTableUserColumn2('toolUseHist106001003',1)
    this.getTableUserColumn2('service106001003',2)
    this.getTableUserColumn2('106001003Table3',3)
    //获取按钮的权限
    this.getButtonAuthData();
    this.getTableUserColumn()
    this.getSysLanguageParamList()
    this.getFunctionButtonList()
    this.favoriteIsOk()
  }
}
</script>

<style scoped>
.el-header, .el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
  height: 300px;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  /*text-align: center;*/
  /*line-height: 200px;*/
}

.el-main {
  background-color: #E9EEF3;
  color: #333;

}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

/deep/ .customer-tab .el-tabs__content {
  padding: 3px !important;

}

/deep/ .customer-tab .el-tabs__item {
  padding: 0 20px;
  height: 30px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  line-height: 30px;
  display: inline-block;
  list-style: none;
  font-size: 12px;
  font-weight: 500;
  color: #303133;
  position: relative;
}

/*统一的input内容颜色样式*/
.customer-input-color-red /deep/ .el-input__inner {
  color: red;
}
</style>
