<template>
  <div class="mod-config yzz">
    <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;">
      <el-form :inline="true" label-position="top" style="margin-top: 0px">
        <el-form-item :label="'申请单号'">
          <el-input v-model="searchData.notifyNo" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'申请账号'">
          <el-input v-model="searchData.userName" 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 style="margin-top: 23px;">
          <label style="margin-left: 0px;font-size: 19px">&#10142</label>
        </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-select v-model="searchData.workShopList" multiple style="width: 360px">
            <el-option
              v-for = "i in workShopList"
              :key = "i.workShopId"
              :label = "i.workShopName"
              :value = "i.workShopId">
            </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-form>
    <el-table
      :data="dataList"
      @row-click="changeData"
      :height="height"
      border
      highlight-current-row
      ref="mainTable"
      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-column-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        width="80"-->
<!--        fixed="left"-->
<!--        label="操作">-->
<!--        <template slot-scope="scope">-->
<!--          <a type="text" size="small" v-if="scope.row.status==='已下达'" @click="closeNotify(scope.row)">结束</a>-->
<!--          <a type="text" size="small" v-if="scope.row.status==='已关闭'" @click="openNotify(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, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>


    <el-tabs style="font-size: 12px;min-height: 200px" class="customer-tab" v-model="activeName"  type="border-card"  @tab-click="tabClick">
      <el-tab-pane label="派工单明细" name="detail">
        <el-table
          :data="dataList2"
          :height="height"
          border
          v-loading="dataListLoading"
          style="width: 100%; ">
          <el-table-column
            v-for="(item,index) in columnList2" :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-->
<!--            header-align="center"-->
<!--            align="center"-->
<!--            width="80"-->
<!--            fixed="left"-->
<!--            label="操作">-->
<!--            <template slot-scope="scope">-->
<!--              <a type="text" size="small" v-if="currentRow.status==='已下达'" @click="deleteNotifySOSPlus(scope.row)">删除</a>-->

<!--            </template>-->
<!--          </el-table-column>-->
        </el-table>

      </el-tab-pane>
      <el-tab-pane label="材料明细" name="sub">
        <el-table
          :data="dataList3"
          :height="height"
          border
          :row-class-name="tableRowClassName"
          v-loading="dataListLoading"
          style="width: 100%; ">
<!--          <el-table-column-->
<!--            header-align="center"-->
<!--            align="center"-->
<!--            width="80"-->
<!--            fixed="left"-->
<!--            label="操作">-->
<!--            <template slot-scope="scope">-->
<!--              <a type="text" size="small" @click="printLabel(scope.row)">打印标签</a>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column
            v-for="(item,index) in columnList3" :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-->
<!--            header-align="center"-->
<!--            align="center"-->
<!--            width="80"-->
<!--            fixed="left"-->
<!--            label="操作">-->
<!--            <template slot-scope="scope">-->
<!--              <a type="text" size="small" v-if="currentRow.status==='已下达'" @click="deleteNotifyMaterial(scope.row)">删除</a>-->

<!--            </template>-->
<!--          </el-table-column>-->
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="材料汇总" name="sum">
        <el-table
          :data="dataList4"
          :height="height"
          border
          v-loading="dataListLoading"
          style="width: 100%; ">
          <!--          <el-table-column-->
          <!--            header-align="center"-->
          <!--            align="center"-->
          <!--            width="80"-->
          <!--            fixed="left"-->
          <!--            label="操作">-->
          <!--            <template slot-scope="scope">-->
          <!--              <a type="text" size="small" @click="printLabel(scope.row)">打印标签</a>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column
            v-for="(item,index) in columnList4" :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>


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

