<template>
  <div class="app-container">
    <!-- 查询表单 start-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="委托单号" prop="supplier">
        <el-input
          v-model="queryParams.wtNumber"
          placeholder="请输入委托单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="批号" prop="lotNumber">
        <el-input
          v-model="queryParams.lotNumber"
          placeholder="请输入批号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格" prop="specification">
        <el-input
          v-model="queryParams.specification"
          placeholder="请输入规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="厂家" prop="manufacturer">
        <el-input
          v-model="queryParams.manufacturer"
          placeholder="请输入厂家"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 查询表单 end-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleUpFileOpen"
          v-hasPermi="['lims:ypjc:jcgc:scfj']"
        >附件上传</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格start -->
    <selsetHeader style="margin-top: 20px" :tLength="9" :options="tableHeadData.slice(1, tableHeadData.length -1 )" @change="cascaderChangeFun"></selsetHeader>
    <el-table v-loading="loading"  style="margin-top:20px" ref="tableTree" :data="detectionResultList" @selection-change="handleSelectionChange">
      <el-table-column :prop="tableHeadData[0].value"  :label="tableHeadData[0].label" align="center" width="180"></el-table-column>
      <el-table-column v-for="(item, index) in optionsData" :key="index" :prop="item.value" :label="item.label" align="center">
        <template  v-slot="scope"  v-if="item.label=='审核状态'">
          <dict-tag  :options="dict.type.shzt" :value="parseInt(scope.row.dataApprovalStatus)"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-dropdown @command="(command)=>{handleCommand(command, scope.row)}">
            <el-button type="warning">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
