liding
11 小时以前 6f2e5c16bdefdf7129809ae303aa5e66b74cd2f7
src/views/CNAS/process/demand/index.vue
@@ -1,163 +1,858 @@
<style lang="scss" scoped>
.standard_method {
    padding: 20px;
}
.search {
  background-color: #fff;
  height: 80px;
  display: flex;
  align-items: center;
}
.search_thing {
//   width: 350px;
  display: flex;
  align-items: center;
}
.search_label {
  width: 110px;
  font-size: 14px;
  text-align: right;
}
.search_input {
  width: calc(100% - 110px);
}
.table {
  margin-top: 10px;
  background-color: #fff;
  width: calc(100% - 40px);
  height: calc(100% - 60px - 80px - 10px - 40px);
  padding: 20px;
}
</style>
<template>
    <div class="standard_method">
        <el-form :model="model" :inline="true" label-width="auto">
            <el-form-item label="试样名称:">
                <el-input size="small"
                    placeholder="请输入"
                    clearable
                    @change="refreshTable()"
                />
            </el-form-item>
            <el-form-item label="委托单位:">
                <el-input size="small"
                    placeholder="请输入"
                    clearable
                    @change="refreshTable()"
                />
            </el-form-item>
            <el-form-item label="生产单位:">
                <el-input size="small"
                    placeholder="请输入"
                    clearable
                    @change="refreshTable()"
                />
            </el-form-item>
            <el-form-item label="委托人:">
                <el-input size="small"
                    placeholder="请输入"
                    clearable
                    @change="refreshTable()"
                />
            </el-form-item>
            <el-form-item>
                <el-button size="small">
                    重 置
                </el-button>
                <el-button size="small" type="primary">
                    查 询
                </el-button>
            </el-form-item>
        </el-form>
        <div style="margin-bottom: 10px">
            <el-button size="small" type="primary" icon="el-icon-plus" @click="openDialog('add')">
                新 增
            </el-button>
        </div>
        <lims-table
            :column="column"
            :tableData="tableData"
            :height="'calc(100vh - 250px)'"
            :page="page"
        />
        <Edit ref="editRef" />
  <div class="app-container">
    <div style="display: flex;justify-content: space-between;">
      <el-form :model="entitySearch" ref="entitySearch" size="small" :inline="true">
        <el-form-item label="委托单号" prop="inspectionOrderCode">
          <el-input size="small" placeholder="请输入" clearable v-model="entitySearch.inspectionOrderCode"
            @keyup.enter.native="refreshTable"></el-input>
        </el-form-item>
        <el-form-item label="试样名称" prop="sampleName">
          <el-input size="small" placeholder="请输入" clearable v-model="entitySearch.sampleName"
            @keyup.enter.native="refreshTable"></el-input>
        </el-form-item>
        <el-form-item label="委托单位" prop="commissionUnit">
          <el-input v-model="entitySearch.commissionUnit" clearable placeholder="请输入" size="small"
            @keyup.enter.native="refreshTable()"></el-input>
        </el-form-item>
        <el-form-item label="生产单位" prop="production">
          <el-input v-model="entitySearch.production" clearable placeholder="请输入" size="small"
            @keyup.enter.native="refreshTable()"></el-input>
        </el-form-item>
        <el-form-item label="委托人" prop="commissionUser">
          <el-input v-model="entitySearch.commissionUser" clearable placeholder="请输入" size="small"
            @keyup.enter.native="refreshTable()"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="refreshTable">查询</el-button>
          <el-button size="mini" @click="refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div style="text-align: right; margin-bottom: 10px">
      <el-button size="small" type="primary" @click="goAdd">新增</el-button>
    </div>
    <div class="table">
      <el-table v-loading="tableListLoading" :data="tableList"
                height="630" border :header-cell-style="{ background: '#f8f8f9', color: '#515a6e' }">
        <el-table-column align="center" label="序号" type="index"></el-table-column>
        <el-table-column label="委托单号" prop="inspectionOrderCode" min-width="160" show-overflow-tooltip></el-table-column>
        <el-table-column label="试样名称" prop="sampleName" show-overflow-tooltip></el-table-column>
        <el-table-column label="委托编号" prop="entrustCode" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.entrustCode || '待生成' }}</template>
        </el-table-column>
        <el-table-column label="关联状态" min-width="90">
          <template slot-scope="scope">{{ scope.row.bindingStatus === 1 ? '已绑定' : '未绑定' }}</template>
        </el-table-column>
        <el-table-column label="下单状态" min-width="90">
          <template slot-scope="scope">{{ orderStateText(scope.row.orderState) }}</template>
        </el-table-column>
        <el-table-column label="检验进度" prop="insProgress" min-width="90">
          <template slot-scope="scope">{{ scope.row.insProgress || '--' }}</template>
        </el-table-column>
        <el-table-column label="检验结果" min-width="90">
          <template slot-scope="scope">{{ insResultText(scope.row.insResult) }}</template>
        </el-table-column>
        <el-table-column label="报告状态" min-width="90">
          <template slot-scope="scope">{{ reportStatusText(scope.row.reportStatus) }}</template>
        </el-table-column>
        <el-table-column label="委托时间" prop="commissionDate" show-overflow-tooltip></el-table-column>
        <el-table-column label="型号" prop="modelNo" show-overflow-tooltip></el-table-column>
        <el-table-column label="委托单位" prop="commissionUnit" show-overflow-tooltip></el-table-column>
        <el-table-column label="生产单位" prop="production" show-overflow-tooltip></el-table-column>
        <el-table-column label="委托人" prop="commissionUser"></el-table-column>
        <el-table-column label="样品数量" prop="quantity"></el-table-column>
        <el-table-column label="样品状态" prop="sampleStatus"></el-table-column>
        <el-table-column label="是否留样" prop="isLeave">
          <template slot-scope="scope">
            <span v-if="scope.row.isLeave === 1">是</span>
            <span v-if="scope.row.isLeave === 0">否</span>
          </template>
        </el-table-column>
        <el-table-column label="样品处理方式" prop="processing" width="150">
          <template slot-scope="scope">
            <span v-if="scope.row.processing === 1">实验室处理</span>
            <span v-if="scope.row.processing === 0">委托单位取回</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="320">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="goUpdate(scope.row)">编辑</el-button>
            <el-button size="mini" type="text" @click="handleLook(scope.row)">查看</el-button>
            <el-button size="mini" style="color:#F56C6C" type="text" @click="deleteOrder(scope.row)">删除</el-button>
            <el-button :disabled="!scope.row.fileUrl" size="mini" type="text" @click="openDownloadDia(scope.row)">下载</el-button>
            <el-button v-if="canChangeBinding(scope.row)" size="mini" type="text" @click="openChangeBinding(scope.row)">变更关联</el-button>
            <el-upload ref='upload' :action="action" :data="{ inspectionOrderId: scope.row.inspectionOrderId }"
              :headers="uploadHeader" :on-error="onError" :on-success="handleSuccessUp" :show-file-list="false"
              accept='image/jpg,image/jpeg,image/png,application/pdf,.doc,.docx,.xlsx' name="file"
              style="background: transparent;display: inline;margin-left: 4px">
              <span style="color: #409EFF">上传</span>
            </el-upload>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="1" :page-size="pages.size" :page-sizes="[10, 20, 30, 50, 100]" :total="total1"
        layout="->,total, sizes, prev, pager, next" style="margin-top: 10px" background @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1">
      </el-pagination>
    </div>
    <el-dialog :class="{ downPdf: title == '下载' }" :close-on-click-modal="false" :close-on-press-escape="false"
      :modal="title != '下载'" :title="title" :visible.sync="detailDialogVisible" top="20px" width="1200px">
      <div style="max-height: 75vh;overflow-y: auto;">
        <div id="dialogBody">
          <table border="1" cellpadding="10" class="tables heads" style="border: 1px dashed black;width: 100%">
            <tr>
              <td rowspan="2">
                <img alt="" src="@/assets/logo/ZTTlogo.png" style="width: 80%;">
              </td>
              <td>
                <p>记录名称:检验委托单</p>
              </td>
              <td>
                <p>保存期限:6年</p>
              </td>
            </tr>
            <tr>
              <td>
                <p>记录编号: ZTT/QR-16-04-a</p>
              </td>
              <td>
                <p>归档部门:质量部</p>
              </td>
            </tr>
          </table>
          <h4 style="display: flex;align-items: center;flex-direction: column;justify-content: center;">
            <span style="font-size: 28px;">检 验 委 托 单</span>
          </h4>
          <p style="margin-left: 560px;display: flex;align-items: center">
            <span style="width: 100px">委托单号:</span>
            <el-input v-model="currentInfo.inspectionOrderCode" disabled placeholder="保存后系统生成" size="small"></el-input>
          </p>
          <p style="margin-top: 16px;margin-left: 600px;">委托编号:{{
            currentInfo.entrustCode || '待生成' }}
          </p>
          <table border="1" cellpadding="10" class="tables" style="width: 100%">
            <tr>
              <td colspan="2">
                <p>试样名称</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.sampleName" clearable
                  size="small"></el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.sampleName }}</td>
              <td>
                <p>委托时间</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-date-picker v-model="currentInfo.commissionDate" clearable format="yyyy-MM-dd" placeholder="选择日期"
                  size="small" style="width: 100%" type="date" value-format="yyyy-MM-dd">
                </el-date-picker>
              </td>
              <td v-if="operationType === 'view'">{{ currentInfo.commissionDate }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>型 号</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.modelNo" clearable
                  size="small"></el-input>
              </td>
              <td v-if="operationType === 'view'">{{ currentInfo.modelNo }}</td>
              <td>
                <p>委托单位</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.commissionUnit" disabled
                  placeholder="请选择委托单位" size="small">
                  <template slot="append"><el-button icon="el-icon-search" @click="openCommissionUnitDialog"></el-button></template>
                </el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.commissionUnit }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>生产单位</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.production" clearable
                  size="small"></el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.production }}</td>
              <td>
                <p>委托人</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.commissionUser" disabled
                  placeholder="请选择委托人" size="small">
                  <template slot="append"><el-button icon="el-icon-search" @click="openCommissionUserDialog"></el-button></template>
                </el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.commissionUser }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>样品数量</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.quantity" clearable
                  size="small"></el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.quantity }}</td>
              <td>
                <p>样品状态</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.sampleStatus" clearable
                  size="small"></el-input></td>
              <td v-if="operationType === 'view'">{{
                insStateList.find(m => m.value == currentInfo.sampleStatus) ? insStateList.find(m => m.value == currentInfo.sampleStatus).label:'/'
                }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>是否留样</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-radio-group v-model="currentInfo.isLeave" v-removeAriaHidden>
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
              </td>
              <td v-if="operationType === 'view'">
                <span v-if="currentInfo.isLeave == 1">是</span>
                <span v-else>否</span>
              </td>
              <td>
                <p>样品处理方式</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-radio-group v-model="currentInfo.processing" v-removeAriaHidden>
                  <el-radio :label="0">委托单位取回</el-radio>
                  <el-radio :label="1">实验室处理</el-radio>
                </el-radio-group>
              </td>
              <td v-if="operationType === 'view'">
                <span v-if="currentInfo.processing == 0">委托单位取回</span>
                <span v-else>实验室处理</span>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <p>约定完成时间(报告日期)</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-date-picker v-model="currentInfo.appointed" clearable format="yyyy-MM-dd" placeholder="选择日期"
                  size="small" style="width: 100%" type="date" value-format="yyyy-MM-dd">
                </el-date-picker>
              </td>
              <td v-if="operationType === 'view'">{{ currentInfo.appointed }}</td>
              <td>
                <p>报告发送方式</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-radio-group v-model="currentInfo.send" v-removeAriaHidden>
                  <el-radio :label="1">自取</el-radio>
                  <el-radio :label="0">其他</el-radio>
                </el-radio-group>
              </td>
              <td v-if="operationType === 'view'">
                <span v-if="currentInfo.send == 1">自取</span>
                <span v-else>其他</span>
              </td>
            </tr>
            <el-button size="small" type="primary" @click="addOrderDetailList"
              v-if="operationType !== 'view'">添加</el-button>
            <tr>
              <td>
                <p>序号</p>
              </td>
              <td>
                <p>样品编号</p>
              </td>
              <td>
                <p>试验项目</p>
              </td>
              <td>
                <p>检验依据</p>
              </td>
              <td>
                <p>备注</p>
              </td>
            </tr>
            <tr v-for="(item, index) in currentInfo.orderDetailList" :key="index">
              <td>{{ index + 1 }}</td>
              <td v-if="operationType !== 'view'"><el-input v-model="item.sampleNumber" clearable
                  size="small"></el-input>
              </td>
              <td v-if="operationType === 'view'">{{ item.sampleNumber }}</td>
              <td v-if="operationType !== 'view'"><el-input v-model="item.testItem" clearable size="small"></el-input>
              </td>
              <td v-if="operationType === 'view'">{{ item.testItem }}</td>
              <td v-if="operationType !== 'view'"><el-input v-model="item.testStandard" clearable
                  size="small"></el-input>
              </td>
              <td v-if="operationType === 'view'">{{ item.testStandard }}</td>
              <td v-if="operationType !== 'view'"><el-input v-model="item.remark" clearable size="small"></el-input>
              </td>
              <td v-if="operationType === 'view'">{{ item.remark }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>判定规则</p>
              </td>
              <td v-if="operationType !== 'view'" colspan="3">
                <el-radio-group v-model="currentInfo.criterionRule" v-removeAriaHidden>
                  <el-radio :label="0">不考虑不确定度</el-radio>
                  <el-radio :label="1">考虑不确定度</el-radio>
                </el-radio-group>
                <span v-if="currentInfo.criterionRule === 1"><el-input v-model="currentInfo.criterionRuleRemark"
                    clearable size="small" style="width: 60px"></el-input>%</span>
              </td>
              <td v-if="operationType === 'view'" colspan="3">
                <span v-if="currentInfo.criterionRule === 0">不考虑不确定度</span>
                <span v-if="currentInfo.criterionRule === 1">考虑不确定度</span>
                <span v-if="currentInfo.criterionRule === 1">{{ currentInfo.criterionRuleRemark + '%' }}</span>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <p>委托人签名</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.commissionUser" clearable
                  size="small"></el-input></td>
              <td v-if="operationType === 'view'">
                {{ currentInfo.commissionUser }}
              </td>
              <td>
                <p>委托日期</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-date-picker v-model="currentInfo.commissionDate" clearable format="yyyy-MM-dd" placeholder="选择日期"
                  size="small" style="width: 100%" type="date" value-format="yyyy-MM-dd">
                </el-date-picker>
              </td>
              <td v-if="operationType === 'view'">{{ currentInfo.commissionDate }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>委托人联系电话</p>
              </td>
              <td v-if="operationType !== 'view'" colspan="3"><el-input v-model="currentInfo.commissionPhone" disabled
                  placeholder="选择委托人后自动带出" size="small"></el-input></td>
              <td v-if="operationType === 'view'" colspan="3">{{ currentInfo.commissionPhone }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>综合室签名</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.generalOfficeUser" clearable
                  size="small"></el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.generalOfficeUser }}</td>
              <td>
                <p>接收日期</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-date-picker v-model="currentInfo.receiptData" clearable format="yyyy-MM-dd" placeholder="选择日期"
                  size="small" style="width: 100%" type="date" value-format="yyyy-MM-dd">
                </el-date-picker>
              </td>
              <td v-if="operationType === 'view'">{{ currentInfo.receiptData }}</td>
            </tr>
            <tr>
              <td colspan="2">
                <p>领样员签名</p>
              </td>
              <td v-if="operationType !== 'view'"><el-input v-model="currentInfo.sampleTakerUser" disabled
                  placeholder="下单关联后自动记录当前登录人" size="small"></el-input></td>
              <td v-if="operationType === 'view'">{{ currentInfo.sampleTakerUser }}</td>
              <td>
                <p>领样日期</p>
              </td>
              <td v-if="operationType !== 'view'">
                <el-date-picker v-model="currentInfo.sampleData" clearable format="yyyy-MM-dd" placeholder="选择日期"
                  size="small" style="width: 100%" type="date" value-format="yyyy-MM-dd">
                </el-date-picker>
              </td>
              <td v-if="operationType === 'view'">{{ currentInfo.sampleData }}</td>
            </tr>
            <tr>
              <td colspan="2" rowspan="3">
                <p>检测机构信息</p>
              </td>
              <td colspan="3">
                <p>江苏中天科技股份有限公司(软电缆检测室)</p>
              </td>
            </tr>
            <tr>
              <td colspan="3">
                <p>地址:江苏省南通市如东县河口镇中天村五组168号</p>
              </td>
            </tr>
            <tr>
              <td colspan="3">
                <p>电话:0513-84882686</p>
              </td>
            </tr>
          </table>
          <p style="margin-top: 10px;margin-left: 20px;">注:本检验委托单一式二份,一份综合室归档,一份委托单位留存。</p>
        </div>
      </div>
      <span v-if="operationType !== 'view'" slot="footer" class="dialog-footer">
        <el-button @click="detailDialogVisible = false">取 消</el-button>
        <el-button v-if="operationType === 'add'" :loading="buttonLoading" type="primary" @click="handleAdd">确
          定</el-button>
        <el-button v-if="operationType === 'edit'" :loading="buttonLoading" type="primary" @click="handleEdit">确
          定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="downloadDialog" title="下载" width="600px">
      <span>
        <el-button :loading="outLoading" plain type="primary" @click="orderReportDown">下载委托单</el-button>
        <el-button :loading="outLoading" plain type="primary" @click="orderFormDown">下载委托报告</el-button>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="downloadDialog = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="changeBindingVisible" title="变更关联委托单" width="500px" append-to-body>
      <el-form ref="bindingForm" :model="bindingForm" :rules="bindingRules" label-width="100px">
        <el-form-item label="新的委托单" prop="inspectionOrderId">
          <el-select v-model="bindingForm.inspectionOrderId" filterable remote reserve-keyword
            :remote-method="searchUnboundInspectionOrders" :loading="bindingLoading" placeholder="请选择未绑定委托单"
            style="width: 100%" @focus="loadUnboundInspectionOrders">
            <el-option v-for="item in unboundInspectionOrders" :key="item.inspectionOrderId"
              :label="`${item.inspectionOrderCode} / ${item.sampleName || ''}`" :value="item.inspectionOrderId" />
          </el-select>
        </el-form-item>
        <el-form-item label="变更原因" prop="reason">
          <el-input v-model="bindingForm.reason" type="textarea" :rows="3" maxlength="200" show-word-limit />
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="changeBindingVisible = false">取 消</el-button>
        <el-button type="primary" :loading="bindingSubmitting" @click="submitChangeBinding">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="commissionUnitDialogVisible" title="选择委托单位" width="70%" append-to-body>
      <lims-table :tableData="commissionUnitList" :column="commissionUnitColumns" :isSelection="true"
        :handleSelectionChange="selectCommissionUnit" @pagination="changeCommissionUnitPage" :height="400"
        :page="commissionUnitPage" :tableLoading="commissionUnitLoading" />
      <span slot="footer"><el-button @click="commissionUnitDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmCommissionUnit">确 定</el-button></span>
    </el-dialog>
    <el-dialog :visible.sync="commissionUserDialogVisible" title="选择委托人" width="70%" append-to-body>
      <lims-table :tableData="commissionUserList" :column="commissionUserColumns" :isSelection="true"
        :handleSelectionChange="selectCommissionUser" :height="400" :page="{ total: commissionUserList.length, size: 100, current: 1 }" />
      <span slot="footer"><el-button @click="commissionUserDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmCommissionUser">确 定</el-button></span>
    </el-dialog>
  </div>
</template>
<script>
import {
  addInspectionOrder, delInspectionOrder, exportInspectionOrder,
  changeInspectionOrderBinding,
  getInspectionOrderOne,
  pageUnboundInspectionOrder,
  pageInspectionOrder,
  updateInspectionOrder
} from "@/api/cnas/process/demand/demand";
import limsTable from "@/components/Table/lims-table.vue";
import Edit from './Edit.vue'
import { getInspectionOrder } from "@/api/cnas/process/demand/demand.js"
import { selectUserCondition } from "@/api/business/inspectionTask";
import { selectCustomPageList } from "@/api/system/customer";
export default {
    name: 'Demand',
    components: {
        limsTable,
        Edit
    },
    data() {
        return {
            queryParams: {
                code: ''
            },
            model: {},
            column: [
                { label: '序号', minWidth: '100px' },
                { label: '试样名称', minWidth: '100px' },
                { label: '委托编号' },
                { label: '委托时间' },
                { label: '型号' },
                { label: '委托单位' },
                { label: '生产单位' },
                { label: '委托人' },
                { label: '样品数量' },
                { label: '样品状态' },
                { label: '是否留样' },
                { label: '样品处理方式' },
                {
                    dataType: "action",
                    fixed: "right",
                    label: "操作",
                    operation: [
                        {
                            name: "编 辑",
                            type: "text",
                            clickFun: (row) => {
                                this.$refs.editRef.openAddContracts(row)
                            }
                        }
                    ],
                },
            ],
            tableData: [], // 表格数据
            page: {
                total: 0,
                size: 10,
                current: 1,
            },
        }
    },
    mounted() {
        this.refreshTable()
    },
    methods: {
        /**
         * @desc 刷新表格
         */
        async refreshTable() {
            await getInspectionOrder({ ...this.page })
  name: "Demand",
  components: { limsTable },
  data() {
    return {
      title: '检验委托单',
      detailDialogVisible: false,
      addLoading: false,
      outLoading: false,
      currentInfo: {
        orderDetailList: []
      },
      personList: [],
      insStateList: [
        {
          label: '待审核',
          value: 0
        }, {
          label: '待检验',
          value: 1
        },
        /**
         * @desc 打开模态框
         */
        openDialog(type) {
            this.$refs.editRef.open(type)
        }
        {
          label: '已检验',
          value: 4
        },
        {
          label: '退回',
          value: 2
        },
        {
          label: '撤销',
          value: 3
        },
      ],
      operationType: '',
      tableList: [],
      tableListLoading: false,
      pages: {
        current: 1,
        size: 20,
      },
      total1: 0,
      entitySearch: {
        inspectionOrderCode: '',
        sampleName: '',
        commissionUnit: '',
        production: '',
        commissionUser: '',
      },
      buttonLoading: false,
      downloadDialog: false,
      download: {},
      changeBindingVisible: false,
      bindingLoading: false,
      bindingSubmitting: false,
      unboundInspectionOrders: [],
      bindingForm: {
        insOrderId: null,
        inspectionOrderId: null,
        reason: ''
      },
      bindingRules: {
        inspectionOrderId: [{ required: true, message: '请选择新的委托单', trigger: 'change' }],
        reason: [{ required: true, message: '请输入变更原因', trigger: 'blur' }]
      },
      commissionUnitDialogVisible: false,
      commissionUnitLoading: false,
      commissionUnitList: [],
      commissionUnitSelection: [],
      commissionUnitPage: { total: 0, size: 10, current: 1 },
      commissionUnitColumns: [
        { label: '客户名称', prop: 'company' },
        { label: '客户单位EN', prop: 'companyEn' },
        { label: '单位地址', prop: 'address' },
        { label: '单位电话', prop: 'phone' }
      ],
      commissionUserDialogVisible: false,
      commissionUserList: [],
      commissionUserSelection: [],
      commissionUserColumns: [
        { label: '姓名', prop: 'name' },
        { label: '账号', prop: 'account' },
        { label: '联系电话', prop: 'phone' }
      ],
    };
  },
  mounted() {
    this.getAuthorizedPerson()
    this.refreshTable()
  },
  computed: {
    action() {
      return this.javaApi + '/inspectionOrder/uploadInspectionOrderFile'
    }
  },
  methods: {
    openCommissionUnitDialog() {
      this.commissionUnitSelection = []
      this.commissionUnitDialogVisible = true
      this.loadCommissionUnitList()
    },
    loadCommissionUnitList() {
      this.commissionUnitLoading = true
      selectCustomPageList({ ...this.commissionUnitPage }).then(res => {
        this.commissionUnitList = res.data.records || []
        this.commissionUnitPage.total = res.data.total || 0
      }).finally(() => { this.commissionUnitLoading = false })
    },
    changeCommissionUnitPage({ page, limit }) {
      this.commissionUnitPage.current = page
      this.commissionUnitPage.size = limit
      this.loadCommissionUnitList()
    },
    selectCommissionUnit(rows) { this.commissionUnitSelection = rows },
    confirmCommissionUnit() {
      if (this.commissionUnitSelection.length !== 1) {
        this.$message.error('请选择一条委托单位')
        return
      }
      const custom = this.commissionUnitSelection[0]
      this.currentInfo.commissionUnitId = custom.id
      this.currentInfo.commissionUnit = custom.company
      this.commissionUnitDialogVisible = false
    },
    openCommissionUserDialog() {
      this.commissionUserSelection = []
      this.commissionUserDialogVisible = true
      selectUserCondition().then(res => { this.commissionUserList = res.data || [] })
    },
    selectCommissionUser(rows) { this.commissionUserSelection = rows },
    confirmCommissionUser() {
      if (this.commissionUserSelection.length !== 1) {
        this.$message.error('请选择一位委托人')
        return
      }
      const user = this.commissionUserSelection[0]
      this.currentInfo.commissionUserId = user.id
      this.currentInfo.commissionUser = user.name
      this.currentInfo.commissionPhone = user.phone || ''
      this.commissionUserDialogVisible = false
    },
    loadDefaultCommissionUnit() {
      selectCustomPageList({ current: 1, size: 10, company: '中天科技装备电缆有限公司' }).then(res => {
        const custom = (res.data.records || []).find(item => item.company === '中天科技装备电缆有限公司')
        if (custom) {
          this.currentInfo.commissionUnitId = custom.id
          this.currentInfo.commissionUnit = custom.company
        } else {
          this.$message.warning('未找到默认委托单位,请手动选择')
        }
      })
    },
    orderStateText(state) {
      const states = {
        0: '待审核',
        1: '检验中',
        2: '退回',
        3: '撤销',
        4: '已检验'
      }
      return state === null || state === undefined ? '未下单' : (states[state] || '--')
    },
    insResultText(result) {
      const results = {
        0: '不合格',
        1: '合格',
        3: '不判定'
      }
      return result === null || result === undefined ? '待检验' : (results[result] || '--')
    },
    reportStatusText(status) {
      const statuses = {
        0: '未生成',
        1: '待同步',
        2: '可下载'
      }
      return statuses[status] || '未生成'
    },
    canChangeBinding(row) {
      return row.insOrderId && (row.orderState === 0 || row.orderState === 2) && !row.entrustCode
    },
    openChangeBinding(row) {
      this.bindingForm = { insOrderId: row.insOrderId, inspectionOrderId: null, reason: '' }
      this.unboundInspectionOrders = []
      this.changeBindingVisible = true
      this.loadUnboundInspectionOrders()
      this.$nextTick(() => this.$refs.bindingForm && this.$refs.bindingForm.clearValidate())
    },
    loadUnboundInspectionOrders() {
      this.searchUnboundInspectionOrders('')
    },
    searchUnboundInspectionOrders(keyword) {
      this.bindingLoading = true
      pageUnboundInspectionOrder({ current: 1, size: 20, inspectionOrderCode: keyword }).then(res => {
        this.unboundInspectionOrders = res.data.records || []
      }).finally(() => {
        this.bindingLoading = false
      })
    },
    submitChangeBinding() {
      this.$refs.bindingForm.validate(valid => {
        if (!valid) return
        this.bindingSubmitting = true
        changeInspectionOrderBinding(this.bindingForm).then(() => {
          this.$message.success('关联已变更')
          this.changeBindingVisible = false
          this.refreshTable()
        }).finally(() => {
          this.bindingSubmitting = false
        })
      })
    },
    addOrderDetailList() {
      if (this.currentInfo.orderDetailList == null) {
        this.currentInfo.orderDetailList = []
      }
      this.currentInfo.orderDetailList.push({
        sampleNumber: '',
        testItem: '',
        testStandard: '',
        standardMethodList: '',
        remark: '',
      })
    },
    // 查询列表
    refreshTable() {
      this.tableListLoading = true
      pageInspectionOrder({
        ...this.pages,
        ...this.entitySearch
      }).then(res => {
        this.tableListLoading = false
        this.tableList = res.data.records
        this.total1 = res.data.total
      }).catch(err => {
        this.tableListLoading = false
      })
    },
    // 重置
    refresh() {
      this.entitySearch = {
        inspectionOrderCode: '',
        sampleName: '',
        commissionUnit: '',
        production: '',
        commissionUser: '',
      }
      this.pages = {
        current: 1,
        size: 20,
      }
      this.refreshTable()
    },
    // 打开新增弹框
    goAdd() {
      this.operationType = 'add'
      this.title = '新增检验委托单';
      this.currentInfo = {
        isLeave: 1,
        processing: 0,
        send: 1,
        criterionRule: 0,
        orderDetailList: []
      }
      this.detailDialogVisible = true
      this.loadDefaultCommissionUnit()
    },
    // 列表分页
    handleSizeChange1(val) {
      this.pages.size = val
      this.refreshTable();
    },
    handleCurrentChange1(val) {
      this.pages.current = val
      this.refreshTable();
    },
    // 提交新增
    handleAdd() {
      this.buttonLoading = true
      addInspectionOrder(this.currentInfo).then(res => {
        this.buttonLoading = false
        this.$message.success(`新增成功,委托单号:${res.data.inspectionOrderCode}`)
        this.detailDialogVisible = false
        this.refreshTable()
      }).catch(err => {
        this.buttonLoading = false
      })
    },
    // 提交修改
    handleEdit() {
      this.buttonLoading = true
      updateInspectionOrder(this.currentInfo).then(res => {
        this.buttonLoading = false
        this.$message.success('修改成功')
        this.detailDialogVisible = false
        this.refreshTable()
      }).catch(err => {
        this.buttonLoading = false
      })
    },
    // 打开编辑弹框
    goUpdate(row) {
      this.operationType = 'edit'
      getInspectionOrderOne({ inspectionOrderId: row.inspectionOrderId }).then(res => {
        this.currentInfo = res.data
        this.title = '编辑检验委托单';
        this.detailDialogVisible = true
      }).catch(err => {
        console.log('err----', err)
      })
    },
    // 查看
    handleLook(row) {
      this.operationType = 'view'
      getInspectionOrderOne({ inspectionOrderId: row.inspectionOrderId }).then(res => {
        this.currentInfo = res.data
        this.title = '查看检验委托单';
        this.detailDialogVisible = true
      }).catch(err => {
        console.log('err----', err)
      })
    },
    // 删除
    deleteOrder(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delInspectionOrder({ inspectionOrderId: row.inspectionOrderId }).then(res => {
          this.$message.success('删除成功!');
          this.refreshTable();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 打开下载弹框
    openDownloadDia(row) {
      this.downloadDialog = true
      this.download = row
    },
    // 委托单下载
    orderFormDown() {
      let url = this.download.fileUrl;
      const link = document.createElement('a');
      link.href = this.javaApi + url;
      link.target = '_blank';
      document.body.appendChild(link);
      link.click();
    },
    // 委托报告下载
    orderReportDown() {
      this.outLoading = true;
      exportInspectionOrder({ inspectionOrderId: this.download.inspectionOrderId }).then(res => {
        this.outLoading = false;
        const blob = new Blob([res], { type: 'application/octet-stream' });
        this.$download.saveAs(blob, '检验委托单.docx')
      }).catch(err => {
        this.outLoading = false;
      })
    },
    // 上传
    handleSuccessUp(response,) {
      if (response.code == 200) {
        this.$message.success('上传成功');
        this.refreshTable()
      }
    },
    beforeUpload(file) {
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        return false;
      } else {
        return true;
      }
    },
    onError(err, file, fileList) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
    // 人员列表
    getAuthorizedPerson() {
      selectUserCondition().then(res => {
        let data = []
        res.data.forEach(a => {
          data.push({
            label: a.name,
            value: a.id
          })
        })
        this.personList = data
      })
    },
  },
}
</script>
</script>
<style scoped></style>