<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="'申请单号'">
        <el-input v-model="searchData.applyNo" clearable style="width: 160px"></el-input>
      </el-form-item>
      <el-form-item label="申请日期">
        <el-date-picker
          value-format="yyyy-MM-dd"
          style="width: 100%"
          v-model="searchData.startDate"
          type="date"
          placeholder="开始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="到">
        <el-date-picker
          value-format="yyyy-MM-dd"
          style="width: 100%"
          v-model="searchData.endDate"
          type="date"
          placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.status" clearable style="width: 80px">
          <el-option label="全部" value=""></el-option>
          <el-option label="草稿" value="草稿"></el-option>
          <el-option label="审批中" value="审批中"></el-option>
          <el-option label="下达" value="下达"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="search()" type="primary" style="margin-left: 2px;margin-top:0px">查询</el-button>
        <!--        <el-button @click="addOrUpdateHandle('save')" type="primary" style="margin-left: 2px;margin-top: 0px">新增</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-button @click="filterVisible = true">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :height="height"
      :data="dataList1"
      border
      ref="mainTable"
      @row-click="changeData"
      highlight-current-row
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="150"
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <template v-if="isAuth('106002:issued')">
            <a type="text" size="small" v-if="scope.row.status==='草稿'" @click="comfirmApply(scope.row)">下达</a>
          </template>
          <template v-if="isAuth('106002:update')">
            <a type="text" size="small" v-if="scope.row.status==='草稿'" @click="editModalU(scope.row)">修改</a>
          </template>
          <template v-if="isAuth('106002:approval')">
            <a type="text" size="small" v-if="scope.row.status==='审批中'" @click="editModal(scope.row)">审批</a>
          </template>
          <template v-if="isAuth('106002:remove')">
            <a type="text" size="small" v-if="scope.row.status==='草稿'" @click="cancelApply(scope.row)">删除</a>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList1" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>

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

    <el-tabs style="font-size: 12px;min-height: 330px" class="customer-tab" v-model="activeName" type="border-card" @tab-click="tabClick">
      <el-tab-pane label="基本信息" name="attribute">
        <order-attribute
          ref="dialogAttribute"
          :disabled="currentRow.status === '已完成'"
          :order-no="currentRow.applyNo"
          :approval-username="currentRow.sp"
          :proofing-status="currentRow.status"
          :super-admin="superAdmin"
          :code-no="'toolApply'"
          :function-type="'TL_Receipt'">
        </order-attribute>
      </el-tab-pane>
      <el-tab-pane label="工具明细" name="detail">
        <el-table
          :data="detailList"
          height="240"
          border
          v-loading="dataListLoading"
          style="width: 100%; ">
          <el-table-column
            v-for="(item,index) in columnList2" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            width="120"
            fixed="right"
            label="操作">
            <template slot-scope="scope">
              <a type="text" size="small" @click="jumpBM(scope.row)">跳转BenchMark</a>
            </template>
          </el-table-column>
          <!--          <el-table-column-->
          <!--            fixed="right"-->
          <!--            header-align="center"-->
          <!--            align="center"-->
          <!--            width="100"-->
          <!--            label="操作">-->
          <!--            <template slot-scope="scope">-->
          <!--              &lt;!&ndash;              <a :href="'http://192.168.1.130:80/file/'+scope.row.url" :download="scope.row.fileName">下载</a>&ndash;&gt;-->
          <!--              <a  @click="downloadFile(scope.row)" >下载</a>-->
          <!--              <a type="text" size="small"  @click="deleteFile(scope.row)">删除</a>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="处理信息" name="tab4">
        <el-form :inline="true" label-position="top" style="margin-top: 0px">
          <!--          <el-button type="primary" :disabled="!(currentRow.statusCode==='50'||currentRow.statusCode==='60')" @click="openMassageModel()">申请信息录入</el-button>-->
          <!--          <el-button type="primary"  @click="openMassageModel()">申请信息录入</el-button>-->
        </el-form>
        <el-form label-position="top" :model="currentRow">
          <el-row :gutter="15">
            <el-col :span="6">
              <el-form-item label="IFS PR编号">
                <el-input v-model="currentRow.prNo" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="18">
              <el-form-item label="备注">
                <el-input v-model="currentRow.remark1" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" style="margin-top: 20px">
            <el-col :span="6">
              <el-form-item label="采购订单号">
                <el-input v-model="currentRow.poNo" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="厂商名称">
                <el-input v-model="currentRow.supplierName" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="总成本(元)">
                <el-input v-if="accessField('10601001')" v-model="currentRow.allCost" readonly></el-input>
                <el-input v-if="!accessField('10601001')" v-model="valueNull" style="width: 130px" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" style="margin-top: 0px">
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input v-model="currentRow.remark2" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="附件信息" name="down">
        <oss-components height="25vh" label="附件" :columns="ossColumns" :order-ref1="currentRow.site" :order-ref2="currentRow.applyNo"></oss-components>
      </el-tab-pane>
      <!-- 审批信息 -->
      <el-tab-pane label="审批信息" name="approvalInformation">
        <approval-information ref="approvalTable" v-model:data-list="approvalList" :height="240"></approval-information>
      </el-tab-pane>
    </el-tabs>

    <el-dialog width="950px" v-drag :title="'刀模申请修改'" :close-on-click-modal="false" :visible.sync="visibleU">
      <el-form :inline="true" label-position="top" label-width="100px">
        <el-form-item :label="'申请编号'">
          <el-input v-model="dataForm.applyNo" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'申请总数'">
          <el-input v-model="dataForm.applySumQty" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'总成本'">
          <el-input v-if="accessField('10601001')" v-model="dataForm.totalCost" style="width: 130px" disabled></el-input>
          <el-input v-if="!accessField('10601001')" v-model="valueNull" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'申请人'" required="required">
          <el-input v-model="dataForm.applyBy" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'申请日期'" required="required">
          <el-date-picker
            value-format="yyyy-MM-dd"
            style="width: 100%"
            v-model="dataForm.applyDate"
            type="date"
            disabled
            placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="部门" required="required">
          <dict-data-select
            :site="$store.state.user.site"
            v-model="dataForm.department"
            dict-type="tool_application_department"
            disabled style="width: 130px">
          </dict-data-select>
        </el-form-item>
        <el-form-item required="required">
          <span slot="label" style="" @click="getBaseList(2002,1)"><a herf="#">报价员</a></span>
          <el-input v-model="dataForm.quoterName" ref="quoterName" placeholder="请选择人员" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item required="required">
          <span slot="label" style="" @click="getBaseList(2042,2)"><a herf="#">TP</a></span>
          <el-input v-model="dataForm.tpName" ref="tpName" placeholder="请选择人员" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item required="required">
          <span slot="label" style="" @click="getBaseList(2000,3)"><a herf="#">采购员</a></span>
          <el-input v-model="dataForm.purchaserName" ref="purchaserName" placeholder="请选择人员" readonly style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px">
        <el-form-item :label="'申请原因'">
          <el-input type="textarea" style="width: 930px" resize="none" :autosize="{minRows: 3, maxRows: 3}" v-model="dataForm.applyReason"/>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 60px">
        <el-form-item :label="'备注'">
          <el-input type="textarea" style="width: 930px" resize="none" :autosize="{minRows: 3, maxRows: 3}" v-model="dataForm.remark"/>
        </el-form-item>
      </el-form>
      <el-tabs style="font-size: 12px;min-height: 330px;margin-top: 60px" class="customer-tab" v-model="activeModelName" type="border-card">
        <el-tab-pane label="工具明细" name="detail">
          <div class="rq">
            <el-table
              height="278"
              :data="toolData"
              border
              ref="toolTable"
              v-loading="dataListLoading"
              style="width: 100%;">
              <el-table-column
                v-for="(item,index) in columnList2" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed==''?false:item.fixed"
                :min-width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <div v-if="(item.columnProp !== 'applyQty')&& (item.columnProp !== 'standardCost')">
                    <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>
                  </div>
                  <div v-else-if=" (item.columnProp === 'standardCost')">
                    <el-input v-if="accessField('10601001')" v-model="scope.row.standardCost" type="number" @change="changeSum(scope.row)" placeholder="请输入成本" style="width:98%"></el-input>
                  </div>
                  <div v-else>
                    <el-input v-model="scope.row.applyQty" type="number" @change="changeSum(scope.row)" placeholder="请输入数量" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" style="width:98%"></el-input>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="TP处理结果" name="tp">
          <el-form label-position="top">
            <el-row :gutter="15">
              <el-col :span="6">
                <el-form-item label="IFS PR编号">
                  <el-input v-model="modelData.prNo" :disabled="$store.state.user.name!==dataForm.tp"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注" style="height: 80px">
                  <el-input type="textarea" v-model="modelData.remark1" :rows="3" style="height: 60px" :disabled="$store.state.user.name!==dataForm.tp"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="采购处理结果" name="caigou">
          <el-form label-position="top">
            <el-row :gutter="15" style="margin-top: 0px">
              <el-col :span="6">
                <el-form-item label="采购订单号">
                  <el-input v-model="modelData.poNo" :disabled="$store.state.user.name!==dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="厂商名称">
                  <el-input v-model="modelData.supplierName" :disabled="$store.state.user.name!==dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="总成本(元)">
                  <el-input v-model="modelData.allCost" type="number" :disabled="$store.state.user.name!==dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="15" style="margin-top: 0px">
              <el-col :span="24">
                <el-form-item label="备注" style="height: 80px">
                  <el-input type="textarea" v-model="modelData.remark2" :rows="3" style="height: 60px" :disabled="$store.state.user.name!==dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <el-footer style="height:35px;margin-top:15px;text-align:center">
        <el-button type="primary" @click="saveData()" class="bigButton">{{ '保存' }}</el-button>
        <el-button type="primary" @click="visibleU = false" class="bigButton">{{ '取消' }}</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog width="950px" v-drag :title="'刀模申请审批'" :close-on-click-modal="false" :visible.sync="visible">
      <el-form :inline="true" label-position="top" label-width="100px">
        <el-form-item :label="'申请编号'">
          <el-input v-model="dataForm.applyNo" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'申请总数'">
          <el-input v-model="dataForm.applySumQty" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'总成本'">
          <el-input v-if="accessField('10601001')" v-model="dataForm.totalCost" style="width: 130px" disabled></el-input>
          <el-input v-if="!accessField('10601001')" v-model="valueNull" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'申请人'" required="required">
          <el-input v-model="dataForm.applyBy" style="width: 130px" disabled></el-input>
        </el-form-item>
        <el-form-item :label="'申请日期'" required="required">
          <el-date-picker
            value-format="yyyy-MM-dd"
            style="width: 100%"
            v-model="dataForm.applyDate"
            type="date"
            disabled
            placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="部门" required="required">
          <dict-data-select :site="$store.state.user.site" v-model="dataForm.department" dict-type="tool_application_department" disabled style="width: 130px"></dict-data-select>
        </el-form-item>
        <el-form-item required="required">
          <span slot="label" style="" @click="getBaseList(2002,1)"><a herf="#">报价员</a></span>
          <el-input v-model="dataForm.quoterName" ref="quoterName" placeholder="请选择人员" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item required="required">
          <span slot="label" style="" @click="getBaseList(2042,2)"><a herf="#">TP</a></span>
          <el-input v-model="dataForm.tpName" ref="tpName" placeholder="请选择人员" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item required="required">
          <span slot="label" style="" @click="getBaseList(2000,3)"><a herf="#">采购员</a></span>
          <el-input v-model="dataForm.purchaserName" ref="purchaserName" placeholder="请选择人员" readonly style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px">
        <el-form-item :label="'申请原因'">
          <el-input type="textarea" style="width: 930px" resize="none" :autosize="{minRows: 3, maxRows: 3}" v-model="dataForm.applyReason"/>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 45px">
        <el-form-item :label="'备注'">
          <el-input type="textarea" style="width: 930px" resize="none" :autosize="{minRows: 3, maxRows: 3}" v-model="dataForm.remark"/>
        </el-form-item>
      </el-form>
      <el-tabs style="font-size: 12px;min-height: 330px;margin-top: 60px" class="customer-tab" v-model="activeModelName" type="border-card">
        <el-tab-pane label="工具明细" name="detail">
          <div class="rq">
            <el-table
              height="278"
              :data="toolData"
              border
              ref="toolTable"
              v-loading="dataListLoading"
              style="width: 100%;">
              <el-table-column
                v-for="(item,index) in columnList2" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed==''?false:item.fixed"
                :min-width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <div v-if="(item.columnProp !== 'applyQty')&& (item.columnProp !== 'standardCost')">
                    <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>
                  </div>
                  <div v-else-if=" (item.columnProp === 'standardCost')">
                    <el-input v-if="accessField('10601001')" v-model="scope.row.standardCost" type="number" @change="changeSum(scope.row)" placeholder="请输入成本" style="width:98%"></el-input>
                  </div>
                  <div v-else>
                    <el-input v-model="scope.row.applyQty" type="number" @change="changeSum(scope.row)" :disabled="changeApplyDetailFlag('applyQty') === 'N'" placeholder="请输入数量" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" style="width:98%"></el-input>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="TP处理结果" name="tp">
          <el-form label-position="top">
            <el-row :gutter="15">
              <el-col :span="6">
                <el-form-item label="IFS PR编号">
                  <el-input v-model="modelData.prNo" :disabled="$store.state.user.name !== dataForm.tp"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注" style="height: 100px">
                  <el-input type="textarea" v-model="modelData.remark1" :rows="3" :disabled="$store.state.user.name !== dataForm.tp"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="采购处理结果" name="caigou">
          <el-form label-position="top">
            <el-row :gutter="15">
              <el-col :span="6">
                <el-form-item label="采购订单号">
                  <el-input v-model="modelData.poNo" :disabled="$store.state.user.name !== dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="厂商名称">
                  <el-input v-model="modelData.supplierName" :disabled="$store.state.user.name !== dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="总成本(元)">
                  <el-input v-if="accessField('10601001')" v-model="modelData.allCost" type="number" :disabled="$store.state.user.name!==dataForm.purchaser"></el-input>
                  <el-input v-if="!accessField('10601001')" v-model="valueNull" style="width: 130px" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="15">
              <el-col :span="24">
                <el-form-item label="备注" style="height: 100px">
                  <el-input type="textarea" v-model="modelData.remark2" :rows="3" :disabled="$store.state.user.name!==dataForm.purchaser"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <el-footer style="height:35px;margin-top:15px;text-align:center">
        <template v-if="dataForm.status === '草稿' || (dataForm.sp && dataForm.sp.split(';').includes(sp) && dataForm.status === '审批中')">
          <el-button type="primary" @click="saveData" class="bigButton">保存</el-button>
        </template>
        <el-button type="primary" @click="visible = false" class="bigButton">{{ '取消' }}</el-button>
        <template v-if="isAuth('106002:submit')">
          <template v-if="superAdmin || (dataForm.sp && dataForm.sp.split(';').includes(sp))">
            <el-button v-if="dataForm.status === '审批中'" type="primary" @click="agreeSubmit" class="bigButton">同意</el-button>
          </template>
        </template>
        <template v-if="isAuth('106002:rejected')">
          <template v-if="superAdmin || (dataForm.sp && dataForm.sp.split(';').includes(sp))">
            <el-button v-if="dataForm.status === '审批中' && dataForm.isReject === 'Y'" type="primary" @click="submitDataModal" class="bigButton">驳回</el-button>
          </template>
        </template>
      </el-footer>
    </el-dialog>

    <el-dialog width="600px" v-drag :title="'处理信息'" :close-on-click-modal="false" :visible.sync="modelFlag">
      <el-form label-position="top">
        <el-row :gutter="15">
          <el-col :span="6">
            <el-form-item label="IFS PR编号">
              <el-input v-model="modelData.prNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="备注">
              <el-input v-model="modelData.remark1"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15" style="margin-top: 20px">
          <el-col :span="6">
            <el-form-item label="采购订单号">
              <el-input v-model="modelData.poNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="厂商名称">
              <el-input v-model="modelData.supplierName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="总成本(元)">
              <el-input v-if="accessField('10601001')" v-model="modelData.allCost" type="number"></el-input>
              <el-input v-if="!accessField('10601001')" v-model="valueNull" style="width: 130px" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15" style="margin-top: 0px">
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="modelData.remark2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveHeaderMessage()">{{ '保存' }}</el-button>
        <el-button type="primary" @click="modelFlag = false">{{ '取消' }}</el-button>
      </span>
    </el-dialog>

    <!-- 提交 -->
    <el-dialog title="驳回" top="30vh" :close-on-click-modal="false" v-drag :visible.sync="submitModalFlag"
               width="500px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'驳回意见'">
          <el-input type="textarea" v-model="rejectOpinion" :rows="3" resize='none' show-word-limit
                    style="width: 479px;height: 30px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:30px;margin-top: 50px;text-align:center">
        <el-button type="primary" @click="rejectSubmit">确定</el-button>
        <el-button type="primary" @click="submitModalFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <!-- 上传文件的modal -->
    <projectUploadFile ref="projectUploadFile" @refreshPageTables="getFileContentData()" v-drag></projectUploadFile>

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

    <filter-search :visible.sync="filterVisible" @search="queryByAnyField"></filter-search>
  </div>
