<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-select v-model="searchData.status" placeholder="请选择" style="width: 120px">
            <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-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>
      <el-form :inline="true" label-position="top" style="margin-top: 0px">
        <el-form-item label="是否领料" >
          <el-select v-model="searchData.issueFlag" placeholder="请选择" style="width: 120px">
            <el-option label="全部" value=""></el-option>
            <el-option label="Y" value="Y"></el-option>
            <el-option label="N" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="领料结果" >
          <el-select v-model="searchData.issueResult" placeholder="请选择" style="width: 120px">
            <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-button type="primary" @click="searchTable()">查询</el-button>
          <el-button type="primary" @click="createNotifyModal()">新增</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"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" v-if="scope.row.status==='草稿' || scope.row.status==='编辑中'" @click="xiadaNotifyModel(scope.row)">下达</a>
          <a type="text" size="small" v-if="scope.row.status==='待出库'" @click="editNotifyMaterialFun(scope.row)">编辑</a>
          <a type="text" size="small" v-if="scope.row.status!=='已完成'" @click="closeNotifyModel(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-form :inline="true" label-position="top" label-width="100px" style="margin-top: -10px;">
          <el-button
            @click="createOrderDetail()"
            type="primary"
            style="margin-left: 10px;margin-top: 0px"
            :disabled="(currentRow.status !== '草稿' && currentRow.status !== '编辑中')">
            {{'新增'}}
          </el-button>
        </el-form>
        <el-table
          :data="dataList2"
          :height="height"
          border
          v-loading="dataListLoading"
          style="width: 100%; ">
          <el-table-column
            header-align="center"
            align="center"
            width="80"
            label="操作">
            <template slot-scope="scope">
              <a
                type="text"
                size="small"
                @click="deleteNotifySOSPlus(scope.row)"
                :class="{ 'disabled-link': currentRow.status !== '草稿' && currentRow.status !== '编辑中' }">
                删除
              </a>
            </template>
          </el-table-column>
          <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>

      </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
            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>
      </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-tab-pane label="删除记录" name="change">
        <el-table
          :data="dataList5"
          :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 columnList5" :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-tab-pane label="关闭记录" name="close">
        <el-table
          :data="dataList6"
          :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 columnList6" :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>

    <el-dialog title="关闭原因" :close-on-click-modal="false" v-drag :visible.sync="closeModalFlag" width="450px">
      <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item >
              <el-input
                type="textarea"
                v-model="closeData.closeRemark "
                :rows="3"
                resize='none'
                maxlength="200"
                show-word-limit
                style="height: 60px" >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 60px;text-align:center">
        <el-button type="primary" @click="closeNotify()">保存</el-button>
        <el-button type="primary" @click="closeModalFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>


    <el-dialog title="新建领料申请单" :close-on-click-modal="false" v-drag :visible.sync="createNotifyFlag" width="300px">
      <el-form :inline="true" label-position="top"  style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item :label="'工厂_BU'"  style="width: 97%" >
              <el-select v-model="notifyData.bu" placeholder="请选择"  style="width: 100%">
                <el-option
                    v-for = "i in userBuList"
                    :key = "i.buNo"
                    :label = "i.sitename"
                    :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-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item :label="'备注'" style="width: 97%">
              <el-input v-model="notifyData.remark" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveNotify()">保存</el-button>
        <el-button type="primary" @click="createNotifyFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 选择物料模态框 -->
    <el-dialog    width="1000px"
      title="选择物料"
      :close-on-click-modal="false"
      :visible.sync="choosePartModalFlag">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'物料编码'" >
              <el-input v-model="choosePartData.partNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'物料名称'" >
              <el-input v-model="choosePartData.partDesc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'规格型号'" >
              <el-input v-model="choosePartData.spec"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item  >
              <el-button  type="primary" @click="searchPartModel" style="margin-top: 5px" class="">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :height="400"
        :data="choosePartList"
        border
        style="width: 100%;">
        <el-table-column
          prop="partNo"
          header-align="center"
          align="left"
          min-width="80"
          label="物料编码">
        </el-table-column>
        <el-table-column
          prop="partDesc"
          header-align="center"
          align="left"
          min-width="120"
          label="物料描述">
        </el-table-column>
        <el-table-column
          prop="spec"
          header-align="center"
          align="left"
          min-width="120"
          label="规格型号">
        </el-table-column>
        <el-table-column
          prop="sku"
          header-align="center"
          align="left"
          min-width="80"
          label="SKU">
        </el-table-column>
        <el-table-column
          prop="umid"
          header-align="center"
          align="left"
          min-width="60"
          label="计量单位">
        </el-table-column>
        <el-table-column
          fixed="left"
          header-align="center"
          align="center"
          width="60"
          label="操作">
          <template slot-scope="scope">
            <a  type="text" size="small" @click="choosePart(scope.row)">选择</a>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="pp_sizeChangeHandle"
        @current-change="pp_currentChangeHandle"
        :current-page="pp_pageIndex"
        :page-sizes="[20, 50, 100, 1000]"
        :page-size="pp_pageSize"
        :total="pp_totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="choosePartModalFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="选择派工单" :close-on-click-modal="false" v-drag :visible.sync="chooseSOSModalFlag" width="1000px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item :label="'生产订单'" >
              <el-input v-model="chooseSOSData.orderno"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'派工单号'" >
              <el-input v-model="chooseSOSData.seqno"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'机台'" >
              <el-input v-model="chooseSOSData.sResourceid"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'派工日期'" >
              <el-date-picker
                style="width: 100%"
                v-model="chooseSOSData.startDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'到'" >
              <el-date-picker
                style="width: 100%"
                v-model="chooseSOSData.endDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item  >
              <el-button  type="primary" @click="searchSOSRouting()" style="margin-top: 5px" class="">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :height="400"
        :data="chooseSOSList"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in chooseSOSColumnList" :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="left"
          header-align="center"
          align="center"
          width="60"
          label="操作">
          <template slot-scope="scope">
            <a  type="text" size="small" @click="chooseSOS(scope.row)">选择</a>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="ss_sizeChangeHandle"
        @current-change="ss_currentChangeHandle"
        :current-page="ss_pageIndex"
        :page-sizes="[20, 50, 100, 1000]"
        :page-size="ss_pageSize"
        :total="ss_totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseSOSModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="选择工单" :close-on-click-modal="false" v-drag :visible.sync="chooseOrderModalFlag" width="1000px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'生产订单'" >
              <el-input v-model="chooseOrderData.orderNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'工单状态'" >
              <el-select multiple collapse-tags v-model="chooseOrderData.statusList" style="width: 220px">
                <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-option label="已关闭" value="已关闭"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'开始日期'" >
              <el-date-picker
                style="width: 100%"
                v-model="chooseOrderData.date3"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
                      <el-col :span="6">
            <el-form-item :label="'结束日期'" >
              <el-date-picker
                style="width: 100%"
                v-model="chooseOrderData.date4"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item  >
              <el-button  type="primary" @click="searchOrder()" style="margin-top: 5px" class="">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :height="400"
        :data="chooseOrderList"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in chooseOrderColumnList" :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="left"
          header-align="center"
          align="center"
          width="60"
          label="操作">
          <template slot-scope="scope">
            <a  type="text" size="small" @click="chooseOrder(scope.row)">选择</a>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="co_sizeChangeHandle"
        @current-change="co_currentChangeHandle"
        :current-page="co_pageIndex"
        :page-sizes="[20, 50, 100, 1000]"
        :page-size="co_pageSize"
        :total="co_totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseOrderModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="选择工序" :close-on-click-modal="false" v-drag :visible.sync="chooseOperationModalFlag" width="800px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'工序名称'" >
              <el-input v-model="chooseOperationData.itemDesc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item  >
              <el-button  type="primary" @click="searchOperation()" style="margin-top: 5px" class="">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :height="400"
        :data="chooseOperationList"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in chooseOperationColumnList" :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="left"
          header-align="center"
          align="center"
          width="60"
          label="操作">
          <template slot-scope="scope">
            <a  type="text" size="small" @click="chooseOperation(scope.row)">选择</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseOperationModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="选择机台" :close-on-click-modal="false" v-drag :visible.sync="chooseResourceModalFlag" width="800px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'机台编号'" >
              <el-input v-model="chooseResourceData.resourceId"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'机台描述'" >
              <el-input v-model="chooseResourceData.resourceDesc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item  >
              <el-button  type="primary" @click="searchResource()" style="margin-top: 5px" class="">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :height="400"
        :data="chooseResourceList"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in chooseResourceColumnList" :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="left"
          header-align="center"
          align="center"
          width="60"
          label="操作">
          <template slot-scope="scope">
            <a  type="text" size="small" @click="chooseResource(scope.row)">选择</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseResourceModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="申请单明细" :close-on-click-modal="false" v-drag :visible.sync="saveOrderDetailFlag" width="750px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <!-- BOM物料和非BOM物料选择 -->
        <el-row :gutter="20" style="margin-bottom: 15px;">
          <el-col :span="24">
            <el-form-item :label="'物料类型'" style="display: none;">
              <el-radio-group v-model="orderDetailData.materialType" @change="onMaterialTypeChange">
                <el-radio label="BOM物料">BOM物料</el-radio>
                <el-radio label="非BOM物料">非BOM物料</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item>
              <template slot="label">
                <span v-if="orderDetailData.materialType === '非BOM物料'" slot="label">生产订单</span>
                <span v-else style="cursor: pointer" slot="label" @click="openChooseOrderModal"><a>生产订单</a></span>
              </template>
              <el-input v-model="orderDetailData.orderNo" disabled placeholder="请选择生产订单"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <template slot="label">
                <span v-if="orderDetailData.materialType === '非BOM物料'" slot="label">派工单号</span>
                <span v-else style="cursor: pointer" slot="label" @click="openChooseSOSModal"><a>派工单号</a></span>
              </template>
              <el-input v-model="orderDetailData.seqNo" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <template slot="label">
                <span v-if="orderDetailData.orderNo && !orderDetailData.seqNo"  style="cursor: pointer" slot="label" @click="openChooseOperationModal"><a>工序名称</a></span>
                <span v-else slot="label">工序名称</span>
              </template>
              <el-input v-model="orderDetailData.itemDesc" disabled placeholder="请选择工序"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <template slot="label">
                <span v-if="orderDetailData.orderNo && !orderDetailData.seqNo"  style="cursor: pointer" slot="label" @click="openChooseResourceModal"><a>机台</a></span>
                <span v-else slot="label">机台</span>
              </template>
              <el-input v-model="orderDetailData.resourceDesc" disabled placeholder="请选择机台"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item>
              <template slot="label">
                <span v-if="orderDetailData.materialType === 'BOM物料'" slot="label">物料编码</span>
                <span v-else style="cursor: pointer" slot="label" @click="openChoosePartModal"><a>物料编码</a></span>
              </template>
              <el-input v-model="orderDetailData.partNo" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item :label="'物料描述'" style="display: block">
              <el-input v-model="orderDetailData.partDesc" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'工单/派工数量'">
              <el-input v-model="orderDetailData.qtyRequired" disabled style="text-align: right"
                        class="text-right"></el-input>
            </el-form-item>
          </el-col>
