<template>
  <div class="mod-config">

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

    <!-- 条件查询 -->
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item label="工单号">
        <el-input v-model="searchData.orderNo" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="派工单号">
        <el-input v-model="searchData.seqNo" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="物料编码">
        <el-input v-model="searchData.partNo" clearable style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="物料名称">
        <el-input v-model="searchData.partDesc" clearable style="width: 315px"></el-input>
      </el-form-item>
<!--      <el-form-item label="状态">-->
<!--        <el-select v-model="searchData.status" style="width: 100px" placeholder="请选择">-->
<!--          <el-option label="全部" value=""></el-option>-->
<!--          <el-option label="已发料" value="已发料"></el-option>-->
<!--          <el-option label="已关闭" value="已关闭"></el-option>-->
<!--          <el-option label="已计划" value="已计划"></el-option>-->
<!--          <el-option label="已开工" value="已开工"></el-option>-->
<!--          <el-option label="已入库" value="已入库"></el-option>-->
<!--          <el-option label="已下达" value="已下达"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label=" ">
        <el-checkbox v-model="searchData.cancelFlag" true-label="Y">显示超出派工数量单据</el-checkbox>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item label="车间编码">
        <el-input v-model="searchData.departmentID" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="加工中心">
        <el-input v-model="searchData.workCenterNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="工序">
        <el-input v-model="searchData.operationDesc" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="派工单创建人">
        <el-input v-model="searchData.operatorName" clearable style="width: 100px"></el-input>
      </el-form-item>
      <el-form-item :label="'班次'">
        <el-select v-model="searchData.shiftDesc" placeholder="请选择" clearable style="width: 80px">
          <el-option
            v-for = "i in shiftList"
            :key = "i.shiftDesc"
            :label = "i.shiftDesc"
            :value = "i.shiftDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="检验类型">
        <el-select v-model="searchData.inspectionTypeNo" style="width: 100px" clearable placeholder="请选择">
          <el-option label="IPQC首检" value="首件检"></el-option>
          <el-option label="IPQC自检" value="自检"></el-option>
          <el-option label="IPQC巡检" value="巡检"></el-option>
          <el-option label="IPQC末件检" value="末件检"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'派工日期'">
        <el-date-picker style="width: 125px" v-model="searchData.startDate" type="date" value-format='yyyy-MM-dd' format='yyyy-MM-dd' placeholder="开始日期"></el-date-picker>
        -
        <el-date-picker style="width: 125px" v-model="searchData.endDate" type="date" value-format='yyyy-MM-dd' format='yyyy-MM-dd' placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 展示列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      :row-style="rowStyle"
      @row-click="clickRow"
      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="130"
        label="操作">
        <template slot-scope="scope">
          <a v-if="!authDoInspection" type="text" size="small" @click="doInspectionModal(scope.row)">生成检验任务</a>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 新增巡检记录 -->
    <el-dialog title="新增检验记录" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="495px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="BU" prop="bu" :rules="rules.bu">
          <el-select v-model="modalData.bu" placeholder="请选择" @change="buChange" style="width: 221px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.buNo"
              :value = "i.buNo">
              <span style="float: left;width: 100px">{{ i.sitename }}</span>
              <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
                {{ i.buDesc }}
              </span>
            </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="orderNo" :rules="rules.seqNoType">
          <span slot="label">派工单号</span>
          <el-input v-model="modalData.seqNo" disabled style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="工单号" prop="orderNo" :rules="rules.orderNoType">
          <el-input v-model="modalData.orderNo" style="width: 221px" disabled></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 label="工序" prop="operationDesc" :rules="rules.operationDescType">
          <el-select v-model="modalData.operationDesc" placeholder="请选择" style="width: 221px">
            <el-option
              v-for = "i in operationList"
              :key = "i.operationDesc"
              :label = "i.operationDesc"
              :value = "i.operationDesc">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <span style="cursor: pointer" slot="label" @click="getBaseList(505)"><a herf="#">机台</a></span>
          <el-input v-model="modalData.resourceDesc" readonly style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="物料编码" prop="partNo" :rules="rules.partNoType">
          <el-input v-model="modalData.partNo" readonly style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="规格型号">
          <el-input v-model="modalData.spec" readonly style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="物料名称">
          <el-input v-model="modalData.partDesc" readonly style="width: 456px"></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 label="检验类型" prop="inspectionTypeNo" :rules="rules.inspectionTypeNoType">
          <el-select v-model="modalData.inspectionTypeNo" style="width: 104px">
            <el-option label="首件检" value="首件检"></el-option>
            <el-option label="自检" value="自检"></el-option>
            <el-option label="巡检" value="巡检"></el-option>
            <el-option label="末件检" value="末件检"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="送检数量" prop="rollQty" :rules="rules.rollQtyType">
          <el-input v-model="modalData.rollQty" type="number" style="width: 104px"></el-input>
        </el-form-item>
        <el-form-item label="单位" prop="umId" :rules="rules.umIdType">
          <el-select v-model="modalData.umId" placeholder="请选择" style="width: 104px">
            <el-option
              v-for = "i in umList"
              :key = "i.umId"
              :label = "i.umName"
              :value = "i.umId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" ">
          <el-checkbox v-model="modalData.importantFlag" true-label="Y">重点检验</el-checkbox>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="templateId" :rules="rules.templateId">
          <span style="cursor: pointer" v-if="this.controlData.baseData === '控制'" slot="label" @click="queryTemplateList"><a>检验模板</a></span>
          <span v-else slot="label">检验模板</span>
          <el-input v-model="modalData.templateName" readonly style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="送检总数">
          <el-input v-model="modalData.sjzs" disabled style="width: 104px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="特殊要求">
          <el-input type="textarea" v-model="modalData.specialRequirements" :rows="3" resize='none' show-word-limit style="width: 456px;height: 30px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 55px;text-align:center">
        <el-button :loading="saveLoading" type="primary" @click="saveData">保存</el-button>
        <el-button type="primary" @click="modalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 检验模板 -->
    <el-dialog title="检验模板清单" :close-on-click-modal="false" v-drag :visible.sync="templateModelFlag" width="520px">
      <div class="rq">
        <el-form :inline="true" label-position="top" :model="templateData">
          <el-form-item :label="'模板编码'">
            <el-input v-model="templateData.templateId" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'模板名称'">
            <el-input v-model="templateData.templateName" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="queryTemplateList">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="300"
          :data="templateList"
          @row-dblclick="getRowData"
          border
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in templateDetailList" :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>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="templateModelFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

  </div>