</template>

<script>
import {
  customerInformationSearch, // 客户信息列表查询`
} from '@/api/customer/customerInformation.js'
import projectUploadFile from "./com_tool_upload_file";/*上传文件的組件*/
import Chooselist from '@/views/modules/common/Chooselist'
import {
  searchProjectToolApplyHeader,
  searchProjectToolApplyDetail,
  comfirmProjectToolApply,
  cancelProjectToolApply,
  saveProjectHeaderMessage,
  editToolApplication,
  submitChange
} from "@/api/tool/toolApply.js"
import {
  deleteProjectFile,
  getFileContentList,
  downLoadProjectFile,
  getProjectPartNowBm,
} from "@/api/project/project.js"
import {
  getNodeAuthority, // 获取节点权限
  getApprovalList, // 查询审批信息
  checkSuperAdmin, // 校验是否为超级管理员
} from '@/api/changeManagement/changeManagement.js'
import ApprovalInformation from "../changeManagement/approvalInformation.vue";
import OssComponents from "../oss/ossComponents";
import DictDataSelect from "../sys/dict-data-select.vue"
import orderAttribute from "../demoComponents/orderProperties"
import FilterSearch from "../../common/filterSearch.vue";
import {technicalSpecificationListSearchByAnyField} from "../../../api/sampleManagement/technicalSpecificationList";
import {searchProjectToolApplyHeaderByAnyField} from "../../../api/tool/toolApply";
/*組件*/
export default {
  components: {
    FilterSearch,
    ApprovalInformation,
    OssComponents,
    Chooselist,
    projectUploadFile,
    DictDataSelect,
    orderAttribute,
  },
  computed: {
    changeApplyHeaderFlag() {
      return (value) => {
        if (!this.plmChangeApplyHeaderArr) {
          return 'N'
        }
        let arr = this.plmChangeApplyHeaderArr.filter(a => a.fieldId === value)
        if (arr.length > 0) {
          return arr[0].updateFlag
        }
        return 'N'
      }
    },
    changeApplyDetailFlag() {
      return (value) => {
        if (!this.plmChangeApplyDetailArr) {
          return 'N'
        }
        let arr = this.plmChangeApplyDetailArr.filter(a => a.fieldId === value)
        if (arr.length > 0) {
          return arr[0].updateFlag
        }
        return 'N'
      }
    },
  },
  name: "null",
  data() {
    return {
      visible: false,
      filterVisible: false,
      isFilterSearch: false,
      filterSearchData: {},
      fileContentList: [],
      activeName: 'detail',
      activeModelName: 'detail',
      searchData: {
        page: 1,
        limit: 100,
        site: this.$store.state.user.site,
        applyNo: '',
        startDate: '',
        endDate: '',
        status: '',
      },
      toolData: [],
      visibleU: false,
      plmChangeApplyHeaderArr: [],
      plmChangeApplyDetailArr: [],
      dataForm: {
        site: '',
        applyNo: '',
        applyBy: '',
        applyDate: '',
        applySumQty: '',
        applyReason: '',
        remark: '',
        createBy: '',
        detailList: [],
        status: '',
        rejectOpinion: '',
        nodeConclusion: '',
        quoter: '',
        quoterName: '',
        tp: '',
        tpName: '',
        purchaser: '',
        purchaserName: '',
        totalCost: '',
        menuId: this.$route.meta.menuId,
        userName: this.$store.state.user.name,
        nodeId: '',
        sp: ''
      },
      valueNull: '******',
      modelData: {
        site: '',
        applyNo: '',
        prNo: '',
        remark1: '',
        poNo: '',
        supplierName: '',
        allCost: '',
        remark2: '',
      },
      modelFlag: false,
      currentRow: {},
      currentRow2: {},
      height: 200,
      dataList1: [],
      detailList: [],
      dataListLoading: false,
      // 导出 start
      exportData: [],
      exportName: "项目清单" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["项目清单"],
      exportFooter: [],
      exportList: [],
      // 导出 start
      exportData2: [],
      exportName2: "项目客户联系人" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader2: ["项目客户联系人"],
      exportFooter2: [],
      exportList2: [],
      tagNo: '',
      tagNo2: '',
      pageIndex: 1,
      pageSize: 100,
      totalPage: 0,
      ossColumns: [
        {
          userId: this.$store.state.user.name,
          functionId: 103001,
          serialNumber: '103001Table2FileName',
          tableId: '103001Table2',
          tableName: '文件信息表',
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103001,
          serialNumber: '103001Table2FileRemark',
          tableId: '103001Table2',
          tableName: '文件信息表',
          columnProp: 'fileRemark',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 240
        },
        // {
        //   userId: this.$store.state.user.name,
        //   functionId: 103001,
        //   serialNumber: '103001Table2OrderRef3',
        //   tableId: '103001Table2',
        //   tableName: '文件信息表',
        //   columnProp: 'orderRef3',
        //   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: 103001,
          serialNumber: '103001Table2CreateDate',
          tableId: '103001Table2',
          tableName: '文件信息表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140
        },
        {
          userId: this.$store.state.user.name,
          functionId: 103001,
          serialNumber: '103001Table2CreatedBy',
          tableId: '103001Table2',
          tableName: '文件信息表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140
        }
      ],
      // 导出 end
      columnList1: [
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1Site',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "site",
          headerAlign: "center",
          align: "left",
          columnLabel: "工厂编码",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1DepartmentDesc',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "departmentDesc",
          headerAlign: "center",
          align: "left",
          columnLabel: "部门",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1ApplyNo',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "applyNo",
          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: 106002,
          serialNumber: '106002Table1ApplyBy',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "applyBy",
          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: 106002,
          serialNumber: '106002Table1Status',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "status",
          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: 106002,
          serialNumber: '106002Table1NodeId',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "nodeId",
          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: 106002,
          serialNumber: '106002Table1SP',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "sp",
          headerAlign: "center",
          align: "left",
          columnLabel: "当前节点审批人",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 90
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1NodeName',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "nodeName",
          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: 106002,
          serialNumber: '106002Table1ApplySumQty',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "applySumQty",
          headerAlign: "center",
          align: "right",
          columnLabel: "申请数量",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1TotalCost',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "totalCost",
          headerAlign: "center",
          align: "right",
          columnLabel: "总成本",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1QuoterName',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "quoterName",
          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: 106002,
          serialNumber: '106002Table1TpName',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "tpName",
          headerAlign: "center",
          align: "left",
          columnLabel: "TP",
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 60
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table1PurchaserName',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "purchaserName",
          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: 106002,
          serialNumber: '106002Table1ApplyDate',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "applyDate",
          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: 106002,
          serialNumber: '106002Table1ApplyReason',
          tableId: "106002Table1",
          tableName: "刀具申请主表",
          columnProp: "applyReason",
          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: 106002,
          serialNumber: '106002Table1Remark',
          tableId: "106002Table1",
          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: 106002,
          serialNumber: '106002Table2SeqNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'seqNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 40
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2QuotationNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'orderRef1',
          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: 106002,
          serialNumber: '106002Table2ToolNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'toolId',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工具编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2ToolDescription',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'toolDesc',
          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: 106002,
          serialNumber: '106002Table2ApplyQty',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'applyQty',
          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: 106002,
          serialNumber: '106002Table2UnitCost',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'standardCost',
          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: 106002,
          serialNumber: '106002Table2QuotationNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'plmPartNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'PLM物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2IfsPartNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'ifsPartNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'IFS物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2PartDesc',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 160
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2CustomerPartNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'customerPartNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '客户料号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2QuotationNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'orderRef3',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工艺路线版本',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        },
        {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2QuotationNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'orderRef5',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '替代编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        }, {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2QuotationNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'operationNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        }, {
          userId: this.$store.state.user.name,
          functionId: 106002,
          serialNumber: '106002Table2QuotationNo',
          tableId: '106002Table2',
          tableName: '工具申请明细',
          columnProp: 'operationName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工序',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 70
        },
      ],
      columnFileContentArray: [
        {
          columnProp: 'fileName',
          headeralign: 'left',
          align: 'left',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
          // }, {
          //   columnProp: 'createdBy',
          //   headeralign: 'left',
          //   align: 'left',
          //   columnLabel: '上传人',
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: true,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
        }, {
          columnProp: 'createDate',
          headeralign: 'left',
          align: 'left',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: false
        }, {
          columnProp: 'orderRef3',
          headeralign: 'left',
          align: 'left',
          columnLabel: '类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: false
        },
      ],
      approvalList: [],
      rejectOpinion: '',
      submitModalFlag: false,
      processField: '',
      sp: this.$store.state.user.name,
      superAdmin: false,
    }
  },
  watch: {
    // columnList1: {
    //   deep: true,
    //   handler: function (newV, oldV) {
    //     debugger
    //
    //   }
    // }
  },

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

  methods: {

    // 校验是否为超级管理员
    checkSuperAdmin () {
      checkSuperAdmin().then(({data}) => {
        this.superAdmin = data.superAdmin
      })
    },

    accessProcessField(key) {
      return this.processField.indexOf(key) !== -1 || false
    },
    // 查询审批信息
    getApprovalList() {
      if (Object.keys(this.currentRow).length !== 0) {
        let tempData = {
          site: this.$store.state.user.site,
          menuId: this.$route.meta.menuId,
          documentNo: this.currentRow.applyNo
        }
        getApprovalList(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.approvalList = data.rows
          } else {
            this.approvalList = []
          }
        })
      }
    },

    // 获取基础数据列表S
    getBaseList(val, type) {
      this.tagNo = val
      this.tagNo2 = type
      this.$nextTick(() => {
        let strVal = ''
        if (val === 2002) {
          if (this.changeApplyHeaderFlag('quoter') === 'N' && this.currentRow.status === '审批中') {
            this.$alert('没有权限在审批过程中修改!', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          strVal = this.dataForm.quoter
        } else if (val === 2042) {
          if (this.changeApplyHeaderFlag('tp') === 'N' && this.currentRow.status === '审批中') {
            this.$alert('没有权限在审批过程中修改!', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          strVal = this.dataForm.tp
        } else if (val === 2000) {
          if (this.changeApplyHeaderFlag('purchaser') === 'N' && this.currentRow.status === '审批中') {
            this.$alert('没有权限在审批过程中修改!', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          strVal = this.dataForm.purchaser
        }
        this.$refs.baseList.init(val, strVal)
      })
    },
    /* 列表方法的回调 */
    getBaseData(val) {
      if (this.tagNo === 2002) {
        this.dataForm.quoter = val.username
        this.dataForm.quoterName = val.user_display
        this.$nextTick(() => {
          this.$triggerInputEvent(this.$refs.quoterName);
        });
      } else if (this.tagNo === 2042) {
        this.dataForm.tp = val.username
        this.dataForm.tpName = val.user_display
        this.$nextTick(() => {
          this.$triggerInputEvent(this.$refs.tpName);
        });
      } else if (this.tagNo === 2000) {
        this.dataForm.purchaser = val.username
        this.dataForm.purchaserName = val.user_display
        this.$nextTick(() => {
          this.$triggerInputEvent(this.$refs.purchaserName);
        });
      }
    },

    //导出excel
    async createExportData() {
      this.searchData.limit = -1
      this.searchData.page = 1
      await searchProjectToolApplyHeader(this.searchData).then(({data}) => {
        this.exportList = data.page.list;
      })

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

    },
    finishDownload() {

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

      return s
    },
    //导出excel
    async createExportData2() {

      return this.contactList;
    },
    startDownload2() {
      //  this.exportData = this.dataList

    },
    finishDownload2() {

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

      return s
    },
    // 导出 end
    // 获取数据列表
    search() {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      searchProjectToolApplyHeader(this.searchData).then(({data}) => {
        if (data.code == 0) {
          this.dataList1 = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          if (this.dataList1.length > 0) {
            this.$refs.mainTable.setCurrentRow(this.dataList1[0]);
            this.currentRow = JSON.parse(JSON.stringify(this.dataList1[0]));

          } else {
            this.currentRow = {}
          }
          this.refreshCurrentTabTable()
        }
        this.dataListLoading = false
      })
      this.isFilterSearch = false
    },
    //单击切换订单
    changeData(row) {
      this.currentRow = JSON.parse(JSON.stringify(row));
      this.currentRow2 = row;
      this.refreshCurrentTabTable();
    },
    addUploadFileModal() {
      let currentData = {
        site: this.currentRow.site,
        createBy: this.$store.state.user.name,
        projectId: this.currentRow.applyNo,
        projectName: '',
        remark: '',
      };
      //打开组件 去做新增业务
      this.$nextTick(() => {
        this.$refs.projectUploadFile.init(currentData);
      })
    },
    deleteFile(row) {
      this.$confirm('确定要删除此文件?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteProjectFile(row).then(({data}) => {
          if (data && data.code == 0) {
            this.getFileContentData();
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },
    tabClick(tab, event) {
      // 刷新列表数据
      this.refreshCurrentTabTable()
    },
    // 刷新页签的table数据
    refreshCurrentTabTable() {
      if (this.activeName == 'detail') {
        this.searchToolApplyDetail();
      }
      if (this.activeName == 'down') {
        // this.getFileContentData();
      }
      if (this.activeName === 'approvalInformation') {
        this.getApprovalList()
      }
      if (this.activeName == 'attribute') { // 基本信息

      }

    },
    searchToolApplyDetail() {
      if (this.currentRow.applyNo) {
        searchProjectToolApplyDetail(this.currentRow).then(({data}) => {
          if (data.code == 0) {
            this.detailList = data.rows
          }
        })
      } else {
        this.detailList = []
      }
    },

    // 审批
    editModal(row) {
      this.getNodeAuthority(row)
      this.checkSuperAdmin()
      this.dataForm = {
        site: row.site,
        applyNo: row.applyNo,
        applyBy: row.applyBy,
        applyDate: row.applyDate,
        applySumQty: row.applySumQty,
        applyReason: row.applyReason,
        remark: row.remark,
        createBy: row.createBy,
        department: row.department,
        detailList: [],
        status: row.status,
        rejectOpinion: '',
        nodeConclusion: '',
        quoter: row.quoter,
        quoterName: row.quoterName,
        tp: row.tp,
        tpName: row.tpName,
        purchaser: row.purchaser,
        purchaserName: row.purchaserName,
        totalCost: row.totalCost,
        menuId: this.$route.meta.menuId,
        userName: this.$store.state.user.name,
        nodeId: row.nodeId,
        sp: row.sp
      }
      this.openModelMessage()
      searchProjectToolApplyDetail({
        site: row.site,
        applyNo: row.applyNo,
      }).then(({data}) => {
        if (data.code == 0) {
          this.toolData = data.rows
        }
      })
      this.visible = true
    },
    editModalU(row) {
      this.getNodeAuthority(row)
      this.dataForm = {
        site: row.site,
        applyNo: row.applyNo,
        applyBy: row.applyBy,
        applyDate: row.applyDate,
        applySumQty: row.applySumQty,
        applyReason: row.applyReason,
        remark: row.remark,
        createBy: row.createBy,
        department: row.department,
        detailList: [],
        status: row.status,
        rejectOpinion: '',
        nodeConclusion: '',
        quoter: row.quoter,
        quoterName: row.quoterName,
        tp: row.tp,
        tpName: row.tpName,
        purchaser: row.purchaser,
        purchaserName: row.purchaserName,
        totalCost: row.totalCost,
        menuId: this.$route.meta.menuId,
        userName: this.$store.state.user.name,
        nodeId: row.nodeId
      }
      this.openModelMessage()
      searchProjectToolApplyDetail({
        site: row.site,
        applyNo: row.applyNo,
      }).then(({data}) => {
        if (data.code == 0) {
          this.toolData = data.rows
        }
      })
      this.visibleU = true
    },
    comfirmApply(row) {
      this.$confirm(`确定下达这个申请`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let tempData = {
          site: row.site,
          userName: this.$store.state.user.name,
          applyNo: row.applyNo,
          menuId: this.$route.meta.menuId
        }
        comfirmProjectToolApply(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.search()
            // row.statusCode = '10'
            // row.status = '下达'
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },
    cancelApply(row) {
      this.$confirm(`确定删除这个申请`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        cancelProjectToolApply(row).then(({data}) => {
          if (data && data.code === 0) {
            this.search();
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },
    //刷新派设备文档的列表
    getFileContentData() {
      let currentData = {orderRef2: this.currentRow.applyNo};
      getFileContentList(currentData).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code == 200) {
          this.fileContentList = data.rows;
        } else {
          this.fileContentList = [];
        }
      });
    },
    // 下载
    downloadFile(row) {
      // let inData={
      //   site:this.currentRow.site,
      //   username:this.$store.state.user.name,
      //   projectId:this.currentRow.projectId
      // }
      // getProjectUserRole(inData).then(({data}) => {
      //   if(this.$store.state.user.name=='admin'||data.row.downFlag=='Y') {
      downLoadProjectFile(row)
        .then(({data}) => {
          // 不限制文件下载类型
          const blob = new Blob([data], {type: 'application/octet-stream;charset=utf-8'})
          // 下载文件名称
          const fileName = row.fileName
          // a标签下载
          const linkNode = document.createElement('a')
          linkNode.download = fileName // a标签的download属性规定下载文件的名称
          linkNode.style.display = 'none'
          linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
          console.log(linkNode)
          // if(val == 'Y'){
          //   this.pdfVisible = true
          //   this.pdfUrl = linkNode.href
          // }else {
          document.body.appendChild(linkNode)
          linkNode.click() // 模拟在按钮上的一次鼠标单击
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
          // }
        })
      //   }else {
      //     this.$alert('没有权限下载这个项目的文件！', '错误', {
      //       confirmButtonText: '确定'
      //     })
      //   }
      // })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      if ( this.isFilterSearch === false){
        this.search()
      } else {
        this.queryByAnyField(this.filterSearchData)
      }
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      if ( this.isFilterSearch === false){
        this.search()
      } else {
        this.queryByAnyField(this.filterSearchData)
      }
    },
    openModelMessage() {

      this.modelData = {
        site: this.currentRow.site,
        applyNo: this.currentRow.applyNo,
        prNo: this.currentRow.prNo,
        remark1: this.currentRow.remark1,
        poNo: this.currentRow.poNo,
        supplierName: this.currentRow.supplierName,
        allCost: this.currentRow.allCost,
        remark2: this.currentRow.remark2,
      }

    },

    openMassageModel() {
      if (Object.keys(this.currentRow).length === 0) {
        this.$alert('未选择记录！', '错误', {
          confirmButtonText: '确定'
        })
        return false;
      }
      this.modelData = {
        site: this.currentRow.site,
        applyNo: this.currentRow.applyNo,
        prNo: this.currentRow.prNo,
        remark1: this.currentRow.remark1,
        poNo: this.currentRow.poNo,
        supplierName: this.currentRow.supplierName,
        allCost: this.currentRow.allCost,
        remark2: this.currentRow.remark2,
      }
      this.modelFlag = true
    },
    changeSum(row) {
      if (row.standardCost < 0 || row.standardCost == null || row.standardCost == '') {
        row.standardCost = 0
        // this.$alert('成本不能为负数或者不填', '错误', {
        //   confirmButtonText: '确定'
        // })
      }
      this.dataForm.applySumQty = 0
      this.dataForm.totalCost = 0
      for (const item of this.toolData) {
        // 累加之前先确保值存在，并将 null 或 undefined 转换为0
        this.dataForm.applySumQty += Number(item.applyQty != null && item.applyQty !== '' ? item.applyQty : 0);
        this.dataForm.totalCost += Number(item.applyQty != null && item.applyQty !== '' ? item.applyQty * item.standardCost : 0);
      }
    },
    saveHeaderMessage() {
      this.$confirm('确定是否保存', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        saveProjectHeaderMessage(this.modelData).then(({data}) => {
          if (data && data.code === 0) {
            this.modelFlag = false;
            this.currentRow.prNo = this.modelData.prNo
            this.currentRow.remark1 = this.modelData.remark1
            this.currentRow.poNo = this.modelData.poNo
            this.currentRow.supplierName = this.modelData.supplierName
            this.currentRow.allCost = this.modelData.allCost
            this.currentRow.totalCost = this.modelData.totalCost
            this.currentRow.remark2 = this.modelData.remark2

            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },
    saveHeaderMessage2() {

      saveProjectHeaderMessage(this.modelData).then(({data}) => {
        if (data && data.code === 0) {
          this.modelFlag = false;
          this.currentRow.prNo = this.modelData.prNo
          this.currentRow.remark1 = this.modelData.remark1
          this.currentRow.poNo = this.modelData.poNo
          this.currentRow.supplierName = this.modelData.supplierName
          this.currentRow.allCost = this.modelData.allCost
          this.currentRow.totalCost = this.modelData.totalCost
          this.currentRow.remark2 = this.modelData.remark2

          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
            }
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })

    },
    // 同意提交
    agreeSubmit() {
      this.$confirm(`是否确认提交?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.dataForm.nodeConclusion = 'Y'
        this.submitData()
      })
    },

    // 打开提交模态框
    submitDataModal() {
      this.rejectOpinion = ''
      this.submitModalFlag = true
    },

    // 驳回提交
    rejectSubmit() {
      this.$confirm(`是否确认驳回?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.dataForm.rejectOpinion = this.rejectOpinion
        this.dataForm.nodeConclusion = 'N'
        this.submitData()
      })
    },

    // 提交
    submitData() {
      this.dataForm.userName = this.$store.state.user.name
      this.dataForm.menuId = this.$route.meta.menuId
      this.dataForm.detailList = this.toolData
      submitChange(this.dataForm).then(({data}) => {
        if (data && data.code === 0) {
          this.saveHeaderMessage2()
          for (let i = 0; i < this.dataList1.length; i++) {
            if (this.dataList1[i].applyNo === this.dataForm.applyNo) {
              this.dataList1[i].remark = this.dataForm.remark
              this.dataList1[i].applySumQty = this.dataForm.applySumQty
              this.dataList1[i].applyReason = this.dataForm.applyReason
            }
          }
          this.search();
          this.refreshCurrentTabTable()
          this.submitModalFlag = false
          this.visible = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
            }
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    saveData() {
      this.dataForm.detailList = this.toolData
      editToolApplication(this.dataForm).then(({data}) => {
        if (data && data.code === 0) {
          this.saveHeaderMessage2()
          for (let i = 0; i < this.dataList1.length; i++) {
            if (this.dataList1[i].applyNo === this.dataForm.applyNo) {
              this.dataList1[i].remark = this.dataForm.remark
              this.dataList1[i].applySumQty = this.dataForm.applySumQty
              this.dataList1[i].applyReason = this.dataForm.applyReason
              this.dataList1[i].quoter = this.dataForm.quoter
              this.dataList1[i].tp = this.dataForm.tp
              this.dataList1[i].totalCost = this.dataForm.totalCost
              this.dataList1[i].purchaser = this.dataForm.purchaser
              this.dataList1[i].quoterName = this.dataForm.quoterName
              this.dataList1[i].tpName = this.dataForm.tpName
              this.dataList1[i].purchaserName = this.dataForm.purchaserName
            }
          }
          this.visible = false
          this.visibleU = false
          this.refreshCurrentTabTable()
          // this.$message({
          //   message: '操作成功',
          //   type: 'success',
          //   duration: 1500,
          //   onClose: () => {
          //   }
          // })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },
    jumpBM(row) {
      if (this.$router.resolve(`/sampleManagement-technicalSpecificationList`).resolved.name === '404') {
        this.$alert('权限不足,访问失败', '警告', {confirmButtonText: '确定',});
      } else {
        let inData = {
          site: row.site,
          testPartNo: row.orderRef2
        }
        getProjectPartNowBm(inData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code === 0) {
            if (data.rows == null || data.rows.length === 0) {
              this.$alert('该物料没有benchmark', '警告', {confirmButtonText: '确定',});
            }
            this.$router.push({
              name: `sampleManagement-technicalSpecificationList`,
              params: {nowCodeNo: data.rows[0].nowBm},
            })
          } else {

          }
        });
      }
    },
    // 获取流程的配置权限
    async getNodeAuthority(row) {
      let tempData = {
        site: row.site,
        stepId: row.stepId,
        menuId: this.$route.meta.menuId
      }
      await getNodeAuthority(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.plmChangeApplyHeaderArr = data.rows.plm_project_tool_applyHeader;
          this.plmChangeApplyDetailArr = data.rows.plm_project_tool_applyDetail;
          // this.plmChangeRequestArr = data.rows.plm_change_request
          // this.plmChangeRequestDetailArr = data.rows.plm_change_request_detail
          // this.plmChangeCostImpactArr = data.rows.plm_change_cost_impact
          // this.plmChangeFAItemArr = data.rows.plm_change_FA_item
          // this.plmChangeExecutionInfoArr = data.rows.plm_change_execution_info
          // this.plmChangeItemArr = data.rows.plm_change_item
          // this.plmChangeCountersignatureItemArr = data.rows.plm_change_countersignature_item
        }
      })
    },
    fieldColumn() {
      if (!this.accessField('10601001')) {
        this.columnList2 = this.columnList2.filter(item => item.columnProp !== 'standardCost');
        this.columnList1 = this.columnList1.filter(item => item.columnProp !== 'totalCost');
      }

    },

    queryByAnyField(params){
      params.no = this.pageIndex
      params.size = this.pageSize
      params.site = this.$store.state.user.site
      params.userId = this.$store.state.user.id.toString()
      this.dataListLoading = true;
      searchProjectToolApplyHeaderByAnyField(params).then(({data})=>{
        if (data && data.code === 0){
          this.dataList1 = data.page.list
          this.totalPage = data.page.totalCount
        }else {
          this.$message.warning(data.msg)
        }
        this.dataListLoading = false;
      }).catch((error)=>{
        this.$message.error(error)
        this.dataListLoading = false;
      })
      this.filterSearchData = params
      this.isFilterSearch = true
      this.filterVisible = false
    },
  },

  activated() {
    if (this.$route.params.type === 'tokenLogin') {
      console.log("进来啦")
      if (this.$route.params.docNo) {
        this.searchData.applyNo = this.$route.params.docNo
      }
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex

      searchProjectToolApplyHeader(this.searchData).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList1 = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          if (this.dataList1.length > 0) {
            this.$refs.mainTable.setCurrentRow(this.dataList1[0]);
            this.currentRow = JSON.parse(JSON.stringify(this.dataList1[0]));
            //进入审批界面
            this.editModal(this.dataList1[0])
          } else {
            this.currentRow = {}
          }
          this.refreshCurrentTabTable()
        }
        this.dataListLoading = false
      })
    }

    if (localStorage.getItem('ToolApplyData') != null && localStorage.getItem('ToolApplyData') !== undefined) {
      let data = JSON.parse(localStorage.getItem('ToolApplyData'));
      if (data) {
        this.searchData.applyNo = data.applyNo
      }
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      // console.log(this.searchData)
      searchProjectToolApplyHeader(this.searchData).then(({data}) => {
        if (data.code == 0) {
          this.dataList1 = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          if (this.dataList1.length > 0) {
            this.$refs.mainTable.setCurrentRow(this.dataList1[0]);
            this.currentRow = JSON.parse(JSON.stringify(this.dataList1[0]));
            //进入编辑界面
            // this.editModalU(this.dataList1[0])
          } else {
            this.currentRow = {}
          }
          this.refreshCurrentTabTable()
        }
        this.dataListLoading = false
      })
      localStorage.removeItem('ToolApplyData');
    }
  },
}
</script>

<style scoped lang="scss">
/deep/ .el-dialog__footer {
  height: 50px !important;
}
/deep/ .customer-tab .el-tabs__content {
  padding: 5px !important;
}
</style>
