liding
2025-04-02 82f959cbd727e94a2273b73402a04d35f06d008a
可靠性计划产品
已修改3个文件
254 ■■■■ 文件已修改
src/api/business/reliabilityPlan.js 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/business/reliabilityPlan/index.vue 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/business/reliabilityPlan/plan.vue 164 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/business/reliabilityPlan.js
@@ -49,3 +49,48 @@
    params: query,
  });
}
//查询产品计划
export function selectProductItem(query) {
  return request({
    url: "/reliabilityPlanProductItem/selectProductItem",
    method: "get",
    params: query,
  });
}
//获取产品检验项
export function itemList(query) {
  return request({
    url: "/reliabilityPlanProductItem/itemList",
    method: "get",
    params: query,
  });
}
//获取产品检验项
export function codeList(query) {
  return request({
    url: "/reliabilityPlanProductItem/codeList",
    method: "get",
    params: query,
  });
}
//更新插入产品计划
export function addOrUpdateItem(query) {
  return request({
    url: "/reliabilityPlanProductItem/addOrUpdateItem",
    method: "post",
    data: query,
  });
}
//删除
export function deleteItem(query) {
  return request({
    url: "/reliabilityPlanProductItem/deleteItem",
    method: "delete",
    params: query,
  });
}
src/views/business/reliabilityPlan/index.vue
@@ -79,7 +79,7 @@
      <div slot="footer" class="foot">
        <el-button v-if="operationType !== 'review'" @click="closeProDia">取 消</el-button>
        <el-button v-if="operationType !== 'review' && operationType !== 'submit'" type="primary"
          :loading="submitProLoading" @click="submitProForm">保
          :loading="submitProLoading" @click="submitProForm(0)">保
          存</el-button>
        <el-button v-if="operationType == 'submit'" type="primary" :loading="submitProLoading"
          @click="submitProForm(1)">提 交</el-button>
@@ -95,9 +95,10 @@
      <el-form :model="materialForm" ref="materialForm" :rules="materialRules" label-width="90px" size="small">
        <el-form-item label="原辅材名称" prop="materialName">
          <el-cascader v-model="materialForm.materialName" :options="itemParameterData.cascaderField.sample.tree"
            :props="{ value: 'name', label: 'name', checkStrictly: false, multiple: false }" :show-all-levels="false"
            clearable filterable placeholder="请选择原辅材名称" size="small" style="width: 100%;"
            :disabled="operationType === 'review' || operationType === 'submit'"></el-cascader>
            :props="{ value: 'name', label: 'name', checkStrictly: false, multiple: false, emitPath: false }"
            :show-all-levels="false" clearable filterable placeholder="请选择原辅材名称" size="small" style="width: 100%;"
            :disabled="operationType === 'review' || operationType === 'submit'">
          </el-cascader>
        </el-form-item>
        <el-form-item label="零件号" prop="partNo">
          <el-input v-model="materialForm.partNo" placeholder="请填写零件号"
@@ -115,7 +116,7 @@
        <el-button v-if="operationType !== 'review'" @click="closeMaterialRulesDia">取
          消</el-button>
        <el-button v-if="operationType !== 'review' && operationType !== 'submit'" type="primary"
          :loading="submitMatLoading" @click="submitMaterialRulesForm">保 存</el-button>
          :loading="submitMatLoading" @click="submitMaterialRulesForm(0)">保 存</el-button>
        <el-button v-if="operationType == 'submit'" type="primary" :loading="submitProLoading"
          @click="submitMaterialRulesForm(1)">提 交</el-button>
        <el-button v-if="operationType === 'review'" :loading="submitMatLoading"
