<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.applyId" 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-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-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">
          <a type="text" size="small" v-if="scope.row.statusCode==='05'" @click="comfirmApply(scope.row)">下达</a>
          <a type="text" size="small" v-if="scope.row.statusCode==='05'" @click="cancelApply(scope.row)">取消申请</a>
        </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="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-->
<!--            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="down">
        <!--文件上传-->
        <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;">
          <el-form :inline="true" label-position="top" style="margin-top: 0px">
            <el-button type="primary" @click="addUploadFileModal()">上传文件</el-button>
          </el-form>
        </el-form>
        <el-table
          :data="fileContentList"
          height="240"
          border
          v-loading="dataListLoading"
          style="width: 100%; ">
          <el-table-column
            v-for="(item,index) in columnFileContentArray" :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="right"
            header-align="center"
            align="center"
            width="100"
            label="操作">
            <template slot-scope="scope">
              <!--              <a :href="'http://192.168.1.130:80/file/'+scope.row.url" :download="scope.row.fileName">下载</a>-->
              <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="approvalInformation">
        <approval-information ref="approvalTable" v-model:data-list="approvalList" :height="240"></approval-information>
      </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-model="currentRow.allCost" readonly></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-tabs>
    <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-model="modelData.allCost" type="number" ></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>
    <!-- 上传文件的modal   -->
    <projectUploadFile  ref="projectUploadFile" @refreshPageTables="getFileContentData()" v-drag></projectUploadFile>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </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,
  } from "@/api/tool/toolApply.js"
  import {
    deleteProjectFile,
    getFileContentList,
    downLoadProjectFile,
    getProjectUserRole,
  } from "@/api/project/project.js"
  import {
    getNodeAuthority, // 获取节点权限
    getApprovalList, // 查询审批信息
  } from '@/api/changeManagement/changeManagement.js'
  import ApprovalInformation from "../changeManagement/approvalInformation.vue";

  /*組件*/
  export default {
    components: {
      ApprovalInformation,

      Chooselist,
      projectUploadFile,

    },
    name: "null",
    data() {
      return {
        fileContentList: [],
        activeName: 'detail',
        searchData:{
          page: 1,
          limit: 100,
          site:this.$store.state.user.site,
          applyId:'',
          startDate:'',
          endDate:'',
        },
        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,
        // 导出 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: '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: '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: 70
          },
          {
            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: 60
          },
          {
            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: 60
          },
          {
            userId: this.$store.state.user.name,
            functionId: 106002,
            serialNumber: '106002Table2Remark',
            tableId: '106002Table2',
            tableName: '工具申请明细',
            columnProp: 'remark',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200
          },
          {
            userId: this.$store.state.user.name,
            functionId: 106002,
            serialNumber: '106002Table2QuotationNo',
            tableId: '106002Table2',
            tableName: '工具申请明细',
            columnProp: 'orderRef2',
            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: [],
      }
    },
    watch: {
      // columnList1: {
      //   deep: true,
      //   handler: function (newV, oldV) {
      //     debugger
      //
      //   }
      // }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = window.innerHeight - 520;
      })
    },
    methods: {
      // 查询审批信息
      getApprovalList () {
        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 === 1010) {
            if(type==1) {
              strVal = this.searchData.projectType
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1010) {
          if(this.tagNo2==1) {
            this.searchData.projectType = val.Base_desc
          }
        }
      },

      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        await searchToolApplyHeader(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
        })
      },
      //单击切换订单
      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()
        }

      },
      searchToolApplyDetail(){
        searchProjectToolApplyDetail(this.currentRow).then(({data}) => {
          if (data.code == 0) {
            this.detailList = data.rows
          }
        })
      },
      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) {
            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
        this.search()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.search()
      },

      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
      },
      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.remark2=this.modelData.remark2

              this.currentRow2.prNo=this.modelData.prNo
              this.currentRow2.remark1=this.modelData.remark1
              this.currentRow2.poNo=this.modelData.poNo
              this.currentRow2.supplierName=this.modelData.supplierName
              this.currentRow2.allCost=this.modelData.allCost
              this.currentRow2.remark2=this.modelData.remark2
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },

    },
    activated() {

    },
  }
</script>

<style >
  .el-transfer-panel {
    border: 2px solid #17b3a3;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    display: inline-block;
    vertical-align: middle;
    width: 200px;
    max-height: 100%;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    position: relative;
  }

  .el-transfer-panel .el-transfer-panel__header {
    height: 40px;
    line-height: 40px;
    background: #17b3a3;
    margin: 0;
    padding-left: 15px;
    border-bottom: 1px solid #17b3a3;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #000;
  }

  .el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label {
    font-size: 14px;
    color: #303133;
    font-weight: 400;
  }
</style>