<script>
  import {
    searchNotifyHeader
    ,searchNotifyOrderList
    ,searchNotifyMaterialList
    ,searchSumNotifyMaterialList
    ,deleteNotifySOSPlus
    ,updateNotifyStatus
    ,deleteNotifyMaterial
  }from "@/api/orderIssure/soIssueNotify.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  import {getEamWorkShop} from "@/api/factory/site.js";
  export default {
    components: {
      Chooselist
    },
    data() {
      return {
        height:200,
        modelFlag:false,
        activeName: 'detail',
        dataList: [],
        dataList2: [],
        dataList3: [],
        dataList4: [],
        addOrUpdateVisible:false,
        searchData: {
          page: 1,
          limit: 100,
          site:this.$store.state.user.site,
          userName: '',
          notifyNo: '',
          issueFlag: '',
          issueResult: '',
          workShopList: [],
          startDate: this.dayjs().format("YYYY-MM-DD"),
          endDate: this.dayjs().format("YYYY-MM-DD"),
          sql: " and a.status='已下达' and (issueFlag='N' or issueResult='部分发料' ) ",
        },
        workShopList: [],
        exportList:[],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        currentRow:'',
        headerData:'',
        columnList1:[
          {
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table1NotifyNo',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "notifyNo",
            headerAlign: "center",
            align: "center",
            columnLabel: "申请单单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },{
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table1WorkShopName',
            tableId: "701002Table1",
            tableName: "领料申请主表",
            columnProp: "workShopName",
            headerAlign: "center",
            align: "center",
            columnLabel: "车间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table1NotifyDate',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "notifyDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "申请日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table1UserName',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "userName",
            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: 701003,
            serialNumber: '701003Table1UserName',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "userDisplay",
            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: 701003,
            serialNumber: '701003Table1IssueFlag',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "issueFlag",
            headerAlign: "center",
            align: "center",
            columnLabel: "是否领料",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 60
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table1IssueResult',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "issueResult",
            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: 701003,
          //   serialNumber: '701003Table1PlanIssueDate',
          //   tableId: "701003Table1",
          //   tableName: "领料申请主表",
          //   columnProp: "planIssueDate",
          //   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: 701003,
          //   serialNumber: '701003Table1RealIssueDate',
          //   tableId: "701003Table1",
          //   tableName: "领料申请主表",
          //   columnProp: "realIssueDate",
          //   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: 701003,
            serialNumber: '701003Table1Status',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "status",
            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: 701003,
            serialNumber: '701003Table1Remark',
            tableId: "701003Table1",
            tableName: "领料申请主表",
            columnProp: "remark",
            headerAlign: "center",
            align: "left",
            columnLabel: "备注",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200
          },
        ],
        columnList2:[
          {
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table2ItemNo',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "itemNo",
            headerAlign: "center",
            align: "right",
            columnLabel: "序号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 40
          },
          {
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table2NeedDate',
            tableId: "701003Table2",
            tableName: "领料申请派工单子表",
            columnProp: 'needDate',
            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: 701003,
            serialNumber: '701003Table2SOOrderNo',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "sOOrderNo",
            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: 701003,
            serialNumber: '701003Table2OpsItemNo',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "opsItemNo",
            headerAlign: "center",
            align: "right",
            columnLabel: "工序",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table2ItemDesc',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "itemDesc",
            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: 701003,
            serialNumber: '701003Table2SeqNo',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "seqNo",
            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: 701003,
            serialNumber: '701003Table2FGPartNo',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "fGPartNo",
            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: 701003,
            serialNumber: '701003Table2PartDesc',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "partDesc",
            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: 701003,
            serialNumber: '701003Table2LocationNo',
            tableId: "701003Table2",
            tableName: "领料申请派工单子表",
            columnProp: 'locationNo',
            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: 701003,
            serialNumber: '701003Table2IssureQty',
            tableId: "701003Table2",
            tableName: "申请单派工单明细表",
            columnProp: "issureQty",
            headerAlign: "center",
            align: "right",
            columnLabel: "发料数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
        ],
        columnList3:[
          {
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3ItemNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "itemNo",
            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: 701003,
            serialNumber: '701003Table3NeedDate',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "needDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "需求时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 110
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3ComponentPartNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "componentPartNo",
            headerAlign: "center",
            align: "center",
            columnLabel: "材料编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3PartDesc',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "partDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "材料名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3QtyToIssue',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "qtyToIssue",
            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: 701003,
            serialNumber: '701003Table3QtyToIssueOriginal',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "qtyToIssueOriginal",
            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: 701003,
            serialNumber: '701003Table3IssueType',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "issueType",
            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: 701003,
            serialNumber: '701003Table3SOOrderNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "orderNo",
            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: 701003,
            serialNumber: '701003Table3OpsItemNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "opsItemNo",
            headerAlign: "center",
            align: "right",
            columnLabel: "工序",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3SeqNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "seqNo",
            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: 701003,
            serialNumber: '701003Table3LocationNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "locationNo",
            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: 701003,
            serialNumber: '701003Table3BOMItemNo',
            tableId: "701003Table3",
            tableName: "申请单材料明细表",
            columnProp: "bOMItemNo",
            headerAlign: "center",
            align: "right",
            columnLabel: "BOM序号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
        ],
        columnList4:[
          {
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3IssueType',
            tableId: "701003Table4",
            tableName: "申请单材料明细表",
            columnProp: "issueType",
            headerAlign: "center",
            align: "center",
            columnLabel: "类型",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3ComponentPartNo',
            tableId: "701003Table4",
            tableName: "申请单材料明细表",
            columnProp: "componentPartNo",
            headerAlign: "center",
            align: "center",
            columnLabel: "材料编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3PartDesc',
            tableId: "701003Table4",
            tableName: "申请单材料明细表",
            columnProp: "partDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "材料名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },{
            userId: this.$store.state.user.name,
            functionId: 701003,
            serialNumber: '701003Table3QtyToIssue',
            tableId: "701003Table4",
            tableName: "申请单材料明细表",
            columnProp: "qtyToIssue",
            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: 701003,
            serialNumber: '701003Table3QtyToIssueOriginal',
            tableId: "701003Table4",
            tableName: "申请单材料明细表",
            columnProp: "qtyToIssueOriginal",
            headerAlign: "center",
            align: "right",
            columnLabel: "合计已发数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
        ],
        dataRole: {
          partTypeDesc: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          partName: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
        },
        // 导出 start
        exportData: [],
        exportName: '发料申请单'+this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["发料申请单"],
        exportFooter: [],
        // 导出 end
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = (window.innerHeight- 260) / 2
        this.searchTable()
        getEamWorkShop({}).then(({data}) => {
          if (data && data.code === 0) {
            this.workShopList=data.rows
          }
        })
      })
    },

    // watch: {
    //   searchData: {
    //     deep: true,
    //     handler: function (newV, oldV) {
    //       this.searchData.partNo = this.searchData.partNo.toUpperCase()
    //     }
    //   },
    // },
    methods: {
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          if (val === 1013) {
            if(type==23) {
              strVal = this.modelData.supplierId
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 23) {
          if(this.tagNo1==1) {
            this.modelData.supplierId = val.SupplierID
            this.modelData.supplierName = val.SupplierName
          }
        }
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.searchTable()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.searchTable()
      },
      tabClick (tab, event) {
        // 刷新列表数据
        this.refreshCurrentTabTable()
      },
      changeData(row){
        this.currentRow = JSON.parse(JSON.stringify(row));
        this.headerData=row;
        this.refreshCurrentTabTable ();
      },
      refreshCurrentTabTable(){
        if(this.currentRow===''||this.currentRow===null){
          this.currentRow={site:'',notifyNo:''}
        }
        if(this.activeName==='detail'){
          searchNotifyOrderList(this.currentRow).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code == 0) {
              this.dataList2 = data.rows

            } else {
              this.dataList2 = [];
            }
          });
        }else if(this.activeName==='sub'){
          searchNotifyMaterialList(this.currentRow).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code == 0) {
              this.dataList3 = data.rows

            } else {
              this.dataList3 = [];
            }
          });
        }else {
          searchSumNotifyMaterialList(this.currentRow).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code == 0) {
              this.dataList4 = data.rows

            } else {
              this.dataList4 = [];
            }
          });
        }
      },
      searchTable(){
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        searchNotifyHeader(this.searchData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code == 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            if(this.dataList.length>0){
              this.$refs.mainTable.setCurrentRow(this.dataList[0]);
              this.changeData(this.dataList[0])
            }else {
              this.changeData(null)
            }
          } else {
            this.dataList = [];
          }
        });
      },
      closeNotify(row){
        this.$confirm('确认关闭?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            let inData={
              site:row.site,
              notifyNo:row.notifyNo,
              status:'已关闭',
            }
          updateNotifyStatus(inData).then(({data}) => {
            if (data && data.code === 0) {
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      openNotify(row){
        this.$confirm('确认打开?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let inData={
            site:row.site,
            notifyNo:row.notifyNo,
            status:'已下达',
          }
          updateNotifyStatus(inData).then(({data}) => {
            if (data && data.code === 0) {
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      deleteNotifyMaterial(row){
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteNotifyMaterial(row).then(({data}) => {
            if (data && data.code === 0) {
              this.refreshCurrentTabTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      deleteNotifySOSPlus(row){
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteNotifySOSPlus(row).then(({data}) => {
            if (data && data.code === 0) {
              this.refreshCurrentTabTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      //导出excel
      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        await searchNotifyHeader(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
      },
      tableRowClassName ({row, rowIndex}) {

        if (row.qtyToIssueOriginal<row.qtyToIssue&&new Date(row.needDate)<new Date(this.dayjs().format("YYYY-MM-DD HH:mm"))) {
          return 'error-row'
        }

        return ''
      },
    },
  }
</script>

<style scoped>

</style>
