<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-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="差异超过1KG">-->
<!--        <el-select v-model="searchData.sql" style="width: 120px">-->
<!--          <el-option label="全部" value=""></el-option>-->
<!--          <el-option label="是" value="( Round(dbo.Get_scheduleIssure(a.Site,a.SeqNo) -QtyReported*dbo.Get_PartWeightFactorForReport(a.Site,a.partNo,null),2) >1 or -1>Round(dbo.Get_scheduleIssure(a.Site,a.SeqNo) -QtyReported*dbo.Get_PartWeightFactorForReport(a.Site,a.partNo,null),2))"></el-option>-->
<!--        </el-select>-->
<!--      </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 {
    liuhuaIssureAndReport,
  } from "@/api/production/query.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    components: {
      Chooselist
    },
    data() {
      return {
        dataList: [],
        searchData: {
          page: 1,
          limit: 20,
          site:this.$store.state.user.site,
          username: this.$store.state.user.name,
          seqNo: '',
          partNo :'',
          sql:'',
          startDate:'',
          endDate:'',
        },
        exportList:[],
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        visible:false,
        dataListLoading: false,
        columnList1:[
          {
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1SeqNo',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "seqNo",
            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: 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: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1PartDesc',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "partDesc",
            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: 400003,
            serialNumber: '400003Table1OperatorId',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "operatorName",
            headerAlign: "center",
            align: "left",
            columnLabel: "操作员",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1ScheduledDate',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "sScheduledDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "派工日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1QtyIssure',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "qtyIssure",
            headerAlign: "center",
            align: "right",
            columnLabel: "实际领料重量kg",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1ReportWeight',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "reportWeight",
            headerAlign: "center",
            align: "right",
            columnLabel: "报工重量kg",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1Qty',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "qty",
            headerAlign: "center",
            align: "right",
            columnLabel: "差异数kg",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1Qty',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "realQty",
            headerAlign: "center",
            align: "right",
            columnLabel: "单体废边重量g",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90
          },{
            userId: this.$store.state.user.name,
            functionId: 400003,
            serialNumber: '400003Table1IssurePartNo',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "issurePartNo",
            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: '400003Table1TaskNo',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "taskNo",
            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: '400003Table1IssurePartDesc',
            tableId: "400003Table1",
            tableName: "硫化发料产出",
            columnProp: "issurePartDesc",
            headerAlign: "center",
            align: "center",
            columnLabel: "发料物料名称型号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150

          },
        ],
        // 导出 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
        liuhuaIssureAndReport(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 liuhuaIssureAndReport(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>
