1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<template>
  <div>
    <el-dialog
        v-model="dialogFormVisible"
        title="填写检验记录"
        width="70%"
        @close="closeDia"
    >
      <div v-if="!isViewMode" style="margin-bottom: 10px;text-align: right">
        <el-button type="danger" plain @click="handleDelete">删除</el-button>
      </div>
      <PIMTable
          rowKey="id"
          :column="tableColumn"
          :tableData="tableData"
          :tableLoading="tableLoading"
          :isSelection="true"
          :isShowPagination="false"
          @selection-change="handleSelectionChange"
          height="400"
      >
        <template #judgeTypeSlot="{ row }">
          <el-tag v-if="row.judgeType === '≥'" type="success">≥</el-tag>
          <el-tag v-else-if="row.judgeType === '≤'" type="warning">≤</el-tag>
          <el-tag v-else-if="row.judgeType === '范围'" type="info">范围</el-tag>
          <el-tag v-else>文字</el-tag>
        </template>
        <template #isRequiredSlot="{ row }">
          <el-tag v-if="row.isRequired === 1" type="danger">是</el-tag>
          <el-tag v-else type="info">否</el-tag>
        </template>
        <template #testValueSlot="{ row }">
          <el-input v-model="row.testValue" clearable :disabled="isViewMode" @input="handleTestValueChange(row)" />
        </template>
        <template #isQualifiedSlot="{ row }">
          <template v-if="row.judgeType !== '文字描述'">
            <el-tag v-if="row.isQualified === 1" type="success">合格</el-tag>
            <el-tag v-else-if="row.isQualified === 0" type="danger">不合格</el-tag>
            <span v-else>-</span>
          </template>
          <template v-else>
            <el-select v-model="row.isQualified" placeholder="请选择" size="small" :disabled="isViewMode" @change="handleTextResultChange(row)">
              <el-option :value="1" label="合格" />
              <el-option :value="0" label="不合格" />
            </el-select>
          </template>
        </template>
      </PIMTable>
 
      <div style="margin-top: 16px;">
        <el-form label-width="120px">
          <el-form-item label="自动判断结果">
            <template v-if="autoJudgeResult">
              <el-tag v-if="autoJudgeResult === '合格'" type="success" size="large">合格</el-tag>
              <el-tag v-else-if="autoJudgeResult === '部分合格'" type="warning" size="large">部分合格</el-tag>
              <el-tag v-else type="danger" size="large">不合格</el-tag>
              <span v-if="autoJudgeResult === '不合格'" style="margin-left: 10px; color: #909399;">
                (必要判断参数有不合格项,不可手动修改)
              </span>
              <span v-if="autoJudgeResult === '部分合格'" style="margin-left: 10px; color: #909399;">
                (必要判断参数均合格,非必要参数有不合格项,可手动选择最终结果)
              </span>
            </template>
            <template v-else>
              <el-tag type="info" size="large">需手动判断</el-tag>
              <span style="margin-left: 10px; color: #909399;">
                (所有参数均为文字描述类型,请手动选择)
              </span>
            </template>
          </el-form-item>
          <el-form-item label="最终判定">
            <el-radio-group v-model="checkResult" :disabled="isViewMode || autoJudgeResult === '不合格'">
              <el-radio label="合格">合格</el-radio>
              <el-radio label="不合格">不合格</el-radio>
              <el-radio label="部分合格">部分合格</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
 
      <template #footer>
        <div class="dialog-footer">
          <template v-if="!isViewMode">
            <el-button type="primary" @click="submitForm">确认</el-button>
            <el-button @click="closeDia">取消</el-button>
          </template>
          <el-button v-else @click="closeDia">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { ref, computed, getCurrentInstance } from "vue";
import {
  qualityInspectParamDel,
  qualityInspectParamInfo,
  qualityInspectParamUpdate
} from "@/api/qualityManagement/qualityInspectParam.js";
import { ElMessageBox } from "element-plus";
const { proxy } = getCurrentInstance()
const emit = defineEmits(['close'])
 
const dialogFormVisible = ref(false);
const operationType = ref('')
const currentId = ref('')
const selectedRows = ref([]);
const autoJudgeResult = ref(null)
const checkResult = ref('')
const isViewMode = computed(() => operationType.value === 'view')
 