<!--              <el-dropdown-item  icon="el-icon-edit"  command="handleUpdate">修改</el-dropdown-item>-->
<!--              <el-dropdown-item  icon="el-icon-delete" command="handleDelete">删除</el-dropdown-item>-->
              <el-dropdown-item  icon="el-icon-edit" v-hasPermi="['lims:ypjc:jcgc:ckfj']"    command="catbg">报告预览</el-dropdown-item>
              <el-dropdown-item  icon="el-icon-edit" v-hasPermi="['lims:ypjc:jcgc:ckfj']"  v-if="scope.row.dataApprovalStatus==1||scope.row.dataApprovalStatus==0"  command="bgsh">报告审核</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格end -->

    <!-- 分页器start -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 分页器end -->

    <!-- 添加或修改性能检测结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="序号" prop="serialNumber">
          <el-input v-model="form.serialNumber" placeholder="请输入序号" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="批号" prop="lotNumber">
          <el-input v-model="form.lotNumber" placeholder="请输入批号" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="合金状态" prop="alloyState">
          <el-input v-model="form.alloyState" placeholder="请输入合金状态" />
        </el-form-item>
        <el-form-item label="厂家" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入厂家" />
        </el-form-item>
        <el-form-item label="抗拉值Mpa" prop="tensileValueMpa">
          <el-input v-model="form.tensileValueMpa" placeholder="请输入抗拉值Mpa" />
        </el-form-item>
        <el-form-item label="延伸率%" prop="rateOfElongation">
          <el-input v-model="form.rateOfElongation" placeholder="请输入延伸率%" />
        </el-form-item>
        <el-form-item label="断裂力变形mm" prop="fractureDeformation">
          <el-input v-model="form.fractureDeformation" placeholder="请输入断裂力变形mm" />
        </el-form-item>
        <el-form-item label="最大力" prop="maximumForce">
          <el-input v-model="form.maximumForce" placeholder="请输入最大力" />
        </el-form-item>
        <el-form-item label="抗拉强度(平均值)" prop="tensileStrengthAvg">
          <el-input v-model="form.tensileStrengthAvg" placeholder="请输入抗拉强度(平均值)" />
        </el-form-item>
        <el-form-item label="断裂力变形率(平均值)" prop="fractureForceRateAvg">
          <el-input v-model="form.fractureForceRateAvg" placeholder="请输入断裂力变形率(平均值)" />
        </el-form-item>
        <el-form-item label="复测" prop="repeatSurvey">
          <el-input v-model="form.repeatSurvey" placeholder="请输入复测" />
        </el-form-item>
        <el-form-item label="制作方向" prop="productionDirection">
          <el-input v-model="form.productionDirection" placeholder="请输入制作方向" />
        </el-form-item>
        <el-form-item label="抗拉值Mpa" prop="tensileValueMpaTwo">
          <el-input v-model="form.tensileValueMpaTwo" placeholder="请输入抗拉值Mpa" />
        </el-form-item>
        <el-form-item label="延伸率&" prop="rateOfElongationTwo">
          <el-input v-model="form.rateOfElongationTwo" placeholder="请输入延伸率&" />
        </el-form-item>
        <el-form-item label="标准" prop="standard">
          <el-input v-model="form.standard" placeholder="请输入标准" />
        </el-form-item>
        <el-form-item label="判定结果" prop="decisionResult">
          <el-input v-model="form.decisionResult" placeholder="请输入判定结果" />
        </el-form-item>
        <el-form-item label="LSL1" prop="lslOne">
          <el-input v-model="form.lslOne" placeholder="请输入LSL1" />
        </el-form-item>
        <el-form-item label="USL" prop="usl">
          <el-input v-model="form.usl" placeholder="请输入USL" />
        </el-form-item>
        <el-form-item label="LSL2" prop="lsl2">
          <el-input v-model="form.lsl2" placeholder="请输入LSL2" />
        </el-form-item>
        <el-form-item label="检测员" prop="inspector">
          <el-input v-model="form.inspector" placeholder="请输入检测员" />
        </el-form-item>
        <el-form-item label="性能创建时间" prop="performanceCreationTime">
          <el-input v-model="form.performanceCreationTime" placeholder="请输入性能创建时间" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="创建者id" prop="createById">
          <el-input v-model="form.createById" placeholder="请输入创建者id" />
        </el-form-item>
        <el-form-item label="更新者id" prop="updateById">
          <el-input v-model="form.updateById" placeholder="请输入更新者id" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="流程编号" prop="processKey">
          <el-input v-model="form.processKey" placeholder="请输入流程编号" />
        </el-form-item>
        <el-form-item label="任务编码" prop="taskProcessKey">
          <el-input v-model="form.taskProcessKey" placeholder="请输入任务编码" />
        </el-form-item>
        <el-form-item label="任务节点编码" prop="taskNodeKey">
          <el-input v-model="form.taskNodeKey" placeholder="请输入任务节点编码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 文件上传 -->
    <el-dialog title="附件上传"   v-if="upFileOpen" :visible.sync="upFileOpen" width="800px" append-to-body>
      <uploadFileCustom :upload="upload"></uploadFileCustom>
    </el-dialog>

    <!--文件预览-->
    <fileView visible.sync="fjzs" ref="fileView"></fileView>


    <!-- 审核弹窗 -->
    <el-dialog title="报告审核"  :visible.sync="sHOpen" width="500px" append-to-body>
      <el-form ref="shForm" :model="shForm" :rules="shrules" label-width="80px">
        <el-radio v-model="shForm.dataApprovalStatus" label="1">通过</el-radio>
        <el-radio v-model="shForm.dataApprovalStatus" label="2">作废</el-radio>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="shSubmitForm">确 定</el-button>
        <el-button @click="cancelSH">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetectionResult, getDetectionResult, delDetectionResult, addDetectionResult, updateDetectionResult } from "@/api/lims/materielInfo/detectionResult";
import selsetHeader from "@/views/amichi/materiel/components/selsetHeader.vue";
import {getToken} from "@/utils/auth";
// 引入
import fileView from '@/views/lims/components/fileView.vue'

