<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" style="margin-top: 1px; margin-left: 0px;">
      <el-form-item :label="'派工单号'">
        <el-input v-model="searchData.seqNo" type="number"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料编码'">
        <el-input v-model="searchData.partNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'规格型号'">
        <el-input v-model="searchData.partDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'操作员姓名'">
        <el-input v-model="searchData.operatorName" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="异常备注" >
        <el-select v-model="searchData.remark">
          <el-option value="" label="全部"></el-option>
          <el-option value="开工超时" label="开工超时"></el-option>
          <el-option value="报工超时" label="报工超时"></el-option>
          <el-option value="完工不及时" label="完工不及时"></el-option>
          <el-option value="完成率异常" label="完成率异常"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'派工单日期'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'至'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button type="primary" @click="searchTable()">查询</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ '导出' }}
        </download-excel>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      :height="height"
      border
      v-loading="dataListLoading"
      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"
        :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-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    scheduleAbnormalReport,
  } from "@/api/production/query.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    components: {
      Chooselist
    },
    data() {
      return {
        dataList: [],
        searchData: {
          page: 1,
          limit: 20,
          operatorName: '',
          username: this.$store.state.user.name,
          seqNo: '',
          partNo :'',
          partDesc:'',
          startDate:'',
          endDate:'',
          remark:'',
        },
        exportList:[],
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        visible:false,
        dataListLoading: false,
        columnList1:[
          {
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1Site',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "site",
            headerAlign: "center",
            align: "left",
            columnLabel: "工厂编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 60
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1SeqNo',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "seqNo",
            headerAlign: "center",
            align: "center",
            columnLabel: "派工单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1SScheduledDate',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "sScheduledDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "派工日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1StartWorkDate',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "startWorkDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "开工时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1ReportDate',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "reportDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "报工时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1LastItemReportDate',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "lastItemReportDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "上道报工时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1StartUseTime',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "startUseTime",
            headerAlign: "center",
            align: "right",
            columnLabel: "开工间隔",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1WorkTime',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "workTime",
            headerAlign: "center",
            align: "right",
            columnLabel: "生产时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1IssureWeight',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "issureWeight",
            headerAlign: "center",
            align: "right",
            columnLabel: "领料重量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1TwoDayReport',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "twoDayReport",
            headerAlign: "center",
            align: "right",
            columnLabel: "48小时报工重量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 110
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1ApprovePercent',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "approvePercent",
            headerAlign: "center",
            align: "right",
            columnLabel: "完成率",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80

          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1Remark',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "remark",
            headerAlign: "center",
            align: "center",
            columnLabel: "异常备注",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1OperatorName',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "operatorName",
            headerAlign: "center",
            align: "center",
            columnLabel: "操作员姓名",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1OperationDesc',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "operationDesc",
            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: 400003,
            serialNumber: '400003Table1PartNo',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "partNo",
            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: 400003,
            serialNumber: '400003Table1PartDesc',
            tableId: "400003Table1",
            tableName: "异常派工单清单",
            columnProp: "partDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "规格型号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200
          }
        ],
        // 导出 start
        exportData: [],
        exportName: '异常派工单清单'+this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["异常派工单清单"],
        exportFooter: [],
        // 导出 end
        height:200,
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight- 200

      })
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          if (val === 1013) {
            if(type==1) {
              strVal = this.dataForm.partType
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1013) {
          if(this.tagNo1==1) {
            this.dataForm.partType = val.Base_id
            this.dataForm.partTypeDesc = val.Base_desc
          }
        }
      },
      //初始化组件的参数
      init(inData) {
        //初始化参数
        this.searchData = JSON.parse(JSON.stringify(inData));
        //刷新表格
        this.searchTable();

      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.searchTable()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.searchTable()
      },
      searchTable(){
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        scheduleAbnormalReport(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
          }
          this.dataListLoading = false
        })
      },
      //导出excel
      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        await scheduleAbnormalReport(this.searchData).then(({data}) => {
          this.exportList= data.page.list;
        })

        return this.exportList;
      },
      startDownload() {
        //  this.exportData = this.dataList

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

        return s
      },
    },
  }
</script>

<style scoped>

</style>
