广丰卷烟厂数采质量分析系统
zhuguifei
7 天以前 2b31fa203f3435a582be51f45899d99164c9917a
ruoyi-plus-soybean/src/views/qm/checkitem/modules/checkitem-operate-drawer.vue
@@ -1,11 +1,8 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { jsonClone } from '@sa/utils';
import {
  fetchCreateCheckitem,
  fetchGetRid,
  fetchUpdateCheckitem
} from '@/service/api/qm/checkitem';
import { fetchCreateCheckitem, fetchGetRid, fetchUpdateCheckitem } from '@/service/api/qm/checkitem';
import { fetchGetInstrumentList } from '@/service/api/md/instrument';
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';
@@ -76,6 +73,7 @@
const model = ref<Model>(createDefaultModel());
const ridOptions = ref<{ label: string; value: string | number }[]>([]);
const instrumentOptions = ref<{ label: string; value: string | number }[]>([]);
async function fetchRidOptions(searchText?: string) {
  const params: any = {};
@@ -98,35 +96,51 @@
  fetchRidOptions(query);
}
async function fetchInstrumentOptions(searchText?: string) {
  const params: any = {};
  if (searchText) {
    params.instrumentName = searchText;
  }
  const { data } = await fetchGetInstrumentList(params);
  if (data && data.rows) {
    instrumentOptions.value = data.rows.map(item => ({
      label: item.instrumentName,
      value: item.instrumentCode
    }));
  } else {
    instrumentOptions.value = [];
  }
}
function handleInstrumentSelectSearch(query: string) {
  fetchInstrumentOptions(query);
}
function createDefaultModel(): Model {
  return {
      id: '',
      itemCode: '',
      itemName: '',
      unit: '',
      enable: 1,
      del: 0,
      itemDes: '',
      stdCode: '',
      instrumentDes: '',
      location: '',
      checkLevel: '',
      ismix: null,
      rid: null,
      category: null,
      instrumentCode: '',
      score: null
    id: '',
    itemCode: '',
    itemName: '',
    unit: '',
    enable: 1,
    del: 0,
    itemDes: '',
    stdCode: '',
    instrumentDes: '',
    location: '',
    checkLevel: '',
    ismix: null,
    rid: null,
    category: null,
    instrumentCode: '',
    score: null
  };
}
type RuleKey = Extract<
  keyof Model,
  | 'id'
>;
type RuleKey = Extract<keyof Model, 'id'>;
const rules: Record<RuleKey, App.Global.FormRule> = {
  id: createRequiredRule('编码不能为空'),
  id: createRequiredRule('编码不能为空')
};
async function handleUpdateModelWhenEdit() {
@@ -139,6 +153,8 @@
  // Fetch options for rid
  await fetchRidOptions();
  // Fetch options for instrument
  await fetchInstrumentOptions();
  if (props.operateType === 'add' && props.stdCode) {
    model.value.stdCode = props.stdCode;
@@ -152,17 +168,67 @@
async function handleSubmit() {
  await validate();
  const { id, itemCode, itemName, unit, enable, del, itemDes, stdCode, instrumentDes, location, checkLevel, ismix, rid, category, instrumentCode, score } = model.value;
  const {
    id,
    itemCode,
    itemName,
    unit,
    enable,
    del,
    itemDes,
    stdCode,
    instrumentDes,
    location,
    checkLevel,
    ismix,
    rid,
    category,
    instrumentCode,
    score
  } = model.value;
  // request
  if (props.operateType === 'add') {
    const payload = { itemCode, itemName, unit, enable, del, itemDes, stdCode, instrumentDes, location, checkLevel, ismix, rid, category, instrumentCode, score };
    const payload = {
      itemCode,
      itemName,
      unit,
      enable,
      del,
      itemDes,
      stdCode,
      instrumentDes,
      location,
      checkLevel,
      ismix,
      rid,
      category,
      instrumentCode,
      score
    };
    const { error } = await fetchCreateCheckitem(payload);
    if (error) return;
  }
  if (props.operateType === 'edit') {
    const payload = { id, itemCode, itemName, unit, enable, del, itemDes, stdCode, instrumentDes, location, checkLevel, ismix, rid, category, instrumentCode, score };
    const payload = {
      id,
      itemCode,
      itemName,
      unit,
      enable,
      del,
      itemDes,
      stdCode,
      instrumentDes,
      location,
      checkLevel,
      ismix,
      rid,
      category,
      instrumentCode,
      score
    };
    const { error } = await fetchUpdateCheckitem(payload);
    if (error) return;
  }
@@ -202,7 +268,17 @@
        <NFormItem label="检验项描述" path="itemDes">
          <NInput v-model:value="model.itemDes" placeholder="请输入检验项描述" />
        </NFormItem>
        <NFormItem label="检测仪器" path="instrumentCode">
          <NSelect
            v-model:value="model.instrumentCode"
            :options="instrumentOptions"
            placeholder="请选择检测仪器"
            clearable
            filterable
            @search="handleInstrumentSelectSearch"
            @focus="() => fetchInstrumentOptions()"
          />
        </NFormItem>
        <NFormItem label="仪器描述" path="instrumentDes">
          <NInput v-model:value="model.instrumentDes" placeholder="请输入仪器描述" />
        </NFormItem>