const tableColumn = ref([
  { label: "指标", prop: "parameterItem" },
  { label: "单位", prop: "unit" },
  { label: "厂家标准值", prop: "standardValue" },
  { label: "下限值", prop: "minValue" },
  { label: "上限值", prop: "maxValue" },
  { label: "内控值", prop: "controlValue" },
  { label: "判断类型", prop: "judgeType", dataType: 'slot', slot: 'judgeTypeSlot' },
  { label: "必要判断", prop: "isRequired", dataType: 'slot', slot: 'isRequiredSlot' },
  { label: "检验值", prop: "testValue", dataType: 'slot', slot: 'testValueSlot' },
  { label: "是否合格", prop: "isQualified", dataType: 'slot', slot: 'isQualifiedSlot' },
]);
const tableData = ref([]);
const tableLoading = ref(false);
 
const openDialog = (type, row) => {
  operationType.value = type;
  dialogFormVisible.value = true;
  autoJudgeResult.value = null
  checkResult.value = ''
  if (operationType.value === 'edit' || operationType.value === 'view') {
    currentId.value = row.id;
    getList()
  }
}
const getList = () => {
  qualityInspectParamInfo(currentId.value).then(res => {
    tableData.value = res.data;
  })
}
const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};
 
const handleTestValueChange = (row) => {
  if (isViewMode.value) return;
  if (!row.testValue || !row.judgeType || row.judgeType === '文字描述') {
    return;
  }
  const testVal = parseFloat(row.testValue);
  if (isNaN(testVal)) return;
 
  let qualified = false;
  if (row.judgeType === '≥') {
    const stdVal = parseFloat(row.standardValue);
    if (isNaN(stdVal)) return;
    qualified = testVal >= stdVal;
  } else if (row.judgeType === '≤') {
    const stdVal = parseFloat(row.standardValue);
    if (isNaN(stdVal)) return;
    qualified = testVal <= stdVal;
  } else if (row.judgeType === '范围') {
    const minVal = parseFloat(row.minValue);
    const maxVal = parseFloat(row.maxValue);
    if (isNaN(minVal) || isNaN(maxVal)) return;
    qualified = testVal >= minVal && testVal <= maxVal;
  } else {
    return;
  }
  row.isQualified = qualified ? 1 : 0;
  performAutoJudgeAll();
};
 
const handleTextResultChange = () => {
  performAutoJudgeAll()
};
 
const performAutoJudgeAll = () => {
  if (!tableData.value.length) return;
  const allTextDesc = tableData.value.every(item => item.judgeType === '文字描述');
  if (allTextDesc) {
    autoJudgeResult.value = null;
    return;
  }
  const requiredParams = tableData.value.filter(item => item.isRequired === 1);
  if (requiredParams.length === 0) {
    autoJudgeResult.value = null;
    return;
  }
  const hasUnqualified = requiredParams.some(item => item.isQualified === 0);
  const allJudged = requiredParams.every(item => item.isQualified === 1 || item.isQualified === 0);
  if (!allJudged) {
    autoJudgeResult.value = null;
    return;
  }
  if (hasUnqualified) {
    autoJudgeResult.value = '不合格';
    checkResult.value = '不合格';
    return;
  }
  const nonRequiredUnqualified = tableData.value.filter(item => item.isRequired !== 1 && item.isQualified === 0);
  if (nonRequiredUnqualified.length > 0) {
    autoJudgeResult.value = '部分合格';
    checkResult.value = '部分合格';
  } else {
    autoJudgeResult.value = '合格';
    checkResult.value = '合格';
  }
};
 
const submitForm = () => {
  performAutoJudgeAll();
  qualityInspectParamUpdate(tableData.value).then(res => {
    proxy.$modal.msgSuccess("提交成功");
    closeDia();
  })
}
const closeDia = () => {
  dialogFormVisible.value = false;
  emit('close')
};
const handleDelete = () => {
  let ids = [];
  if (selectedRows.value.length > 0) {
    ids = selectedRows.value.map((item) => item.id);
  } else {
    proxy.$modal.msgWarning("请选择数据");
    return;
  }
  ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "导出", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
      .then(() => {
        qualityInspectParamDel(ids).then((res) => {
          proxy.$modal.msgSuccess("删除成功");
          getList();
        });
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
};
defineExpose({
  openDialog,
});
</script>
 
<style scoped>
 
</style>