</template>

<script>
  import {
    getSiteAndBuByUserName, // 获取site、bu
    searchSeqInfo2, // 派工单号查询
    getOperationList, // 查询工序列表
    umSearch, // 查询单位列表
    queryController, // 检查动控
    queryTemplateList, // 获取检验模板列表
    saveOsInspection, // 新增检验记录
    inspectionTypeSearch, // 搜索所有检验类型
    getShiftList, // 获取班次
  } from "@/api/qc/qc.js"
  import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  export default {
    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "派工单" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["派工单"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        searchData: {
          userName: this.$store.state.user.name,
          orderNo: '',
          seqNo: '',
          partNo: '',
          partDesc: '',
          operationDesc: '',
          status: '',
          cancelFlag: '',
          startDate: new Date(),
          endDate: new Date(),
          workCenterNo: '',
          operatorName: '',
          departmentID: '',
          inspectionTypeNo: '',
          shiftDesc: '',
          page: 1,
          limit: 10
        },
        pageIndex: 1,
        pageSize: 50,
        totalPage: 0,
        height: 200,
        dataList: [],
        modalFlag: false,
        modalDisableFlag: false,
        modalData: {
          flag: '',
          site: '',
          bu: '',
          inspectionNo:'',
          partNo: '',
          partDesc: '',
          inspectionTypeNo:'',
          inspectionTypeName:'',
          inspectorNo:'',
          inspectorName:'',
          orderNo: '',
          operationDesc: '',
          resourceId: '',
          resourceDesc: '',
          rollQty: '',
          seqNo: '',
          spec: '',
          qtyrequired: '',
          lotsize:'',
          specialRequirements: '',
          templateId: '',
          templateName: '',
          specialTaskFlag: '',
          workCenterNo: '',
          rollNo: '',
          umId: '',
          umName: '',
          sjzs: '',
          boxNo: '',
          createBy: '',
          importantFlag: ''
        },
        rules: {
          seqNoType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          orderNoType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          operationDescType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          resourceIdType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          rollQtyType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          inspectionTypeNoType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          partNoType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          umIdType: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          templateId: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          bu:[
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ]
        },
        templateData: {
          site: '',
          bu: '',
          templateId: '',
          templateName: '',
          inspectionTypeNo: '',
          inspectionTypeName: ''
        },
        // 标头展示
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1OrderNo',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'orderNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '工单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1SeqNo',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'seqNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '派工单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1PartNo',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'partNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1PartDesc',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'partDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 300,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1DepartmentID',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'departmentID',
            headerAlign: "center",
            align: "left",
            columnLabel: '车间编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1DepartmentName',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'departmentName',
            headerAlign: "center",
            align: "left",
            columnLabel: '车间名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1WorkCenterNo',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'workCenterNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '加工中心编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1WorkCenterDesc',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'workCenterDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '加工中心名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1OperationDesc',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'operationDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '工序',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1ResourceId',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'resourceId',
            headerAlign: "center",
            align: "left",
            columnLabel: '机台编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1ResourceDesc',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'resourceDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '机台名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1Lotsize',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'lotsize',
            headerAlign: "center",
            align: "right",
            columnLabel: '工单数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1Qtyrequired',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'qtyrequired',
            headerAlign: "center",
            align: "right",
            columnLabel: '派工数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1RollQty',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'rollQty',
            headerAlign: "center",
            align: "right",
            columnLabel: '送检数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1ScheduledDate',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'scheduledDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '派工日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1OperatorName',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'operatorName',
            headerAlign: "center",
            align: "left",
            columnLabel: '派工单创建人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1TypeFlag1',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'typeFlag1',
            headerAlign: "center",
            align: "center",
            columnLabel: 'IPQC首检',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1TypeFlag2',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'typeFlag2',
            headerAlign: "center",
            align: "center",
            columnLabel: 'IPQC自检',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1TypeFlag3',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'typeFlag3',
            headerAlign: "center",
            align: "center",
            columnLabel: 'IPQC巡检',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1TypeFlag4',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'typeFlag4',
            headerAlign: "center",
            align: "center",
            columnLabel: 'IPQC末件检',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 3010005001,
            serialNumber: '3010005001Table1ShiftDesc',
            tableId: "3010005001Table1",
            tableName: "派工单号表",
            fixed: '',
            columnProp: 'shiftDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '班次',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            columnWidth: 80,
          },
        ],
        templateDetailList: [
          {
            columnProp: 'templateId',
            headerAlign: "center",
            align: "center",
            columnLabel: '模板编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'templateName',
            headerAlign: "center",
            align: "center",
            columnLabel: '模板名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'inspectionTypeName',
            headerAlign: "center",
            align: "center",
            columnLabel: '检验类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        operationList: [],
        userBuList: [],
        umList: [],
        templateList: [],
        authSearch: false,
        authDoInspection: false,
        menuId: this.$route.meta.menuId,
        checked: false,
        controlData: {},
        templateModelFlag: false,
        saveLoading: false,
        typeOptions: [],
        currentRow: {},
        shiftList: [],
      }
    },

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

    created () {
      // 按钮控制
      this.getButtonAuthData()
      // 获取用户的 site 和 bu
      this.getSiteAndBuByUserName()
      // 获取班次
      this.getShiftList()
      // 校验用户是否收藏
      this.favoriteIsOk()
      // 检验类型
      this.inspectionTypeSearch()
      // 单位
      this.umSearch()
      // 查看 质量任务生成规则控制 动控是否开启
      this.queryController()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
    },

    methods: {
      // 获取班次
      getShiftList () {
        let tempData = {
          site: this.$store.state.user.site,
        }
        getShiftList(tempData).then(({data}) => {
          if (data.code === 0) {
            this.shiftList = data.rows
          }
        })
      },

      // 查询检验类型
      inspectionTypeSearch () {
        let tempData = {
          site: this.$store.state.user.site
        }
        inspectionTypeSearch(tempData).then(({data}) => {
          if (data.code === 0) {
            this.typeOptions = data.rows
            this.typeOptions.forEach(val => {
              if (val.inspectionTypeName.includes('IPQC')) {
                this.templateData.inspectionTypeNo = val.inspectionTypeNo
                this.templateData.inspectionTypeName = val.inspectionTypeName
              }
            })
          }
        })
      },

      // 检查动控是否开启
      queryController () {
        let tempData = {
          controlNo: '10004',
          site: this.$store.state.user.site,
        }
        queryController(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.controlData = data.rows
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 查询单位
      umSearch () {
        let tempData = {
          site: this.$store.state.user.site,
          active: 'Y'
        }
        umSearch(tempData).then(({data}) => {
          if (data.code === 0) {
            this.umList = data.rows
          }
        })
      },

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

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

      // 生成检验任务
      doInspectionModal (row) {
        this.modalData = {
          flag: 'doInspection',
          site: row.site,
          bu: this.userBuList[0].buNo,
          inspectionNo: '',
          partNo: row.partNo,
          partDesc: row.partDesc,
          inspectionTypeNo: '',
          inspectionTypeName: '',
          inspectorNo: '',
          inspectorName: '',
          orderNo: row.orderNo,
          operationDesc: row.operationDesc,
          resourceId: row.resourceId,
          resourceDesc: row.resourceDesc,
          rollQty: row.qtyrequired - row.rollQty > 0 ? row.qtyrequired - row.rollQty : 0,
          seqNo: row.seqNo,
          spec: row.spec,
          specialRequirements: '',
          templateId: '',
          templateName: '',
          specialTaskFlag: '',
          workCenterNo: row.workCenterNo,
          rollNo: '',
          umId: row.umId,
          sjzs: row.sjzs,
          boxNo: '',
          createBy: this.$store.state.user.name,
          importantFlag: ''
        }
        this.getOperationList()
        this.modalDisableFlag = false
        this.modalFlag = true
        this.checked = false
      },

      // 新增IPQC巡检记录
      saveData () {
        if (this.modalData.bu === '' || this.modalData.bu == null) {
          this.$message.warning('请选择BU！')
          return
        }
        if (this.modalData.seqNo === '' || this.modalData.seqNo == null) {
          this.$message.warning('请选择派工单！')
          return
        }
        if (this.modalData.orderNo === '' || this.modalData.orderNo == null) {
          this.$message.warning('请选择工单！')
          return
        }
        if (this.modalData.inspectionTypeNo === '' || this.modalData.inspectionTypeNo == null) {
          this.$message.warning('请选择检验类型！')
          return
        }
        if (this.modalData.specialTaskFlag !== 'Y' && (this.modalData.partNo === '' || this.modalData.partNo == null)) {
          this.$message.warning('请选择物料！')
          return
        }
        if (this.modalData.operationDesc === '' || this.modalData.operationDesc == null) {
          this.$message.warning('请选择工序！')
          return
        }
        if (this.modalData.rollQty === '' || this.modalData.rollQty == null) {
          this.$message.warning('请填写送检数量！')
          return
        }
        if (this.modalData.umId === '' || this.modalData.umId == null) {
          this.$message.warning('请选择单位！')
          return
        }
        if (this.controlData.baseData === '控制' && (this.modalData.templateId == null || this.modalData.templateId === '')) {
          this.$message.warning('请选择检验模板！')
          return
        }
        this.saveLoading = true
        saveOsInspection(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.operationList = []
            this.modalFlag = false
            // 跳转IPQC任务
            this.checkOutToIPQC(data.no)
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveLoading = false
        }).catch(()=>{
          this.saveLoading = false
        })
      },

      // 获取工序列表
      getOperationList () {
        getOperationList(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.operationList = data.rows
          } else {
            this.operationList = []
          }
        })
      },

      // bu内容改变事件
      buChange () {
        if (this.modalData.specialTaskFlag !== 'Y') { // 正常检验
          this.modalData.templateId = ''
          this.modalData.templateName = ''
        } else { // 无工单检验
          this.modalData.partNo = ''
          this.modalData.partDesc = ''
          this.modalData.spec = ''
          this.modalData.templateId = ''
          this.modalData.templateName = ''
        }
      },

      // 获取检验模板列表
      queryTemplateList () {
        this.templateData.bu = this.modalData.bu
        // 查询所有检验模板
        queryTemplateList(this.templateData).then(({data}) => {
          if (data && data.code === 0) {
            this.templateList = data.rows
            this.templateModelFlag = true
          } else {
            this.templateList = []
          }
        })
      },

      // 选中检验模板
      getRowData (row) {
        this.modalData.templateId = row.templateId
        this.modalData.templateName = row.templateName
        this.templateModelFlag = false
      },

      // 单机选中
      clickRow (row) {
        this.currentRow = JSON.parse(JSON.stringify(row))
      },

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

      // 切换到IPQC检验单
      checkOutToIPQC (no) {
        this.$router.push({name: "qc-IPQCResultEntry", params: {inspectionNo: no}})
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 505) {
            strVal = this.modalData.resourceDesc
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 509) {
            strVal = this.detailData.responsiblePerson
            this.$refs.baseList.init(val, strVal)
          }
        })
      },

      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 505) {
          this.modalData.resourceId = val.ResourceID
          this.modalData.resourceDesc = val.ResourceDesc
        }
        if (this.tagNo === 509) {
          this.detailData.responsiblePerson = val.SupplierID
        }
      },

      // 校验用户是否收藏
      favoriteIsOk () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          for (let i = 0; i < data.list.length; i++) {
            if(this.$route.meta.menuId === data.list[i].menuId){
              this.favorite = true
            }
          }
        })
      },

      // 收藏 OR 取消收藏
      favoriteFunction () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        } else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = true
          })
        }
      },

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

      startDownload() {},

      finishDownload() {},

      fields () {
        let json = "{"
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")
        return s
      },

      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn (tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break
            }
          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },

      // 获取 tableDefault 列
      async getColumnList (tableId, columnId) {
        let queryTable = {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break
            }
          } else {
            // this.showDefault = true.
          }
        })
      },

      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        let doInspectionFlag = this.isAuth(this.menuId+":doInspection")
        //处理页面的权限数据
        this.authSearch = !searchFlag
        this.authDoInspection = !doInspectionFlag
      },
    }
  }
</script>