import uploadFileCustom from "@/views/lims/components/CustomFileUploadComponent.vue"
// 引入VueOfficeDocx组件
import VueOfficeDocx from '@vue-office/docx';
import { Base64 } from 'js-base64';
// 引入相关样式
import '@vue-office/docx/lib/index.css';
export default {
  name: "DetectionResult",
  components: {selsetHeader,uploadFileCustom,fileView,VueOfficeDocx},
  dicts:["shzt"],
  data() {
    return {
      shForm:{
        dataApprovalStatus:"1"
      },
      shrules:{

      },
      sHOpen:false,
      fjzs:false,
      // 用户导入参数
      // upload: {
      //   // 是否显示弹出层（用户导入）
      //   open: false,
      //   // 弹出层标题（用户导入）
      //   title: "",
      //   // 是否禁用上传
      //   isUploading: false,
      //   // 是否更新已经存在的用户数据
      //   updateSupport: 0,
      //   // 设置上传的请求头部
      //   headers: {Authorization: "Bearer " + getToken()},
      //   // 上传的地址
      //   url: process.env.VUE_APP_BASE_API + "/system/user/importData",
      // },
      // 上传参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken()
        },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/laboratory/detectionResult/uploads",
        // 上传的文件列表
        fileList: [],
        upFilePath: [],
      },
      tableHeadData: [
        {label: '委托单号',value: 'wtNumber',},
        {label: '批号', value: 'lotNumber',},
        {label: '规格',value: 'specification',},
        {label: '合金状态',value: 'alloyState',},
        {label: '厂家', value: 'manufacturer',},
        {label: '判定结果',value: 'decisionResult',},
        {label: '审核状态',value: 'dataApprovalStatus',},
        {label: '审批人',value: 'taskNodeKey',},
        {label: '审批时间',value: 'taskProcessKey',},
        {label: '抗拉值Mpa',value: 'tensileValueMpa',},
        {label: '延伸率%',value: 'rateOfElongation',},
        {label: '断裂力变形mm',value: 'fractureDeformation',},
        {label: '最大力',value: 'maximumForce',},
        {label: '抗拉强度(平均值)',value: 'tensileStrengthAvg',},
        {label: '断裂力变形率(平均值)',value: 'fractureForceRateAvg',},
        {label: '复测',value: 'repeatSurvey',},
        {label: '产品类型',value: 'productType',},
        {label: '制作方向',value: 'productionDirection',},
        {label: '抗拉值Mpa', value: 'tensileValueMpaTwo',},
        {label: '延伸率&',value: 'rateOfElongationTwo',},
        {label: '标准',value: 'standard',},
        {label: 'LSL1',value: 'lslOne',},
        {label: 'USL',value: 'usl'},
        {label: 'LSL2',value: 'lsl2'},
        {label: '检测员',value: 'inspector',},
        {label: '性能创建时间',value: 'performanceCreationTime',},
        {label: '备注',value: 'remark',}
      ], //表头存储
      optionsData: [
        {label: '委托单号',value: 'wtNumber',},
        {label: '批号', value: 'lotNumber',},
        {label: '规格',value: 'specification',},
        {label: '合金状态',value: 'alloyState',},
        {label: '厂家', value: 'manufacturer',},
        {label: '判定结果',value: 'decisionResult',},
        {label: '审核状态',value: 'dataApprovalStatus',},
        {label: '审批人',value: 'taskNodeKey',},
        {label: '审批时间',value: 'taskProcessKey',},
      ],
      // 遮罩层
      loading: true,
      upFileOpen:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 性能检测结果表格数据
      detectionResultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNumber: null,
        date: null,
        lotNumber: null,
        specification: null,
        alloyState: null,
        manufacturer: null,
        tensileValueMpa: null,
        rateOfElongation: null,
        fractureDeformation: null,
        maximumForce: null,
        tensileStrengthAvg: null,
        fractureForceRateAvg: null,
        repeatSurvey: null,
        productType: null,
        productionDirection: null,
        tensileValueMpaTwo: null,
        rateOfElongationTwo: null,
        standard: null,
        decisionResult: null,
        lslOne: null,
        usl: null,
        lsl2: null,
        inspector: null,
        performanceCreationTime: null,
        createById: null,
        updateById: null,
        dataApprovalStatus: null,
        processKey: null,
        taskProcessKey: null,
        taskNodeKey: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      showType: '',
      docUrl: ''
    };
  },
  provide() {
    return {
      handleFileSuccess: this.handleFileSuccess,
      closeFileDialog: this.handleCloseFileDialog,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //下拉菜单点击事件
    handleCommand(command, row) {
      switch (command) {
        case "handleUpdate":
          this.handleUpdate(row)
          break;
        case "handleDelete":
          this.handleDelete(row)
          break;
        case "catbg":
          this.catbg(row)
          break;
        case "bgsh":
          this.bgsh(row);
          break;
        default:
          break;
      }
    },
    catbg(row){
      // console.log("查看报告") VUE_APP_BASE_IMG_API_MINIO
      //let path=process.env.VUE_APP_BASE_IMG_API+"/profile/upload/"
      let path=process.env.VUE_APP_BASE_IMG_API_MINIO+"/"
      let url=path+row.wtNumber+".rtf"
      // console.log(url)
      // // this.$router.push({
      // //   path: '/gygl/pdfdyl',
      // //   query: {
      // //     url:url,
      // //     name: row.wtNumber+row.lotNumber
      // //   },
      // // })
      //
      // // // 创建一个新的标签页
      // const newTab = window.open('', '_blank');
      // //
      // // 如果浏览器允许，在新标签页中嵌入iframe并打开PDF
      // if (newTab) {
      //   const iframeHTML = `<iframe src="${url}" width="100%" height="100%" style="border: none;"></iframe>`;
      //   newTab.document.write(iframeHTML);
      // }
      let aa='http://192.168.128.171:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(url));
      console.log(aa)
      window.open(aa,'_blank');
      //创建一个新的标签页
      // const newTab = window.open('', '_blank');
      // //如果浏览器允许，在新标签页中嵌入iframe并打开PDF
      // console.log("0",newTab)
      // if (newTab) {
      //   console.log("1")
      //
      // }else {
      //   console.log("2")
      //   window.open('http://192.168.128.171:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(url)));
      // }
    },
    previewPdf() {
// // 调用 （url就是文件的地址）
      this.$refs.fileView.open("http://192.168.110.83:8066/profile/2024/07/29/1_20240729181033A003.docx")
    },
    rendered(){
      console.log("6666")
    },
    // previewPdf(url) {
    //
    // },
    // openInNewTab(url) {
    //   window.open(url, '_blank', 'noopener,noreferrer');
    // },
    //关闭文件上传
    handleCloseFileDialog(){
      this.upFileOpen=false;
    },
    //打开文件上传
    handleUpFileOpen(){
      this.upFileOpen=true
      this.upload.fileList=[];
    },
    submitFileForm(){
    },
    importTemplate(){
      console.log("dddddd")
    },
    /**文件上传成功*/
    handleFileSuccess(response, file, fileList) {
      this.upload.isUploading = false;
      let obj={
        name:response.fileNames,
        url:response.urls,
        //后台返回文件大小kb
        size:response.size,
        percentage:100
      }
      this.upload.upFilePath.push(obj);
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // // 文件上传成功处理
    // handleFileSuccess(response, file, fileList) {
    //   this.upload.open = false;
    //   this.upload.isUploading = false;
    //   this.$refs.upload.clearFiles();
    //   this.$alert(
    //     "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
    //     response.msg +
    //     "</div>",
    //     "导入结果",
    //     {dangerouslyUseHTMLString: true}
    //   );
    //   this.getList();
    // },

    // 表头筛选
    cascaderChangeFun(e) {
      this.optionsData = e
      this.$nextTick(() => {
        this.$refs['tableTree'].doLayout();
      });
    },
    /** 查询性能检测结果列表 */
    getList() {
      this.loading = true;
      listDetectionResult(this.queryParams).then(response => {
        this.detectionResultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelSH() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serialNumber: null,
        date: null,
        lotNumber: null,
        specification: null,
        alloyState: null,
        manufacturer: null,
        tensileValueMpa: null,
        rateOfElongation: null,
        fractureDeformation: null,
        maximumForce: null,
        tensileStrengthAvg: null,
        fractureForceRateAvg: null,
        repeatSurvey: null,
        productType: null,
        productionDirection: null,
        tensileValueMpaTwo: null,
        rateOfElongationTwo: null,
        standard: null,
        decisionResult: null,
        lslOne: null,
        usl: null,
        lsl2: null,
        inspector: null,
        performanceCreationTime: null,
        remark: null,
        createById: null,
        createBy: null,
        createTime: null,
        updateById: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        dataApprovalStatus: null,
        processKey: null,
        taskProcessKey: null,
        taskNodeKey: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加性能检测结果";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetectionResult(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改性能检测结果";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetectionResult(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetectionResult(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    bgsh(row){
      this.shForm={
        "id":"",
        "dataApprovalStatus":""
      }
      const id = row.id || this.ids
      getDetectionResult(id).then(response => {
        this.shForm = response.data;
        if(this.shForm.dataApprovalStatus=="0"){
           this.shForm.dataApprovalStatus="1";
        }else if(this.shForm.dataApprovalStatus=="1"){
          this.shForm.dataApprovalStatus="2";
        }else if(this.shForm.dataApprovalStatus=="2"){
          this.shForm.dataApprovalStatus="1";
        }
        this.sHOpen = true;
        console.log(this.shForm)
      });

    },
    shSubmitForm(){
      updateDetectionResult(this.shForm).then(resp=>{
        if(resp.code==200){
          this.sHOpen = false;
          this.getList();
          this.$modal.msgSuccess("审批成功");
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除性能检测结果编号为"' + ids + '"的数据项？').then(function() {
        return delDetectionResult(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('laboratory/detectionResult/export', {
        ...this.queryParams
      }, `detectionResult_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