@@ -448,9 +449,6 @@
    // 打开新增弹框
    openAddDia(type, row) {
      this.operationType = type
      this.getTypeOptions()
      this.getPartNoOptions()
      // this.getUserList()
      if (this.tabIndex === 0) {
        this.proPlanDia = true
        if (this.operationType === 'add') {
@@ -463,6 +461,12 @@
          }
        } else {
          this.proPlanForm = { ...row }
          // 编辑时获取选中节点的ID并加载相关数据
          const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, row.productName)
          if (selectedNode) {
            this.getTypeOptions(selectedNode.id)
            this.getPartNoOptions(selectedNode.id)
          }
        }
      } else {
        this.materialDia = true
@@ -482,18 +486,15 @@
    // 成品信息提交
    submitProForm(state) {
      this.submitProLoading = true
      if (this.operationType === 'add') {
        this.proPlanForm.state = ''
      } else {
        this.proPlanForm.state = state
      }
      // 获取选中节点的ID
      const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, this.proPlanForm.productName)
      if (selectedNode) {
        this.proPlanForm.productId = selectedNode.id
      const params = {
        ...this.proPlanForm,
        state: state === undefined ? null : parseInt(state),
        productId: selectedNode?.id
      }
      addOrUpdateProduct(this.proPlanForm).then(res => {
      addOrUpdateProduct(params).then(res => {
        if (res.code === 200) {
          this.closeProDia()
          this.$message.success('操作成功')
@@ -513,12 +514,14 @@
    // 原辅材信息提交
    submitMaterialRulesForm(state) {
      this.submitMatLoading = true
      if (this.operationType === 'add') {
        this.materialForm.state = ''
      } else {
        this.materialForm.state = state
      // 获取选中节点的ID
      const selectedNode = this.findNodeById(this.itemParameterData.cascaderField.sample.tree, this.materialForm.materialName)
      const params = {
        ...this.materialForm,
        state: state === undefined ? null : parseInt(state),
        materialId: selectedNode?.id
      }
      addOrUpdateMaterial(this.materialForm).then(res => {
      addOrUpdateMaterial(params).then(res => {
        if (res.code === 200) {
          this.closeMaterialRulesDia()
          this.$message.success('操作成功')
src/views/business/reliabilityPlan/plan.vue
@@ -10,32 +10,35 @@
      </div>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="date" label="检测项" width="180">
      </el-table-column>
      <el-table-column prop="name" label="测试标准" width="180">
      <el-table-column prop="inspectionItem" label="检测项" width="180">
        <template slot-scope="scope">
          <el-select v-model="scope.row.name" placeholder="请选择" v-if="isEdit" size="small">
            <el-option v-for="item in standardList" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
          <span v-else>{{ scope.row.name }}</span>
          <span>{{ scope.row.inspectionItem }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="频次">
      <el-table-column prop="standard" label="测试标准" width="180">
        <template slot-scope="scope">
          <el-select v-model="scope.row.name" placeholder="请选择" v-if="isEdit" size="small">
          <el-select v-model="scope.row.standard" placeholder="请选择" v-if="isEdit" size="small">
            <el-option v-for="item in codeList" :key="item.id" :label="item.label" :value="item.standard">
            </el-option>
          </el-select>
          <span v-else>{{ scope.row.standard }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="frequency" label="频次">
        <template slot-scope="scope">
          <el-select v-model="scope.row.frequency" placeholder="请选择" v-if="isEdit" size="small">
            <el-option v-for="item in dict.type.planned_frequency" :key="item.value" :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <span v-else>{{ scope.row.name }}</span>
          <dict-tag v-else :options="dict.type.planned_frequency" :value="scope.row.frequency" />
        </template>
      </el-table-column>
      <el-table-column prop="address" label="备注">
      <el-table-column prop="remark" label="备注">
        <template slot-scope="scope">
          <el-input size="small" placeholder="请输入" v-model="scope.row.address" v-if="isEdit">
          <el-input size="small" placeholder="请输入" v-model="scope.row.remark" v-if="isEdit">
          </el-input>
          <span v-else>{{ scope.row.address }}</span>
          <span v-else>{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100" v-if="planState == 0">
@@ -48,25 +51,26 @@
      <el-form :model="addForm" ref="addForm" :rules="addRules" label-position="right" label-width="120px">
        <el-form-item label="检验项" prop="name">
          <el-select v-model="addForm.name" placeholder="请选择" size="small" style="width: 100%;">
            <el-option v-for="item in itemList" :key="item.value" :label="item.label" :value="item.value">
            <el-option v-for="item in itemList" :key="item.id" :label="item.inspectionItem"
              :value="item.inspectionItem">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="测试标准" prop="number">
          <el-select v-model="addForm.name" placeholder="请选择" size="small" style="width: 100%;">
            <el-option v-for="item in standardList" :key="item.value" :label="item.label" :value="item.value">
        <el-form-item label="测试标准" prop="standard">
          <el-select v-model="addForm.standard" placeholder="请选择" size="small" style="width: 100%;">
            <el-option v-for="item in codeList" :key="item.id" :label="item.label" :value="item.standard">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="频次" prop="number">
          <el-select v-model="addForm.name" placeholder="请选择" size="small" style="width: 100%;">
        <el-form-item label="频次" prop="frequency">
          <el-select v-model="addForm.frequency" placeholder="请选择" size="small" style="width: 100%;">
            <el-option v-for="item in dict.type.planned_frequency" :key="item.value" :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="number">
          <el-input size="small" placeholder="请输入" v-model="addForm.address">
        <el-form-item label="备注" prop="remark">
          <el-input size="small" placeholder="请输入" v-model="addForm.remark">
          </el-input>
        </el-form-item>
      </el-form>
@@ -79,15 +83,15 @@
</template>
<script>
import { selectProductItem, itemList, codeList, addOrUpdateItem, deleteItem } from "@/api/business/reliabilityPlan";
export default {
  dicts: ["planned_frequency"],
  data() {
    return {
      tableData: [
        {}
      ],
      tableData: [],
      codeList: [],//标准列表
      isEdit: false,
      standardList: [],//标准列表
      saveLoading: false,
      addForm: {},
      addRules: {
@@ -104,15 +108,94 @@
    const { id, type, state } = this.$route.query
    this.planId = id;
    this.planType = type;
    this.planState = state
    this.planState = state;
    this.getTableData();
    this.getItemList();
    this.getCodeList();
  },
  methods: {
    getTableData() {
      selectProductItem({ rePlanId: this.planId }).then(res => {
        if (res.code === 200) {
          this.tableData = res.data || [];
        }
      }).catch(err => {
        console.error('获取数据失败:', err);
      });
    },
    // 获取检验项列表
    getItemList() {
      itemList({ rePlanId: this.planId }).then(res => {
        if (res.code === 200) {
          this.itemList = res.data.map(item => ({
            label: item.inspectionItem,  // 修改为 inspectionItem
            value: item.id,
            inspectionItem: item.inspectionItem  // 添加 inspectionItem 字段
          })) || [];
        }
      }).catch(err => {
        console.error('获取检验项列表失败:', err);
      });
    },
    // 获取测试标准列表
    getCodeList() {
      codeList({ rePlanId: this.planId }).then(res => {
        if (res.code === 200) {
          this.codeList = res.data.map(item => ({
            label: item.standard,
            value: item.id,
            standard: item.standard
          })) || [];
        }
      }).catch(err => {
        console.error('获取测试标准列表失败:', err);
      });
    },
    // 删除
    handleDelete(row) { },
    handleDelete(row) {
      this.$modal.confirm('是否确认删除该检验项?').then(() => {
        deleteItem({ id: row.id }).then(res => {
          if (res.code === 200) {
            this.$message.success('删除成功');
            this.getTableData();
          }
        }).catch(err => {
          console.error('删除失败:', err);
        });
      }).catch(() => { });
    },
    // 保存
    save() {
      this.saveLoading = true;
      this.isEdit = false
      const promises = this.tableData.map(item => {
        const params = {
          id: item.id,
          rePlanId: this.planId,
          inspectionItem: item.inspectionItem,
          standard: item.standard,
          frequency: item.frequency,
          remark: item.remark
        };
        return addOrUpdateItem(params);
      });
      Promise.all(promises)
        .then(responses => {
          if (responses.every(res => res.code === 200)) {
            this.$message.success('保存成功');
            this.isEdit = false;
            this.getTableData();
          }
        })
        .catch(err => {
          console.error('保存失败:', err);
          this.$message.error('保存失败');
        })
        .finally(() => {
          this.saveLoading = false;
        });
    },
    goback() {
      this.$tab.closePage();
@@ -121,7 +204,28 @@
      this.addForm = {}
      this.addDia = true;
    },
    submitProduct() { }
    submitProduct(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const params = {
            rePlanId: this.planId,
            inspectionItem: this.addForm.name,
            standard: this.addForm.standard,
            frequency: this.addForm.frequency,
            remark: this.addForm.remark
          }
          addOrUpdateItem(params).then(res => {
            if (res.code === 200) {
              this.$message.success('保存成功');
              this.addDia = false;
              this.getTableData();
            }
          }).catch(err => {
            console.error('保存失败:', err);
          });
        }
      });
    }
  }
}
</script>