<!--          <el-col :span="6">
            <el-form-item :label="'已申请领料总和'">
              <el-input v-model="orderDetailData.alreadyApplyTotal" disabled style="text-align: right"
                        class="text-right"></el-input>
            </el-form-item>
          </el-col>-->
          <el-col :span="6">
            <el-form-item :label="'此次领料数量'">
              <el-input-number v-model="orderDetailData.issureQty" style="line-height: 20px;padding: 0;width: 100%"
                               :controls="false" :step="0" :min="0" class="text-right"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'要求发料时间'">
              <el-date-picker
                style="width: 155px"
                v-model="orderDetailData.needDate"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveIssueNoOrderDetail()">保存</el-button>
        <el-button type="primary" @click="saveOrderDetailFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>



  </div>
</template>

<script>
  import {
    searchNotifyHeader
    , searchNotifyOrderList
    , searchNotifyMaterialList
    , searchSumNotifyMaterialList
    , deleteNotifySOSPlus
    , updateNotifyStatus
    , deleteNotifyMaterial
    , searchNotifyLog
    , searchNotifyLogClose
    , getSiteAndBuByUserName
    , createNotify
    , getSOScheduledRoutingListForIssureByPaging
    , getPartListByPaging
    , xiadaNotify
    , editNotifyMaterial
  } from "@/api/orderIssure/soIssueNotify.js"
  import {
    searchShopOrderByPaging
    , getRouteInShopOrder
  } from "@/api/shopOrder/shopOrder.js"
  import {
    searchAllResource
  } from "@/api/base/site.js"

  import {
    getTableDefaultListLanguage,
    getTableUserListLanguage,
  } from "@/api/table.js"
  import {saveIssueNoOrderDetail} from "../../../../api/orderIssure/soIssueNotify";


  export default {

    data() {
      return {
        height:200,
        activeName: 'detail',
        dataList: [],
        dataList2: [],
        dataList3: [],
        dataList4: [],
        dataList5: [],
        dataList6: [],
        userBuList:[],
        createNotifyFlag: false,
        saveOrderDetailFlag: false,
        closeData:{
          site:'',
          notifyNo:'',
          closeRemark:'',
          username:this.$store.state.user.name,
        },
        closeModalFlag:false,
        searchData: {
          page: 1,
          limit: 100,
          site:'',
          userName: '',
          notifyNo: '',
          status: '',
          issueFlag: '',
          loginUserName: this.$store.state.user.name,
          issueResult: '',
          startDate: this.dayjs().format("YYYY-MM-DD"),
          endDate: this.dayjs().format("YYYY-MM-DD"),
          sql: "",
        },
        notifyData:{
          site: '',
          bu: '',
          notifyNo: '',
          notifyDate: '',
          enteredDate: '',
          userName: this.$store.state.user.name,
          userDisplay: '',
          remark: '',
          planIssueDate: '',
        },
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        //工单分页
        co_pageIndex: 1,
        co_pageSize: 100,
        co_totalPage: 0,
        //派工单分页
        ss_pageIndex: 1,
        ss_pageSize: 100,
        ss_totalPage: 0,
        //非BOM物料分页
        pp_pageIndex: 1,
        pp_pageSize: 100,
        pp_totalPage: 0,
        dataListLoading: false,
        currentRow:'',
        columnList1:[
          {
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table1NotifyNo',
            tableId: "701002Table1",
            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: '701002Table1Bu',
            tableId: "701002Table1",
            tableName: "领料申请主表",
            columnProp: "bu",
            headerAlign: "center",
            align: "center",
            columnLabel: "BU",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },{
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table1NotifyDate',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table1UserName',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table1UserDisplay',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table1IssueFlag',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table1IssueResult',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table1Status',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table1Remark',
            tableId: "701002Table1",
            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: 701002,
            serialNumber: '701002Table2ItemNo',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2NeedDate',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2SOOrderNo',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2OpsItemNo',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2ItemDesc',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2SeqNo',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2FGPartNo',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2PartDesc',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table2ResourceId',
            tableId: "701002Table2",
            tableName: "申请单工单信息明细表",
            columnProp: 'resourceId',
            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: 701002,
            serialNumber: '701002Table2IssureQty',
            tableId: "701002Table2",
            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: 701002,
            serialNumber: '701002Table3ItemNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3ComponentPartNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3PartDesc',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3NeedDate',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3QtyToIssue',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3QtyToIssueOriginal',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3IssueType',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3Remark',
            tableId: "701002Table3",
            tableName: "申请单材料明细表",
            columnProp: "remark",
            headerAlign: "center",
            align: "left",
            columnLabel: "备注",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 160
          },{
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table3SOOrderNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3OpsItemNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3SeqNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3LocationNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table3BOMItemNo',
            tableId: "701002Table3",
            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: 701002,
            serialNumber: '701002Table4IssueType',
            tableId: "701002Table4",
            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: 701002,
            serialNumber: '701002Table4ComponentPartNo',
            tableId: "701002Table4",
            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: 701002,
            serialNumber: '701002Table4PartDesc',
            tableId: "701002Table4",
            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: 701002,
            serialNumber: '701002Table4QtyToIssue',
            tableId: "701002Table4",
            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: 701002,
            serialNumber: '701002Table4QtyToIssueOriginal',
            tableId: "701002Table4",
            tableName: "申请单材料明细表",
            columnProp: "qtyToIssueOriginal",
            headerAlign: "center",
            align: "right",
            columnLabel: "合计已发数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
        ],
        columnList5:[
          {
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table5UpdateType',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "updateType",
            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: '701002Table5ItemNo',
            tableId: "701002Table5",
            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: 701002,
            serialNumber: '701002Table5SOOrderNo',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "sOOrderNo",
            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: 701002,
            serialNumber: '701002Table5SeqNo',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "seqNo",
            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: 701002,
            serialNumber: '701002Table5ComponentPartNo',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "componentPartNo",
            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: 701002,
            serialNumber: '701002Table5IssueType',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "issueType",
            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: 701002,
            serialNumber: '701002Table5QtyToIssue',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "qtyToIssue",
            headerAlign: "center",
            align: "right",
            columnLabel: "要求领料数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table5UpdateBy',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "updateBy",
            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: 701002,
            serialNumber: '701002Table5UpdateDate',
            tableId: "701002Table5",
            tableName: "申请单材料删除记录表",
            columnProp: "updateDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "删除时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
        ],
        columnList6:[
          {
            userId: this.$store.state.user.name,
            functionId: 701002,
            serialNumber: '701002Table6UserDisplay',
            tableId: "701002Table6",
            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: 701002,
            serialNumber: '701002Table6ActionTime',
            tableId: "701002Table6",
            tableName: "申请单材料关闭明细",
            columnProp: "actionTime",
            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: 701002,
            serialNumber: '701002Table6ActionRemark',
            tableId: "701002Table6",
            tableName: "申请单材料关闭明细",
            columnProp: "actionRemark",
            headerAlign: "center",
            align: "left",
            columnLabel: "关闭原因",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
        ],

        // 导出 start
        exportData: [],
        exportName: '发料申请单'+this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["发料申请单"],
        exportFooter: [],
        // 导出 end
        orderDetailData:{
          orderNo:'',
          seqNo:'',
          locationNo:'',
          qtyrequired:'',
          issureQty:0,
          partDesc:'',
          partNo:'',
          resourceId:'',
          resourceDesc:'',
          needDate:'',
          itemDesc:'',
          workCenterNo:'',
          itemNo:0,
          materialType:'BOM物料',
          alreadyApplyTotal: 0
        },
        chooseSOSModalFlag: false,
        chooseSOSData: {
          page: 1,
          limit: 100,
          orderno: '',
          seqno: '',
          sResourceid: '',
          startDate: '',
          endDate: '',
        },
        chooseOrderModalFlag: false,
        chooseOrderData: {
          page: 1,
          limit: 100,
          orderNo: '',
          status: '',
          date3: '',
          date4: '',
          statusList: '',
        },
        chooseOrderList: [],
        chooseOperationModalFlag: false,
        chooseOperationData: {
          orderNo: '',
          site: '',
          itemDesc: ''
        },
        chooseOperationList: [],
        chooseResourceModalFlag: false,
        chooseResourceData: {
          site: '',
          workCenterNo: '',
          resourceID: '',
          resourceDesc: '',
        },
        chooseResourceList: [],
        chooseSOSList: [],
        choosePartModalFlag: false,
        choosePartData: {
          page: 1,
          limit: 100,
          site: '',
          sourceBu: '',
          partNo: '',
          partDesc: '',
          spec: '',
        },
        choosePartList: [],
        chooseSOSColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 701001,
            serialNumber: '701001Table2Orderno',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'orderno',
            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: 701001,
            serialNumber: '701001Table2Seqno',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'seqno',
            headerAlign: "center",
            align: "center",
            columnLabel: '派工单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 701001,
            serialNumber: '701001Table2PartNo',
            tableId: "701001Table2",
            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: 701001,
            serialNumber: '701001Table2PartDesc',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'partDesc',
            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: 701001,
            serialNumber: '701001Table2Qtyrequired',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'qtyrequired',
            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: 701001,
            serialNumber: '701001Table2SResourceid',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'sResourceid',
            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: 701001,
            serialNumber: '701001Table2ResourceDesc',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'resourceDesc',
            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: 701001,
            serialNumber: '701001Table2StartDate',
            tableId: "701001Table2",
            tableName: "查询派工单",
            columnProp: 'startDate',
            headerAlign: "center",
            align: "left",
            columnLabel: '开始日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        chooseOrderColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 701001,
            serialNumber: '701001Table2Orderno',
            tableId: "701001Table2",
            tableName: "查询工单",
            columnProp: 'orderNo',
            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: 701001,
            serialNumber: '701001Table2PartNo',
            tableId: "701001Table2",
            tableName: "查询工单",
            columnProp: 'partNo',
            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: 701001,
            serialNumber: '701001Table2PartDescription',
            tableId: "701001Table2",
            tableName: "查询工单",
            columnProp: 'partDescription',
            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: 701001,
            serialNumber: '701001Table2LotSize',
            tableId: "701001Table2",
            tableName: "查询工单",
            columnProp: 'lotSize',
            headerAlign: "center",
            align: "right",
            columnLabel: '工单数量',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 701001,
            serialNumber: '701001Table2Status',
            tableId: "701001Table2",
            tableName: "查询工单",
            columnProp: 'status',
            headerAlign: "center",
            align: "center",
            columnLabel: '状态',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
        ],
        chooseOperationColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 701001,
            serialNumber: '701001Table2ItemNo',
            tableId: "701001Table2",
            tableName: "查询工序",
            columnProp: 'itemNo',
            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: 701001,
            serialNumber: '701001Table2OperationDesc',
            tableId: "701001Table2",
            tableName: "查询工序",
            columnProp: 'operationDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '工序名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          }
        ],
        chooseResourceColumnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 701001,
            serialNumber: '701001Table2ResourceID',
            tableId: "701001Table2",
            tableName: "查询机台",
            columnProp: 'resourceID',
            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: 701001,
            serialNumber: '701001Table2ResourceDesc',
            tableId: "701001Table2",
            tableName: "查询机台",
            columnProp: 'resourceDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '机台描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
        ],
      }
    },
    computed: {
      // 计算属性：判断当前状态是否可编辑
      isEditableStatusComputed() {
        if (!this.currentRow || !this.currentRow.status) {
          return false;
        }
        return this.currentRow.status === '草稿' || this.currentRow.status === '编辑中';
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = (window.innerHeight- 315) / 2
      })
    },

    // watch: {
    //   searchData: {
    //     deep: true,
    //     handler: function (newV, oldV) {
    //       this.searchData.partNo = this.searchData.partNo.toUpperCase()
    //     }
    //   },
    // },
    created () {
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      this.getTableUserColumn(this.$route.meta.menuId+'table2',2)
      this.getTableUserColumn(this.$route.meta.menuId+'table3',3)
      this.getTableUserColumn(this.$route.meta.menuId+'table4',4)
      this.getTableUserColumn(this.$route.meta.menuId+'table5',5)
      this.getTableUserColumn(this.$route.meta.menuId+'table6',6)
    },
    methods: {
      saveIssueNoOrderDetail,
      // 动态列开始 获取 用户保存的 格式列
      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.columnList1 = data.rows
                break;
              case 2:
                this.columnList2 = data.rows
                break;
              case 3:
                this.columnList3 = data.rows
                break;
              case 4:
                this.columnList4 = data.rows
                break;
              case 5:
                this.columnList5 = data.rows
                break;
              case 6:
                this.columnList6 = 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.columnList1 = data.rows
                break;
              case 2:
                this.columnList2 = data.rows
                break;
              case 3:
                this.columnList3 = data.rows
                break;
              case 4:
                this.columnList4 = data.rows
                break;
              case 5:
                this.columnList5 = data.rows
                break;
              case 6:
                this.columnList6 = data.rows
                break;
            }
          } else {
            // this.showDefault = true.
          }
        })

      },

      // 每页数
      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.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 if(this.activeName==='change'){
          searchNotifyLog(this.currentRow).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code == 0) {
              this.dataList5 = data.rows

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

            } else {
              this.dataList6 = [];
            }
          });
        }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
        // 返回 Promise，让外部可以等它完成
        return new Promise((resolve, reject) => {
          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;
              resolve(); // 请求成功，执行 resolve
            } else {
              this.dataList = [];
              reject(new Error(data ? data.msg : '请求失败'));
            }
          }).catch(err => {
            this.dataList = [];
            reject(err); // 请求出错
          });
        });
      },
      closeNotifyModel(row){
        this.closeData.site=row.site
        this.closeData.notifyNo=row.notifyNo
        this.closeData.closeRemark=''
        this.closeModalFlag=true
      },
      closeNotify(){
        if(this.closeData.closeRemark==null||this.closeData.closeRemark===''){
          this.$alert("必须输入关闭原因", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }

        let inData={
          site:this.closeData.site,
          notifyNo:this.closeData.notifyNo,
          closeRemark:this.closeData.closeRemark,
          username:this.$store.state.user.name,
          status:'已关闭',
        }
        updateNotifyStatus(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.closeModalFlag=false
            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){
        // 检查当前状态是否允许编辑
        if (!this.isEditableStatusComputed) {
          this.$alert('当前状态不允许编辑！只有草稿或编辑中状态才能删除明细。', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        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: '确定'
              })
            }
          })
        })
      },


//申请单主表新增方法
      //新增领料申请单模态框
      createNotifyModal(){
        let inData={
          username:this.$store.state.user.name
        }
        getSiteAndBuByUserName(inData).then(({data}) =>{
          if (data && data.code === 0) {
            this.userBuList=data.rows
            if (this.userBuList.length > 0) {
              this.notifyData.bu = this.userBuList[0].buNo
            }
          }
        })
        this.createNotifyFlag=true
      },
      //保存领料申请单
      saveNotify(){
        let buValue = this.notifyData.bu
        let site = buValue.split('_')[0]
        let bu = buValue.split('_')[1]

        let inData={
          site: site,
          bu: bu,
          userName:this.$store.state.user.name,
          remark: this.notifyData.remark
        }
        createNotify(inData).then(({data})=>{
          if (data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
            this.createNotifyFlag = false
            // 刷新主表数据
            this.searchTable()
            // 清空表单数据
            this.notifyData = {
              site: '',
              bu: '',
              notifyNo: '',
              notifyDate: '',
              enteredDate: '',
              userName: this.$store.state.user.name,
              userDisplay: '',
              remark: '',
              planIssueDate: '',
            }
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      //新增派工单明细
      createOrderDetail(){
        // 检查是否选择了主表行
        if (!this.currentRow || !this.currentRow.notifyNo) {
          this.$alert('请先选择一条主表记录！', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        // 检查当前状态是否允许编辑
        if (!this.isEditableStatusComputed) {
          this.$alert('当前状态不允许编辑！只有草稿或编辑中状态才能新增明细。', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        // 清除所有数据，设置默认值
        this.orderDetailData = {
          orderNo: '',
          seqNo: '',
          operationNo: '',
          locationNo: '',
          qtyRequired: '',
          issureQty: 0,
          partDesc: '',
          partNo: '',
          resourceId: '',
          resourceDesc: '',
          itemDesc: '',
          itemNo: 0,
          workCenterNo: '',
          needDate: '',
          materialType: 'BOM物料',
          alreadyApplyTotal: 0
        }

        this.saveOrderDetailFlag = true
      },

      saveIssueNoOrderDetail(){
        // 数据验证
        // 非BOM物料时，只校验领取数量和要求发料时间
        if (this.orderDetailData.materialType === 'BOM物料') {
          if (!this.orderDetailData.orderNo ) {
            this.$message.error('请选择工单或者派工单');
            return false
          }
          if (!this.orderDetailData.itemNo) {
            this.$message.error('请选择工序');
            return false
          }
          /*//校验如果是BOM物料的话，领料数量不能大于工单数量
          if (this.orderDetailData.issureQty > this.orderDetailData.qtyRequired){
            this.$message.error('领取数量不可大于工单/派工数量！');
            return false
          }

          //校验如果是BOM物料的话，领料数量不能大于工单数量
          if ((this.orderDetailData.issureQty +  this.orderDetailData.alreadyApplyTotal) > this.orderDetailData.qtyRequired){
            this.$message.error('申请总和不可超出工单/派工数量！');
            return false
          }*/
        }

        if (!this.orderDetailData.needDate) {
          this.$message.error('请选择要求发料时间');
          return false
        }

        if (!this.orderDetailData.issureQty || this.orderDetailData.issureQty <= 0) {
          this.$message.error('请填写领取数量');
          return false
        }

        // 构建API请求参数
        let inData = {
          site: this.currentRow.site,
          bu: this.currentRow.bu,
          notifyNo: this.currentRow.notifyNo,
          materialType: this.orderDetailData.materialType,
          sOOrderNo: this.orderDetailData.orderNo,
          seqNo: this.orderDetailData.seqNo,
          fGPartNo: this.orderDetailData.partNo,
          opsItemNo: this.orderDetailData.itemNo,
          issureQty: this.orderDetailData.issureQty,
          needDate: this.orderDetailData.needDate,
          outWorkOrderFlag: 'N',
          username: this.$store.state.user.name,
          // 扩展字段
          itemDesc: this.orderDetailData.itemDesc,
          partDesc: this.orderDetailData.partDesc,
          resourceDesc: this.orderDetailData.resourceDesc,
          resourceId: this.orderDetailData.resourceId,
          workCenterNo: this.orderDetailData.workCenterNo,
          qtyrequired: this.orderDetailData.qtyRequired
        }

        // 调用API保存派工单数据
        saveIssueNoOrderDetail(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '保存成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })

            // 关闭模态框
            this.saveOrderDetailFlag = false

            // 刷新当前标签页数据
            this.refreshCurrentTabTable()

            // 清空表单数据
            this.orderDetailData = {
              orderNo: '',
              seqNo: '',
              operationNo: '',
              locationNo: '',
              qtyRequired: '',
              issureQty: 0,
              partDesc: '',
              partNo: '',
              resourceId: '',
              resourceDesc: '',
              itemDesc: '',
              itemNo: 0,
              workCenterNo: '',
              needDate: '',
              materialType: 'BOM物料',
              alreadyApplyTotal: 0
            }
          } else {
            this.$alert(data.msg || '保存失败', '错误', {
              confirmButtonText: '确定'
            })
          }
        }).catch(error => {
          console.error('保存派工单明细失败:', error)
          this.$alert('保存失败，请稍后重试', '错误', {
            confirmButtonText: '确定'
          })
        })
      },


      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        const {data} = await searchNotifyHeader(this.searchData)
        return data.page.list;
      },
      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 ''
      },

      onMaterialTypeChange(value) {
        // 清空相关字段
        this.orderDetailData.orderNo = '';
        this.orderDetailData.seqNo = '';
        this.orderDetailData.operationNo = '';
        this.orderDetailData.partNo = '';
        this.orderDetailData.partDesc = '';
        this.orderDetailData.locationNo = '';
        this.orderDetailData.resourceId = '';
        this.orderDetailData.resourceDesc = '';
        this.orderDetailData.qtyRequired = '';
        this.orderDetailData.itemDesc = '';
        this.orderDetailData.itemNo = '';
        this.orderDetailData.workCenterNo = '';
        this.orderDetailData.issureQty = 0;
        this.orderDetailData.alreadyApplyTotal = 0;
      },

//派工单选择部分
      openChooseSOSModal() {
        // 检查是否选择了主表行
        if (!this.currentRow || !this.currentRow.notifyNo) {
          this.$alert('请先选择一条主表记录！', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        this.ss_totalPage= 0;

        // 初始化选择派工单数据
        this.chooseSOSData = {
          page: 1,
          limit: 100,
          site: this.currentRow.site,
          bu: this.currentRow.bu,
          orderNo: '',
          seqNo: '',
          sResourceid: '',
          startDate: this.dayjs().format('YYYY-MM-DD'),
          endDate: this.dayjs().format('YYYY-MM-DD'),
        }
        // 清空选择列表
        this.chooseSOSList = []
        // 打开选择模态框
        this.chooseSOSModalFlag = true
      },
      searchSOSRouting() {
        this.chooseSOSData.limit = this.ss_pageSize
        this.chooseSOSData.page = this.ss_pageIndex
        // 调用API查询派工单信息
        getSOScheduledRoutingListForIssureByPaging(this.chooseSOSData).then(({data}) => {
          if (data.code === 0) {
            this.chooseSOSList = data.page.list;
            if (this.chooseSOSList.length === 0) {
              this.$message.warning('未查询到符合条件的派工单');
            }
            this.ss_pageIndex = data.page.currPage
            this.ss_pageSize = data.page.pageSize
            this.ss_totalPage = data.page.totalCount
          } else {
            // 清空选择列表
            this.chooseSOSList = []
            this.$message.error(data.msg || '查询失败');
          }
        }).catch(error => {
          // 清空选择列表
          this.chooseSOSList = []
          console.error('查询派工单失败:', error);
          this.$message.error('查询失败，请稍后重试');
        });
      },
      // 每页数  工单分页信息
      ss_sizeChangeHandle(val) {
        this.ss_pageSize = val
        this.ss_pageIndex = 1
        this.searchSOSRouting()
      },
      // 当前页  工单分页信息
      ss_currentChangeHandle(val) {
        this.ss_pageIndex = val
        this.searchSOSRouting()
      },
      chooseSOS(row) {
        // 关闭选择模态框
        this.chooseSOSModalFlag = false

        // 将选择的数据填入到保存派工单模态框中
        this.orderDetailData.orderNo = row.orderno || '';
        this.orderDetailData.seqNo = row.seqno || '';
        this.orderDetailData.itemNo = row.itemno || '';
        this.orderDetailData.itemDesc = row.itemDesc || '';
        this.orderDetailData.resourceId = row.sResourceid || '';
        this.orderDetailData.resourceDesc = row.resourceDesc || '';
        this.orderDetailData.qtyRequired = row.qtyrequired || '';
        this.orderDetailData.partDesc = row.partDesc || '';
        this.orderDetailData.partNo = row.partNo || '';
        this.orderDetailData.workCenterNo = row.sWorkcenterno || '';
        this.orderDetailData.alreadyApplyTotal = row.alreadyApplyTotal || 0;
        this.orderDetailData.needDate = this.dayjs().format('YYYY-MM-DD HH:mm:ss');

        // 根据物料类型设置
        if (row.issueType === '非BOM物料') {
          this.orderDetailData.materialType = '非BOM物料';
        } else {
          this.orderDetailData.materialType = 'BOM物料';
        }

        this.$message.success('选择派工单成功，数据已填入表单');
      },


//工单选择部分
      // 打开选择工单模态框
      openChooseOrderModal() {
        // 检查是否选择了主表行
        if (!this.currentRow || !this.currentRow.notifyNo) {
          this.$alert('请先选择一条主表记录！', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }
        this.co_totalPage= 0;
        // 初始化选择工单数据
        this.chooseOrderData = {
          page: 1,
          limit: 100,
          site: this.currentRow.site,
          buNo: this.currentRow.bu,
          user: this.$store.state.user.name,
          orderNo: '',
          statusList: ['已下达', '已计划', '已排产'],
          date3: this.dayjs().format('YYYY-MM-DD'),
          date4: this.dayjs().format('YYYY-MM-DD'),
        }

        // 清空选择列表
        this.chooseOrderList = []

        // 打开选择模态框
        this.chooseOrderModalFlag = true
      },
      // 查询工单信息
      searchOrder() {
        this.chooseOrderData.limit = this.co_pageSize
        this.chooseOrderData.page = this.co_pageIndex
        searchShopOrderByPaging(this.chooseOrderData).then(({data}) => {
          if (data.code === 0) {
            this.chooseOrderList = data.page.list;
            if (this.chooseOrderList.length === 0) {
              this.$message.warning('未查询到符合条件的工单');
            }
            this.co_pageIndex = data.page.currPage
            this.co_pageSize = data.page.pageSize
            this.co_totalPage = data.page.totalCount
          } else {
            this.chooseOrderList = [];
            this.$message.error(data.msg || '查询失败');
          }
        }).catch(error => {
          this.chooseOrderList = [];
          console.error('查询工单失败:', error);
          this.$message.error('查询失败，请稍后重试');
        });
      },
      // 每页数  工单分页信息
      co_sizeChangeHandle(val) {
        this.co_pageSize = val
        this.co_pageIndex = 1
        this.searchOrder()
      },
      // 当前页  工单分页信息
      co_currentChangeHandle(val) {
        this.co_pageIndex = val
        this.searchOrder()
      },
      // 选择工单
      chooseOrder(row) {
        // 关闭选择模态框
        this.chooseOrderModalFlag = false

        // 将选择的数据填入到保存派工单模态框中
        this.orderDetailData.orderNo = row.orderNo || '';
        this.orderDetailData.partNo = row.partNo || '';
        this.orderDetailData.partDesc = row.partDescription || '';
        this.orderDetailData.qtyRequired = row.lotSize || '';
        this.orderDetailData.alreadyApplyTotal = row.alreadyApplyTotal || 0;

        // 清空相关字段
        this.orderDetailData.seqNo = '';
        this.orderDetailData.operationNo = '';
        this.orderDetailData.locationNo = '';
      },
//工序选择部分
      // 打开选择工序模态框
      openChooseOperationModal() {
        // 检查是否选择了工单
        if (!this.orderDetailData.orderNo) {
          this.$alert('请先选择工单！', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        // 初始化选择工序数据
        this.chooseOperationData = {
          orderNo: this.orderDetailData.orderNo,
          site: this.currentRow.site,
        }

        // 清空选择列表
        this.chooseOperationList = []
        //
        this.searchOperation();
        // 打开选择模态框
        this.chooseOperationModalFlag = true
      },
      // 查询工序信息
      searchOperation() {
        // 调用API查询工序信息
        getRouteInShopOrder(this.chooseOperationData).then(({data}) => {
          if (data.code === 0) {
            this.chooseOperationList = data.dataList;
            if (this.chooseOperationList.length === 0) {
              this.$message.warning('未查询到符合条件的工序');
            }
          } else {
            // 清空选择列表
            this.chooseOperationList = [];
            this.$message.error(data.msg || '查询失败');
          }
        }).catch(error => {
          // 清空选择列表
          this.chooseOperationList = [];
          console.error('查询工序失败:', error);
          this.$message.error('查询失败，请稍后重试');
        });
      },
      // 选择工序
      chooseOperation(row) {
        // 关闭选择模态框
        this.chooseOperationModalFlag = false

        // 将选择的数据填入到保存派工单模态框中
        this.orderDetailData.itemDesc = row.operationDesc || '';
        this.orderDetailData.itemNo = row.itemNo || '';
        this.orderDetailData.workCenterNo = row.workCenterNo || '';

        this.$message.success('操作成功');
      },
//机台选择部分
      // 打开选择机台模态框
      openChooseResourceModal() {
        // 检查是否选择了工单
        if (!this.orderDetailData.orderNo) {
          this.$alert('请先选择工单！', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        // 初始化选择机台数据
        this.chooseResourceData = {
          site: this.currentRow.site,
          workCenterNo: this.orderDetailData.workCenterNo,
          resourceID: '',
          resourceDesc: '',
        }

        // 清空选择列表
        this.chooseResourceList = []
        this.searchResource();
        // 打开选择模态框
        this.chooseResourceModalFlag = true
      },
      // 查询机台信息
      searchResource() {
        // 调用API查询机台信息
        searchAllResource(this.chooseResourceData).then(({data}) => {
          if (data.code === 0) {
            this.chooseResourceList = data.rows;
            if (this.chooseResourceList.length === 0) {
              this.$message.warning('未查询到符合条件的机台');
            }
          } else {
            // 清空选择列表
            this.chooseResourceList = [];
            this.$message.error(data.msg || '查询失败');
          }
        }).catch(error => {
          // 清空选择列表
          this.chooseResourceList = [];
          console.error('查询机台失败:', error);
          this.$message.error('查询失败，请稍后重试');
        });
      },
      // 选择机台
      chooseResource(row) {
        // 关闭选择模态框
        this.chooseResourceModalFlag = false

        // 将选择的数据填入到保存派工单模态框中
        this.orderDetailData.resourceId = row.resourceId || '';
        this.orderDetailData.resourceDesc = row.resourceDesc || '';

        this.$message.success('操作成功');
      },
//非BOM物料选择部分
      // 打开选择物料模态框
      openChoosePartModal() {
        // 检查是否选择了主表行
        if (!this.currentRow || !this.currentRow.notifyNo) {
          this.$alert('请先选择一条主表记录！', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        // 初始化选择物料数据
        this.choosePartData = {
          site: this.currentRow.site,
          sourceBu: this.currentRow.bu,
          partNo: '',
          partDesc: '',
          spec: '',
        }

        // 清空选择列表
        this.choosePartList = []

        // 打开选择模态框
        this.choosePartModalFlag = true
        this.searchPartModel()
      },
      // 查询物料信息
      searchPartModel() {
        this.choosePartData.limit = this.pp_pageSize
        this.choosePartData.page = this.pp_pageIndex
        // 调用API查询物料信息
        getPartListByPaging(this.choosePartData).then(({data}) => {
          if (data.code === 0) {
            this.choosePartList = data.page.list;
            if (this.choosePartList.length === 0) {
              this.$message.warning('未查询到符合条件的物料');
            }
            this.pp_pageIndex = data.page.currPage
            this.pp_pageSize = data.page.pageSize
            this.pp_totalPage = data.page.totalCount
          } else {
            // 清空选择列表
            this.choosePartList = []
            this.$message.error(data.msg || '查询失败');
          }
        }).catch(error => {
          // 清空选择列表
          this.choosePartList = []
          console.error('查询物料失败:', error);
          this.$message.error('查询失败，请稍后重试');
        });
      },

      // 每页数  工单分页信息
      pp_sizeChangeHandle(val) {
        this.pp_pageSize = val
        this.pp_pageIndex = 1
        this.searchPartModel()
      },
      // 当前页  工单分页信息
      pp_currentChangeHandle(val) {
        this.pp_pageIndex = val
        this.searchPartModel()
      },
      // 选择物料
      choosePart(row) {
        // 关闭选择模态框
        this.choosePartModalFlag = false

        // 将选择的数据填入到保存派工单模态框中
        this.orderDetailData.partNo = row.partNo || '';
        this.orderDetailData.partDesc = row.partDesc || '';
        this.orderDetailData.materialType = '非BOM物料';

        this.$message.success('选择物料成功，数据已填入表单');
      },
//下达申请单方法
      async xiadaNotifyModel(row){
        // 设置当前行为要下达的行
        this.currentRow = JSON.parse(JSON.stringify(row));

        // 先刷新子表数据，确保获取最新数据
        await this.refreshAllSubTables();

        console.log('申请单明细数据:', this.dataList2);
        console.log('材料明细数据:', this.dataList3);

        if(this.dataList2.length==0 || this.dataList3.length==0){
          this.$alert('没有明细记录无法下达！!', '提示', {
            confirmButtonText: '确定'
          })
          return false
        }

        xiadaNotify(row).then(({data})=>{
          if (data.code === 0) {
            //刷新主表数据
            this.searchTable().then(() => { // 等刷新完成
              const foundRow = this.dataList.find(item => item.notifyNo === row.notifyNo);
              if (foundRow) {
                this.currentRow = JSON.parse(JSON.stringify(foundRow));
                this.$nextTick(() => {
                  this.$refs.mainTable.setCurrentRow(foundRow);
                });
              }
            });
            this.$message.success( '操作成功')
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      // 刷新所有子表数据
      async refreshAllSubTables() {
        if(!this.currentRow || !this.currentRow.notifyNo) {
          console.warn('当前行数据为空，无法刷新子表数据');
          return;
        }

        try {
          // 并行请求所有子表数据
          const [detailData, materialData] = await Promise.all([
            searchNotifyOrderList(this.currentRow),
            searchNotifyMaterialList(this.currentRow)
          ]);

          // 更新申请单明细数据
          if (detailData.data && detailData.data.code == 0) {
            this.dataList2 = detailData.data.rows;
          } else {
            this.dataList2 = [];
          }

          // 更新材料明细数据
          if (materialData.data && materialData.data.code == 0) {
            this.dataList3 = materialData.data.rows;
          } else {
            this.dataList3 = [];
          }

        } catch (error) {
          console.error('刷新子表数据失败:', error);
          this.$message.error('刷新子表数据失败，请稍后重试');
        }
      },

      editNotifyMaterialFun(row){
        // 设置当前行为要编辑的行
        this.currentRow = JSON.parse(JSON.stringify(row));

        editNotifyMaterial(row).then(({data})=>{
          if (data.code === 0) {
            //刷新主表数据
            this.searchTable().then(() => { // 等刷新完成
              const foundRow = this.dataList.find(item => item.notifyNo === row.notifyNo);
              if (foundRow) {
                this.currentRow = JSON.parse(JSON.stringify(foundRow));
                this.$nextTick(() => {
                  this.$refs.mainTable.setCurrentRow(foundRow);
                });
              }
            });
            this.$message.success( '操作成功')
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 判断当前状态是否可编辑
      isEditableStatus() {
        if (!this.currentRow || !this.currentRow.status) {
          return false;
        }
        return this.currentRow.status === '草稿' || this.currentRow.status === '编辑中';
      },
    },
  }
</script>

<style scoped>
.disabled {
  cursor: not-allowed !important;
  color: #C0C4CC !important;
  pointer-events: none;
}

.text-right >>> .el-input__inner {
  text-align: right !important;
}

.text-right >>> .el-input-number__input {
  text-align: right !important;
}

.single-line-multi-select >>> .el-select__tags {
  display: flex;
  flex-wrap: nowrap;
  overflow: hidden;
  white-space: nowrap;
  max-width: 100%;
}

.single-line-multi-select >>> .el-tag {
  flex-shrink: 0;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.single-line-multi-select >>> .el-select__input {
  flex-shrink: 0;
  min-width: 30px;
}

.disabled-link {
  cursor: not-allowed !important;
  color: #C0C4CC !important;
  pointer-events: none;
}

.disabled-text {
  color: #C0C4CC !important;
  cursor: not-allowed !important;
}
</style>
